📄 imoments.m
字号:
%IMOMENTS Compute image moments%% [F,M] = IMOMENTS(image)%% [F,M] = IMOMENTS(rows, cols)% [F,M] = IMOMENTS(rows, cols, w)%% The first form computes the grey-scale moments of the image (non-zero % elements) image. The actual pixel values are used as pixel weights.% The return vector is F = [area xc yc a b theta] where:% area is the number of pixels (for a binary image)% (xc, yc) is the centroid with respect to top-left point which% is (1,1)% (a, b) are axis lengths of the "equivalent ellipse"% theta the angle of the major ellipse axis to the % horizontal axis.%% The raw moments can also be returned M = [m00 m10 m01 m20 m02 m11].%% The second form is used when the coordinates of the non-zero elements % are known.%% NOTE: this function does not perform connectivity, if connected blobs% are required then the ILABEL function must be used first.%% SEE ALSO: ilabel%% Copyright (c) Peter Corke, 1999 Machine Vision Toolbox for Matlab% 1996 Peter Corkefunction [F,M] = imoments(a1, a2, a3) if nargin == 1, [i,j] = find(a1) w = a1(find(a1 > 0)) else i = a1; j = a2; if nargin == 3, w = a3; else w = ones(size(i)); end end % compute basic moments m00 = sum(w); m10 = sum(j.*w); m01 = sum(i.*w); m20 = sum((j.^2).*w); m02 = sum((i.^2).*w); m11 = sum((i.*j).*w); % figure some central moments u20 = m20 - m10^2/m00; u02 = m02 - m01^2/m00; u11 = m11 - m10*m01/m00; % figure the equivalent axis lengths, function of the principal axis lengths e = eig([u20 u11; u11 u02]); a = 2*sqrt(max(e)/m00); b = 2*sqrt(min(e)/m00); th = 0.5*atan(2*u11/(u20-u02)); F = [m00 m10/m00 m01/m00 a b th]; if nargin > 1, M = [m00 m10 m01 m20 m02 m11]; end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -