[PYTHON] (Image processing) Petit Thinning --Filter that performs loose thinning processing

I wrote a filter that loosely thins the line art image with black lines drawn on a white background. The thinning is not for analysis such as extracting a 1-pixel line, but rather for practical use in the retouching software area. Along with thinning the lines, it also includes the aim of making several lines of different thicknesses as uniform as possible.

image

Source

Works with Python.

https://github.com/a-nakanosora/blender-scripts/blob/master/Image/Petit%20Thinning%20CLI/petit_thinning.py

You need Pillow to use it. (It is recommended to use Anaconda that includes this library from standard Python)

Addendum: In the first version, Numpy and Pillow were required for the external library, but with the improvement by @ pashango2, Pillow has been unified and speeded up. Many thanks! </ font>

How to use

$ python petit_thinning.py 6 0.95 5 input.png output.png

Command line arguments

petit_thinning.py <emptyrange> <emptythres> <dilation_max_depth> <path_in> [<path_out>] [-p]

It looks like this. ʻEmptyrange, ʻemptythres, dilation_max_depth are the parameters that change the effect of the filter.

  • ʻEmptyrange`: An integer greater than or equal to 1. A guideline for how smoothly each level of thinning is mixed
  • ʻEmptythres`: A real number in the range 0.0-1.0. The closer it is to 1.0, the stronger the effect of thinning the line, but the line tends to be interrupted.
  • dilation_max_depth: An integer greater than or equal to 1. By specifying a large number, it is possible to make thicker lines thinner, but if the lines are too thick, noise tends to occur.
  • path_in: Input file path
  • path_out: Output file path. If omitted, the input path name with _out at the end will be used.
  • -p flag: Print various parameters and calculation time

Basically, if ʻempty rangeis set to a value larger thandilation_max_depth, noise will be reduced, but the degree of thinning will also be reduced. It is safe to set dilation_max_depth to about 5`.

Basic principle

I'm just doing some dilation of the morphology filter and synthesizing them.

  • Perform several stages of dilation on the input image and stock the results of each.
  • Select the image with the highest dilation depth, overwrite the blank part where there is no line with an image with a shallow depth, and use it as the next image.
  • Perform the same process while increasing the depth one by one.

Recommended Posts

(Image processing) Petit Thinning --Filter that performs loose thinning processing
Image processing 100 knocks Q9, Q10 (filter) speedup
Image processing with Python 100 knock # 10 median filter
Image processing with Python 100 knock # 12 motion filter
Image processing with Python 100 knocks # 9 Gaussian filter
Image processing by Python 100 knock # 11 smoothing filter (average filter)
python image processing
Image processing 100 knocks ①