필터 지우기
필터 지우기

How to get 2d slices from a 3D image.

조회 수: 22 (최근 30일)
Shweta
Shweta 2014년 1월 13일
댓글: Walter Roberson 2021년 11월 27일
How to get 2D slices from a 3D image? The image is grayscale, it is a .mhd file and the dimensions of the Image matrix after loading into matlab are 179x200x159 single.
  댓글 수: 1
Mia Grahn
Mia Grahn 2021년 6월 20일
Were you able to find a method?

댓글을 달려면 로그인하십시오.

답변 (3개)

Chunru
Chunru 2021년 6월 20일
From 'doc slice':
[X,Y,Z] = meshgrid(-2:.2:2);
V = X.*exp(-X.^2-Y.^2-Z.^2); % replace this with your 3D data
xslice = [-1.2,0.8,2]; % slices along x
yslice = [];
zslice = 0; % slices along y
slice(X,Y,Z,V,xslice,yslice,zslice)
% if you don't hnow X, Y, you can use index value along x and y axes.

r r
r r 2021년 11월 21일
%https://www.mathworks.com/matlabcentral/answers/403570-how-to-make-a-3d-volume-out-of-a-2d-tiff-stack
%Rafael S.T. Vieira on 1 Jun 2020::How to make a 3D Volume out of a 2D Tiff stack?
fileFolder = '/Users/Desktop/Slice3D';
filePattern = fullfile(fileFolder, '*.jpg');
all_jpg = dir(filePattern);
first_image = imread(all_jpg(1).name);
[W,H] = size(first_image);
D = numel(all_jpg);
stack = zeros(W,H,D);
stack(:,:,1) = first_image;
for i = 1:D
stack(:,:,i) = imread(all_jpg(i).name);
% uncomment next line for seeing the reading progress
% disp(string(i*100.0/D) + "%");
end
% The app volumeViewer will handle the visualization
volumeViewer(stack);
  댓글 수: 1
Walter Roberson
Walter Roberson 2021년 11월 21일
I would suggest the for loop should be 2:D to avoid re-reading the first image.

댓글을 달려면 로그인하십시오.


r r
r r 2021년 11월 21일
편집: Walter Roberson 2021년 11월 27일
can you help me
What do you suggest to me , plaeas help me .
I have 30 images converted from 2D to 3D
I used in a methode
and using sliceViewer for convert images to save by *gif
s = sliceViewer(stack); %View the data in the slice viewer.
hAx = getAxesHandle(s); %Get the handle of the axes containing the displayed slice.
filename = 'Slice.gif';%Specify the name of the GIF file you want to create.
sliceNums = 1:24;
for idx = sliceNums
% Update slice number
s.SliceNumber = idx;
% Use getframe to capture image
I = getframe(hAx);
[indI,cm] = rgb2ind(I.cdata,256);
% Write frame to the GIF file
if idx == 1
imwrite(indI,cm,filename,'gif','Loopcount',inf,'DelayTime', 0.05);
else
imwrite(indI,cm,filename,'gif','WriteMode','append','DelayTime', 0.05);
end
end
Now I want to insert it in 3D to compare it with another 3D model in Matlab? I find it difficult
  댓글 수: 1
Walter Roberson
Walter Roberson 2021년 11월 27일
%gif animations are pseudocolored, not RGB.
[slices, cmap] = imread(filename, 'index', 'all');
rgbslices = zeros(size(slices,1), size(slices,2), 3, size(slices,4), 'like', slices);
for K = 1 : size(slices,4)
rgbslices(:,:,:,K) = ind2rgb(slices(:,:,:,K), cmap);
end
Now rgbslices will be rows x columns x 3 x slices .
I would suggest to you that there are easier ways to do this then to use sliceViewer() and write to a file and read back from the file.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by