Learn R Programming

Rvision (version 0.6.0)

moments: Calculate the Moments of a Shape

Description

moments calculates all of the moments up to the third order of a polygon or rasterized shape.

Usage

moments(contours, id = NULL)

Arguments

contours

A list of two matrices as produced by findContours.

id

An optional vector indicating the identity of the specific contours for which to run the function.

Value

A data frame with 3 columns:

  • "id": the contour identity (indicates the set of points belonging to the same contour).

  • "moment": the name of the moment. See Note below.

  • "value": the value of the moment.

See Also

findContours

Examples

Run this code
# NOT RUN {
dots <- image(system.file("sample_img/dots.jpg", package = "Rvision"))
dots_gray <- changeColorSpace(dots, "GRAY")
dots_bin <- dots_gray < 200
contours <- findContours(dots_bin)
moments(contours, id = c(3, 5))

# }

Run the code above in your browser using DataLab