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常用正则表达式符号浅析
Aug 13 Python
[原创]windows下Anaconda的安装与配置正解(Anaconda入门教程)
Apr 05 Python
利用Python如何制作好玩的GIF动图详解
Jul 11 Python
详解PyCharm配置Anaconda的艰难心路历程
Aug 13 Python
使用PM2+nginx部署python项目的方法示例
Nov 07 Python
使用CodeMirror实现Python3在线编辑器的示例代码
Jan 14 Python
selenium处理元素定位点击无效问题
Jun 12 Python
django 使用全局搜索功能的实例详解
Jul 18 Python
python给图像加上mask,并提取mask区域实例
Jan 19 Python
Python利用for循环打印星号三角形的案例
Apr 12 Python
将pymysql获取到的数据类型是tuple转化为pandas方式
May 15 Python
python中entry用法讲解
Dec 04 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
一个阿拉伯数字转中文数字的函数
2006/10/09 PHP
PHP生成静态页面详解
2006/11/19 PHP
php5.3不能连接mssql数据库的解决方法
2014/12/27 PHP
利用PHP绘图函数实现简单验证码功能的方法
2016/10/18 PHP
php使用goto实现自动重启swoole、reactphp、workerman服务的代码
2020/04/13 PHP
禁止JQuery中的load方法装载IE缓存中文件的方法
2009/09/11 Javascript
JavaScript.Encode手动解码技巧
2010/07/14 Javascript
jquery清空textarea等输入框实现代码
2013/04/22 Javascript
JS中Json数据的处理和解析JSON数据的方法详解
2016/06/29 Javascript
基于jQuery代码实现圆形菜单展开收缩效果
2017/02/13 Javascript
JS批量替换内容中关键词为超链接
2017/02/20 Javascript
ES6数组的扩展详解
2017/04/25 Javascript
详解angularjs利用ui-route异步加载组件
2017/05/21 Javascript
Easyui在treegrid添加控件的实现方法
2017/06/23 Javascript
使用store来优化React组件的方法
2017/10/23 Javascript
微信小程序App生命周期详解
2018/01/31 Javascript
React Native悬浮按钮组件的示例代码
2018/04/05 Javascript
ES6 Generator基本使用方法示例
2020/06/06 Javascript
[48:21]Mski vs VGJ.S Supermajor小组赛C组 BO3 第一场 6.3
2018/06/04 DOTA
Django中ORM表的创建和增删改查方法示例
2017/11/15 Python
python3实现表白神器
2019/04/09 Python
python带参数打包exe及调用方式
2019/12/21 Python
深入浅析python变量加逗号,的含义
2020/02/22 Python
使用Pyhton 分析酒店针孔摄像头
2020/03/04 Python
印度尼西亚值得信赖的第一家网店:Bhinneka
2018/07/16 全球购物
Converse匡威法国官网:美国著名帆布鞋品牌
2018/12/05 全球购物
Unix如何添加新的用户
2014/08/20 面试题
快餐公司创业计划书
2014/04/29 职场文书
环境保护建议书
2014/08/26 职场文书
教师节慰问信
2015/02/15 职场文书
实习推荐信格式模板
2015/03/27 职场文书
结婚通知短信怎么写
2015/04/17 职场文书
2015年行风建设工作总结
2015/05/15 职场文书
2015年财务个人工作总结范文
2015/05/22 职场文书
MySQL中datetime时间字段的四舍五入操作
2021/10/05 MySQL
mysql 8.0.27 绿色解压版安装教程及配置方法
2022/04/20 MySQL