matchShapes | R Documentation |
matchShapes
computes the difference between two shapes
using the Hu invariants.
matchShapes(x1, x2, method = "I1")
x1 |
Either a Nx2 matrix of the X-Y coordinates of a polygon (e.g., a
contour produced by |
x2 |
Either a Nx2 matrix of the X-Y coordinates of a polygon (e.g., a
contour produced by |
method |
The comparison method to compute the difference between the two shapes (see Notes; default: "I1"). |
A numerical value.
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.
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]
contour1 <- contours$contours[contours$contours[, 1] == 1, 2:3]
matchShapes(contour0, contour1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.