I need to perform a flood fill on a region of an image. However I do not actually need the resulting image, I only need to know the smallest rectangle containing all pixels that would be changed by the flood fill.
Is there a variant of a flood fill algorithm that can compute this rectangle more cheaply than doing a full flood fill?
Example input and output (only the red rectangle is required):
Edit: Example #2 with islands:
Example #3: