Reputation: 359
l have a a set of 250 images. From each image l apply SLIC superpixel algorithm.
Now, given superpixels of each image, l would like to track the superpixels of image 1 in image 2.
How to do that ?
take 5 superpixels mask for instance in image 1, each mask with a different color. let's say we take superpixel regions 1,2,3,4 and 5 with
color_maks=['red', 'green', 'white','yellow', 'orange']
l would like to get these mask in image 1 and their corresponding mask in image 2.
My question ?
1)How to assign different color for each superpixel mask and display them in image 1 and 2 ?
2) Given mask 1 (with color red) corresponding to superpixel 1 in image 1, how can display its mask in image 2
. for instance :
regions_image_1=[ 1,2,3,4,5]
corresponding_region_in_image_2=[7,2,5,8,12]
For the sake of illustration :
Let's take region 1 in image 1 with mask_color='red'
. Display it in image 1 and dispaly its correspoding in image 2 which is region 7 with the same mask_color='red'
What l have tried ?
def display_mask_superpixel(image):
image = cv2.imread(image)
segments = slic(img_as_float(image), n_segments=50, sigma=5)
# show the output of SLIC
fig = plt.figure("Superpixels")
ax = fig.add_subplot(1, 1, 1)
ax.imshow(mark_boundaries(img_as_float(cv2.cvtColor(image, cv2.COLOR_BGR2RGB)), segments))
plt.axis("off")
plt.show()
plt.cla()
plt.close()
for (i, segVal) in enumerate(np.unique(segments)):
# construct a mask for the segment
print("[x] inspecting segment %d" % (i))
mask = np.zeros(image.shape[:2], dtype="uint8")
mask[segments == segVal] = 255
# show the masked region
cv2.imshow("Mask", mask)
cv2.imshow("Applied", cv2.bitwise_and(image, image, mask=mask))
cv2.waitKey(0)
List_of images=images
for image in list_of_images:
display_mask_superpixel(image)
The limit here is that :
1) l display all superpixels of a given image , however l would like to display just some regions
2) all the mask are in white, however l'm looking for a different color for each mask
3) Don't handle tracking superpixel region of image 1 in image 2
Hope it's clear Thank you
Upvotes: 1
Views: 647