Documentation

# imrotate3

Rotate 3-D volumetric grayscale image

## Syntax

``B = imrotate3(V,angle,W)``
``B = imrotate3(V,angle,W,method)``
``B = imrotate3(V,angle,W,method,bbox)``
``B = imrotate3(___,Name,Value)``

## Description

example

````B = imrotate3(V,angle,W)` rotates the 3-D volumetric grayscale image `V` (referred to as a volume) by `angle` degrees counterclockwise around an axis passing through the origin ```[0 0 0]```. `W` is a 1-by-3 vector which specifies the direction of the axis of rotation in 3-D space. By default, `imrotate3` uses trilinear interpolation and sets the values of voxels in `B` that are outside the boundaries of the rotated volume to `0`.```
````B = imrotate3(V,angle,W,method)` rotates the volume `V`, where `method` specifies the interpolation method. ```
````B = imrotate3(V,angle,W,method,bbox)` rotates the volume `V`, where `bbox` specifies the size of the output volume. If you specify `'crop'`, `imrotate3` makes the output volume the same size as the input volume. If you specify `'loose'`, then `imrotate3` makes the output volume large enough to include the entirety of the rotated volume.```
````B = imrotate3(___,Name,Value)` specifies additional parameters that control various aspects of the geometric transformation.```

## Examples

collapse all

Load a 3-D volumetric grayscale image into the workspace, and display it.

```s = load('mri'); mriVolume = squeeze(s.D); volshow(mriVolume); ``` Rotate the volume 90 degrees around the Z axis.

```B = imrotate3(mriVolume,90,[0 0 1],'nearest','loose','FillValues',0); ```

Display the rotated output volume. You can also explore the volume in the Volume Viewer app.

```volshow(B); ``` ## Input Arguments

collapse all

Volume to be rotated, specified as a 3-D grayscale image.

`imrotate3` assumes that the input volume `V` is centered on the origin `[0 0 0]`. If your volume is not centered on the origin, use `imtranslate` to translate the volume to `[0 0 0]` before using `imrotate3`. You can translate the output volume `B` back to the original position with the opposite translation vector.

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

Rotation angle in degrees, specified as numeric scalar. To rotate the volume clockwise, specify a negative value for `angle`. `imrotate3` makes the output volume `B` large enough to contain the entire rotated 3-D volume.

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

Direction of the axis of rotation in 3-D space in Cartesian coordinates, specified as a 1-by-3 numeric vector.

If you want to specify the direction of the axis of rotation in spherical coordinates, use `sph2cart` to convert values to Cartesian coordinates before passing it to `imrotate3`.

Example: `[0 0 1]` rotates the volume around the Z axis

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

Interpolation method, specified as one of the following values.

MethodDescription
`'cubic'`

Tricubic interpolation

### Note

Tricubic interpolation can produce pixel values outside the original range.

`'linear'`

Trilinear interpolation

`'nearest'`

Nearest neighbor interpolation

Data Types: `char` | `string`

Size of the output volume, specified as either of the following values.

MethodDescription
`'crop'`

Make the output volume the same size as the input volume, cropping the rotated volume to fit.

`'loose'`

Make the output volume large enough to contain the entire rotated volume. Usually, the rotated volume is larger than the input volume.

Data Types: `char` | `string`

### Name-Value Pair Arguments

Specify optional comma-separated pairs of `Name,Value` arguments. `Name` is the argument name and `Value` is the corresponding value. `Name` must appear inside quotes. You can specify several name and value pair arguments in any order as `Name1,Value1,...,NameN,ValueN`.

Example: `B = imrotate3(V,angle,W,'nearest','loose','FillValues',5);`

Fill values used to fill voxels in the output volume that are outside the limits of the rotated volume, specified as the comma-separated pair consisting of `'FillValues'` and a numeric scalar.

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

## Output Arguments

collapse all

Rotated volume, returned as a numeric array of the same class as the input volume `V`.