# jlopezv0401/ocr

### Subversion checkout URL

You can clone with
or
.
Fetching contributors…
Cannot retrieve contributors at this time
92 lines (76 sloc) 3.25 KB
 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 ) + ... 4 * e.eta11 * (e.eta30 + e.eta12) * (e.eta21 + e.eta03); phi(7) = (3*e.eta21 - e.eta03) * (e.eta30 + e.eta12) * ... ( (e.eta30 + e.eta12)^2 - 3*(e.eta21 + e.eta03)^2 ) + ... (3*e.eta12 - e.eta30) * (e.eta21 + e.eta03) * ... ( 3*(e.eta30 + e.eta12)^2 - (e.eta21 + e.eta03)^2 ); ...
Something went wrong with that request. Please try again.