我想从超像素表示中重建和显示图像。
让我们用一个简单的例子来说明它:
我有一个(224,224,3)图像。我在其上应用超像素SLIC算法来获得超像素。
这是我的代码:
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)
现在给出图像的超像素:
如何以超像素格式显示图像?
我希望得到以下内容:
`plt.imshow(image_1)` and `plt.imshow(image_superpixels)`
显示相同的东西(至少在视觉上可比较)