Sorry that was wrong assumption == non-sense. So another idea.
If the white mask of the water would contain empty places, would you perform compare (slow) or could you perform a search of rectangle inside the white area? Let's have this mask as a result of some search of water surface. Let's suppose that the water surface is light blue while the rectangles are dark blue so they are not in the mask. Well, I could use this mask, but it is not perfect because it contains gaps. I do not want to expand and contract because that is problematic. Is it possible to locate these black rectangles inside white areas - I mean not to search complete image but only the white part. Does compare.exe search complete image? I think it does. And that would be not effective.
It is the similar thing like here with routes:
viewtopic.php?f=1&t=29791
Check the last post with these images:
https://1.bp.blogspot.com/-66QdLjN0SDc/ ... y_mask.gif
extend makes problematic result - you would see 1 route instead 2 routes:
https://3.bp.blogspot.com/-6RuP5XZ65gE/ ... old_40.png
or black rectangles would stay in mask if we make less blur
https://1.bp.blogspot.com/-_RFXLBfMf_I/ ... blur_2.png
Here is example of such surface:
https://4.bp.blogspot.com/-zXbhxlS2fHw/ ... /map_2.png
So when I did the search of some surface, I have gaps there.
Making standard compare search is slow because it will search all pixels black and white. But if we would search only for white area and then check the areas within the outer borders of the white, then hopefully we could get better performance using shape search.