How to open and work with dicom images, which has no .dcm file extension.

18 visualizzazioni (ultimi 30 giorni)
Errorusing dicom images. Unable to perform assignment because the size of the left side is 564-by-800 and the size of the right side is 564-by-800-by-1-by-56. This is the code.
img_folder = uigetdir;
dirOutput = dir(img_folder);
dirOutput([dirOutput.isdir]) = [];
filenames = fullfile(img_folder, {dirOutput.name});
file_num = length(filenames);
X = repmat(int16(0), [564 800 1 file_num]);
for y = 1:file_num
X(:,:,1,y) = uint16(dicomread(filenames{y}));
end
My images are ultrasound images with 564X800 diemesion. Any help is appreciated.

Risposta accettata

DGM
DGM il 7 Apr 2021
Modificato: DGM il 9 Apr 2021
I don't really know what this has to do with filename extensions, though I would imagine that the right way to handle that would be to rename the files instead of writing a script that will explode because it's designed to avoid the most rudimentary filetype discrimination.
% there's nothing stopping this from breaking
% the moment it finds something that's not a dicom file
img_folder = uigetdir;
dirOutput = dir(img_folder);
dirOutput([dirOutput.isdir]) = [];
filenames = fullfile(img_folder, {dirOutput.name});
file_num = length(filenames);
% avoid hard-coding properties like geometry into scripts
info=dicominfo(filenames{1});
% why were you creating an int16 array and then putting uint16 data in it?
% pick a class and use zeros().
X = zeros([info.Height info.Width info.SamplesPerPixel file_num],'uint16');
for y = 1:file_num
% add some basic error messaging so the user knows why it exploded
thisinfo=dicominfo(filenames{y});
if thisinfo.Height~=info.Height || thisinfo.Width~=info.Width
error('%s does not have the expected height or width',filenames{y})
elseif thisinfo.SamplesPerPixel~=info.SamplesPerPixel
error('%s does not have the expected number of channels',filenames{y})
elseif isfield(thisinfo,'NumberOfFrames') && thisinfo.NumberOfFrames>1
error('%s is a multiframe image',filenames{y})
end
% casting the image with uint16() does not rescale the data to fit the range.
% im2uint16 does, which makes the images viewable with imshow.
% use whichever suits your needs
X(:,:,:,y) = im2uint16(dicomread(filenames{y}));
end
Like Walter said, you can use a cell array if you want to potentially handle mismatched file sizes. If you really want to concatenate them all into a multiframe image array, you might want to read them into a cell array first, and then build the multiframe image from that. If the page size matches, you should just be able to do it with cell2mat. If you don't want to do it that way, you'll probably have to check all your file sizes before you start trying to read them, otherwise you won't know how big to make the output array.
  8 Commenti
MINO GEORGE
MINO GEORGE il 12 Apr 2021
Can anyone help me to apply image filters to these images. When i tried with median filter, errors are showing. Any help is appreciated
Walter Roberson
Walter Roberson il 12 Apr 2021
medfilt1 accepts multidimensional arrays and accepts a dimension number, but the dimension number must be scalar.
medfilt2 is 2d only and medfilt3 is 3d only. You are working with either 4d or 5d (depending on how you resolved the fact that you are using image sequences.)
Which dimensions do you want to filter over?

Accedi per commentare.

Più risposte (1)

Walter Roberson
Walter Roberson il 7 Apr 2021
My images are ultrasound images with 564X800 diemesion
It appears that instead you have ultrasound sequences, the first of which has 56 time points. You cannot guarantee in general that they will have the same number of time points, so you should probably read the sequences into a cell array before deciding how to merge the information.

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