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
Avatarsourav asked 5 months 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 :

ORIGINAL_IMAGE

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=regions[15].bbox
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 :

mask

Its application on the original image is :

mask_application

What l got ? :

wrong_result

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 :

desired_output

1 Answers
Best Answer
AvatarArben answered 5 months ago
Your Answer

14 + 9 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com