码迷,mamicode.com
首页 > 其他好文 > 详细

Hu矩

时间:2016-06-24 14:29:27      阅读:277      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

技术分享

技术分享
close all;
clear all;
I1=imread(lena.bmp);
angle=30;
T=[cos(angle),sin(angle),0;-sin(angle),cos(angle),0;0,0,1];
t1 = maketform(affine,T);
I2 = imtransform(I1,t1,bilinear,fill,0);%旋转
I2=imresize(I2,0.5);%缩放
figure;
imshow(I1);
figure;
imshow(I2);
H1=Humoment(I1)
H2=Humoment(I2)
View Code
技术分享
function Hu = Humoment(I)
I=double(I);
m00=sum(sum(I));
m10=0;m01=0;
[row,col]=size(I);
for i=1:row
    for j=1:col
        m10=m10+i*I(i,j);
        m01=m01+j*I(i,j);
    end
end
xb=m10/m00;%重心坐标
yb=m01/m00;

%中心距
u02 = 0;u03 = 0;u11 = 0;u12 = 0;u20 = 0;u21 = 0;u30 = 0;
for i=1:row
    for j=1:col        
        u02=u02+(j-yb)^2*I(i,j);
        u03=u03+(j-yb)^3*I(i,j);
        u11=u11+(i-xb)*(j-yb)*I(i,j);
        u12=u12+(i-xb)*(j-yb)^2*I(i,j);
        u20=u20+(i-xb)^2*I(i,j);
        u21=u21+(i-xb)^2*(j-yb)*I(i,j);
        u30=u30+(i-xb)^3*I(i,j);
    end
end

%归一化中心距
n02=u02/m00^2;
n03=u03/m00^2.5;
n11=u11/m00^2;
n12=u12/m00^2.5;
n20=u20/m00^2;
n21=u21/m00^2.5;
n30=u30/m00^2.5;        

%Hu矩
h1 = n20 + n02;                     
h2 = (n20-n02)^2 + 4*(n11)^2;
h3 = (n30-3*n12)^2 + (3*n21-n03)^2;  
h4 = (n30+n12)^2 + (n21+n03)^2;
h5 = (n30-3*n12)*(n30+n12)*((n30+n12)^2-3*(n21+n03)^2)+(3*n21-n03)*(n21+n03)*(3*(n30+n12)^2-(n21+n03)^2);
h6 = (n20-n02)*((n30+n12)^2-(n21+n03)^2)+4*n11*(n30+n12)*(n21+n03);
h7 = (3*n21-n03)*(n30+n12)*((n30+n12)^2-3*(n21+n03)^2)-(3*n12-n30)*(n21+n03)*(3*(n30+n12)^2-(n21+n03)^2);
Hu = [h1 h2 h3 h4 h5 h6 h7];   
View Code

结果:

对于两图像做测试,其中第二幅是第一幅旋转30度并缩小到1/4大小:

技术分享技术分享

上述两幅图计算出的Hu矩都为:

 0.0012    0.0000    0.0000    0.0000   -0.0000   -0.0000    0.0000

Hu矩

标签:

原文地址:http://www.cnblogs.com/luo-peng/p/5613634.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!