I'm trying to find the most white-space (maximum white pixels) in a any rectangle of an image that I will overlay with another smaller image. The rectangle's dimensions are X pixels by Y pixels as dictated by the size of the overlay image (Height, Width).
At the moment the only solution I have is to try every pixel as the TLC of the overlay image and count how many white pixels would be underneath. Once I have the maximum I can position the overlay images.
For example, given a fixed submatrix size of 2x2 and this array: -
int[,] arr = { { 1, 1, 1, 1, 0 },
{ 0, 1, 0, 0, 1 },
{ 1, 0, 1, 1, 1 },
{ 1, 0, 1, 1, 0 } };
I want to the max result to be 4 and the coordinates to be 2,2
The problem, needless to say, this is extremely inefficient :-(
I tried Kadane's algorithm but that only seems to work on disparate values and even then produces a variable size sub-matrix.
Any ideas? Better Algorithms?
I'll count the whitespace in the (0,0) TLC rectangle then just subtract the out of viewport col or row and add the new row or col as the overlay rectangle moves over the base image.