Main Content

orthosliceViewer

Browse orthogonal slices in grayscale or RGB volume

Description

AnorthosliceViewerobject displays volumetric image data by presenting three orthogonal views of the volume along thex,y, andzdimensions.

UseorthosliceViewerto look at individual slices in a volume. TheorthosliceVieweropens, 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.

TheorthosliceViewerobject supports properties, object functions, and events that you can use to customize its appearance and functioning. TheorthosliceViewerobject can send notifications when certain events occur, such as the crosshair moving. For more information, seeEvents.

Note

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

Creation

Description

example

orthosliceViewer(V)displays the volumeVin a figure.

orthosliceViewer(___,Name,Value)setspropertiesusing name-value pair arguments. You can specify multiple name-value pairs. Enclose each property name in single quotes.

Example:orthosliceViewer (V,”Colormap',cmap)creates anorthosliceViewerobject and specifies the colormap used to display the volume.

s= orthosliceViewer(___)returns anorthosliceViewerobject,s,属性,可用于控制visualization of the images. Use input arguments from any of the previous syntaxes.

Input Arguments

expand all

Input volume, specified as anm-by-n-by-p-by-cnumeric array. For grayscale volumes,cis 1. For RGB volumes,cis 3. RGB volumes can only be of classuint8,uint16,single, anddouble.

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

Properties

expand all

General Properties

Colormap of the image stack, specified as anm-by-3 numeric array with values in the range [0, 1]. TheColormapproperty has no effect whenVis an RGB image stack.

Display range of grayscale volume, specified as a 2-element vector of the form[low high]. The valuelow(and any value less thanlow) displays as black. The valuehigh(and any value greater thanhigh) 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([]),orthosliceVieweruses the default value.DisplayRangehas 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 an RGB image stack. For more information about using this capability, seeEvents.

Value Description
'on'(default for grayscale intensity volumes) You can control the display range of a grayscale image stack by left-clicking the mouse and dragging it on the axes.
'off'(default for logical and RGB volumes) No display range interactivity.

Parent of theorthosliceViewerobject, specified as a handle to auipanelor as a figure created with either thefigureoruifigurefunction. If you do not specify a parent, the parent of theorthosliceViewerobject isgcf.

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 thex,y, andzdirections.

Indices of image slices to be displayed, specified as a 1-by-3 nonnegative numeric array.orthosliceViewerdisplays the corresponding slices at the[x,y,z]indices in theYZ,XZ, andXYviews.

Crosshair Properties

Crosshair color, specified as an RGB triplet, a color name, or a short color name.

You can specify any color using an RGB triplet. An RGB triplet is a 3-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range [0,1].

You can specify some common colors by name as a string scalar or character vector. This table lists the named color options and the equivalent RGB triplets.

Color Name Short Name RGB Triplet 外观
“红色” 'r' [1 0 0]

A rectangle colored pure red

'green' 'g' [0 1 0]

A rectangle colored pure green

'blue' 'b' [0 0 1]

A rectangle colored pure blue

'cyan' 'c' [0 1 1]

A rectangle colored pure cyan

'magenta' 'm' [1 0 1]

A rectangle colored pure magenta

'yellow' 'y' [1 1 0]

A rectangle colored pure yellow

'black' 'k' [0 0 0]

A rectangle colored black

'white' 'w' [1 1 1]

A rectangle colored white

Here are the RGB triplets for the default colors that MATLAB®uses in many types of plots.

RGB Triplet 外观
[0 0.4470 0.7410]

A rectangle colored medium blue

[0.8500 0.3250 0.0980]

A rectangle colored reddish-orange

[0.9290 0.6940 0.1250]

A rectangle colored dark yellow

[0.4940 0.1840 0.5560]

A rectangle colored dark purple

[0.4660 0.6740 0.1880]

A rectangle colored light green

[0.3010 0.7450 0.9330]

A rectangle colored light blue

[0.6350 0.0780 0.1840]

A rectangle colored dark red

Example:'CrosshairColor','r'

Example:'CrosshairColor','green'

Example:'CrosshairColor',[0 0.4470 0.7410]

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

Value Description
'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 crosshair stripe, specified as an RGB triplet, a color name, a short color name, or'none'. If you specify'none', then the crosshair is a solid color specified by theCrosshairColorproperty. Otherwise, the crosshair is striped, with colors alternating between the color specified by this property and the color specified by theCrosshairColorproperty.

You can specify any color using an RGB triplet. An RGB triplet is a 3-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range [0,1].

You can specify some common colors by name as a string scalar or character vector. This table lists the named color options and the equivalent RGB triplets.

Color Name Short Name RGB Triplet 外观
“红色” 'r' [1 0 0]

A rectangle colored pure red

'green' 'g' [0 1 0]

A rectangle colored pure green

'blue' 'b' [0 0 1]

A rectangle colored pure blue

'cyan' 'c' [0 1 1]

A rectangle colored pure cyan

'magenta' 'm' [1 0 1]

A rectangle colored pure magenta

'yellow' 'y' [1 1 0]

A rectangle colored pure yellow

'black' 'k' [0 0 0]

A rectangle colored black

'white' 'w' [1 1 1]

A rectangle colored white

Here are the RGB triplets for the default colors that MATLAB uses in many types of plots.

RGB Triplet 外观
[0 0.4470 0.7410]

A rectangle colored medium blue

[0.8500 0.3250 0.0980]

A rectangle colored reddish-orange

[0.9290 0.6940 0.1250]

A rectangle colored dark yellow

[0.4940 0.1840 0.5560]

A rectangle colored dark purple

[0.4660 0.6740 0.1880]

A rectangle colored light green

[0.3010 0.7450 0.9330]

A rectangle colored light blue

[0.6350 0.0780 0.1840]

A rectangle colored dark red

Example:'CrosshairStripeColor','r'

Example:'CrosshairStripeColor','green'

Example:'CrosshairStripeColor',[0 0.4470 0.7410]

Object Functions

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

文件名='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.

foridx = 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.ifidx == 1 imwrite(indI,cm,filename,'gif','Loopcount'正,'DelayTime',0.05);elseimwrite(indI,cm,filename,'gif','WriteMode','append','DelayTime',0.05);endend

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);

Thealleventscallback function displays the name of each event with the previous position and the current position of the crosshair.

functionallevents(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)]);endend

More About

expand all

版本History

Introduced in R2019b