matlab 图像主方向,得到图像的主方向(Matlab)

function [mdex ] = MainDirec(a)

% function: the main direction of the image

% description: the direction edge is [0,180],and the direction are divided

% to 18 part by 10,

% output: the index of the direction ,form 1 to 18;where 1 is defined as the

% direction belong to[0,18],the rest can be done in the same manner,18

% derecting to [170,180]

% last modification:Dec.19,2011 by Lucifer.jia

if(size(a,3)~=1)

a=rgb2gray(a);

end

[w,h]=size(a);

edge_a=edge(a,'sobel');

figure,imshow(edge_a);

fedge_a=fftshift(fft2(edge_a));

%power of fft

realf=real(fedge_a);

imagf=imag(fedge_a);

pfa=sqrt(realf.^2+imagf.^2);

% theat=atan2(imagf,realf);

% normalization theat to [0,pi]

dhist=zeros(1,180);

%round dot of the pol

x0=w/2; y0=h/2;

for i=1:w

for j=1:h

temp=atan2(j-y0,i-x0);

if(temp<0)

temp=temp+pi;

end

temp=mod(round(temp*180/pi),180);

dhist(temp+1)=dhist(temp+1)+pfa(i,j);

end

end

dsp=[0:5:170;10:5:180];

hist=zeros(1,36);

for i=1:180

for k=1:35

if(i>dsp(1,k) && i<=dsp(2,k))

hist(k)=hist(k)+dhist(i);

end

end

end

[mhist,mdex]=max(hist);

end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值