【问题标题】:How to apply a function to a series of CT dicom images in Matlab?如何将函数应用于 Matlab 中的一系列 CT dicom 图像?
【发布时间】:2017-04-22 17:22:13
【问题描述】:

我是 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

【问题讨论】:

    标签: matlab image-processing dicom


    【解决方案1】:

    请将此代码添加到您的函数所在的同一文件夹中。保存这个文件 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
    

    现在您可以从同一个文件夹中获取数百张图片。

    【讨论】:

      猜你喜欢
      • 2019-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-30
      • 2011-01-19
      相关资源
      最近更新 更多