1
$\begingroup$

I have this degraded image :

enter image description here

Using paintbucket tool in Paint.NET Windows application, I fill the character image black.

enter image description here

My questions are :

  1. What algorithm can we use to fill up the holes within the character image?
  2. Is there any corresponding built-in function in Python that fills up the white holes in a character image?
  3. What probable algorithm does the paint bucket tool in Paint.Net uses ?

Thanks.

$\endgroup$
  • 2
    $\begingroup$ Looks like median filter docs.scipy.org/doc/scipy/reference/generated/… $\endgroup$ – Gideon Genadi Kogan Jun 14 '20 at 7:05
  • 1
    $\begingroup$ The easiest way to go would be to use morphological operations (closing, area closing). Scikit image should have those implemented. $\endgroup$ – jojek Jun 14 '20 at 9:59
  • $\begingroup$ @alyssaeliyah, Could you please review my answer? $\endgroup$ – Royi Dec 16 '20 at 5:20
2
$\begingroup$

Based on the blog post - The Paint Bucket in Paint.Net 4.0 (Video) I can tell it uses some edge detection to handle similar colors within a piece wise smooth area.
More information is given in the Paint Bucket Tool documentation.

Usually the way it can be implemented is by defining color metric. How far a color is form another color. If it within the tolerance, it is within the mask.

  1. Morphological operation can fill small holes.
  2. I am not sure, but it won't be too hard to implement something similar.
  3. Probably they convert the RGB data to HSL / HSV Color Model. Then just create a mask based on the distance between the reference point to the surrounding colors. Now the mask creates a logical (Black and White) mask to be filled.
    In case of Paint.NET the algorithm should be something like Flood Fill.

So the steps are:

  1. Convert image to the Color Model of choice (HSV / HSL or even LAB).
  2. Generate a mask using color similarity (Distance Function) on the Color Model. The distance function is parameterized by some Threshold parameter.
  3. Use Flood Fill like algorithm to fill the pixels in the mask using the target color. The mask is basically the stopping condition for the Flood Fill operation.

In MATLAB you have imfill() and Flood Fill.
For something more advanced you may use adaptive morphological functions like Active Contours and Morphological Snakes.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.