Python查找图像轮廓

 时间:2026-02-14 01:32:33

1、打开IDLE。

Python查找图像轮廓

2、导入库,和其他语言一样在编写程序的时候需要导入先关的库文件。

import numpy as np

import matplotlib.pyplot as plt

from skimage import measure,draw

Python查找图像轮廓

3、产生一个图像,这里采用手工的方式画出了一张图。

img=np.zeros([100,100])

img[20:40,60:80]=1 

rr,cc=draw.circle(60,60,10) 

rr1,cc1=draw.circle(20,30,15)

img[rr,cc]=1

img[rr1,cc1]=1

Python查找图像轮廓

4、采用下面的程序进行查询图片的轮廓。

contours = measure.find_contours(img, 0.5)

Python查找图像轮廓

5、采用下面代码,显示我们的结果。

fig, (ax0,ax1) = plt.subplots(1,2) 

ax0.imshow(img,plt.cm.gray) 

ax1.imshow(img,plt.cm.gray)

for n, contour in enumerate(contours):

    ax1.plot(contour[:, 1], contour[:, 0], linewidth=2)

plt.show()

Python查找图像轮廓

6、显示的结果如下图所示。

Python查找图像轮廓

  • VSCODE打开后黑屏解决方法
  • visual studio该如何布局窗体界面
  • html如何解决输入框有自动出现的下拉选项
  • mysql8.0如何解决Access denied的问题
  • VS文本格式设置方法如何设置为显示属性值
  • 热门搜索
    西安旅游报价 旅游年票官网 元旦旅游 宁波旅游景点一日游 长白山旅游路线 秦皇岛旅游地图 北极光旅游 中国生态旅游 四川旅游信息网 苏州旅游财经学院