matlab humoments,humoments.m · zigzag2015/machinevision-toolbox-matlab - Gitee.com

该博客介绍了如何使用Hu矩来计算二值图像的不变矩,这是计算机视觉中的一种模式识别技术。Hu矩是从图像的二阶和三阶矩导出的七个不变量,对于形状分析特别有用。代码示例展示了如何在MATLAB中实现这一计算过程。
摘要由CSDN通过智能技术生成

%HUMOMENTS Hu moments

%

% PHI = HUMOMENTS(IM) is the vector (1x7) of Hu moment invariants for the binary

% image IM.

%

% Notes::

% - IM is assumed to be a binary image of a single connected region

%

% Reference::

% M-K. Hu,

% Visual pattern recognition by moment invariants.

% IRE Trans. on Information Theory, IT-8:pp. 179-187, 1962.

%

% See also NPQ.

% Copyright (C) 1993-2011, by Peter I. Corke

%

% This file is part of The Machine Vision Toolbox for Matlab (MVTB).

%

% MVTB is free software: you can redistribute it and/or modify

% it under the terms of the GNU Lesser General Public License as published by

% the Free Software Foundation, either version 3 of the License, or

% (at your option) any later version.

%

% MVTB is distributed in the hope that it will be useful,

% but WITHOUT ANY WARRANTY; without even the implied warranty of

% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

% GNU Lesser General Public License for more details.

%

% You should have received a copy of the GNU Leser General Public License

% along with MVTB. If not, see .

function phi = humoments(im)

% second moments

eta_20 = npq(im, 2, 0);

eta_02 = npq(im, 0, 2);

eta_11 = npq(im, 1, 1);

% third moments

eta_30 = npq(im, 3, 0);

eta_03 = npq(im, 0, 3);

eta_21 = npq(im, 2, 1);

eta_12 = npq(im, 1, 2);

phi = zeros(1,7);

phi(1) = eta_20 + eta_02;

phi(2) = (eta_20 - eta_02)^2 + 4*eta_11^2;

phi(3) = (eta_30 - 3*eta_12)^2 + (3*eta_21 - eta_03)^2;

phi(4) = (eta_30 + eta_12)^2 + (eta_21 + eta_03)^2;

phi(5) = (eta_30 - 3*eta_12)*(eta_30+eta_12)* ...

((eta_30 +eta_12)^2 - 3*(eta_21+eta_03)^2) + ...

(3*eta_21 - eta_03)*(eta_21+eta_03)* ...

(3*(eta_30+eta_12)^2 - (eta_21+eta_03)^2);

phi(6) = (eta_20 - eta_02)*((eta_30 +eta_12)^2 - (eta_21+eta_03)^2) + ...

4*eta_11 *(eta_30+eta_12)*(eta_21+eta_03);

phi(7) = (3*eta_21 - eta_03)*(eta_30+eta_12)* ...

((eta_30 +eta_12)^2 - 3*(eta_21+eta_03)^2) + ...

(3*eta_12 - eta_30)*(eta_21+eta_03)*( 3*(eta_30+eta_12)^2 - (eta_21+eta_03)^2);

一键复制

编辑

Web IDE

原始数据

按行查看

历史

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值