在 Matlab 中对 dicom 图像进行排序

Sorting dicom images in Matlab

我在 matlab 中处理肺部数据集,但我需要正确排序切片并显示它们。

我知道可以使用 Dicom header 中的 "instance number" 参数来完成,但我没能 运行 正确的代码。

我该怎么做?

这是我的一段代码:

Dicom_directory = uigetdir();
sdir = strcat(Dicom_directory,'\*.dcm');
files = dir(sdir);
I = strcat(Dicom_directory, '\',files(i).name);
x = repmat(double(0), [512 512 1 ]);
x(:,:,1) = double(dicomread(I));
axes(handles.axes1);
imshow(x,[]);

首先,要获得 DICOM header,您需要使用 dicominfo,它将 return 包含每个字段的 struct。如果你想使用InstanceNumber字段来排序,那么你可以这样做。

%// Get all of the files
directory = uigetdir();
files = dir(fullfile(directory, '*.dcm'));
filenames = cellfun(@(x)fullfile(directory, x), {files.name}, 'uni', 0);

%// Ensure that they are actually DICOM files and remove the ones that aren't
notdicom = ~cellfun(@isdicom, filenames);
files(notdicom) = [];

%// Now load all the DICOM headers into an array of structs
infos = cellfun(@dicominfo, filenames);

%// Now sort these by the instance number
[~, inds] = sort([infos.InstanceNumber]);
infos = infos(inds);

%// Now you can loop through and display them
dcm = dicomread(infos(1));
him = imshow(dcm, []);

for k = 1:numel(infos)
    set(him, 'CData', dicomread(infos(k)));
    pause(0.1)
end

也就是说,您必须小心使用 InstanceNumber 对 DICOM 进行排序。这不是一种可靠的方法,因为 "InstanceNumber" 可以指随时间获取的同一图像或整个 3D 体积的不同切片。如果你想要一个或另一个,我会选择更具体的东西。

如果要对物理切片进行排序,我建议按 SliceLocation 字段(如果可用)进行排序。如果按时间排序,您可以使用 TriggerTime(如果可用)。

此外,您还需要考虑到您的文件夹中可能还有多个 系列 ,因此可以考虑使用 SeriesNumber 来区分它们。