簡體   English   中英

如何在Matlab中將功能應用於一系列CT dicom圖像?

[英]How to apply a function to a series of CT dicom images in Matlab?

Matlab的新手,正在嘗試編寫將CT肺DICOM圖像轉換為Hounsfield Units(HU)的代碼。 我已經創建了一個函數來執行此操作,並將其保存在M文件中。 我想知道如何將該功能應用於一系列dicom圖像(每個患者文件夾包含大約200張圖像,並且有多個文件夾!),或者通常如何將功能應用於一系列dicom圖像。 提前致謝! 功能如下:

function [z,y] = med (i)
z = dicominfo(i);
x = dicomread(z);

if isa(x,'int16')
    y = x * z.RescaleSlope + z.RescaleIntercept;
else
    a = int16(x);
    y = a * z.RescaleSlope + z.RescaleIntercept;
end

請將此代碼添加到您的函數所在的文件夾中。 保存此文件start.m

 FD1=getAllFiles('Dataset\your_data_folder');
   for f=1:size(FD1)
   im=dicomread(FD1{f});
   [z,y] = med (f)  %your function

 end

保存此文件getAllFiles.m

function fileList = getAllFiles(dirName)

dirData = dir(dirName);      %# Get the data for the current directory
dirIndex = [dirData.isdir];  %# Find the index for directories
fileList = {dirData(~dirIndex).name}';  %'# Get a list of the files
if ~isempty(fileList)
fileList = cellfun(@(x) fullfile(dirName,x),...  %# Prepend path to files
fileList,'UniformOutput',false);

end

subDirs = {dirData(dirIndex).name};  %# Get a list of the subdirectories
validIndex = ~ismember(subDirs,{'.','..'});  %# Find index of     subdirectories
                                    %#   that are not '.' or '..'
for iDir = find(validIndex)        %# Loop over valid subdirectories
nextDir = fullfile(dirName,subDirs{iDir});  %# Get the subdirectory path
fileList = [fileList; getAllFiles(nextDir)];%# Recursively call getAllFiles
end

end

現在,您可以從同一文件夾中拍攝大量圖像。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM