分类: IT业界
2014-04-05 13:52:25
f=imread('C:\Documents and Settings\Administrator\桌面\first.jpg');
g=rgb2gray(f);
g=imresize(g,0.5);
g=im2double(g);
[Gx,Gy]=gradient(g);
G=sqrt(Gx.*Gx+Gy.*Gy);
B=mat2gray(G);
thta=atan2(Gy,Gx);
subplot(2,2,1);
imshow(B);
title('幅度图');
subplot(2,2,2)
imhist(B);
title('幅度直方图');
subplot(2,2,3);
imshow(thta);
title('方向图')
subplot(2,2,4);
imhist(thta);
title('方向直方图')
2.
f=imread('C:\Documents and Settings\Administrator\桌面\first.jpg');
g=rgb2gray(f);
g=imresize(g,0.5);
g=im2double(g);
%sobelx=[-1 2 -1,0 0 0,1 2 1];
%sobely=[-1 0 1 ,-2 0 2 ,-1 0 1];
sobelx=[-1 0 1;-2 0 2;-1 0 1];
sobely=[-1 -2 -1 ,0 0 0 ,1 2 1];
Gx=conv2(g,sobelx,'same');
Gy=conv2(g,sobely,'same');
G=sqrt(Gx.*Gx+Gy.*Gy);
B=mat2gray(G);
thta=atan2(Gy,Gx);
subplot(2,2,1);
imshow(B);
title('幅度图');
subplot(2,2,2)
imhist(B);
title('幅度直方');
subplot(2,2,3);
imshow(thta);
title('方向图')
subplot(2,2,4);
imhist(thta);
title('方向直方图')