Code covered by the BSD License  

5.0 | 8 ratings Rate this file 115 Downloads (last 30 days) File Size: 335 KB File ID: #27983 Version: 1.10



David Legland (view profile)


22 Jun 2010 (Updated )

Slicer to visualize 3D images (grayscale, color, vector)

| Watch this File

File Information

interface for exploring 3D images by visualizing planar slices. The interface also allows displaying 3 orthogonal slices, either in 3D or in three subplots.
Among the interface features:
- navigation within image,
- zoom management,
- edition of grayscale range (from datataype, from image, manual)
- interactively change display range, color map, spatial resolution...
- 3D image flip or 90-degrees rotation,
- import of metaimage, analyze or dicom images
- interactive 3D orthogonal slices, planar or 3D
- management of several look-up tables

It supports 3D grayscale, binary, RGB, or vector images (in this case, the vector norm is used for display).

The package includes functions to read/write image stacks stored as tif slices or bundle, as well as basic support for reading and writing images in metaimage format (mhd).

Examples of use:
 Slicer(img); % display the 3D or 4D imge
 Slicer('fileName.tif'); % read the 3D image from file
 Slicer('img000.tif'); % read a series of images
 Slicer % opens a dialog to choose the file
 Slicer(img, 'DisplayRange', [0 80], 'Spacing', [1 1 2.5], 'Origin', [0 0 0], 'unitName', '┬Ám'); % Specify some options

Type "help Slicer" at matlab prompt, or "help imStacks" to have an overview of all functions within the package.


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 8.4 (R2014b)
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 (25)
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

Contact us