How to find bounding rectangle?
Posted: 2019-05-03T11:43:00-07:00
Hello. I'm trying to extract the topleftmost subimage from an image. Nothing is known about the image at the time of processing, but it is in the same general format and has an alpha layer. The image is a kind of a mosaic, but there is no pattern to where subimages are placed.
In my first attempt, I tried to find X and Y (width and height) by trying looking for X number of fully transparent pixels at Xx1+0+X and then Y number of fully transparent pixels at 1xY+Y+0. If either of these fails, it tries again, but FOUND_Xx1+0+X and 1xFOUND_Y+Y+0. This recalculates with the actual width or height instead of looking with height and width equal.
Now this new case has me stumped. I'm not able to find either width or height with my algorithm.
Here are screenshots of bounding squares for width and height. 1 pixel off from actual content because it is checking for transparent pixels.
How should I proceed?
In my first attempt, I tried to find X and Y (width and height) by trying looking for X number of fully transparent pixels at Xx1+0+X and then Y number of fully transparent pixels at 1xY+Y+0. If either of these fails, it tries again, but FOUND_Xx1+0+X and 1xFOUND_Y+Y+0. This recalculates with the actual width or height instead of looking with height and width equal.
Now this new case has me stumped. I'm not able to find either width or height with my algorithm.
Here are screenshots of bounding squares for width and height. 1 pixel off from actual content because it is checking for transparent pixels.
How should I proceed?