Effacer les filtres
Effacer les filtres

How can I locate dicom images?

2 vues (au cours des 30 derniers jours)
Tomislav
Tomislav le 13 Nov 2012
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.

Réponse acceptée

Jan
Jan le 13 Nov 2012
Modifié(e) : Jan le 13 Nov 2012
[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
  1 commentaire
Tomislav
Tomislav le 13 Nov 2012
Awesome. Thanks.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur DICOM Format dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by