View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

4.9 | 11 ratings Rate this file 100 Downloads (last 30 days) File Size: 190 KB File ID: #27983 Version: 1.0.2



David Legland (view profile)


22 Jun 2010 (Updated )

GUI for exploration of 3D images (stacks)

| Watch this File

File Information

A graphical user interface for display and exploration of 3D images of various types. Manages grayscale, RGB, label images. Allows orthoslices display, isosurface reconstruction, changing intensity range or look-up table, and basic type conversions.
Part of the "MatImage" toolbox ( )


Tiffread2.M, Myslicer Make Mouse Interactive Slices Of A 3 D Volume, and Gui Layout Toolbox inspired this file.

This file inspired Pcolor3.

Required Products Image Processing Toolbox
MATLAB release MATLAB 9.1 (R2016b)
MATLAB Search Path
Other requirements image processing toolbox
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (33)
31 Jan 2017 David Legland

David Legland (view profile)

Hi Walter,
I have juste submitted a new version that should avoid losing track of the handle. It should be more stable.
The difficulty was to have a code valid both when an image was available, or not. But this can surely still be improved!

Comment only
31 Jan 2017 Walter Roberson

Near line 367 you initialize scrollPanel with a ResizeFcn; near line 378 you conditionally store it into this.handles . Unfortunately, the ResizeFcn can become active before you reach that line, leading to an error in the resize callback because the field does not exist yet. You should either store directly into handles or you should postpone setting the ResizeFcn callback until you know you have stored the field into handles.

I am not clear on why it is stored into handles only conditionally? It is created unconditionally and you could be losing track of it.

Comment only
10 Sep 2016 Dennis Köhnke

06 Sep 2016 Brani Dzepina

Thank you David for such a wonderful app. I could not get any slicer code to work for me on v2015 and v2016 other than your code! Top class

20 May 2016 David Legland

David Legland (view profile)

Hi Sebastian,
there was still some code refering to the old version of GUI Layout Toolbox. I have tried to fix all cases, while keeping compatibility with both versions. I have tested quickly for GUI Layout 2.1, this should work better now.

Comment only
12 May 2016 Sebastian

Dear David,

running Slicer on Matlab 2015b on different systems leads to the following error:

Error using uiextras.Container (line 66)
Trying to run using double-handle MATLAB graphics against the new graphics system. Please re-install.

Error in uiextras.Box (line 38)
obj@uiextras.Container( varargin{:} );

Error in uiextras.HBox (line 44)
obj@uiextras.Box( varargin{:} );

