Search code examples
pythonopencvimage-processingcomputer-visionmathematical-morphology

How to reduce the width of lines in black and white images and make them thinner and smoother


I have a set of black and white images as shown below like Figure 1 and I want to have them with much smaller lines like Figure 2, even though no lines are missing as much as possible. I also tried morphological methods and algorithms like Canny with Python, but I did not get the result I wanted.

enter image description here Figure 1

enter image description here Figure 2


Solution

  • I think you are looking for skeletonization, see skimage.skeletonize, example here :

    import skimage.morphology
    import skimage.io
    import skimage.util
    import matplotlib.pyplot as plt
    img = skimage.io.imread('shoes.png')
    image = skimage.util.invert(img)
    image = image >125
    skel = skimage.morphology.skeletonize(image)
    
    plt.imshow(skel)
    

    enter image description here