Azzera filtri
Azzera filtri

How can I locate dicom images?

1 visualizzazione (ultimi 30 giorni)
Tomislav
Tomislav il 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.

Risposta accettata

Jan
Jan il 13 Nov 2012
Modificato: Jan il 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

Più risposte (0)

Categorie

Scopri di più su DICOM Format in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by