orthosliceViewer

Browse orthogonal slices in grayscale or RGB volume

Description

orthosliceViewer is a viewer for exploring volumes, presenting three orthogonal views of the volume along the x, y, and z dimensions.

Use orthosliceViewer to look at individual slices in a volume. The orthosliceViewer opens, displaying the center slice in 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 that 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 functioning. The orthosliceViewer can send notifications when certain events occur, such as the crosshair moving. For more information, see More About.

Note

By default, clicking and dragging the mouse in the slices displayed interactively changes their brightness and contrast, a technique called window/level. Dragging the mouse horizontally from left to right changes the contrast. Dragging the mouse vertically up and down changes the brightness. Holding down the Ctrl key when clicking and dragging the mouse accelerates changes. Holding down the Shift key while clicking and dragging the mouse slows the rate of change. Press these keys before clicking and dragging. To control this behavior, use the DisplayRangeInteraction property.

Creation

Description

example

orthosliceViewer(V) displays the volume V in a figure.

orthosliceViewer(___,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 only be of class uint8, uint16, single, and 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]. Colormap has no effect when S is an m-by-n-by-p-by-c RGB image stack.

Display range of grayscale volume, specified as a two-element 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 between are displayed as intermediate shades of gray, using the default number of gray levels. If you specify an empty matrix ([]), sliceViewer uses the default value. DisplayRange has no effect when you specify an RGB volume.

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

ValueDescription
'on' (default)You can control the display range of a grayscale image stack by left-clicking the mouse and dragging it on the axes.
'off'No display range interactivity.

Parent of the orthosliceViewer object, specified as a handle to a uipanel or as a figure created with either the figure or uifigure function. 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 can be interacted with.
'inactive'Crosshair is visible but cannot be interacted with
'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 ROI stripe, specified as a MATLAB ColorSpec (Color Specification) value or 'none'. By default, the edge of an ROI is solid colored ('none'). If you specify StripeColor, the ROI edge is striped. The striping consists of a combination of the value specified by 'Color' and this value.

Example: 'green'

Example: 'g'

Example: [0 1 0]

Object Functions

addlistenerCreate event listener bound to event source
getAxesHandlesGet 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