File Exchange

image thumbnail


version (4.21 KB) by Maysam Shahedi
imshow3D:(3D imshow) Displays 3D images slice by slice.Intensity adjusting & slice browsing by mouse


Updated 29 Oct 2018

View License

imshow3D displays 3D grayscale or RGB images in a slice by slice fashion with mouse-based slice browsing and window and level adjustment control, and auto slice browsing control.
imshow3D ( Image )
imshow3D ( Image , [] )
imshow3D ( Image , [LOW HIGH] )
imshow3D ( Image , [] , initsn )

Image: 3D image MxNxKxC (K slices of MxN images) C is either 1 for grayscale images) or 3 (for RGB images)
[LOW HIGH]: display range that controls the display intensity range of a grayscale image (default: the broadest available range)
initsn: The slice number to be displayed initially (default: mid-slice number)
Use the scroll bar or mouse scroll wheel to switch between slices. To adjust window and level values keep the mouse right button pressed, and drag the mouse up and down (for level adjustment) or right and left (for window adjustment). Window and level adjustment control works only for grayscale images.
"Play" button displays all the slices as a sequence of frames. The time interval value can also be adjusted (default time interval is 100 ms).
"Auto W/L" button adjust the window and level automatically for grayscale images.

While "Fine Tune" checkbox is checked the window/level adjustment gets 16 times less sensitive to mouse movement, to make it easier to control
display intensity rang.

Note: The sensitivity of mouse-based window and level adjustment is set based on the user-defined display intensity range; the wider the range, the more sensitivity to mouse drag.

Note: IMSHOW3DFULL is a newer version of IMSHOW3D (also available on MathWorks) that displays 3D grayscale or RGB images from three perpendicular views (i.e., axial, sagittal, and coronal).

% To display an image (MRI example)
load mri
Image = squeeze(D);

% To display the image, and adjust the display range
imshow3D(Image,[20 100]);

% To define the initial slice number

Cite As

Maysam Shahedi (2020). imshow3D (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (62)

Xingwang Yong

Perfect! Thank you!

SA Yoganathan

Simone B

really excellent!

Nicolai Jørgensen


Good job!

Fiona Gong

Really good code, easy to use perfect!!! Thanks!

Shujaat Khan


Kyrie long

Kunal Aggarwal

Heui Chang Lee


Doaa Mousa

Mahta Mazloumi


Jianhao Song

Gardar Gislason

jiwoong Jung


Dinesh Palanisamy

Stephen Cross

Maysam Shahedi

Hi Adam,
My suggestion is to modify imshow3D code and make your own version of imshow3D. You can add the plot command within the code.
Hope it helps.


I am fairly new to MATLAB, and I am using the 'imshow3D' GUI for displaying 3D images and using the slider to switch through each slices. I wish to plot points on specific slices.

Each points have an X,Y, and Z component (Z being the slice number). I have tried using the code below;

[I,J,Z] = ind2sub(size(Eroded_EntropyFilterQ_3D_n16_pt3_Filter5_Struct_pt31012),cursor_info1(:,3))
hold on
The points do plot in the slice viewer, however I get an error when switching through the slices, and the points appear on every slices.

Is there a way to fix this problem?

Thank you so much!

Maysam Shahedi

You can send me your questions about the function via the email address I have provided (
Thank you!

Sigal Cohen

It's my first time using Matlab and I'm having a difficult time trying to understand the function you wrote regarding imshow3D. Do you have any advice for me how to get to the bottom of it?
Thank you,

Maysam Shahedi

My apology if the name was misleading to you. I called it imshow3D because, as I mentioned in the subtitle, it displays "3D images" slice-by-slice. I also wanted to make it similar to imshow command of Matlab.


I don't understand why you call it 3d show while it is showing 2d images and show slice by slice?

Maysam Shahedi

The accepted data type for imwrite is unsigned integer (e.g. uint16). Try
imwrite(im2uint16(image(:,:,150)), 'raw3D.jpg','BitDepth',16);
for 'jpeg' format or
imwrite(im2uint16(image(:,:,150)), 'raw3D.png');
for png format.
Hope it helps


thanks again Maysam. i tried saving one of the slice like
imwrite(image(:,:,150),'raw3D.jpg'); but it says that this is int16 and can't save as jpg or png.
can you help

Maysam Shahedi

try this
figure, imshow3D(img, [])
and see if it helps to see the images in full dynamic range or not.

For saving the image, if you use the figure menu bar you will get a snapshot of the whole GUI and you need to crop it. To avoid that you can try saving your image using "imwrite" command.

Hope it helps


thanks. i wrote this code which help to see every image but the image looks like binary whereas my format is uint16
W=reshape(W,[512 512 459]);
figure; imshow3D(img);
moreover when i try to store image as jpg,full screen is getting saved, not just image

Maysam Shahedi

It does not matter what is the image file format. What you need to do is read the 3D image and store it as a 3D matrix, then call imshow3D("matrix_name").


does this work on raw file. i wrote load('......raw') but not working


Ran Kafri

Ander Biguri


mouna lahouidheg

can help me how imshow image 3D on ghraphic interface (GUI) just code simple .
thank you answer me please on this mail:

faisal aziz

i need a code to 3d visualization from brain mri multiple slices can any one help me??

Maqlin Paramanandam


Just a waste of time. Better use figure;imagesc.


Moamen Abdelwahed

Mattia Chini


how can i get this file please ??



Nazanin Makkinejad

Majid Sabbagh


Majid Sabbagh


Maysam Shahedi

Hi Matthew,
Thank you for your interest in imshow3D. You need to input your image as a 3D matrix (e.g. Img) as follows:


You can also follow this example in Matlab to test it:

load mri
Image = squeeze(D);

Hope it works for you

Matthew Bourn

I am new to Matlab and I'm having difficulty using this function. where exactly do I input my image? I keep getting 'undefined function or variable 'Img''.


Great work! thanks!


Thank you, It was very useful for me.



simplest usage and absolute intuitive! Very nice, thank you very much!

Zhaoheng Xie

Fantastic work! Very useful~


Jehan Ziad Ghafuri

Well done, I have tried it and it is awsome

Maysam Shahedi

Hi Mohammad,

if you mean to control the display intensity range of the image, yes, you can do it by pressing the right button of the mouse on the image and dragging the mouse to left and right or up and down.

By the way, in the next update (in few days) an option will be added to the function for calling the function with a specific display intensity range, similar to what we have for "imshow" function.

Hope it addressed your question. Please feel free to contact me if you have any further question about it.

Mohammad Azizian

is there a way to scale matrices in color map using this function?

Jehan Ziad Ghafuri


Bug fixed; the previous figure is now cleared before displaying a new image.

An auto sequential display option has been added.

Title revised

Now it can also display 3D RGB images.

New Version of imshow3D has been released under imshow3Dfull name. It displays 3 orthogonal views (axial, sagittal, and coronal views) one by one.

Display intensity range option has been added.
Minor bugs have been fixed.
It is more similar to Matlab imshow function now.
One example has been added to the help page.

This function needs image processing toolbox too.

MATLAB Release Compatibility
Created with R2017b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired: Visualize 3D data