Hello,

I'm trying to determine where a small matrix would fit inside a big matrix.. But, the small matrix is not in the big matrix so I need to see how simular they are.. The one with the lowest value, is the best fit..

So my difference function is this:

```
float difference(int row, int col, vector<double> &matrix2, vector<double>& background)
{
int matrix2_width = 2;
int matrix2_height = 2;
int background_width = 4;
int background_hight = 4;
int i=0;
int j=0;
float diffSum = 0;
float percentDiff = 0;
if(col+matrix2_width >= background_width || row+matrix2_height >= background_hight)
return 1;
for(int i=0; (i < matrix2_width); i++)
{
for(int j=0; (j < matrix2_height); j++)
{
int sum1 = background[(row+j)*background_width+(col+i)];
int sum2 = matrix2[j*matrix2_width+i];
diffSum += abs(sum1 - sum2);
}
}
percentDiff = diffSum/(matrix2_width*matrix2_height*255);
return percentDiff;
}
```

And the Algorithm that I'm using:

```
int mat1Rows(4), mat1Cols(4), mat2Rows(2), mat2Cols(2);
const int ROW_BOUNDS(mat1Rows-mat2Rows+1);
const int COL_BOUNDS(mat1Cols-mat2Cols+1);
for(int i=0; (i < ROW_BOUNDS); i++) {
for(int j=0; (j < COL_BOUNDS); j++) {
for (int row(0); row < mat2Rows; row++){
for (int col(0); col < mat2Cols; col++){
float corr = difference(i, j, matrix2, matrix1);
}
}
}
}
```

The only problem that I'm having is capturing the corrdiants of the matching block..

Could anyone offer any advice?

Thanks :)