HU-MOMENTS
'nach Ming-Kuei Hu, "Visual Pattern Recognition by Moment Invariants",
(0) I[x,y]=Ortsintensität des Pixels, üblicherweise digitalisierte Intensität 0..127 = 0, 127..255=1
'Procedure HU_Moments :parameters Pic.raw = I(Zeile,Spalte)
(1) M = SUM(x, SUM(y, I[x,y]) ) 'Einfaches Moment (wäre Trägheitsmoment, wenn massebehaftet gedacht)
(2) M[i,j] = SUM(x, SUM(y, x^i*y^j*I[x,y]) ) 'Rohes Moment
(3) xm = M[1,0]/M_[0,0] ; ym = M[0,1]/M[0,0] 'Zentroid
(4) µ[i,j] = SUM(x, SUM(y, (x-xm)^i *(y-ym)^j *I[x,y]) ) 'Zentrales Moment
(5) eta[i,j] = µ[i,j] / ( µ[0,0]^((i+j)/2 +1) ) 'Skalennormiertes zentrales Moment
(6) Die 7 Hu-Momente: Translations-, Rotations- und Größenunabhängige Momente
'Def.: Hu Moments (Hu moment invariants) are a set of 7 numbers calculated
'using central moments that are invariant to image transformations.
'The first 6 moments have been proved to be invariant to
'translation, scale, and rotation, and reflection,
'while the 7th moment’s sign changes for image reflection.
h[0]=e[2,0]+e[0,2]
h[1]=(e[2,0]-e[0,2])^2+4*e[1,1]^2
h[2]=(e[3,0]-3*e[1,2])^2+(3*e[2,1]-e[0,3])^2
h[3]=(e[3,0]+e[1,2])^2+(e[2,1]+e[0,3])^2
h[4]=(e[3,0]-3*e[1,2])*(e[3,0]+e[1,2])*((e[3,0]+e[1,2])^2-3*(e[2,1]+e[0,3])^2)+(3*e[2,1]-e[0,3])*(3*(e[3,0]+e[1,2])^2-(e[2,1]+e[0,3])^2)
h[5]=(e[2,0]-e[02])*((e[3,0]+e[1,2])^2-(e[2,1]+e[0,3])^2+4*e[1,1]*(e[3,0]+e[1,2])*(e[2,1]+e[0,3]))
h[6]=(3*e[2,1]-e[0,3])*(e[3,0]+e[1,2])*( (e[3,0]+e[1,2])^2-3*(e[2,1]+e[0,3])^2 )+(e[3,0]-3*e[1,2])*(e[2,1]+e[0,3])*( 3*(e[3,0]+e[1,2])^2-(e[2,1]+e[0,3])^2 )
'h[6]=(3*e21 - e03 )*( e30 + e12 )*[ ( e30 + e12 )^2-3*( e21 + e03 )^2 ]+( e30 -3* e12 )*( e21 + e03 )*[ 3*( e30 + e12 )^2-( e21 + e03 )^2 ]
(7) H_ = -1*sign(h[i])*if(h[i]=0, 0, log(abs(h[i])) )'Log-Transformation
(8) Shape Matching using Hu Moments
'As mentioned earlier, all 7 Hu Moments are invariant under translations (move in x or y direction),
'scale and rotation. If one shape is the mirror image of the other, the seventh Hu Moment flips in sign.
'Isn’t that beautiful?: 6 images and their Hu Moments.
(9) Shape Matching
'Contour-Distance D2 between two shapes using matchShapes:
'How to use Hu Moments to find the distance between two shapes.
'If the distance is small, the shapes are close in appearance
'and if the distance is large, the shapes are farther apart in appearance.
(10) A,B sind Grauskalenbilder. D1,D2,D3 geben ähnliche Ergebnisse:
(Ein empfehlenswertes und bewährtes Konturendistanzmaß ist vor allem D2(A,B) )
D1(A,B) = SUM(i=0..6; abs(1/HB[i]-1/HA[i]) )
D2(A,B) = SUM(i=0..6; abs(HA[i]-HB[i]) ) 'empfohlen
D3(A,B) = SUM(i=0..6; abs(HA[i]-HB[i])/abs(HA[i]) )
(11) Individuelle Distanzmaße sind möglich, z.B. Euklidische Distanz:
'First, you calculate log transformed Hu Moments as mentioned in the previous section,
'and then calculate the distance yourself:
D(A,B) = sqrt(SUM(i=0..6;(HB[i]-HA[i])^2) 'Nachteil: Rechenintensiv
---