Code covered by the BSD License  

Highlights from
3D Slicer

5.0 | 8 ratings Rate this file 116 Downloads (last 30 days) File Size: 173 KB File ID: #27983
image thumbnail

3D Slicer


David Legland (view profile)


22 Jun 2010 (Updated )

Slicer for exploring 3D images (grayscale, color or vectorial) through planar or 3D slices.

| Watch this File

File Information

Simple 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
 Slice(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.

To install, simply unzip, and add the directory "imStacks" to the path. The new version of the Slicer (from July 2012) uses the GUILayout toolbox by Ben Tordoff (FEx #27758). Version 1.10 is included in the archive for convenience.


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.0 (R2012b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (21)
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

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

27 Apr 2011

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

12 Aug 2011

fix bug when opening without arguments

18 Aug 2011

better control on size/spacing when importing metaImage format

13 Jul 2012

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

12 Sep 2012

Updated to include an App file for R2012b

02 Dec 2013

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

Contact us