File Exchange

image thumbnail


version (190 KB) by David Legland
GUI for exploration of 3D images (stacks)


Updated 01 Mar 2019

View Version History

View License

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 ( )
Requires the GUI Layout Toolbox to be installed

Cite As

David Legland (2021). Slicer (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (47)


Revert to 2018b solved the issues. Thanks.


Now I have a new error:

No constructor 'handle.listener' with matching signature found.

Error in uiextras.Container (line 92)
obj.Listeners{end+1,1} = handle.listener( containerObj, findprop(
containerObj, 'PixelBounds' ), 'PropertyPostSet', @obj.onResized );

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 231)
mainPanel = uiextras.HBox('Parent', hf, ...

Error in Slicer (line 175)


Hi David,

I have runned into this error:
Unrecognized 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 231)
mainPanel = uiextras.HBox('Parent', hf, ...

Error in Slicer (line 175)

I have installed the GUI layout toolbox and running version 2019b update 4 on a mac.

Do you know how to fix this? Many thanks.

Abhay Nayak

This app is amazing! Thank you very much for sharing it.

Ahmed Zankoor

David Legland


I have published a new release that should fix the problem.
It's packages as an app, if you can not extract it, you can try to get the code from GitHub.


Sara Mahdavi

Hi David, Running on R2013a I get the following error. Thanks

Error using uix.FigureObserver (line 34)
Expected subject to be one of these types:

Instead its type was uix.HBox.

Error in uix.mixin.Container (line 46)
figureObserver = uix.FigureObserver( obj );

Error in uix.Box (line 1)
classdef Box < uix.Container & uix.mixin.Container

Error in uix.HBox (line 26)
function obj = HBox( varargin )

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

Error in Slicer (line 211)

Error in Slicer/onOpenDemoImage (line 934)
Slicer(img, ...

Error in Slicer>@(varargin)this.onOpenDemoImage(varargin{:}) (line 2208)
'Callback', @this.onOpenDemoImage);

Error while evaluating uimenu Callback

David Legland

Hi Vanessa,
you can try the following syntax: "Slicer('file.dcm');". If the file can be loaded, it should open up in a new frame!

Vanessa Azzopardi

This is a great tool, well done. Just wanted to ask: is there a way I could open a file into slicer via code please? Something like: load('file.dcm') or open('file.dcm'). I'd like to have the image slicer open up with the desired file directly. Thanks!


Paul FitzGerald


Ala Bani irshid

thank you so much david

David Legland

Hi Ala Bani irshid,
the Slicer toolbow is inteded to visualize 3D images represented as 3D or 4D arrays of intensities or colors. STL files corresponds to polygonal meshes, and can not be used as inputs of this contribution. You can perform a search using 'mesh' on the FEx, there a several tools for manipulation of meshes.

Ala Bani irshid

Dear please could you explain the required input file and parameters for this slicer
function slicefr(x,y,z,v,xs,ys,zs) i couldn't understand what are these inputs.
i have read stl file and save the facet,vertices and normal matrices i am trying to slice this file but i can not could you help me i need to slice stl file in matlab.

David Legland

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!

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.

Dennis Köhnke

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

David Legland

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.


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!

David Legland

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

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

David Legland

@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...

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!

David Legland

@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.

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{:});

David Legland

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.

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.

David Legland

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...

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

David Legland

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!

Gianni Schena

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



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,

David Legland

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.

Niru C

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

Sean de Wolski

Hi David,

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


Gianni Schena

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.

Gianni Schena

David Legland

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.


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?


David Legland

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 ?

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{:});

David Legland

@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.


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


??? 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.

J Rey

Excellent, thank you very much.

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

Community Treasure Hunt

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

Start Hunting!