matchShapes: Compare Two Shapes

View source: R/shape.R

matchShapesR Documentation

Compare Two Shapes

Description

matchShapes computes the difference between two shapes using the Hu invariants.

Usage

matchShapes(x1, x2, method = "I1")

Arguments

x1

Either a Nx2 matrix of the X-Y coordinates of a polygon (e.g., a contour produced by findContours), or a single-channel Image object.

x2

Either a Nx2 matrix of the X-Y coordinates of a polygon (e.g., a contour produced by findContours), or a single-channel Image object.

method

The comparison method to compute the difference between the two shapes (see Notes; default: "I1").

Value

A numerical value.

Note

The available shape matching methods are defined as follows:

  • I_1(A,B) = \sum _{i=1...7} \left | \frac{1}{m^A_i} - \frac{1}{m^B_i} \right |

  • I_2(A,B) = \sum _{i=1...7} \left | m^A_i - m^B_i \right |

  • I_3(A,B) = \max _{i=1...7} \frac{ \left| m^A_i - m^B_i \right| }{ \left| m^A_i \right| }

where

  • A denotes x1, B denotes x2.

  • m^A_i = \mathrm{sign} (h^A_i) \cdot \log{h^A_i}

  • m^B_i = \mathrm{sign} (h^B_i) \cdot \log{h^B_i}

  • and h^A_i, h^B_i are the Hu invariants of A and B, respectively.

Author(s)

Simon Garnier, garnier@njit.edu

See Also

findContours, huInvariants

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]
contour1 <- contours$contours[contours$contours[, 1] == 1, 2:3]
matchShapes(contour0, contour1)


swarm-lab/Rvision documentation built on Feb. 7, 2024, 4:59 a.m.