You are here : matlabImage Processingimgradientxy

imgradientxy() - Image Processing

[Gx,Gy]
= imgradientxy(I) returns the directional
gradients, Gx and Gy, the
same size as the input image I.When applying the gradient operator at the boundaries of the
image, values outside the bounds of the image are assumed to equal
the nearest image border value.example[Gx,Gy]
= imgradientxy(I,method) returns
the directional gradients using the specified method.example[gpuarrayGx,gpuarrayGy]
= imgradientxy(gpuarrayI,___) performs
the operation on a GPU. The input image and the return values are
gpuArrays. This syntax requires the Parallel Computing Toolbox™


Syntax

[Gx,Gy]
= imgradientxy(I) example[Gx,Gy]
= imgradientxy(I,method) example[gpuarrayGx,gpuarrayGy]
= imgradientxy(gpuarrayI,___) example


Example

Calculate Directional GradientsOpen This Example
Read image into workspace.I = imread('coins.png');
Calculate gradient magnitude and gradient direction using Prewitt gradient operator.[Gx, Gy] = imgradientxy(I,'prewitt');

figure; imshowpair(Gx, Gy, 'montage');
title('Directional Gradients: x-direction, Gx (left), y-direction, Gy (right), using Prewitt method')
axis off;

Calculate directional gradients on a GPURead image into a gpuArray.I = gpuArray(imread('coins.png'));
imshow(I)Calculate gradient magnitude and gradient direction using
Prewitt's gradient operator and display images.[Gx, Gy] = imgradientxy(I,'prewitt');

figure, imshow(Gx, []), title('Directional gradient: X axis')
figure, imshow(Gy, []), title('Directional gradient: Y axis')Calculate Directional Gradients and Then Magnitude and DirectionOpen This Example
Read image into workspace.I = imread('coins.png');
Calculate x and y directional gradients and then gradient magnitude and direction.[Gx, Gy] = imgradientxy(I);
[Gmag, Gdir] = imgradient(Gx, Gy);
figure; imshowpair(Gmag, Gdir, 'montage'); axis off;
title('Gradient Magnitude, Gmag (left), and Gradient Direction, Gdir (right), using Sobel method')
figure; imshowpair(Gx, Gy, 'montage'); axis off;
title('Directional Gradients, Gx and Gy, using Sobel method')


Calculate gradient magnitude and direction in addition to directional gradients on a GPU
Read image and return directional gradients, Gx and Gx,
as well as gradient magnitude and direction, Gmag and Gdir,
utilizing default Sobel gradient operator.
Read image into a gpuArray.I = gpuArray(imread('coins.png'));
imshow(I)
Calculate gradient and display images.[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