Python库skimage绘制二值图像代码实例


Posted in Python onApril 10, 2020

二值图像的凸壳指的是包围输入二值图像白色区域的最小的凸多边形的像素集合。

skimage中的函数

from skimage.morphology import convex_hull_image
chull = convex_hull_image(image)

完整代码:

"""
===========
Convex Hull
===========

The convex hull of a binary image is the set of pixels included in the
smallest convex polygon that surround all white pixels in the input.

A good overview of the algorithm is given on `Steve Eddin's blog
<http://blogs.mathworks.com/steve/2011/10/04/binary-image-convex-hull-algorithm-notes/>`__.

"""

import matplotlib.pyplot as plt

from skimage.morphology import convex_hull_image
from skimage import data, img_as_float
from skimage.util import invert

# The original image is inverted as the object must be white.
image = invert(data.horse())

chull = convex_hull_image(image)

fig, axes = plt.subplots(1, 2, figsize=(8, 4))
ax = axes.ravel()

ax[0].set_title('Original picture')
ax[0].imshow(image, cmap=plt.cm.gray)
ax[0].set_axis_off()

ax[1].set_title('Transformed picture')
ax[1].imshow(chull, cmap=plt.cm.gray)
ax[1].set_axis_off()

plt.tight_layout()
plt.show()

######################################################################
# We prepare a second plot to show the difference.
#

chull_diff = img_as_float(chull.copy())
chull_diff[image] = 2

fig, ax = plt.subplots()
ax.imshow(chull_diff, cmap=plt.cm.gray)
ax.set_title('Difference')
plt.show()

实验输出

Python库skimage绘制二值图像代码实例

Python库skimage绘制二值图像代码实例

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Python 相关文章推荐
python脚本实现查找webshell的方法
Jul 31 Python
使用70行Python代码实现一个递归下降解析器的教程
Apr 17 Python
Python+树莓派+YOLO打造一款人工智能照相机
Jan 02 Python
python实现数据写入excel表格
Mar 25 Python
启动Atom并运行python文件的步骤
Nov 09 Python
使用selenium模拟登录解决滑块验证问题的实现
May 10 Python
Python 实现输入任意多个数,并计算其平均值的例子
Jul 16 Python
pycharm 批量修改变量名称的方法
Aug 01 Python
python如何将多个PDF进行合并
Aug 13 Python
Python 如何调试程序崩溃错误
Aug 03 Python
Python pathlib模块使用方法及实例解析
Oct 05 Python
python 获取剪切板内容的两种方法
Nov 28 Python
解决Jupyter因卸载重装导致的问题修复
Apr 10 #Python
解决jupyter notebook打不开无反应 浏览器未启动的问题
Apr 10 #Python
Python批量安装卸载1000个apk的方法
Apr 10 #Python
Window版下在Jupyter中编写TensorFlow的环境搭建
Apr 10 #Python
Selenium常见异常解析及解决方案示范
Apr 10 #Python
pandas分组聚合详解
Apr 10 #Python
使用jupyter notebook直接打开.md格式的文件
Apr 10 #Python
You might like
php 向访客和爬虫显示不同的内容
2009/11/09 PHP
ThinkPHP文件上传实例教程
2014/08/22 PHP
php使用CURL不依赖COOKIEJAR获取COOKIE的方法
2015/06/17 PHP
PHPExcel简单读取excel文件示例
2016/05/26 PHP
PHP使用递归算法无限遍历数组示例
2017/01/13 PHP
PHP有序表查找之二分查找(折半查找)算法示例
2018/02/09 PHP
php数值计算num类简单操作示例
2020/05/15 PHP
jquery实现的超出屏幕时把固定层变为定位层的代码
2010/02/23 Javascript
基于jquery的仿百度的鼠标移入图片抖动效果
2010/09/17 Javascript
图标线性回归斜着移动到指定的位置
2013/08/16 Javascript
JavaScript编程的10个实用小技巧
2014/04/18 Javascript
调整小数的格式保留小数点后两位
2014/05/14 Javascript
jQuery实现异步获取json数据的2种方式
2014/08/29 Javascript
js实现简洁大方的二级下拉菜单效果代码
2015/09/01 Javascript
基于JavaScript实现全屏透明遮罩div层锁屏效果
2016/01/26 Javascript
vue地址栏直接输入路由无效问题的解决
2018/11/15 Javascript
微信小程序实现点击效果
2019/06/21 Javascript
layUI实现列表查询功能
2019/07/27 Javascript
如何封装Vue Element的table表格组件
2021/02/06 Vue.js
Python语言实现机器学习的K-近邻算法
2015/06/11 Python
python的socket编程入门
2018/01/29 Python
基于Django用户认证系统详解
2018/02/21 Python
Python实现查询某个目录下修改时间最新的文件示例
2018/08/29 Python
利用python、tensorflow、opencv、pyqt5实现人脸实时签到系统
2019/09/25 Python
解决pyCharm中 module 调用失败的问题
2020/02/12 Python
Python Django中的STATIC_URL 设置和使用方式
2020/03/27 Python
详解anaconda安装步骤
2020/11/23 Python
Python tkinter实现日期选择器
2021/02/22 Python
西班牙最大的婴儿用品网上商店:Bebitus
2019/05/30 全球购物
物业管理工作方案
2014/05/10 职场文书
慈善晚会策划方案
2014/05/14 职场文书
辞职信标准格式
2015/02/27 职场文书
检讨书范文大全
2015/05/07 职场文书
投诉信回复范文
2015/07/03 职场文书
《狮子和鹿》教学反思
2016/02/16 职场文书
用Python可视化新冠疫情数据
2022/01/18 Python