matlab imfill,Python相当于Matlab的灰度函数imfill?

Matlab infl()依次使用函数IM=imreconstruct(marker,mask)

有关算法的详细信息,请参见

Soille,P.,《形态图像分析:原理和应用》,Springer Verlag,1999年,第208-209页。第6.3.7节“填充孔”部分import numpy as np

from skimage.morphology import reconstruction

import matplotlib.pyplot as plt

from skimage.io import imread, imsave

# Use the matlab reference Soille, P., Morphological Image Analysis: Principles and Applications, Springer-Verlag, 1999, pp. 208-209.

# 6.3.7 Fillhole

# The holes of a binary image correspond to the set of its regional minima which

# are not connected to the image border. This definition holds for grey scale

# images. Hence, filling the holes of a grey scale image comes down to remove

# all minima which are not connected to the image border, or, equivalently,

# impose the set of minima which are connected to the image border. The

# marker image 1m used in the morphological reconstruction by erosion is set

# to the maximum image value except along its border where the values of the

# original image are kept:

img = imread("tyre.jpg")

seed = np.ones_like(img)*255

img[ : ,0] = 0

img[ : ,-1] = 0

img[ 0 ,:] = 0

img[ -1 ,:] = 0

seed[ : ,0] = 0

seed[ : ,-1] = 0

seed[ 0 ,:] = 0

seed[ -1 ,:] = 0

fill = reconstruction(seed, img, method='erosion')

f, (ax0, ax1) = plt.subplots(1, 2,

subplot_kw={'xticks': [], 'yticks': []},

figsize=(12, 8))

ax0.imshow(img)

ax1.imshow(fill)

plt.show()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值