You are here : matlabImage Processingimgradient

imgradient() - Image Processing

[Gmag,Gdir]
= imgradient(I) returns the gradient
magnitude, Gmag, and the gradient direction, Gdir,
for the grayscale or binary image I. example[Gmag,Gdir]
= imgradient(I,method) returns
the gradient magnitude and direction using specified method.example[gpuarrayGmag,gpuarrayGdir]
= imgradient(gpuarrayI,___) performs
the operation on a GPU. The input image and the return values are
gpuArrays. This syntax requires the Parallel Computing Toolbox™.example[Gmag,Gdir]
= imgradient(GxGy) returns
the gradient magnitude and direction using directional gradients along
the x-axis, Gx, and the y-axis, Gy,
such as that returned by imgradientxy. The x-axis
points in the direction of increasing column subscripts and the y-axis
points in the direction of increasing row subscripts.example[gpuarrayGmag,gpuarrayGdir]
= imgradient(gpuarrayGx,gpuarrayGy) performs
the operation on a GPU. The input x and y gradients
and the return values are gpuArrays. This syntax requires the Parallel Computing Toolbox.


Syntax

[Gmag,Gdir]
= imgradient(I)[Gmag,Gdir]
= imgradient(I,method) example[gpuarrayGmag,gpuarrayGdir]
= imgradient(gpuarrayI,___) example[Gmag,Gdir]
= imgradient(GxGy) example[gpuarrayGmag,gpuarrayGdir]
= imgradient(gpuarrayGx,gpuarrayGy) example


Example

Calculate Gradient Magnitude and Gradient DirectionOpen This Example
Read image into workspace.I = imread('coins.png');
Calculate gradients and display.[Gmag, Gdir] = imgradient(I,'prewitt');

figure; imshowpair(Gmag, Gdir, 'montage');
title('Gradient Magnitude, Gmag (left), and Gradient Direction, Gdir (right), using Prewitt method')
axis off;

Calculate gradient magnitude and gradient direction on a GPU
Read image and compute gradient magnitude and
gradient direction using Prewitt's gradient operator. 
Read image.I = gpuArray(imread('coins.png'));
imshow(I)Calculate gradients and display.[Gmag, Gdir] = imgradient(I,'prewitt');

figure, imshow(Gmag, []), title('Gradient magnitude')
figure, imshow(Gdir, []), title('Gradient direction')Calculate Directional GradientsOpen This Example
Read image into workspace.I = imread('coins.png');
Calculate gradients and display them.[Gx, Gy] = imgradientxy(I);
[Gmag, Gdir] = imgradient(Gx, Gy);

figure, imshow(Gmag, []), title('Gradient magnitude')
figure, imshow(Gdir, []), title('Gradient direction')
title('Gradient Magnitude and Gradient Direction')
figure; imshowpair(Gx, Gy, 'montage'); axis off;
title('Directional Gradients, Gx and Gy')



Calculate directional gradients in addition to gradient magnitude and direction on a GPU
Read image and return directional gradients, Gx and Gy,
as well as gradient magnitude and direction, Gmag and Gdir,
utilizing default Sobel gradient operator.
Read image.I = gpuArray(imread('coins.png'))
Calculate gradients and display them. Note that when you
specify a gpuArray to imgradientxy, it returns Gx and Gy as
gpuArrays. The results are the same as the previous example.[Gx, Gy] = imgradientxy(I);
[Gmag, Gdir] = imgradient(Gx, Gy);

figure, imshow(Gmag, []), title('Gradient magnitude')
figure, imshow(Gdir, []), title('Gradient direction')
figure, imshow(Gx, []), title('Directional gradient: X axis')
figure, imshow(Gy, []), title('Directional gradient: Y axis')


Output / Return Value


Limitations


Alternatives / See Also


Reference