Unable to perform assignment

1 Ansicht (letzte 30 Tage)
Eisa Alyaqoub
Eisa Alyaqoub am 28 Feb. 2020
Kommentiert: Eisa Alyaqoub am 28 Feb. 2020
Hello Helpers,
I am not seeing the error that I have. Could any one please help.
close all;
clc;
% locate the file
my_path = uigetdir();
files = dir(fullfile(my_path, '*.dcm'));
f_names = {files.name};
info = dicominfo(fullfile(my_path, f_names{1}));
%% read all slices and write them to 3D matrix
ct_scans = zeros(512, 512, length(f_names)); % here where I got the error
for scan = 1:length(f_names)
slices = fullfile(my_path, f_names{scan});
ct_scans(:,:,scan) = uint16(dicomread(slices));
end
The eroor:
Unable to perform assignment because the size of the left side is 512-by-512 and the size of the right side is
917-by-888.
I tride to change the inizilation, but still get the same error
ct_scans = zeros(917, 888, length(f_names));
The error:
Unable to perform assignment because the size of the left side is 917-by-888 and the size of the right side is
512-by-512.
  1 Kommentar
Eisa Alyaqoub
Eisa Alyaqoub am 28 Feb. 2020
I figured out the issue.
The issue is that the first 3 files are 917x888, but the rest files that in the same folder that I am trying to read are 512x512.
Can any one suggest a solution for this problem ?
Thank you,

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 28 Feb. 2020
this_scan = uint16(dicomread(slices));
ct_scans(1:size(this_scan,1), 1:size(this_scan,2), scan) = this_scan;
This will put the 512 x 512 into the upper left corner, zero padded. If you happen to encounter a file that is larger than the original size, then the ct_scans array would be extended with zero padding.
Some people would instead imresize() to a consistent size. However, that can distort aspect ratios, and can blur edges.
It is questionable as to whether the smaller scans belong at the upper left of the larger scans. imresize() is not always the right answer either. Sometimes the right answer is to do image registration, to find regions of correspondance even though there might be rescaling or rotation or localized distoration.
  3 Kommentare
Walter Roberson
Walter Roberson am 28 Feb. 2020
Before the loop:
ctr = size(ct_scans,1);
ctc = size(ct_scans,2);
In the loop:
this_scan = uint16(dicomread(slices));
tr = size(this_scan,1);
tc = size(this_scan,2);
roff = floor((ctr - tr)/2);
coff = floor((ctc - tc)/2);
ct_scans(roff:roff+tr-1, coff:coff+tc-1, scan) = this_scan;
This would fail if one of the later images was larger than the original.
Eisa Alyaqoub
Eisa Alyaqoub am 28 Feb. 2020
Thank you so much.
I think your first solution works prefect sice I have many files, and each files contains soo many of images.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by