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实现的检测web服务器健康状况的小程序
Sep 17 Python
从局部变量和全局变量开始全面解析Python中变量的作用域
Jun 16 Python
Python内建模块struct实例详解
Feb 02 Python
Python查找文件中包含中文的行方法
Dec 19 Python
Python开发网站目录扫描器的实现
Feb 21 Python
详解django2中关于时间处理策略
Mar 06 Python
python logging日志模块原理及操作解析
Oct 12 Python
python tkinter控件布局项目实例
Nov 04 Python
Python实现企业微信机器人每天定时发消息实例
Feb 25 Python
Python迭代器Iterable判断方法解析
Mar 16 Python
Python基于pyecharts实现关联图绘制
Mar 27 Python
Matplotlib绘制条形图的方法你知道吗
Mar 21 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设计模式 Prototype (原型模式)代码
2011/06/26 PHP
深入php var_dump()函数的详解
2013/06/05 PHP
php递归获取目录内文件(包含子目录)封装类分享
2013/12/25 PHP
Js 本页面传值实现代码
2009/05/17 Javascript
深入理解Javascript闭包 新手版
2010/12/28 Javascript
javascript开发随笔二 动态加载js和文件
2011/11/25 Javascript
给html超链接设置事件不使用href来完成跳
2014/04/20 Javascript
jquery使用经验小结
2015/05/20 Javascript
详解JavaScript正则表达式之分组匹配及反向引用
2016/03/09 Javascript
AngularJS实现textarea记录只能输入规定数量的字符并显示
2016/04/26 Javascript
jquery获取form表单input元素值的简单实例
2016/05/30 Javascript
json对象与数组以及转换成js对象的简单实现方法
2016/06/24 Javascript
jQuery实现弹窗居中效果类似alert()
2017/02/27 Javascript
jQuery实现表单动态添加与删除数据操作示例
2018/07/03 jQuery
element-ui table span-method(行合并)的实现代码
2018/12/20 Javascript
JS div匀速移动动画与变速移动动画代码实例
2019/03/26 Javascript
[03:38]2014DOTA2西雅图国际邀请赛 VG战队巡礼
2014/07/07 DOTA
[48:22]VGJ.S vs VG 2018国际邀请赛小组赛BO2 第一场 8.16
2018/08/17 DOTA
简单文件操作python 修改文件指定行的方法
2013/05/15 Python
浅析Python中的for 循环
2016/06/09 Python
Python实现的科学计算器功能示例
2017/08/04 Python
Python3.6基于正则实现的计算器示例【无优化简单注释版】
2018/06/14 Python
Python实现的网页截图功能【PyQt4与selenium组件】
2018/07/12 Python
Python 安装第三方库 pip install 安装慢安装不上的解决办法
2019/06/18 Python
pandas DataFrame的修改方法(值、列、索引)
2019/08/02 Python
Django 查询数据库并返回页面的例子
2019/08/12 Python
Pycharm创建项目时如何自动添加头部信息
2019/11/14 Python
python递归调用中的坑:打印有值, 返回却None
2020/03/16 Python
python中entry用法讲解
2020/12/04 Python
Selenium Webdriver元素定位的八种常用方式(小结)
2021/01/13 Python
python 进制转换 int、bin、oct、hex的原理
2021/01/13 Python
CSS3中的Media Queries学习笔记
2016/05/23 HTML / CSS
党的群众路线教育实践活动个人对照检查材料(四风)
2014/11/05 职场文书
初中生物教学反思
2016/02/20 职场文书
室外天线与收音机天线杆接合方法
2022/04/05 无线电
Linux磁盘管理方法介绍
2022/06/01 Servers