Matlab riempimento() a sua volta utilizza una funzione IM = imreconstruct (marker, maschera)
Scikit-image ha un simile funzione di ... skimage.morphology.reconstruction(seed, mask, method='dilation', selem=None, offset=None)
L'algoritmo è dettagliato nel Soille, P., Morfologiche Image Analysis:. Principi e applicazioni, Springer-Verlag, 1999, pp 208-209. sezione sezione 6.3.7 "_FillHole"
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()
Link to tyre image and filled image
Controllare [questo link] (http://www.learnopencv.com/filling-holes-in-an-image-using-opencv-python -c /) per vedere una sua implementazione in Python. –
@BillBEGUERADJ Questo vale per le immagini binarie. L'OP vuole fare questo per le immagini in scala di grigi. – rayryeng