资源简介
基于MATLAB的树叶图像特征分类识别,图像分析处理 分割 特征提取 分类识别等
代码片段和文件信息
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);
%-------------------------------------------------------------------%
function e = compute_eta(m)
% DIP equations (11.3-14) through (11.3-16).
xbar = m.m10 / m.m00;
ybar = m.m01 / m.m00;
e.eta11 = (m.m11 - ybar*m.m10) / m.m00^2;
e.eta20 = (m.m20 - xbar*m.m10) / m.m00^2;
e.eta02 = (m.m02 - ybar*m.m01) / m.m00^2;
e.eta30 = (m.m30 - 3 * xbar * m.m20 + 2 * xbar^2 * m.m10) / m.m00^2.5;
e.eta03 = (m.m03 - 3 * ybar * m.m02 + 2 * ybar^2 * m.m01) / m.m00^2.5;
e.eta21 = (m.m21 - 2 * xbar * m.m11 - ybar * m.m20 + ...
2 * xbar^2 * m.m01) / m.m00^2.5;
e.eta12 = (m.m12 - 2 * ybar * m.m11 - xbar * m.m02 + ...
2 * ybar^2 * m.m10) / m.m00^2.5;
%-------------------------------------------------------------------%
function phi = compute_phi(e)
% DIP equations (11.3-17) through (11.3-23).
phi(1) = e.eta20 + e.eta02;
phi(2) = (e.eta20 - e.eta02)^2 + 4*e.eta11^2;
phi(3) = (e.eta30 - 3*e.eta12)^2 + (3*e.eta21 - e.eta03)^2;
phi(4) = (e.eta30 + e.eta12)^2 + (e.eta21 + e.eta03)^2;
phi(5) = (e.eta30 - 3*e.eta12) * (e.eta30 + e.eta12) * ...
( (e.eta30 + e.eta12)^2 - 3*(e.eta21 + e.eta03)^2 ) + ...
(3*e.eta21 - e.eta03) * (e.eta21 + e.eta03) * ...
( 3*(e.eta30 + e.eta12)^2 - (e.eta21 + e.eta03)^2 );
phi(6) = (e.eta20 - e.eta02) * ( (e.eta30 + e.eta12)^2 - ...
(e.eta21 + e.eta03)^2 ) + ...
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2012-12-21 20:44 新建文件夹\
文件 3319 2012-12-12 15:37 新建文件夹\invmoments.m
文件 1209 2012-12-21 20:42 新建文件夹\TASK2.m
文件 5617342 2012-12-05 20:26 新建文件夹\test.tif
文件 573 2012-12-16 14:56 新建文件夹\train.m
文件 570 2012-12-16 15:29 新建文件夹\train2.m
文件 564 2012-12-16 16:10 新建文件夹\train3.m
文件 456772 2006-12-29 18:54 新建文件夹\train_1.tif
文件 98456 2006-12-29 19:11 新建文件夹\train_2.tif
文件 1156394 2006-12-30 16:11 新建文件夹\train_3.tif
评论
共有 条评论