其他分享
首页 > 其他分享> > Hu不变矩

Hu不变矩

作者:互联网

模式识别课期末作业:静态手势识别

特征向量:Hu不变矩

代码:

function [data_vec]= mat2vector_bbj(data,sample_num)     
%  mat2vector_bbj.m 
% 输入:图片数据(矩阵),样本个数 
% 函数作用:提取Hu不变矩,每个向量作为一张图片的特征 
% 输出:样本数*图片像素数量大小的矩阵   
for i = 1 : sample_num
    I=data(:,:,i);
    [x,y]=meshgrid(1:M,1:N);
    x=x(:);
    y=y(:);
    I=I(:);
    m00=sum(I);
    m10=sum(x.* I);
    m01=sum(y.* I);
    xcenter=m10/m00;
    ycenter=m01/m00;

% 计算归一化的各阶中心矩,具有平移不变性和伸缩不变性
    cm00=m00;
    cm02=sum((y-ycenter).^2.*I)/(m00^2);
    cm11=sum((x-xcenter).*(y-ycenter).*I)/(m00^2);
    cm12=sum((x-xcenter).*(y-ycenter).^2.*I)/(m00^2.5);
    cm21=sum((x-xcenter).^2.*(y-ycenter).*I)/(m00^2.5);
    cm03=sum((y-ycenter).^3.*I)/(m00^2.5);
    cm30=sum((x-xcenter).^3.*I)/(m00^2.5);
    cm20=sum((x-xcenter).^2.*I)/(m00^2);

%计算七个不变矩
    data_vec(i,1)=abs(log(cm20+cm02));
    data_vec(i,2)=abs(log((cm20-cm02)^2+4*cm11^2));
    data_vec(i,3)=abs(log((cm30-3*cm12)^2+(3*cm21-cm03)^2));
    data_vec(i,4)=abs(log((cm30+cm12)^2+(cm21+cm03)^2));
    data_vec(i,5)=abs(log((cm30-3*cm12)*(cm30+cm12)*((cm30+cm12)^2-3*(cm21+cm03)^2)+(3*cm21-cm03)*(cm21+cm03)*(3*(cm30+cm12)^2-(cm21+cm03)^2)));
    data_vec(i,6)=abs(log((cm20-cm02)*((cm30+cm12)^2-(cm21+cm03)^2)+4*cm11*(cm30-cm12)*(cm21+cm03)));
    data_vec(i,7)=abs(log((3*cm21-cm02)*(cm21+cm30)*((cm30+cm12)^2-3*(cm21+cm03)^2)-(cm30-3*cm12)*(cm21+cm03)*(3*(cm30+cm12)^2-(cm21+cm03)^2)));
end
end 

标签:cm12,cm03,cm30,sum,cm21,m00,Hu,不变
来源: https://blog.csdn.net/weixin_46141330/article/details/118228414