0

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.

McMurphy
  • 1,235
  • 1
  • 15
  • 39
  • I don't understand what's the question. Isn't the rectangle that contains the maximum number of white pixels the whole image? – user202729 Feb 12 '21 at 03:46
  • Yes but I want to get the *fixed* dimensioned maximum. That is "Give me the OffsetTop and OffsetLeft of the pixel that would yield the greatest 100x100 white-space given the underlying image is 1000x800 pixels. – McMurphy Feb 12 '21 at 03:52
  • So are you saying, you have 2 images, want to combine them together, then find the maximum amount of white pixels in a rectangle sized (x,y), in the whole image? – TheGeneral Feb 12 '21 at 03:54
  • No. Just give me the TLC of the 100x100 pixel rectangle on image A that has the most white space of all of the possible 100x100 rectangles. – McMurphy Feb 12 '21 at 03:57
  • Define "*TLC*" ? – TheGeneral Feb 12 '21 at 04:04
  • Top, Left, Corner - Manifesting itself in the pixel offset left and pixel offset top from the base images pixel (0,0) – McMurphy Feb 12 '21 at 04:07
  • (it's recommended that you specify the question in both the question and the title. I see that in the first revision you only explain the "fixed subrectangle size" part in the title) – user202729 Feb 12 '21 at 06:20

0 Answers0