orthosliceViewer

Browse orthogonal slices in grayscale or RGB volume

Description

The orthosliceViewer object opens a viewer for exploring grayscale and RGB volumes. The viewer displays three orthogonal views of the volume: a view along the x, y, and z dimension.

Use orthosliceViewer to look at individual slices in a volume. When the viewer opens, it displays the middle slice in the stack for each dimension. Each view of the image stack includes a crosshair that you can use to view the different slices of the image stack. The crosshairs are linked, so if you move one, the crosshairs in the related views also move.

The orthosliceViewer supports properties, object functions, and events that you can use to customize its appearance and behavior. orthosliceViewer can send notifications when certain events, such as the crosshair moving, occurs. For more information, see More About.

By default, you can interactively adjust the brightness and contrast of the slice displayed in the orthoslice viewer by dragging the mouse horizontally or vertically over the image. For more information, see Interactive Behavior.

Creation

Description

example

orthosliceViewer(V) displays orthogonal slices of the grayscale or RGB volume V in a figure.

orthosliceViewer(V,Name,Value) sets properties using name-value pairs. For example, orthosliceViewer(V,'Colormap',cmap) creates an orthosliceViewer object specifying the colormap used to display the volume. You can specify multiple name-value pairs. Enclose each property name in single quotes.

s = orthosliceViewer(___) returns an orthosliceViewer object, s, with properties that can be used to control visualization of the images. Use input arguments from any of the previous syntaxes.

Input Arguments

expand all

Input volume, specified as an m-by-n-by-p-by-c numeric array. For grayscale volumes, c is 1. For RGB volumes, c is 3. RGB volumes can be only of class uint8, uint16, single, or double.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32

Properties

expand all

General Properties

Colormap of the image stack, specified as an m-by-3 numeric array with values in the range [0 1]. When V is an RGB image stack, Colormap has no effect.

Display range of grayscale volume, specified as a two-element numeric vector of the form [low high]. The value low (and any value less than low) displays as black. The value high (and any value greater than high) displays as white. Values in the range [low high] display as intermediate shades of gray, using the default number of gray levels. If you specify an empty matrix ([]), the sliceViewer object uses the default value. When you specify a stack of RGB images, DisplayRange has no effect.

Enable interactive control of the display range, specified as one of the values in this table. This property has no affect when you specify a stack of RGB volumes. For more information about using this capability, see Interactive Behavior.

ValueDescription
'on' (default)Control the display range of a grayscale volume by left-clicking the mouse and dragging it on the axes.
'off'Disable display range interactivity.

Parent of the orthosliceViewer object, specified as a uipanel or as a figure created with either the figure or uifigure command. If you do not specify a parent, the parent of the orthosliceViewer object is gcf.

Scale factors used to rescale the volume, specified as a 1-by-3 positive numeric vector. The values in the array correspond to the scale factor applied in the x, y, and z directions.

Indices of image slices to be displayed, specified as a 1-by-3 nonnegative numeric array. orthosliceViewer displays the corresponding slices at the [x,y,z] indices in the YZ, XZ, and XY views.

Crosshair Properties

Crosshair color, specified as a MATLAB® ColorSpec (Color Specification).

Example: 'green'

Example: 'g'

Example: [0 1 0]

State of the linked crosshair objects, specified as one of the values in this table.

ValueDescription
'on'Crosshair is visible, and you can interact with it
'inactive'Crosshair is visible, but you cannot interact with it
'off'Crosshair is not visible.

Width of the crosshair line, specified as a positive numeric scalar, measured in points. The default value is the number of points per screen pixel.

Color of the crosshair stripe, specified as a MATLAB ColorSpec (Color Specification) value or 'none'. By default, the crosshair is solid ('none'). Specifying this property creates a striped crosshair line. The striping consists of a combination of the value specified by 'CrosshairColor' and this value.

Example: 'green'

Example: 'g'

Example: [0 1 0]

Object Functions

addlistenerCreate event listener bound to event source
getAxesHandles Get handles to axes in orthoslice viewer

Examples

collapse all

Load an image stack into the workspace.

load(fullfile(toolboxdir('images'),'imdata','BrainMRILabeled','images','vol_001.mat'));

Create a custom Colormap.

cmap = parula(256);

View the MRI data in the Orthoslice Viewer.

s = orthosliceViewer(vol,'Colormap',cmap)
s = 
  orthosliceViewer with properties:

               SliceNumbers: [121 121 78]
             CrosshairColor: [1 1 0]
         CrosshairLineWidth: 1
       CrosshairStripeColor: 'none'
            CrosshairEnable: 'on'
                     Parent: [1×1 Panel]
                   Colormap: [256×3 double]
               DisplayRange: [0 2239]
               ScaleFactors: [1 1 1]
    DisplayRangeInteraction: 'on'

Load MRI data and view it in the Orthoslice Viewer.

load(fullfile(toolboxdir('images'),'imdata','BrainMRILabeled','images','vol_001.mat'));
s = orthosliceViewer(vol);

Get the handle of the axes that contains the slice.

[hXYAxes, hYZAxes, hXZAxes] = getAxesHandles(s);

Turn off crosshair for better visibility.

set(s,'CrosshairEnable','off');

Specify the name of the GIF file.

filename = 'animatedYZSlice.gif';

Create an array of slice numbers in the required direction. Consider the YZ direction.

sliceNums = 1:240;

Loop through and create an image at the specified slice position.

for idx = sliceNums
    % Update X slice number to get YZ Slice.
    s.SliceNumbers(1) = idx;
  
    % Use getframe to capture image.
    I = getframe(hYZAxes);
    [indI,cm] = rgb2ind(I.cdata,256);
  
    % Write frame to the GIF File.
    if idx == 1
        imwrite(indI,cm,filename,'gif','Loopcount',inf,'DelayTime',0.05);
    else
        imwrite(indI,cm,filename,'gif','WriteMode','append','DelayTime',0.05);
    end
end

View the animated GIF.

Load a stack of images.

load(fullfile(toolboxdir('images'),'imdata','BrainMRILabeled','images','vol_001.mat'));

Create a custom colormap for viewing slices.

cmap = parula(256);

View the image stack in the Orthoslice Viewer.

os = orthosliceViewer(vol,'Colormap',cmap);

Set up listeners for the two Orthoslice Viewer crosshair moving events. When you move the crosshair, the Orthoslice Viewer sends notifications of these events and executes the callback function you specify.

addlistener(os,'CrosshairMoving',@allevents);
addlistener(os,'CrosshairMoved',@allevents);

The allevents callback function displays the name of each event with the previous position and the current position of the crosshair.

function allevents(src,evt)
evname = evt.EventName;
    switch(evname)
        case{'CrosshairMoved'}
            disp(['Crosshair moved previous position: ' mat2str(evt.PreviousPosition)]);
            disp(['Crosshair moved current position: ' mat2str(evt.CurrentPosition)]);
        case{'CrosshairMoving'}
            disp(['Crosshair moving previous position: ' mat2str(evt.PreviousPosition)]);
            disp(['Crosshair moving current position: ' mat2str(evt.CurrentPosition)]);
    end
 end

More About

expand all

Introduced in R2019b