得到图像的主方向(Matlab)
2016-09-01 09:58
253 查看
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
% 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
相关文章推荐
- matlab 得到三维图像的左视图以及主视图
- MATLAB 中怎么求图像在水平方向和垂直方向的像素和,用图表示
- 【信号、图像、Matlab】如何得到高斯滤波器的整数模板
- matlab中如何得到图像的坐标
- matlab中如何得到图像的坐标
- matlab中用imwrite()保存图像
- [置顶] 如何在c++ / opencv 中调用matlab 的图像数据
- MATLAB实现图像高帽和低帽变换
- DICOM格式的图像在MATLAB中处理
- 《Matlab 图像处理375例》
- 图像处理发展方向(资料搜集持续更新。。。)
- matlab 图像工具箱 Identifying Round Objects
- Matlab图像处理常用基本函数
- 数字图像处理]常见噪声的分类与Matlab实现
- 将matlab处理结果保存为图像文件
- MATLAB图像处理相关函数
- 灰度图像放大_matlab
- 使用MATLAB在图像中选择矩形框区域的操作函数即过程
- Matlab 图像的邻域和块操作
- 常用Matlab图像加噪方法