2016-03-29 5 views
5

क्या ओपनसीवी या विज्ञानकिट-छवि का उपयोग करके कोई कार्यान्वयन है जो मैटलैब की ग्रेस्केल छवि के बराबर है funciton (यानी ग्रेस्केल होल भरना)?ग्रेथन के लिए मैटलैब funciton 'imfill' के बराबर पाइथन?

ग्रेस्केल (आई 2 = imfill (I)) के लिए imfill अनुभाग देखें उदाहरण के लिए matlab_imfill लिंक करें। matlab_tire_ex

यहाँ उदाहरण में टायर चित्र का कोई लिंक

tire

मैं अलग-अलग समारोह scipy.ndimage.grey_closing का उपयोग कर मैटलैब उत्पादन को दोहराने की कोशिश कर दिया गया है: या छवि देखें आकार पैरामीटर, लेकिन सफल नहीं हुआ है।

मैं पायथन 3.5 का उपयोग कर रहा हूं। बाढ़ भरण एल्गोरिथ्म के

+0

चेक [इस लिंक] (http://www.learnopencv.com/filling-holes-in-an-image-using-opencv-python -सी /) इसके पाइथन कार्यान्वयन को देखने के लिए। –

+2

@BillBEGUERADJ यह बाइनरी छवियों के लिए है। ओपी ग्रेस्केल छवियों के लिए ऐसा करना चाहता है। – rayryeng

उत्तर

1

दो संस्करण यहां अजगर में लागू किया गया है:

http://arcgisandpython.blogspot.de/2012/01/python-flood-fill-algorithm.html

पहले, सरल एक से दो अपरिभाषित चर निहित है, लेकिन यहां एक काम संस्करण है:

import numpy as np 
import scipy as sp 
import scipy.ndimage 

def flood_fill(test_array,h_max=255): 
    input_array = np.copy(test_array) 
    el = sp.ndimage.generate_binary_structure(2,2).astype(np.int) 
    inside_mask = sp.ndimage.binary_erosion(~np.isnan(input_array), structure=el) 
    output_array = np.copy(input_array) 
    output_array[inside_mask]=h_max 
    output_old_array = np.copy(input_array) 
    output_old_array.fill(0) 
    el = sp.ndimage.generate_binary_structure(2,1).astype(np.int) 
    while not np.array_equal(output_old_array, output_array): 
     output_old_array = np.copy(output_array) 
     output_array = np.maximum(input_array,sp.ndimage.grey_erosion(output_array, size=(3,3), footprint=el)) 
    return output_array 
+0

धन्यवाद! टायर उदाहरण पर थक गया और यह अच्छी तरह से काम करता है! –

1

मैटलैब infill() बदले में एक फ़ंक्शन IM = imreconstruct (मार्कर, मास्क)

साइकिट-छवि का समान उपयोग होता है । सिद्धांतों और अनुप्रयोग, स्प्रिंगर-वर्लग, 1999, पीपी 208-209: समारोह ... skimage.morphology.reconstruction(seed, mask, method='dilation', selem=None, offset=None)

एल्गोरिथ्म Soille, पी, रूपात्मक छवि विश्लेषण में विस्तृत है। खंड 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

संबंधित मुद्दे