Reputation: 359
I would like to reconstruct and display an image from its superpixel representation.
Let's illustrate it with a simple example :
l have a (224,224,3) image. I apply on it superpixel SLIC algorithm to get superpixels.
Here is my code :
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
def sp_idx(s, index=True):
u = np.unique(s)
return [np.where(s == i) for i in u]
image_index=[] # store the index of pixels affected to each superpixel
image_superpixels=[] # store the RGB pixel values of the pixels of all superpixels
img = skimageIO.imread(image_1)
segments_slic = slic(img, n_segments=1000, compactness=0.01, sigma=1)
superpixel_list = sp_idx(segments_slic)# get pixel and superpixel index
image_index.append(superpixel_list)
superpixel = [img[idx] for idx in superpixel_list]
superpixel = np.asarray(superpixel)
image_superpixels.append(superpixel)
Now given the superpixels of the image :
How can display the image in superpixel format ?
l would like to get something like the following :
`plt.imshow(image_1)` and `plt.imshow(image_superpixels)`
display the same thing (at least visually comparable)
Upvotes: 0
Views: 235