How to depict an image in an axes?

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

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.
It is a 4D volumetric image (DICOM) that evolves over time. 4th Dimension is time.
What else if not imshow to use?
I don't have problem to imshow it using 4 dimensions as long as I use squeeze with imshow
As I explained. I need to keep slice2 as the z axis but also to have it change as the slider is moving, which is the idx parameter (callback from uicontrol)
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)
Are you trying to tell me that there is no way to achieve this? There must be a way to somehow combine the permute with slice so they become one image. Maybe to create that image by dicomwrite?
And then imshow it? Can you think any other way without having to dicomwrite 15 images?
How you assign idx =2 and at the next line you say that it is 1?
idx is a value that derives from uicontrol of a slider
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.
I run your Demo and I got an error line, "Multi-plane image inputs must be RGB images of size MxNx3.".
You tell me that there is no way to extract one 2D slice at one time point out of 3D volume?
Is there a way to transform that 3D volume to 2D slices and have them run on the slider? Possibly, without using Dicomwrite

Sign in to comment.

Categories

Asked:

on 17 Jun 2018

Community Treasure Hunt

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

Start Hunting!