volshow

Display volume

Description

Display volume, creating a volshow object with properties that control the appearance of the display.

Creation

Description

example

volshow(V) displays 3-D grayscale volume V in a figure. You can rotate and zoom in and out on the display interactively using the mouse.

volshow(V,config) displays the 3-D grayscale volume V. config is a struct exported from the Volume Viewer app. The config struct controls visualization of the volume, containing values for volshow object properties.

volshow(V,Name,Value) displays the volume, using one or more name-value pairs to set properties that control the visualization of the volume. For a list of name-value pairs, see Properties. Enclose each property in quotes. For example, 'BackgroundColor'.

vs = volshow(___) returns a volshow object with properties that can be used to control visualization of the volume.

Input Arguments

expand all

3-D grayscale volume, specified as a numeric array.

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

Rendering information exported by Volume Viewer, specified as a struct.

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

Properties

expand all

Transparency map for the volume content, specified as a 256-by-1 numeric array, with values in the range [0 1].

Color of the background, specified as a MATLAB® ColorSpec. The intensities must be in the range [0,1].

Location of camera, or the viewpoint, specified as a three-element vector of the form [x y z]. This vector defines the axes coordinates of the camera location, which is the point from which you view the axes. The camera is oriented along the view axis, which is a straight line that connects the camera position and the camera target. Changing the CameraPosition property changes the point from which you view the volume. For an illustration, see Camera Graphics Terminology (MATLAB). Interactively rotating the volume modifies the value of this property.

Point used as camera target, specified as a three-element vector of the form [x y z]. The camera is oriented along the view axis, which is a straight line that connects the camera position and the camera target. For an illustration, see Camera Graphics Terminology (MATLAB).

Vector defining upwards direction, specified as a three-element direction vector of the form [x y z]. By default, volshow defines the z-axis as the up direction ([0 0 1]). For an illustration, see Camera Graphics Terminology (MATLAB). Interactively rotating the volume modifies the value of this property.

Field of view, specified as a scalar angle greater than or equal to 0 and less than 180. The greater the angle, the larger the field of view. Also, the bigger the angle, objects appear smaller in the scene. For an illustration, see Camera Graphics Terminology (MATLAB).

Colormap of the volume content, specified as a 256-by-3 numeric array with values in the range [0 1].

Interactivity of the volume, specified as true or false. When true (default), you can zoom using the mouse scroll wheel, and rotate by clicking and dragging on the volume. Rotation and zoom are performed about the value specified by CameraTarget. When false, you cannot interact with the volume.

Isosurface color, specified as a MATLAB ColorSpec, with values in the range [0 1]. This property specifies the volume color when the Renderer is set to 'Isosurface'.

Value that defines the surface of the volume drawn when Renderer is set to 'Isosurface', specified as a numeric array. Value must be in the range [0 1].

Include light source in rendering, specified as a logical scalar.

Parent of volshow object, specified as a handle to a uipanel or figure. If you do not specify a parent, the parent of the volshow object is gcf.

Rendering style, specified as one of the values in this table. When the volume is logical, the default Renderer is 'Isosurface', otherwise the default Renderer is 'VolumeRendering'.

ValueDescription
'VolumeRendering'View the volume based on the specified color and transparency for each voxel.
'MaximumIntensityProjection'View the voxel with the highest intensity value for each ray projected through the data.
'Isosurface'View an isosurface of the volume specified by the value in Isovalue.

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

Object Functions

setVolumeSet new volume

Examples

collapse all

Load and view the volume.

load('spiralVol.mat');
h = volshow(spiralVol);

Specify the name of the GIF file.

filename = 'animatedSpiral.gif';

Create an array of camera positions around the unit circle.

vec = linspace(0,2*pi(),120)';
myPosition = [cos(vec) sin(vec) ones(size(vec))];

Loop through and create an image at each camera position.

for idx = 1:120
    % Update current view.
    h.CameraPosition = myPosition(idx,:);
    % Use getframe to capture image.
    I = getframe(gcf);
    [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

Load MRI data and remove the singleton dimension.

load mri
V = squeeze(D);

Generate a color map and transparency (alpha) map suited for MRI images.

intensity = [0 20 40 120 220 1024];
alpha = [0 0 0.15 0.3 0.38 0.5];
color = ([0 0 0; 43 0 0; 103 37 20; 199 155 97; 216 213 201; 255 255 255]) ./ 255;
queryPoints = linspace(min(intensity),max(intensity),256);
alphamap = interp1(intensity,alpha,queryPoints)';
colormap = interp1(intensity,color,queryPoints);

View the volume with the custom color map and transparency map. Click and drag the mouse to rotate the volume. Use the scroll wheel to zoom in and out of the volume.

vol = volshow(V,'Colormap',colormap,'Alphamap',alphamap);

Load data.

load mri
V = squeeze(D);

Generate a colormap and an alphamap that are ideal for visualizing CT images.

intensity = [-3024,-16.45,641.38,3071];
alpha = [0, 0, 0.72, 0.72];
color = ([0 0 0; 186 65 77; 231 208 141; 255 255 255]) ./ 255;
queryPoints = linspace(min(intensity),max(intensity),256);
alphamap = interp1(intensity,alpha,queryPoints)';
colormap = interp1(intensity,color,queryPoints);

View volume with custom Colormap and Alphamap

volshow(V,'Colormap',colormap,'Alphamap',alphamap);

Tips

  • The volshow function creates a uipanel object in the specified parent figure. Panels are containers that group UI components together. volshow displays volumetric data in the uipanel. In contrast, imshow displays images in an Axes. If you call imshow to display an image in a figure in which volshow has displayed a volume, imshow does not overwrite the volume displayed by volshow. The Axes created by imshow displays behind the uipanel.

Introduced in R2019a