Python库skimage绘制二值图像代码实例
更新时间:2020年04月10日 14:49:42 作者:我坚信阳光灿烂
这篇文章主要介绍了Python库skimage绘制二值图像代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
二值图像的凸壳指的是包围输入二值图像白色区域的最小的凸多边形的像素集合。
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()
实验输出
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
相关文章
pip安装python库时报Failed building wheel for xxx错误的解决方法
最近在使用pip安装python的时候遇到些问题,所以下面这篇文章主要给大家介绍了关于pip安装python库时报Failed building wheel for xxx错误的解决方法,需要的朋友可以参考下2023-01-01Python如何操作office实现自动化及win32com.client的运用
这篇文章主要介绍了Python如何操作office实现自动化及win32com.client的运用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2020-04-04Python打包模块wheel的使用方法与将python包发布到PyPI的方法详解
这篇文章主要介绍了Python打包模块wheel的使用方法与将python包发布到PyPI的方法详解,需要的朋友可以参考下2020-02-02
最新评论