资源简介

invariant moments of image phi = invmoments(F) F为读取的图像矩阵,phi中保存了7个hu不变矩 % Copyright 2002-2004 R. C. Gonzalez, R. E. Woods, & S. L. Eddins % Digital Image Processing Using MATLAB, Prentice-Hall, 2004 % $Revision: 1.5 $ $Date: 2003/11/21 14:39:19 $

资源截图

代码片段和文件信息

function phi = invmoments(F)
%INVMOMENTS Compute invariant moments of image.
%   PHI = INVMOMENTS(F) computes the moment invariants of the image
%   F. PHI is a seven-element row vector containing the moment
%   invariants as defined in equations (11.3-17) through (11.3-23) of
%   Gonzalez and Woods Digital Image Processing 2nd Ed.
%
%   F must be a 2-D real nonsparse numeric or logical matrix.

%   Copyright 2002-2004 R. C. Gonzalez R. E. Woods & S. L. Eddins
%   Digital Image Processing Using MATLAB Prentice-Hall 2004
%   $Revision: 1.5 $  $Date: 2003/11/21 14:39:19 $

if (ndims(F) ~= 2) | issparse(F) | ~isreal(F) | ~(isnumeric(F) | ...
                                                    islogical(F))
   error([‘F must be a 2-D real nonsparse numeric or logical ‘ ...
          ‘matrix.‘]); 
end

F = double(F);

phi = compute_phi(compute_eta(compute_m(F)));
  
%-------------------------------------------------------------------%
function m = compute_m(F)

[M N] = size(F);
[x y] = meshgrid(1:N 1:M);
  
% Turn x y and F into column vectors to make the summations a bit
% easier to compute in the following.
x = x(:);
y = y(:);
F = F(:);
  
% DIP equation (11.3-12)
m.m00 = sum(F);
% Protect against divide-by-zero warnings.
if (m.m00 == 0)
   m.m00 = eps;
end
% The other central moments:  
m.m10 = sum(x .* F);
m.m01 = sum(y .* F);
m.m11 = sum(x .* y .* F);
m.m20 = sum(x.^2 .* F);
m.m02 = sum(y.^2 .* F);
m.m30 = sum(x.^3 .* F);
m.m03 = sum(y.^3 .* F);
m.m12 = sum(x .* y.^2 .* F);
m.m21 = sum(x.^2 .* y .* F);

%-------------------------------------------------------------------%

评论

共有 条评论