huInvariants
calculates the seven original Hu moments
invariants plus an additional one discovered by Suk & Flusser (2011), from
the moments of a polygon or rasterized shape.
Arguments
- moments
A data frame as produced by
moments
.
Value
A data frame with 2 columns:
- "invariant":
the name of the invariant See Note below.
- "value":
the value of the invariant.
Note
The Hu invariants are defined as:
\(\texttt{Hu1}= \eta _{20}+ \eta _{02}\)
\(\texttt{Hu2}= ( \eta _{20}- \eta _{02})^{2}+4 \eta _{11}^{2}\)
\(\texttt{Hu3}= ( \eta _{30}-3 \eta _{12})^{2}+ (3 \eta _{21}- \eta _{03})^{2}\)
\(\texttt{Hu4}= ( \eta _{30}+ \eta _{12})^{2}+ ( \eta _{21}+ \eta _{03})^{2}\)
\(\texttt{Hu5}= ( \eta _{30}-3 \eta _{12})( \eta _{30}+ \eta _{12})[( \eta _{30}+ \eta _{12})^{2}-3( \eta _{21}+ \eta _{03})^{2}]+(3 \eta _{21}- \eta _{03})( \eta _{21}+ \eta _{03})[3( \eta _{30}+ \eta _{12})^{2}-( \eta _{21}+ \eta _{03})^{2}]\)
\(\texttt{Hu6}= ( \eta _{20}- \eta _{02})[( \eta _{30}+ \eta _{12})^{2}- ( \eta _{21}+ \eta _{03})^{2}]+4 \eta _{11}( \eta _{30}+ \eta _{12})( \eta _{21}+ \eta _{03})\)
\(\texttt{Hu7}= (3 \eta _{21}- \eta _{03})( \eta _{21}+ \eta _{03})[3( \eta _{30}+ \eta _{12})^{2}-( \eta _{21}+ \eta _{03})^{2}]-( \eta _{30}-3 \eta _{12})( \eta _{21}+ \eta _{03})[3( \eta _{30}+ \eta _{12})^{2}-( \eta _{21}+ \eta _{03})^{2}]\)
\(\texttt{Hu8}= \eta_ {11}[(\eta_ {30}+ \eta_ {12})^{2}-(\eta_ {03}+ \eta_ {21})^{2}]- (\eta_ {20}+ \eta_ {02})(\eta_ {30}+ \eta_ {12})(\eta_ {03}+ \eta_ {21}) \)
where \(\eta_{ji}\) corresponds to the normalized central moments as
computed by moments
.
Author
Simon Garnier, garnier@njit.edu
Examples
dots <- image(system.file("sample_img/dots.jpg", package = "Rvision"))
dots_gray <- changeColorSpace(dots, "GRAY")
dots_bin <- dots_gray < 200
contours <- findContours(dots_bin)
contour0 <- contours$contours[contours$contours[, 1] == 0, 2:3]
m <- moments(contour0)
huInvariants(m)
#> invariant value
#> 1 Hu1 1.597929e-01
#> 2 Hu2 1.250640e-04
#> 3 Hu3 7.013610e-06
#> 4 Hu4 2.823565e-08
#> 5 Hu5 7.706373e-15
#> 6 Hu6 3.083771e-10
#> 7 Hu7 6.697342e-15
#> 8 Hu8 2.173912e-09