Try to search your question here, if you can't find : Ask Any Question Now ?

Draw object boundaries on the original image given its contour and mask

HomeCategory: stackoverflowDraw object boundaries on the original image given its contour and mask
sourav asked 3 weeks ago

l have an original image called orig_image. l applied superpixel segmentation. l would like to make boundaries on the original image given the coordinates of a specific segments.
In my case it’s segments[15].

My original image is :


My code :

img = skimageIO.imread(orig_image)
segments = slic(img_as_float(img), n_segments=50, sigma=5)
regions = regionprops(segments)

Now l retrieve the coordinates of the segments l would like to trace its boundaries on the original image

contour = np.array(contour).reshape((-1, 1, 2)).astype(np.int32)
cv2.drawContours(img, [contour], -1, (0, 0, 255), 5) 

Here is the mask and its application on the original image, obtained as follow :

    mask = np.zeros(image.shape[0:2], dtype="uint8")
    mask[segments == 15] = 255
    cv2.imshow("Mask", mask)
    cv2.imshow("Applied", cv2.bitwise_and(img, img, mask=mask))

The mask is as follow :


Its application on the original image is :


What l got ? :


However, l’m supposed to get red boundaries of the given mask contour=regions[15].bbox following its shape (mask) on the orignal image.

Something like :


1 Answers
Best Answer
Arben answered 3 weeks ago
Your Answer

14 + 6 =

Popular Tags

WP Facebook Auto Publish Powered By :