Extract external contour or silhouette of image in Python

后端 未结 3 1713
清歌不尽
清歌不尽 2020-12-31 16:51

I want to extract the silhouette of an image, and I\'m trying to do it using the contour function of MatplotLib. This is my code:

from PIL import Image
from          


        
3条回答
  •  情话喂你
    2020-12-31 17:02

    If you want to stick with your contour approach you can simply add a levels argument with a value 'thresholding' the image between the white background and the leaf.

    You could use the histogram to find an appropriate value. But in this case any value slightly lower than 255 will do.

    So:

    contour(im, levels=[245], colors='black', origin='image')
    

    enter image description here

    Make sure you checkout Scikit-Image if you want to do some serious image processing. It contains several edge detection algoritms etc.

    http://scikit-image.org/docs/dev/auto_examples/

提交回复
热议问题