MATLAB Answers

0

How do I convert the four dimension arrays to 3 dimension variable ?

Asked by andhavarapu lokesh on 2 Dec 2016
Latest activity Commented on by andhavarapu lokesh on 2 Dec 2016
Accepted Answer by KSSV
I read a dicom image which has 128 rows and 128 columns, a depth of 1, and each dicom has 72 frames. Like this 72 images
X(128,128,1,72);
Now I need to convert this four-dimensional variable to a 3 dimensional variable for doing volume rendering using isosurface. How do I reduce this dimension by using reshape or squeeze? Can any one help me?
projectdir = 'E:\SHIVA BACKUP\THYROID\P1\newcodes\data1\13002';
% y = length(projectdir);
y=72;
X = zeros(128, 128, 1, 72,'uint8');
p=1;
% Read the series of images.
thisfile = sprintf('IM_%d.dcm', p);
filename = fullfile( projectdir, thisfile );
imdata = dicomread(filename);
imsize = size(imdata);
if ~isequal( imsize, [128 128 1 72] )
fprintf('file is unexpected size %s instead of [128 128 1 72], skipping "%s"\n', mat2str(imsize), filename);
else
X(:, :, :, :) = imdata;
end
v=zeros(128,128,1,1);
v(128,128,1,1)=reshape(X,size);
isoval=-1.5;
y=72;
fig = figure();
ax = axes('Parent', fig);
hiso = patch( isosurface( v, isoval), ...
'Parent',ax,'FaceAlpha', 0.74, ...
'FaceColor',[0.1,0.75,0.65],'EdgeColor','none');
lighting(ax, 'phong');
lightangle(ax, 45, 30);
rotate3d(ax, 'on');
title( sprintf('p = %d', p) )

  0 Comments

Sign in to comment.

2 Answers

Answer by KSSV
on 2 Dec 2016
Edited by KSSV
on 2 Dec 2016
 Accepted Answer

X = rand(128,128,1,72);
[m,n,p,q] = size(X) ;
Y = reshape(X,m,n,q) ;

  3 Comments

but i wanted to display the image like this
Image not attached..look at imshow(Y(:,:,i)) where i = 1.....q

Sign in to comment.


Answer by Image Analyst
on 2 Dec 2016

Why not just do
X = squeeze(imdata);

  0 Comments

Sign in to comment.