我是matlab的新手,我正在尝试编写一个将CT肺DICOM图像转换为Hounsfield单位(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
答案 0 :(得分:0)
请将此代码添加到您的功能所在的文件夹中。保存此文件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
现在你可以从同一个文件夹中获取大量图像。