www.gusucode.com > images 案例代码 matlab源码程序 > images/CalculateDirectionalGradientsExample.m

    %% Calculate Directional Gradients
% 
%%
% 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')