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的Django框架中设置日期和字段可选的方法
Jul 17 Python
python 3.5下xadmin的使用及修复源码bug
May 10 Python
python pandas dataframe 行列选择,切片操作方法
Apr 10 Python
如何在python字符串中输入纯粹的{}
Aug 22 Python
python中cPickle类使用方法详解
Aug 27 Python
解决在Python编辑器pycharm中程序run正常debug错误的问题
Jan 17 Python
python字符串和常用数据结构知识总结
May 21 Python
python搜索包的路径的实现方法
Jul 19 Python
Python assert语句的简单使用示例
Jul 28 Python
pytorch 可视化feature map的示例代码
Aug 20 Python
使用Nibabel库对nii格式图像的读写操作
Jul 01 Python
如何通过python实现IOU计算代码实例
Nov 02 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 split()函数的用法详解
2013/06/05 PHP
基于PHP+Ajax实现表单验证的详解
2013/06/25 PHP
解析php根据ip查询所在地区(非常有用,赶集网就用到)
2013/07/01 PHP
php生成excel文件的简单方法
2014/02/08 PHP
php动态绑定变量的用法
2015/06/16 PHP
PHP使用stream_context_create()模拟POST/GET请求的方法
2016/04/02 PHP
php实现在站点里面添加邮件发送的功能
2020/04/28 PHP
yepnope.js 异步加载资源文件
2011/09/08 Javascript
js 自制滚动条的小例子
2013/03/16 Javascript
JavaScript中用字面量创建对象介绍
2014/12/31 Javascript
JavaScript获取页面中表单(form)数量的方法
2015/04/03 Javascript
jQuery实现默认是闭合的FAQ展开效果菜单
2015/09/14 Javascript
详解vue-validator(vue验证器)
2017/01/16 Javascript
详解javascript中对数据格式化的思考
2017/01/23 Javascript
基于jstree使用AJAX请求获取数据形成树
2017/08/29 Javascript
深入了解query和params的使用区别
2019/06/24 Javascript
react native 仿微信聊天室实例代码
2019/09/17 Javascript
[01:08:09]DOTA2上海特级锦标赛主赛事日 - 1 胜者组第一轮#1Liquid VS Alliance第二局
2016/03/02 DOTA
[01:15:56]2018DOTA2亚洲邀请赛3月30日 小组赛A组 TNC VS Newbee
2018/03/31 DOTA
零基础写python爬虫之抓取糗事百科代码分享
2014/11/06 Python
曼城官方网上商店:Manchester City
2019/09/10 全球购物
Kate Spade澳大利亚官方网站:美国设计师手袋品牌
2019/09/10 全球购物
美国饼干礼物和美食甜点购买网站:Cheryl’s
2020/05/28 全球购物
定义一结构体变量,用其表示点坐标,并输入两点坐标,求两点之间的距离
2015/08/17 面试题
毕业生优秀推荐信
2013/11/26 职场文书
优秀生推荐信范文
2013/11/28 职场文书
医学检验专业个人求职信范文
2013/12/04 职场文书
高中毕业生自我鉴定例文
2013/12/29 职场文书
上班离岗检讨书
2014/01/27 职场文书
工地安全检查制度
2014/02/04 职场文书
公司贷款承诺书
2014/05/30 职场文书
节约粮食标语
2014/06/18 职场文书
机关中层领导干部群众路线教育实践活动个人对照检查材料
2014/09/24 职场文书
用Python将库打包发布到pypi
2021/04/13 Python
Java使用jmeter进行压力测试
2021/07/09 Java/Android
Golang gRPC HTTP协议转换示例
2022/06/16 Golang