opencv - How to Get Image's Object Outline (Outer Boundary) in Python? -


i'm working on image segmentation using python , opencv right now. have binary image contains 1 object (already thresholded using otsu's methods). want know how image's object outline (outer boundary). so, there black image white object outline. tried googling still don't have idea.

i prefer know how manually without built in function.

built in function: findcontours().

example:

import numpy np import matplotlib.pyplot plt  = np.zeros((100,100), np.uint8) a[10:20,30:40] = 1  im2, contours, hierarchy = cv2.findcontours(a, cv2.retr_tree, cv2.chain_approx_simple) cim = np.zeros_like(a) cv2.drawcontours(cim, contours, -1, 255, 1) plt.matshow(cim, cmap=plt.cm.gray) 

 findcontours() manual approach: easy way subtracting eroded image original image using binary_erosion(). not necesarily result in closed contour, depending on geometry.

import numpy np import matplotlib.pyplot plt scipy.ndimage.morphology import binary_erosion  = np.zeros((100,100), np.uint8) a[10:20,30:40] = 1 m = - binary_erosion(a) plt.matshow(m, cmap=plt.cm.gray) 

binary_erosion , subtraction


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -