2017-04-18 4 views
0

matlabに新しく、CT肺DICOM画像をHounsfield Units(HU)に変換するコードを書こうとしています。私はすでにこれを行う関数を作成し、それをM-ファイルに保存しました。私はこの機能を一連のdicom画像にどのように適用することができますか(それぞれの患者のフォルダには約200の画像があり、複数のフォルダがあります)、または一般的な一連のdicom画像にどのように機能を適用するかを知りたいです。前もって感謝します! は、ここに機能だ:Matlabの一連のCTdicom画像に関数を適用するには?

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

どこ機能同じフォルダにこのコードを追加してください。今、あなたが同じフォルダから画像のhunderdsを取ることができ、このファイル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 

このファイルを保存するstart.m

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

end 

を保存します。

関連する問題