在Matlab中对dicom图像进行排序

时间:2016-04-19 21:28:48

标签: matlab sorting dicom

我正在使用matlab中的肺部数据集,但是我需要正确地对切片进行排序并显示它们。

我知道可以使用Dicom标头中的“实例编号”参数来完成,但我没有设法运行正确的代码。

我该怎么做?

这是我的代码:

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,[]);

1 个答案:

答案 0 :(得分:2)

首先,要获取DICOM标头,您需要使用dicominfo,它将返回包含每个字段的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区分这些