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 模板引擎的注入问题分析
Jan 01 Python
python实现unicode转中文及转换默认编码的方法
Apr 29 Python
在django中使用自定义标签实现分页功能
Jul 04 Python
python3实现爬取淘宝美食代码分享
Sep 23 Python
Python常见数字运算操作实例小结
Mar 22 Python
决策树剪枝算法的python实现方法详解
Sep 18 Python
python能做什么 python的含义
Oct 12 Python
在Python中画图(基于Jupyter notebook的魔法函数)
Oct 28 Python
提升python处理速度原理及方法实例
Dec 25 Python
浅谈python3打包与拆包在函数的应用详解
May 02 Python
python 使用事件对象asyncio.Event来同步协程的操作
May 04 Python
python如何遍历指定路径下所有文件(按按照时间区间检索)
Sep 14 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实现的遍历文件夹下所有文件,编辑删除
2010/01/05 PHP
PHP笔记之:日期函数的使用介绍
2013/04/24 PHP
用php制作简单分页(从数据库读取记录)的方法详解
2013/05/04 PHP
php读取csv数据保存到数组的方法
2015/01/03 PHP
为何说PHP引用是个坑,要慎用
2018/04/02 PHP
javascript之锁定表格栏位
2007/06/29 Javascript
基于JQuery的浮动DIV显示提示信息并自动隐藏
2011/02/11 Javascript
js 通过cookie实现刷新不变化树形菜单
2014/10/30 Javascript
JavaScript数组方法大全(推荐)
2016/07/05 Javascript
JavaScript中获取时间的函数集
2016/08/16 Javascript
AngularJS入门教程之REST和定制服务详解
2016/08/19 Javascript
bootstrap模态框跳转到当前模板页面 框消失了而背景存在问题的解决方法
2020/11/30 Javascript
jQuery EasyUI 为Combo,Combobox添加清除值功能的实例
2017/04/13 jQuery
Vue中计算属性computed的示例解读
2017/07/26 Javascript
node.js开发辅助工具nodemon安装与配置详解
2020/02/06 Javascript
es6函数之箭头函数用法实例详解
2020/04/25 Javascript
Python下的Mysql模块MySQLdb安装详解
2014/04/09 Python
PyQt5每天必学之工具提示功能
2018/04/19 Python
Python3批量生成带logo的二维码方法
2019/06/24 Python
pytorch nn.Conv2d()中的padding以及输出大小方式
2020/01/10 Python
Django单元测试中Fixtures用法详解
2020/02/25 Python
在python tkinter界面中添加按钮的实例
2020/03/04 Python
Python语法垃圾回收机制原理解析
2020/03/25 Python
飞利浦比利时官方网站:Philips比利时
2016/08/24 全球购物
Brasty罗马尼亚:购买手表、香水、化妆品、珠宝
2020/04/21 全球购物
Yahoo-PHP面试题4
2012/05/05 面试题
商场端午节活动方案
2014/01/29 职场文书
初二生物教学反思
2014/02/03 职场文书
大学学生会竞选演讲稿
2014/04/25 职场文书
2014年百日安全生产活动总结
2014/05/04 职场文书
运动会口号16字
2014/06/07 职场文书
员工工作及收入证明
2014/10/28 职场文书
出差报告怎么写
2014/11/06 职场文书
证婚人致辞精选
2015/07/28 职场文书
《棉鞋里的阳光》教学反思
2016/02/20 职场文书
详解缓存穿透击穿雪崩解决方案
2021/05/28 Redis