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.
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=regions.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 :
Its application on the original image is :
What l got ? :
However, l’m supposed to get red boundaries of the given mask
contour=regions.bbox following its shape (mask) on the orignal image.
Something like :