Problem 46028. Paint it black!

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

28.57% Correct | 71.43% Incorrect
Last Solution submitted on Oct 12, 2023

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers2

Suggested Problems

More from this Author5

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!