Image outline using python/PIL

前端 未结 2 424
鱼传尺愫
鱼传尺愫 2021-01-31 10:43

I have a color photo of apple, how can I show only its outline (inside white, background black) with python/PIL?

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-31 11:19

    Something like this should work.

    from PIL import Image, ImageFilter
    
    image = Image.open('your_image.png')
    image = image.filter(ImageFilter.FIND_EDGES)
    image.save('new_name.png') 
    

    If that doesn't give you the result you are looking for then you try implementing either Prewitt edge detection, Sobel edge detection or Canny edge detection using PIL and Python and other libraries see related question and the following example .

    If you are trying to do particle detection / analysis rather than just edge detection, you can try using py4ij to call the ImageJ method you link to give you expect the same result, or try another Particle Analysis Python library EMAN alternately you can write a Particle detection algorithm using PIL, SciPy and NumPy.

提交回复
热议问题