4
$\begingroup$

enter image description here

I have two matrix A and B, I want to find pattern B in matrix A. So I get 2 pattern similar like pattern B. What the name of this operation? and How I write this in mathematics notation?

Thank you in advance

$\endgroup$
  • 7
    $\begingroup$ Assuming everything is binary, you compute the spatial convolution of $A$ under filter $B$, and are counting the number of times the convolution is at least the sum of the elements in $B$. $\endgroup$ – cdipaolo Jan 28 at 1:12
  • 1
    $\begingroup$ Concerning the comment/answer by @cdipaolo: Beware that a convolution flips the kernel with respect to the midoint du to the minus-sign in the definition of the convolution. This is not a problem for your particular kernel B, but other patterns need to be point mirrored before applying the convolution. $\endgroup$ – cdalitz Jan 30 at 8:12
2
$\begingroup$

You are looking for Chamfer-Matching: it will yield a zero value at all center points where the pattern occurs.

Ordinary template matching (aka cross correlation) does not work in your case, because that would also consider the white points of the template, not only the black points. Chamfer-Matching, instead, only sums the distance transform values of A at the black points of B. If '1' stands for black, and D is the distance transform of A, and B is centered such that its midpoint has coordinate $(0,0))$, then Chamfer-Matching computes the following image C:

$$C(x,y) = \sum_{dx,dy} D(x+dx, y+dy)\cdot B(dx, dy)$$

| cite | improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.