Error in im2 (line 39) imshow(ImgSg);

ImgAx = siz_img;
if verLessThan('matlab', '8')
ImgSg = flipdim(permute(siz_img, [3 1 2 4]),1); % Sagittal view image
ImgCr = flipdim(permute(siz_img, [3 2 1 4]),1); % Coronal view image
else
ImgSg = flip(permute(siz_img, [3 1 2 4]),1); % Sagittal view image
ImgCr = flip(permute(siz_img, [3 2 1 4]),1); % Coronal view image
end
figure
imshow(ImgSg);
figure
imshow(ImgCr);
Why is this error?

4 comentarios

Geoff Hayes
Geoff Hayes el 5 de Dic. de 2017
Stelios - what is the full error message? What are the dimensions and data type of ImgSg? What is siz_img? Please provide more details so that we can help you determine what to do next.
Stelios Fanourakis
Stelios Fanourakis el 5 de Dic. de 2017
Editada: Geoff Hayes el 5 de Dic. de 2017
clc;
clear all;
close all;
N=25;
img_dir ='D:\Stelios PhD files'
strfile = 'Z01';
img = dicomread(fullfile(img_dir, strfile));
siz_img = size(img);
% create result matrix:
ct3d = NaN([siz_img N]);
ct3d(:,:,1) = img;
% load all the remaining images and put them in the matrix
for i=2:N
strfile = sprintf('Z01',i);
ct3d(:,:,i)= dicomread(fullfile(img_dir, strfile));
end
ImgAx = siz_img;
if verLessThan('matlab', '8')
ImgSg = flipdim(permute(siz_img, [3 1 2 4]),1); % Sagittal view image
ImgCr = flipdim(permute(siz_img, [3 2 1 4]),1); % Coronal view image
else
ImgSg = flip(permute(siz_img, [3 1 2 4]),1); % Sagittal view image
ImgCr = flip(permute(siz_img, [3 2 1 4]),1); % Coronal view image
end
figure
imshow(ImgSg);
figure
imshow(ImgCr);
The whole code. Need to depict dicom pics on different planes based upon transverse plane images
Geoff Hayes
Geoff Hayes el 5 de Dic. de 2017
Stelios - having the full code does not necessarily help as it is the dicom images that may be needed to solve this problem.... Without them, I still won't be able to determine the dimensions or data type of siz_img...
Stelios Fanourakis
Stelios Fanourakis el 6 de Dic. de 2017
they are foot slices 255x255, int16 slices. 25 images in total

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 5 de Dic. de 2017

0 votos

siz_img is a row vector of dimensions of image Z01 . The assignment ct3d(:,:,1) = img would not work if img was more than 2D, so siz_img is a row vector of length 2. When you permute(siz_img, [3 1 2 4]) then the second dimension would move to the third dimension, so the output would be 1 x 1 x length(siz_img) = 1 x 1 x 2. You then try to imshow() that 1 x 1 x 2, which fails because imshow() can only handle arrays that are either 2D or 3D with the third dimension being length 3.
It would probably make more sense to be permuting the ct3d instead. However, when you do so, unless the original image just happened to be 3 pixels wide, you are going to encounter the same problem with imshow()
The only built-in MATLAB function for displaying volumes is the R2017a and later volumeViewer()

Categorías

Más información sobre Convert Image Type en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 5 de Dic. de 2017

Comentada:

el 6 de Dic. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by