Error in Slicer/Slicer/setupLayout (line 297)
mainPanel = uiextras.HBox('Parent', hf, ...

Error in Slicer (line 211)

Thanks in advance!

Comment only
21 Apr 2016 David Legland

David Legland (view profile)

Hi Olaf,
sorry, there was a bug when opening without image. I have added an updated version that should solve this.

Comment only
20 Apr 2016 Olfa Laouini

Hi David
when I run the code I got the following error


Index exceeds matrix dimensions.

Error in Slicer (line 194)
this.sliceIndex = min(this.sliceIndex, this.imageSize(3));

Error in SlicerApp/startApp (line 61)
obj.AppHandle = eval('Slicer');

Error in SlicerApp (line 38)

please could you help me thanks

15 Jun 2015 David Legland

David Legland (view profile)

@Adam Shore:
What I can suggest is that you install the "GUI Layout Toolbox", also availbale on FileExchange (be careful to dowload the first version, for Matlab versions up to 2014a). Then add the paths to the guiLayout, and also to the 'patch' directory inthe guiLayout toolbox. Hopefully this could solve some problems...

Comment only
19 May 2015 Adam Shore

I would like to use the interactive slicer, and I am using R2014a. When i run:

metadata = analyze75info('brainMRI.hdr');
IMG = analyze75read(metadata);

I get this error:

Undefined function or variable 'isHGUsingMATLABClasses'.

Error in uiextras.Container (line 62)
if isHGUsingMATLABClasses()
Error in uiextras.Box (line 38)
obj@uiextras.Container( varargin{:} );

Error in uiextras.HBox (line 44)
obj@uiextras.Box( varargin{:} );
Error in Slicer/Slicer/setupLayout (line 263)
mainPanel = uiextras.HBox('Parent', hf, ...
Error in Slicer (line 197)

I would really like to figure out how to get this software to run on my machine. Thanks!

Comment only
28 Apr 2015 David Legland

David Legland (view profile)

@Don Catanzaro:
which Matlab version do you use? There was a huge update in GUI in Matlab 2014b, and this contribution has now such problems. I will try to post an update soon.

Comment only
27 Apr 2015 Don Catanzaro

Using the example throws the following error:

>> metadata = analyze75info('brainMRI.hdr');
>> IMG = analyze75read(metadata);
>> slicer(IMG);
No constructor 'handle.listener' with matching signature found.

Error in slicer_slicer_OpeningFcn (line 160)
hListener = handle.listener(handles.moveZSlider, 'ActionEvent', ...

Error in gui_mainfcn (line 220)
feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});

Error in slicer (line 128)
gui_mainfcn(gui_State, varargin{:});

Comment only
12 Feb 2015 David Legland

David Legland (view profile)

Hi Jaziel,
there is no simple way to my knowledge to add colorbar to image. I will check if it is possible to add this option in a future release.

Comment only
12 Feb 2015 Jaziel Soto

Hello there.
Is there any way I can add a olor bar in when I display an image using Slicer( ) ?? Thanks in advance.

Comment only
20 Nov 2013 David Legland

David Legland (view profile)

Hi Jun,

From what I remember, the offset is the same as the origin, and the field "origin" is used to specify the coordinates of the first pixel. "origin" and "spacing" are used to display mouse cursor coordinates in user units, but changing the origin does not change the display of the image itself.

The transformMatrix is not used at the moment. This could be used to update cursor coordinates (for example within the displayPixelCoords function). But if you want to display the image after applying the transform, this would require much more work...

Comment only
07 Nov 2013 Jun Hao

Hi David, you really did a brilliant work!
However, I have some doubts here. After reading the mhd file, some of the info retrieved, such as 'TransformMatrix' and 'Offset', you didn't use them to reconstruct the original image, right? Do you know anyway to implement those information during the reconstruction of the image? Thanks

29 Aug 2013 David Legland

David Legland (view profile)

Hi Gianni,
I agree, this would be a nice improvement! Note that there is a limited support for vector images that can be displayed in main frame when they are given as [Ny*Nx*Nc*Nz] arrays. But only the norm of the current slice can be displayed. I will have a look to extend it!

Comment only
28 Aug 2013 G. Sken

G. Sken (view profile)

what about 3d orthoslices of a vector field , i.e. Slicer(U,V,W) as an improvement to the present capability limited to a scalar field (Slicer(M)).

with U,V,W on the 3 orthogonal planes

23 Aug 2013 Bondy

Bondy (view profile)

10 Jun 2013 Colleen

I was using this app on R2012b but recently upgraded to R2013a and now have difficulty running the Slicer app. I'm wondering if that's a result of the new version of Matlab or if I did not install it correctly. Any assistance on this issue would be much appreciated.
Thank you,

Comment only
18 Apr 2013 David Legland

David Legland (view profile)

Hi Niru C,
This contribution is devoted to the visualisation of 3D images. For your problem, I would suggest trying my other contributions geom3d (#24484) and geom2d (#7844), in particular functions intersectPlaneMesh, and polygonLength.

Comment only
15 Apr 2013 Niru C

Niru C (view profile)

Hello David

I have this 3D point-cloud which I made into a triangulation mesh (~4500 points) using the ball-pivot algorithm. I want to find the perimeter of an outline formed from intersection of this 3D mesh and a plane parallel to XY plane say at different Z values. Can I do this in this program ? What will be your suggestion?

Thank you

Comment only
14 Aug 2012 Sean de Wolski

Hi David,

I had to grab the "Patch" folder from the GUI Layout Toolbox in order to avoid run time errors.


14 Aug 2012 G. Sken

G. Sken (view profile)

This function offers the same capability available with expensive commercial software for CT / MR explotation.
It would be desirable to have an option to generate the histogramm of the voxels-luminosity (excluding the background voxels ) e.g. like : hist(Volume(good_voxels),nbins).
The valley of the histrogram can used for region-based volume segmentation.

14 Jul 2012 G. Sken

G. Sken (view profile)

18 Aug 2011 David Legland

David Legland (view profile)

Hi Martijn,
your suggestion is good ! I have just submitted an updated version that fixes it. I'll also try to add support for data stored in header file in a future version.


Comment only
17 Aug 2011 Martijn Steenwijk

Hi David,

Great work! A small suggestion regarding the metaImageInfo function. Currently, if a mhd file contains the tag ElementSize, but not the tag ElementSpacing, ElementSpacing will be set by default as [1 1 1].

This while the specification states (
If ElementSpacing is not specified, it is assumed to be equal to ElementSize. If neither is specified, both are assumed to be 1.

Would it be an idea to follow this ITK convention?


Comment only
22 Jul 2011 David Legland

David Legland (view profile)

I think the problem depends on the image you tried to visualize.

Input should be either a M*N*P 3D grayscale image, or a M*N*3*P 3D color image.

hope this helps ?

Comment only
05 May 2011 ops OPS

not work for me
??? Index exceeds matrix dimensions.

Error in ==> slicer>computeDisplayData at 415
data = img(:, :, zslice);

Error in ==> slicer>setSlice at 656
cdata = computeDisplayData(handles);

Error in ==> slicer>slicer_OpeningFcn at 216

Error in ==> gui_mainfcn at 221
feval(gui_State.gui_OpeningFcn, gui_hFigure, [],
guidata(gui_hFigure), varargin{:});

Error in ==> slicer at 124
gui_mainfcn(gui_State, varargin{:});

Comment only
27 Apr 2011 David Legland

David Legland (view profile)

@sdf: It is actually possible to load dicom images (files->import->dicom). Note that the gui does not support all dicom features. I have submitted an updated version, that should be more intuitive.
If you still have some bugs, please email me.

Comment only
24 Apr 2011 sdf

sdf (view profile)

do not open .dcm image....error of
Index exceeds matrix dimensions.

23 Apr 2011 sdf

sdf (view profile)

??? Attempt to reference field of non-structure array.

Error in ==> slicer>itemOpen_Callback at 980
[filename, pathname] = uigetfile( ...

Error in ==> gui_mainfcn at 96

Error in ==> slicer at 113
gui_mainfcn(gui_State, varargin{:});

Error in ==>

??? Error while evaluating uimenu Callback

plyz tell me my mistake..and i have also added path to matlab.

Comment only
01 Jul 2010 J Rey

J Rey (view profile)

Excellent, thank you very much.

30 Nov 2010 1.1

added options to choose grayscale extent, lut management, and fixed several bugs.

27 Apr 2011 1.3

added display of orthoslices, enhanced loading of new images, enhance display of image infos (name, pixel value...)

12 Aug 2011 1.4

fix bug when opening without arguments

18 Aug 2011 1.5

better control on size/spacing when importing metaImage format

13 Jul 2012 1.6

Switched the interface to GUILayout Toolbox. Lot of code rewritting...

12 Sep 2012 1.7

Updated to include an App file for R2012b

02 Dec 2013 1.9

better support of the different image types (binary, label...), more options for displaying orthoslices and histograms, added demo images, read offset from mhd files

15 Jun 2015 1.10

update to work with GuiLayout Toolbox 2, and package as a Matlab Application

21 Apr 2016 1.0

fix bug when opening with empty image

20 May 2016 1.0.1

Better management of GUI Layout v2.1

31 Jan 2017 1.0.2

fix some GUI bugs.

Contact us