How to depict an image in an axes?
Show older comments
Let's assume I have a 4D image called 'im2'.
I want to imshow a new image called 'im3' which is equal:
im3 = permute(im2, [3 1 2 4]);
And I want the z axis to be
slice = floor(size(im2,2)/2)
So I come to
imshow(squeeze(im3(:,:,slice,:)))
What if I want to imshow the same image as above, to an axes using eg subplot but have a different index as z axis (controlled by a slider).
idx = round((get(hObject, 'Value'));
subplot(2,2,1)
imshow(squeeze(im3(:,:,idx,:)))
It works, but not the way I want. I need to keep the slice as the third dimension and at the same time to run it for times idx (which is the slider callbacks).
I have stuck. Any idea?
Please, ask me if you didn't understand my question
11 Comments
Image Analyst
on 17 Jun 2018
What do the 4 dimensions represent? Is it a volumetric image (like CT or MRI) that is evolving over time and so time is the 4th dimension? So the first dimension is row, second dimension is column, third dimension is z slice, and 4th dimension is time or frame number?
Or is it a color movie, where the first dimension is row, second dimension is column, third dimension is color channel, and 4th dimension is time or frame number?
What are you doing, in effect, when you switch the 3rd dimension to the first and why are you doing that?
imshow(), when it shows a 3-D image is expecting that that image is a color image with 3 color planes/channels/slices in the third dimension. I've never used imshow() to show a volumetric image and don't think it can. If you pass it 3 planes from a volumetric image it will treat them as r, g, and b color channels. I'm pretty sure imshow() cannot show 2 planes, or 4 or more planes (slices). Please provide some sort of context.
Stelios Fanourakis
on 17 Jun 2018
Stelios Fanourakis
on 17 Jun 2018
Stelios Fanourakis
on 17 Jun 2018
Image Analyst
on 18 Jun 2018
No, sorry but I don't believe it does work. See this little demo where I show that the operations you do cannot be shown with imshow():
clc;
clear all;
im2 = randi(255, 5,6,7,8); % 4-D array
whos im2
im3 = permute(im2, [3 1 2 4]); % Still a 4-D array
whos im3
idx = 2;
im3da = im3(:,:,idx,:); % Still a 4-D array but dimension 3 is only 1
whos im3da
im3db = squeeze(im3da); % Get rid of dimension 3 and make a 3-D array.
whos im3db
% Now show the 3-D array and see a big crash!
imshow(im3db)
Stelios Fanourakis
on 18 Jun 2018
Stelios Fanourakis
on 18 Jun 2018
Stelios Fanourakis
on 18 Jun 2018
Image Analyst
on 18 Jun 2018
But you are not extracting one 2-D slice, at one time point, and displaying that. You are extracting a 3-D volume and trying to display that. There is a big difference. Did you run my demo? Did you understand it?
For 3-D visualization, MATLAB is pretty much limited to cutaway views and isosurfaces. For true 3-D volume visualization you'll need a program like Avizo.
Stelios Fanourakis
on 18 Jun 2018
Stelios Fanourakis
on 18 Jun 2018
Answers (1)
Yuvaraj Venkataswamy
on 18 Jun 2018
0 votes
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!