python实现图像轮廓标记工具_使用python / PIL的图像轮廓

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

解决方案

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.

Python中,可以使用一些图像处理库和交互界面库来实现人机交互筛选图像轮廓。以下是一个基本的示例代码,使用OpenCV库和Tkinter库实现人机交互筛选图像轮廓: ```python import cv2 import tkinter as tk from PIL import Image, ImageTk # 创建窗口 window = tk.Tk() # 加载图像 image_path = "path_to_your_image.jpg" image = cv2.imread(image_path) image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) # 创建Canvas canvas = tk.Canvas(window, width=image.shape[1], height=image.shape[0]) canvas.pack() # 将图像显示在Canvas上 image_tk = ImageTk.PhotoImage(Image.fromarray(image)) canvas.create_image(0, 0, anchor=tk.NW, image=image_tk) # 定义鼠标事件处理函数 def mouse_click(event): # 在鼠标点击位置添加一个圆形标记 canvas.create_oval(event.x-3, event.y-3, event.x+3, event.y+3, fill='red') # 将用户标记的点转换为图像坐标 x, y = event.x, event.y # 在这里执行对轮廓的修改或其他处理 # 绑定鼠标点击事件 canvas.bind('<Button-1>', mouse_click) # 运行窗口主循环 window.mainloop() ``` 在这个示例中,首先通过OpenCV库加载图像,并将其转换为RGB格式。然后,使用Tkinter库创建一个窗口,并在窗口中创建一个Canvas来显示图像。当用户在图像上点击时,会触发鼠标点击事件,事件处理函数会在点击位置添加一个红色圆形标记,并将用户标记的点转换为图像坐标。在事件处理函数中,你可以执行对轮廓的修改或其他处理操作。 请注意,这只是一个基本示例,你可以根据实际需求进行更复杂的处理和交互设计。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值