# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English version of the page.

Find 3-D gradient magnitude and direction of images

## Syntax

``````[Gmag,Gazimuth,Gelevation] = imgradient3(I)``````
``````[Gmag,Gazimuth,Gelevation] = imgradient3(I,method)``````
``````[Gmag,Gazimuth,Gelevation] = imgradient3(Gx,Gy,Gz)``````

## Description

example

``````[Gmag,Gazimuth,Gelevation] = imgradient3(I)``` returns the gradient magnitude, `Gmag`, gradient direction, `Gazimuth`, and gradient elevation `Gelevation` for the grayscale or binary 3-D image `I`.```
``````[Gmag,Gazimuth,Gelevation] = imgradient3(I,method)``` calculates the gradient magnitude and direction using the specified `method`.```
``````[Gmag,Gazimuth,Gelevation] = imgradient3(Gx,Gy,Gz)``` calculates the gradient magnitude and direction from the directional gradients along the x-axis, `Gx`, y-axis, `Gy` and z-axis, `Gz`. ```

## Examples

collapse all

Read 3-D data into the workspace and prepare it for processing.

```volData = load('mri'); sz = volData.siz; vol = squeeze(volData.D);```

`[Gmag, Gaz, Gelev] = imgradient3(vol);`

Visualize the gradient magnitude as a montage.

```figure, montage(reshape(Gmag,sz(1),sz(2),1,sz(3)),'DisplayRange',[]) title('Gradient magnitude')```

## Input Arguments

collapse all

Input image, specified as a nonsparse, numeric or logical, 3-D matrix

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

Gradient operator, specified as one of the following values.

Value

Meaning

`'sobel' `

`'prewitt'`

`'central' `Central difference gradient. ```dI/dx = (I(x+1)- I(x-1))/ 2```
`'intermediate'` Intermediate difference gradient. ```dI/dx = I(x+1) - I(x)```

When applying the gradient operator at the boundaries of the image, `imgradient3` assumes values outside the bounds of the image equal the nearest image border value. This behavior is similar to the `'replicate'` boundary option in `imfilter`.

Data Types: `char`

Directional gradient along x-axis (horizontal), specified as a nonsparse, numeric or logical, 3-D matrix. The x-axis points in the direction of increasing column subscripts. The matrix must be equal in size to `Gy` and `Gz`.`imgradientxyz` returns `Gx`.

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

Directional gradient along y-axis (vertical), specified as a nonsparse, numeric or logical, 3-D matrix. The y-axis points in the direction of increasing row subscripts. The matrix must be equal in size to `Gx` and `Gz`.`imgradientxyz` returns `Gy`.

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

Directional gradient along z-axis, specified as a nonsparse, numeric or logical, 3-D matrix. The matrix must be equal in size to `Gx` and `Gy`. `imgradientxyz` returns `Gz`.

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

## Output Arguments

collapse all

Magnitude of the gradient vector, returned as a nonsparse matrix the same size as image `I`.

`Gmag` is of class `double`, unless the input image `I` or any of the directional gradients `Gx`, `Gy`, or `Gz` are of class `single`. In this case, `Gmag` is of class `single`.

Azimuthal angle, returned as a nonsparse matrix the same size as image `I`. `Gazimuth` contains angles in degrees within the range [-180 180] measured between positive x-axis and the projection of the point on the x-y plane.

`Gazimuth` is of class `double`, unless the input image `I` or any of the directional gradients `Gx`, `Gy`, or `Gz` are of class `single`. In this case, `Gazimuth` is of class `single`.

Gazimuth and Gelevation

Gradient elevation, returned as a nonsparse matrix the same size as image `I`. `Gelevation` contains angles in degrees within the range [-90 90] measured between the radial line and the x-y plane.

`Gelevation` is of class `double`, unless the input image `I` or any of the directional gradients `Gx`, `Gy`, or `Gz` are of class `single`. In this case, `Gelevation` is of class `single`.

## Algorithms

`imgradient3` does not normalize the gradient output. If the range of the gradient output image has to match the range of the input image, consider normalizing the gradient image, depending on the `method` argument used. For example, with a Sobel kernel, the normalization factor is 1/44 and for Prewitt, the normalization factor is 1/18.