moments | R Documentation |
moments
calculates all of the moments up to the third
order of a polygon or rasterized shape.
moments(x, binary = FALSE)
x |
Either a Nx2 matrix of the X-Y coordinates of a polygon (e.g., a
contour produced by |
binary |
If set to TRUE (default: FALSE), all non-zero image pixels are treated as 1's. The parameter is used for images only. |
A data frame with 2 columns:
the name of the moment. See Note below.
the value of the moment.
The spatial moments m_{ji}
are computed as:
m_{ji}= \sum _{x,y} \left ( \texttt{contour} (x,y) \cdot x^j \cdot y^i \right )
The central moments \mu_{ji}
are computed as:
{\mu_{ji}}= \sum _{x,y} \left ( \texttt{contour} (x,y) \cdot (x - \bar{x} )^j \cdot (y - \bar{y} )^i \right )
where (\bar{x}, \bar{y})
is the mass center:
\bar{x} = \frac{m_{10}}{m_{00}} , \; \bar{y} = \frac{m_{01}}{m_{00}}
The normalized central moments \eta_{ji}
are computed as:
\eta_{ji}= \frac{\mu_{ji}}{m_{00}^{(i+j)/2+1}} .
Simon Garnier, garnier@njit.edu
findContours
, huInvariants
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]
moments(contour0)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.