source: birds/hu_moments.m @ 118

Last change on this file since 118 was 74, checked in by dtax, 11 years ago

More useful features for images.

  • Property svn:executable set to *
File size: 1.0 KB
Line 
1% M = HU_MOMENTS (IM)
2%
3% Calculates 7 moments of Hu on image IM, invariant to translation,
4% rotation and scale.
5%
6% After: M. Sonka et al., Image processing, analysis and machine vision.
7
8function m = hu_moments (im)
9
10        p = [ 1 0 2 1 2 0 3 ];
11        q = [ 1 2 0 2 1 3 0 ];
12
13  n = moments(im,p,q,1,1);
14   
15  m(1) = n(2) + n(3);
16  m(2) = (n(3) - n(2))^2   + 4*n(1)^2;
17  m(3) = (n(7) - 3*n(4))^2 + (3*n(5) - n(6))^2;
18  m(4) = (n(7) +   n(4))^2 + (  n(5) + n(6))^2;
19  m(5) = (  n(7) - 3*n(4)) * (n(7) + n(4)) * ...
20           (  (n(7) + n(4))^2 - 3*(n(5) + n(6))^2) + ...
21         (3*n(5) -   n(6)) * (n(5) + n(6)) * ...
22           (3*(n(7) + n(4))^2 -   (n(5) + n(6))^2);
23  m(6) = (n(3) - n(2)) * ((n(7) + n(4))^2 - (n(5) + n(6))^2) + ...
24          4*n(1) * (n(7)+n(4)) * (n(5)+n(6));     
25  m(7) = (3*n(5) -   n(6)) * (n(7) + n(4)) * ...
26           (  (n(7) + n(4))^2 - 3*(n(5) + n(6))^2) - ...
27         (  n(7) - 3*n(4)) * (n(5) + n(6)) * ...
28           (3*(n(7) + n(4))^2 -   (n(5) + n(6))^2);
29           
30return;
31
Note: See TracBrowser for help on using the repository browser.