# imgradientxyz

Find directional gradients of 3-D image

## Description

## Examples

### Compute 3-D Directional Image Gradients Using Sobel Method

Read 3-D data and prepare it for processing.

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

Calculate the directional gradients.

[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

`I`

— Input image

3-D grayscale image | 3-D binary image

Input image, specified as a 3-D grayscale image or 3-D binary image.

**Data Types: **`single`

| `double`

| `int8`

| `int16`

| `int32`

| `int64`

| `uint8`

| `uint16`

| `uint32`

| `uint64`

| `logical`

`method`

— Gradient operator

`'sobel'`

(default) | `'prewitt'`

| `'central'`

| `'intermediate'`

Gradient operator, specified as one of the following values.

Value | Meaning | ||||||
---|---|---|---|---|---|---|---|

| Sobel gradient operator. The gradient
of a pixel is a weighted sum of pixels in the
3-by-3-by-3 neighborhood. For example, in the
depth (
| ||||||

| Prewitt gradient operator. The
gradient of a pixel is a weighted sum of pixels in
the 3-by-3-by-3 neighborhood. For example, in the
depth (
| ||||||

`'central' ` | Central difference gradient. The
gradient of a pixel is a weighted difference of
neighboring pixels. For example, in the depth
( | ||||||

`'intermediate'` | Intermediate difference gradient. The
gradient of a pixel is the difference between an
adjacent pixel and the current pixel. For example,
in the depth ( |

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`

| `string`

## Output Arguments

`Gx`

— Horizontal gradient

3-D numeric array

Horizontal gradient, returned as a numeric matrix of
the same size as image `I`

. The
horizontal (*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`

.

**Data Types: **`single`

| `double`

`Gy`

— Vertical gradient

3-D numeric array

Vertical gradient, returned as a numeric matrix of the
same size as image `I`

. The
vertical (*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`

.

**Data Types: **`single`

| `double`

`Gz`

— Depth gradient

3-D numeric array

Depth gradient, returned as a 3-D numeric array of the
same size as image `I`

. The depth
(*z*) axis points in the
direction of increasing plane 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.

## Extended Capabilities

### C/C++ Code Generation

Generate C and C++ code using MATLAB® Coder™.

Usage notes and limitations:

`imgradientxyz`

supports the generation of C code (requires MATLAB^{®}Coder™). For more information, see Code Generation for Image Processing.When generating code, the input argument

`method`

must be a compile-time constant.

### GPU Code Generation

Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.

Usage notes and limitations:

When generating code, the input argument

`method`

must be a compile-time constant.

## Version History

**Introduced in R2016a**

## See Also

## 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)
- Switzerland
- United Kingdom (English)