Dicomread images with different x and y sizes into a cellarray.

Hi. This may be easy for some Matlab users. I am trying to dicomread and process images starting my code with the following commands:
[Filename1,Pathname1]=uigetfile('Multiselect','on');
for i=1:length(Filename1)
images(:,:,i)=dicomread(fullfile(Pathname1,Filename1{i}));
images=double(images);
end
However, my images appear to change size therefore I get the error: 'Subscripted assignment dimension mismatch.'
Any ideas how I could dicomread and place in order all dicom images independently of their size, would be much appreciated.
Thank you

 Réponse acceptée

You've answered your question in its title. Use a cell array:
[Filename1,Pathname1]=uigetfile('Multiselect','on');
images = cell(size(Filename1));
for fileidx = 1:numel(Filename1)
images{fileidx} = double(dicomread(fullfile(Pathname1,Filename1{i})));
end

4 commentaires

GioPapas81
GioPapas81 le 18 Mai 2018
Modifié(e) : GioPapas81 le 18 Mai 2018
Thank you Guillaume. I get an error though:
Error using dicom_getFileDetails (line 14) File "Y:\..\IM-0070-0001.dcm" not found.
Error in dicomread>newDicomread (line 188) fileDetails = dicom_getFileDetails(filename);
Error in dicomread (line 86) [X, map, alpha, overlays] = newDicomread(msgname, frames, useVRHeuristic);
In fact, I am interested to ideally save if possible all images (independently of their size) in images(:,:,i) format. If that's not possible, I would be interested to at least save in images(:,:,i) format all images with size let's say 192 x 154.
Guillaume
Guillaume le 18 Mai 2018
Modifié(e) : Guillaume le 18 Mai 2018
I've not changed the way you read the files. It's a bit puzzling why the file would not be found since it's been selected with uigetfile but that's a completely different issue to your question.
Using a cell array, it will read all images. But the output is obviously not a 3D matrix. it is not clear to me whether your requirement to store the images as images(:, :, i), that is a 3D matrix, is one of lack of familiarity with matlab or truly a necessity. Why do you need the images as a 3D matrix? Isn't the cell array good for you?
If you do need a 3D matrix, then yes, you'll either have to drop the images that don't match your required size, or rescale them.
I'm not even sure that you NEED to have all the images in memory simultaneously. Why do you think you do? Usually it's not necessary. Just process each image one at a time in the loop and don't store them all.
GioPapas81
GioPapas81 le 18 Mai 2018
Modifié(e) : GioPapas81 le 18 Mai 2018
I re-sorted my files, tried again and it worked (I am not sure why I got this error in first place).
I think that I have mis-used the term 'cellarray', instead of using 3D matrix initially but your are right, I can replace the 3D matrix with a cellarray. I only need to incorporate changes in a relatively long code, but there is no free lunch in life.
Thank you again both.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Convert Image Type dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by