Python库skimage绘制二值图像代码实例
2020-04-11 07:05
621 查看
二值图像的凸壳指的是包围输入二值图像白色区域的最小的凸多边形的像素集合。
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绘制神经网络中的Sigmoid和Tanh激活函数图像(附代码)
- python+matplotlib绘制旋转椭圆实例代码
- Python绘制3d螺旋曲线图实例代码
- Python实现七彩蟒蛇绘制实例代码
- python 自动轨迹绘制的实例代码
- python绘制双柱形图代码实例
- python绘制神经网络中的ReLU激活函数图像(附代码)
- python使用pil进行图像处理(等比例压缩、裁剪)实例代码
- PYTHON绘制雷达图代码实例
- 使用python绘制二元函数图像的实例
- 用python中的matplotlib绘制方程图像代码
- Python绘制七段数码管实例代码
- python+matplotlib绘制饼图散点图实例代码
- 使用python图形模块turtle库绘制樱花、玫瑰、圣诞树代码实例
- python+matplotlib实现动态绘制图片实例代码(交互式绘图)
- python+matplotlib绘制3D条形图实例代码
- python 自动轨迹绘制的实例代码
- Python读取MRI并显示为灰度图像实例代码
- Python使用turtle库绘制小猪佩奇(实例代码)
- Python使用统计函数绘制简单图形实例代码