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网络编程之TCP通信实例和socketserver框架使用例子
Apr 25 Python
python实现的生成随机迷宫算法核心代码分享(含游戏完整代码)
Jul 11 Python
使用Mixin设计模式进行Python编程的方法讲解
Jun 21 Python
基于asyncio 异步协程框架实现收集B站直播弹幕
Sep 11 Python
python 读取Linux服务器上的文件方法
Dec 27 Python
Python爬虫 批量爬取下载抖音视频代码实例
Aug 16 Python
Python Django 前后端分离 API的方法
Aug 28 Python
Windows平台Python编程必会模块之pywin32介绍
Oct 01 Python
python实现堆排序的实例讲解
Feb 21 Python
给ubuntu18安装python3.7的详细教程
Jun 08 Python
Python LMDB库的使用示例
Feb 14 Python
Python Pycharm虚拟下百度飞浆PaddleX安装报错问题及处理方法(亲测100%有效)
May 24 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--用万网的接口实现域名查询功能
2012/12/13 PHP
解析coreseek for sphinx的使用
2013/06/21 PHP
JavaScript 在各个浏览器中执行的耐性
2009/04/06 Javascript
基于jQuery的可用于选项卡及幻灯的切换插件
2011/03/28 Javascript
jquery监控数据是否变化(修正版)
2011/04/12 Javascript
jquery入门—选择器实现隔行变色实例代码
2013/01/04 Javascript
将HTML的左右尖括号等转义成实体形式的两种实现方式
2014/05/04 Javascript
jQuery使用之标记元素属性用法实例
2015/01/19 Javascript
第六篇Bootstrap表格样式介绍
2016/06/21 Javascript
第九篇Bootstrap导航菜单创建步骤详解
2016/06/21 Javascript
jQuery简单动画变换效果实例分析
2016/07/04 Javascript
AngularJS基础 ng-open 指令简单实例
2016/08/02 Javascript
针对JavaScript中this指向的简单理解
2016/08/26 Javascript
浅谈javascript中的事件冒泡和事件捕获
2016/12/28 Javascript
JavaScript的事件机制详解
2017/01/17 Javascript
正则表达式基本语法及表单验证操作详解【基于JS】
2017/04/07 Javascript
vue+vue-router转场动画的实例代码
2018/09/01 Javascript
node和vue实现商城用户地址模块
2018/12/05 Javascript
javascript验证form表单数据的案例详解
2019/03/25 Javascript
微信小程序时间戳转日期的详解
2019/04/30 Javascript
详解jQuery如何实现模糊搜索
2019/05/10 jQuery
Vue+ElementUI table实现表格分页
2019/12/14 Javascript
Python yield使用方法示例
2013/12/04 Python
对pandas中iloc,loc取数据差别及按条件取值的方法详解
2018/11/06 Python
解决在pycharm运行代码,调用CMD窗口的命令运行显示乱码问题
2019/08/23 Python
把vgg-face.mat权重迁移到pytorch模型示例
2019/12/27 Python
使用keras实现BiLSTM+CNN+CRF文字标记NER
2020/06/29 Python
运行python提示no module named sklearn的解决方法
2020/11/29 Python
Mountain Hardwear官网:攀岩服装和户外装备
2019/09/26 全球购物
大学同学聚会邀请函
2014/01/19 职场文书
小学生新年寄语
2014/04/03 职场文书
法人授权委托书
2014/09/16 职场文书
2015年重阳节主持词
2015/07/04 职场文书
机械生产实习心得体会
2016/01/22 职场文书
教你解决往mysql数据库中存入汉字报错的方法
2021/05/06 MySQL
Node-Red实现MySQL数据库连接的方法
2021/08/07 MySQL