orthosliceViewer
Browse orthogonal slices in grayscale or RGB volume
Description
AnorthosliceViewer
object displays volumetric image data by presenting three orthogonal views of the volume along thex,y, andzdimensions.
UseorthosliceViewer
to look at individual slices in a volume. TheorthosliceViewer
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.
TheorthosliceViewer
object supports properties, object functions, and events that you can use to customize its appearance and functioning. TheorthosliceViewer
object 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
orthosliceViewer(___,
setspropertiesusing name-value pair arguments. You can specify multiple name-value pairs. Enclose each property name in single quotes.Name,Value
)
Example:orthosliceViewer (V,”Colormap',cmap)
creates anorthosliceViewer
object and specifies the colormap used to display the volume.
returns ans
= orthosliceViewer(___)orthosliceViewer
object,s
,属性,可用于控制visualization of the images. Use input arguments from any of the previous syntaxes.
Input Arguments
V
—Input volume
numeric array
Input volume, specified as anm-by-n-by-p-by-cnumeric array. For grayscale volumes,c
is 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
General Properties
Colormap
—Colormap of image stack
gray(256)
(default) |m-by-3 numeric array
Colormap of the image stack, specified as anm-by-3 numeric array with values in the range [0, 1]. TheColormap
property has no effect whenV
is an RGB image stack.
DisplayRange
—Display range of grayscale volume
[min(V(:)) max(V(:))]
(default) |2-element vector
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([])
,orthosliceViewer
uses the default value.DisplayRange
has no effect when you specify an RGB volume.
DisplayRangeInteraction
—Interactive control of display range
'on'
|'off'
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
—Parent oforthosliceViewer
object
gcf
(default) |uipanel|figure
Parent of theorthosliceViewer
object, specified as a handle to auipanel
or as a figure created with either thefigure
oruifigure
function. If you do not specify a parent, the parent of theorthosliceViewer
object isgcf
.
ScaleFactors
—Scale factors used to rescale the volume
[1 1 1]
(default) |1-by-3 positive numeric vector
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.
SliceNumbers
—Indices of image slices to be displayed
center slices in each orthogonal direction|1-by-3 nonnegative numeric array
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 theYZ
,XZ
, andXY
views.
Crosshair Properties
CrosshairColor
—Crosshair color
[1 1 0]
(default) |RGB triplet|color name|short color name
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] |
|
'green' |
'g' |
[0 1 0] |
|
'blue' |
'b' |
[0 0 1] |
|
'cyan' |
'c' |
[0 1 1] |
|
'magenta' |
'm' |
[1 0 1] |
|
'yellow' |
'y' |
[1 1 0] |
|
'black' |
'k' |
[0 0 0] |
|
'white' |
'w' |
[1 1 1] |
|
Here are the RGB triplets for the default colors that MATLAB®uses in many types of plots.
RGB Triplet | 外观 |
---|---|
[0 0.4470 0.7410] |
|
[0.8500 0.3250 0.0980] |
|
[0.9290 0.6940 0.1250] |
|
[0.4940 0.1840 0.5560] |
|
[0.4660 0.6740 0.1880] |
|
[0.3010 0.7450 0.9330] |
|
[0.6350 0.0780 0.1840] |
|
Example:'CrosshairColor','r'
Example:'CrosshairColor','green'
Example:'CrosshairColor',[0 0.4470 0.7410]
CrosshairEnable
—State of linked crosshair objects
'on'
(default) |'inactive'
|'off'
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. |
CrosshairLineWidth
—Width of crosshair line
number of points per screen pixel(default) |positive numeric scalar
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.
CrosshairStripeColor
—Color of crosshair stripe
'none'
(default) |RGB triplet|color name|short color name
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 theCrosshairColor
property. Otherwise, the crosshair is striped, with colors alternating between the color specified by this property and the color specified by theCrosshairColor
property.
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] |
|
'green' |
'g' |
[0 1 0] |
|
'blue' |
'b' |
[0 0 1] |
|
'cyan' |
'c' |
[0 1 1] |
|
'magenta' |
'm' |
[1 0 1] |
|
'yellow' |
'y' |
[1 1 0] |
|
'black' |
'k' |
[0 0 0] |
|
'white' |
'w' |
[1 1 1] |
|
Here are the RGB triplets for the default colors that MATLAB uses in many types of plots.
RGB Triplet | 外观 |
---|---|
[0 0.4470 0.7410] |
|
[0.8500 0.3250 0.0980] |
|
[0.9290 0.6940 0.1250] |
|
[0.4940 0.1840 0.5560] |
|
[0.4660 0.6740 0.1880] |
|
[0.3010 0.7450 0.9330] |
|
[0.6350 0.0780 0.1840] |
|
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
View MRI Data in Orthoslice Viewer
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'
Create GIF of MRI Data Slices using Orthoslice Viewer
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.
Set Up Listener for Orthoslice Viewer Crosshair Events
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);
Theallevents
callback 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
Events
TheorthosliceViewer
object can send notifications when the crosshair moves. To receive these notifications, use theaddListener
function to set up alistener. To set up a listener, specify the name of the event, for example,'CrosshairMoving'
, and the function you want executed when the event occurs. The following table lists events supported by theorthosliceViewer
object. For an example, seeSet Up Listener for Orthoslice Viewer Crosshair Events.
Event Name | Trigger | Event Data | Event Attributes |
---|---|---|---|
CrosshairMoving |
The crosshair in theorthosliceViewer is moving. |
images.stack.browser.CrosshairMovingEventData |
|
CrosshairMoved |
The crosshair in theorthosliceViewer has stopped moving. |
images.stack.browser.CrosshairMovingEventData |
|
版本History
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina(Español)
- Canada(English)
- United States(English)
Europe
- Belgium(English)
- Denmark(English)
- Deutschland(Deutsch)
- España(Español)
- Finland(English)
- France(Français)
- Ireland(English)
- Italia(Italiano)
- Luxembourg(English)
- Netherlands(English)
- Norway(English)
- Österreich(Deutsch)
- Portugal(English)
- Sweden(English)
- 瑞士
- United Kingdom(English)