Python库skimage绘制二值图像代码实例

作者:我坚信阳光灿烂 时间:2023-06-12 15:05:33 

二值图像的凸壳指的是包围输入二值图像白色区域的最小的凸多边形的像素集合。

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绘制二值图像代码实例

来源:https://www.cnblogs.com/wojianxin/p/12653564.html

标签:Python,库,skimage
0
投稿

猜你喜欢

  • python如何对实例属性进行类型检查

    2021-08-17 09:28:19
  • 用virtualenv建立多个Python独立虚拟开发环境

    2023-10-28 06:24:07
  • Python xlwt工具使用详解,生成excel栏位宽度可自适应内容长度

    2024-01-03 20:20:20
  • php cookie中点号(句号)自动转为下划线问题

    2023-09-07 11:05:04
  • Python连接es之查询方式示例汇总

    2023-06-07 11:11:03
  • Go语言kafka生产消费消息实例搬砖

    2024-06-07 16:06:58
  • mysql prompt的用法详解

    2024-01-28 07:30:32
  • SQL Server自动生成日期加数字的序列号

    2024-01-12 21:29:42
  • Python爬虫实现selenium处理iframe作用域问题

    2021-05-23 03:09:42
  • 解析Go 中的 rune 类型

    2023-09-19 11:59:16
  • zap接收gin框架默认的日志并配置日志归档示例

    2024-05-09 09:46:32
  • 十条建议帮你提高Python编程效率

    2021-07-18 02:55:54
  • CSS的优先级与特殊性

    2008-06-24 11:36:00
  • vue2.0 elementUI制作面包屑导航栏

    2024-05-02 17:12:16
  • Python比较两个日期的两种方法详解

    2023-12-25 03:52:17
  • Python chardet库识别编码原理解析

    2021-03-18 16:41:54
  • 关于python常见异常以及处理方法

    2021-03-17 06:13:34
  • python 实现aes256加密

    2021-01-20 22:31:38
  • 检测SqlServer数据库是否能连接的小技巧

    2024-01-21 04:01:28
  • PHP代码加密和扩展解密实战

    2023-11-17 02:58:00
  • asp之家 网络编程 m.aspxhome.com