Flood fill is the algorithm used by bucket-fill tools in many image editors. The idea is that all connected pixels with the input color should have it changed to an output color starting at a pixel P = (x,y). Your task is to implement this algorithm replacing all colors within some tolerance (distance) from the input color with black.

For instance:

if the input_color=9, tolerance = 0, and P=[1,1], then the following grayscale image,

9 9 9 2 9
9 9 9 2 9
2 2 2 9 9 
9 9 9 9 9

becomes,

0 0 0 2 9
0 0 0 2 9
2 2 2 9 9 
9 9 9 9 9

Assume that all pixels have 4-neighborhoods. And use the Manhattan distance to decide if a color, a 1xn vector, is within tolerance.

Solution Stats

8 Solutions

2 Solvers

Last Solution submitted on Oct 30, 2024

Last 200 Solutions

Problem Comments

Solution Comments

Show comments
Loading...