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中AND、OR的一个使用小技巧
Feb 18 Python
30分钟搭建Python的Flask框架并在上面编写第一个应用
Mar 30 Python
浅谈Python中的数据类型
May 05 Python
详解使用Python处理文件目录的相关方法
Oct 16 Python
python使用folium库绘制地图点击框
Sep 21 Python
浅谈pycharm下找不到sqlalchemy的问题
Dec 03 Python
python时间序列按频率生成日期的方法
May 14 Python
python pytest进阶之fixture详解
Jun 27 Python
Python任务调度利器之APScheduler详解
Apr 02 Python
Python urllib2运行过程原理解析
Jun 04 Python
pytorch训练神经网络爆内存的解决方案
May 22 Python
Matplotlib绘制混淆矩阵的实现
May 27 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程序中的常见漏洞进行攻击
2006/10/09 PHP
php使用Imagick生成图片的方法
2015/07/31 PHP
PHP读取大文件的几种方法介绍
2016/10/27 PHP
php设计模式之观察者模式定义与用法经典示例
2019/09/19 PHP
漂亮的widgets,支持换肤和后期开发新皮肤(2007-4-27已更新1.7alpha)
2007/04/27 Javascript
jCallout 轻松实现气泡提示功能
2013/09/22 Javascript
JS判断不能为空实例代码
2013/11/26 Javascript
MVC Ajax Helper或Jquery异步加载部分视图
2015/11/29 Javascript
Javascript实现跑马灯效果的简单实例
2016/05/31 Javascript
浅谈jQuery 选择器和dom操作
2016/06/07 Javascript
Three.js学习之Lamber材质和Phong材质
2016/08/04 Javascript
jquery获取点击控件的绝对位置简单实例
2016/10/13 Javascript
深入理解javascript的getTime()方法
2017/02/16 Javascript
详解JS获取HTML DOM元素的8种方法
2017/06/17 Javascript
JS中touchstart事件与click事件冲突的解决方法
2018/03/12 Javascript
vue.js做一个简单的编辑菜谱功能
2018/05/08 Javascript
详解vue使用vue-layer-mobile组件实现toast,loading效果
2018/08/31 Javascript
浅谈JS和jQuery的区别
2019/03/27 jQuery
原生js实现针对Dom节点的CRUD操作示例
2019/08/26 Javascript
浅谈Vue为什么不能检测数组变动
2019/10/14 Javascript
使用JS location实现搜索框历史记录功能
2019/12/23 Javascript
JS代码优化的8点建议
2020/02/04 Javascript
Python操作SQLite简明教程
2014/07/10 Python
Linux中安装Python的交互式解释器IPython的教程
2016/06/13 Python
python 把数据 json格式输出的实例代码
2016/10/31 Python
Anaconda的安装与虚拟环境建立
2020/11/18 Python
Laura官网:加拿大女性的顶级时尚目的地
2019/09/20 全球购物
学前教育求职自荐信范文
2013/12/25 职场文书
《灰椋鸟》教学反思
2014/04/27 职场文书
中药学专业求职信
2014/05/31 职场文书
辞旧迎新演讲稿
2014/09/15 职场文书
吴仁宝观后感
2015/06/09 职场文书
暑期工社会实践报告
2015/07/13 职场文书
2016优秀大学生个人事迹材料范文
2016/03/01 职场文书
React配置子路由的实现
2021/06/03 Javascript
德劲DE1105机评
2022/04/05 无线电