# Documentation

### This is machine translation

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

Find the directional gradients of a 3-D image

## Syntax

``````[Gx,Gy,Gz] = imgradientxyz(I)``````
``````[Gx,Gy,Gz] = imgradientxyz(I,method)``````

## Description

example

``````[Gx,Gy,Gz] = imgradientxyz(I)``` returns the gradient along the x-axis, `Gx`, the y-axis, `Gy` and the z-axis, `Gz`, for the grayscale or binary 3-D image `I`. ```
``````[Gx,Gy,Gz] = imgradientxyz(I,method)``` calculates the directional gradients using the specified `method`.```

## Examples

collapse all

Read 3-D data and prepare it for processing.

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

`[Gx, Gy, Gz] = imgradientxyz(vol);`

Visualize the directional gradients as a montage.

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

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

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

## 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, `imgradientxyz` assumes values outside the bounds of the image are equal to the nearest image border value. This behavior is similar to the `'replicate'` boundary option in `imfilter`.

Data Types: `char`

## Output Arguments

collapse all

Directional gradient along x-axis (horizontal), returned as nonsparse matrix equal in size to image `I`. The X-axis points in the direction of increasing column subscripts. `Gx` is of class `double`, unless the input image `I` is of class `single`, in which case `Gx` is of class `single`.

Directional gradient along y-axis (vertical), returned as non-sparse matrix equal in size to image `I`. Y-axis points in the direction of increasing row subscripts. `Gy` is of class `double`, unless the input image `I` is of class `single`, in which case `Gy` is of class `single`.

Directional gradient along z-axis, returned as nonsparse matrix equal in size to image `I`. The Z-axis points in the direction of increasing third dimension subscripts. `Gz` is of class `double`, unless the input image `I` is of class `single`, in which case `Gz` is of class `single`.

## Algorithms

`imgradientxyz` 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, for Prewitt, the normalization factor is 1/18.