I am trying to implement a binary image matching algorithm. And I need to generate the C matrix given below. Given a small pattern image A, I need to match it to large image row-by-row and column-by-column, to find the location where that pattern matches the most.
Given M x M sized pattern A:
0 0 1
0 1 1
1 1 1
and N x N sized input image B:
0 0 0 0 0 1 0 0
0 0 0 0 1 1 0 0
0 0 0 1 1 1 0 0
0 0 0 0 0 0 0 0
1 1 1 0 0 0 1 0
0 0 0 0 0 0 1 0
0 0 0 1 1 1 1 0
0 0 0 0 0 0 0 0
the N x N sized output image C is the similarity of A with B at each row and column of B. Therefore C:
0 0 0 0 0 0 0 0
0 3 4 6 9 4 2 0
0 3 4 6 4 1 1 0
0 6 6 4 2 2 3 0
0 4 3 2 3 5 5 0
0 2 2 4 6 8 5 0
0 3 4 5 4 5 2 0
0 0 0 0 0 0 0 0
I am at stuck at the point where I need to compare the matrix A with B. I have made them as 2D arrays.
This is what I have done so far
for (int i = 0; i <3 ; i++)
{
for (int j = 0; j<3; j++)
{
for (int k = 0; k < 8; i++)
{
for (int s = 0; s < 8; j++)
{
if (A[i][j] == B[k][s])
{
count++;
}
}
}
}