python 凸包

该博客展示了如何使用Python的skimage库进行图像处理,包括将RGB图像转换为灰度,应用阈值处理,计算图像的凸包,并创建凸包与原始图像的差异图像。通过示例代码,演示了如何使用convex_hull_image函数找到图像的凸包,并通过plot_images_horizontally函数展示处理结果。
摘要由CSDN通过智能技术生成
from skimage.morphology import convex_hull_image
from skimage.color import rgb2gray
from skimage.io import imread
import pylab
import numpy as np

def plot_image(image, title=''):
    pylab.title(title, size=20), pylab.imshow(image)
    pylab.axis('off')
#
#
def plot_images_horizontally(original, filtered, Difference, filter_name, Difference_name,sz=(18, 20)):
    pylab.gray()
    pylab.figure(figsize=sz)
    pylab.subplot(131), plot_image(original, 'original')
    pylab.subplot(132), plot_image(filtered, filter_name)
    pylab.subplot(133), plot_image(Difference, Difference_name)
    pylab.show()
from skimage.morphology import convex_hull_image
from skimage.util import invert
im = rgb2gray(imread('./9781789343731_Code/images/horse-dog.png'))
#im = imread('../new images/dynasaurs.png')[...,3] / 255
print(np.max(im))
#im = 1 - im
th = 0.5
im[im < th] = 0
im[im >= th] = 1
#im1 = opening(im, square(6))
chull = convex_hull_image(im)
#im2 = closing(im, square(1))
# plot_images_horizontally(im, chull, 'convex hull',sz=(18,9))

from skimage.util import img_as_float
im = im.astype(np.bool)
chull_diff = img_as_float(chull.copy())
chull_diff[im] = 2

# pylab.figure(figsize=(20,10))
# pylab.imshow(chull_diff, cmap=pylab.cm.gray, interpolation='nearest')
# pylab.title('Difference Image', size=20)
plot_images_horizontally(im, chull,chull_diff,  'convex hull', 'Difference',sz=(18,9))
pylab.show()

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值