is there any additional information that you know about images that can be used for help?
How do images start white and then black and then black? or can any pixel be white or black, and the fact that any of them is white or black does not say anything about the others?
If any pixel can be white or black regardless of other pixels, then I donβt see how you can do much better than checking each pixel in a loop until you find the first one not white ...
If you know that if the fifth pixel on the left is white, then 0-4 is definitely white, and then you can check for fewer pixels instead using some kind of modified binary type (as you could skip checking 0-4 in in this case and just say 5, then 10, and if 5 is white and 10 is black, you know that the point is somewhere between 5-10, so you can divide the difference and check 7, etc., Until find the point at which they change.)
I think you can get a compromise between speed and accuracy here. The most accurate way is to cut each column and row, starting at the end, checking each pixel. Once you find the hit in the column, you find the edge on one side. This can be done in parallel, since each check is independent. you may be able to speed it up, as you said, by checking only every nth pixel, but this will most likely happen with cropping, especially with such a large dataset. it may or may not be acceptable. you can improve this by checking around the area in which you find a match to verify that the match is correct. Therefore, if you check every third pixel and find hit in pixel 15, then check 14 to see if this is a hit (and 13 if 14). using this, you can get away with fewer checks.
source share