Plotting 2D image with different slices in Multiple Figures by means of Loop

5 次查看(过去 30 天)
For example I have a 3D image matrix but I want to plot it for some specific slices like following :
For 5 slices I want to draw 5 figures which will contain the 2D image of the specific slices and Intensity Profile (subplotting) and it should be plot through a LooP. Any kinds of suggestion would be appreciated.
Thanks in Advance !
i = 1:5; % Slice Number
RowProfile = squeeze(image3d(rowNumber, :, SliceNumber_total(i)));
img = image3d(:,:,SliceNumber_total(i));

回答(1 个)

Siraj
Siraj 2023-9-15
Hi! It is my understanding that you want to create a subplot that displays multiple slices of a 3D image using a for loop.
To understand how to achieve the desired result, please refer to the following code:
% Create a 3D image with random pixel values ranging from 0 to 255
image3d = randi([0 255], 1024, 1024, 5);
% Iterate over each slice of the 3D image
for i = 1:5
% Extract the current slice
img = image3d(:,:,i);
% Create a subplot with 1 row and 5 columns, and select the i-th subplot
subplot(1, 5, i)
slice_no = int2str(i);
% Display the current slice using imshow
imshow(img);
title(slice_no);
end
For displaying multiple images, there are various approaches available. You can refer to the following link that provides a detailed explanation of different methods. It will help you choose the one that best suits your task:
Hope this helps.

类别

Help CenterFile Exchange 中查找有关 Display Image 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by