How can I locate dicom images?

2 次查看(过去 30 天)
So now I have:
[filename, pathname] = uigetfile();
set(handles.edit5, 'String', pathname);
img = zeros(165,127,168,'uint8');
for ii = 1:168;
img(:,:,ii) = dicomread([pathname '\' num2str(ii,'%04i') '.dcm']);
end;
And it only works if there are exactly 168 images (165x127 pixels) in the folder and if they are numbered as: 0001, 0002, 0003, and so on. And it stores it as a 3D matrix name img.
How can I make code that it works with any number of dicom images of any size and any name and that it stores them as now, in 3D matrix called img.
Thanks.

采纳的回答

Jan
Jan 2012-11-13
编辑:Jan 2012-11-13
[filename, pathname] = uigetfile();
if ~ischar(filename)
return;
end
set(handles.edit5, 'String', pathname);
fileList = dir(fullfile(pathname, '*.dcm'));
fileList = fileList(not([fileList.isdir]));
nFile = numel(fileList);
imgC = cell(1, nFile);
for ii = 1:nFile;
imgC{ii} = dicomread(fullfile(pathname, fileList(ii).name));
end
Of course you can store pictures in a 3D-array only, if they all have the same size. If this is true:
imgSize = size(imgC{1});
if all(cellfun('size', imgC, 1) == imgSize(1)) && ...
all(cellfun('size', imgC, 2) == imgSize(2))
img = cat(3, imgC{:});
else
error('Pictures have different sizes.');
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 DICOM Format 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by