Algy / fast-slic

20x Real-time superpixel SLIC Implementation with CPU
MIT License
263 stars 34 forks source link

How to show the segmented image? #25

Closed SuperBruceJia closed 3 years ago

SuperBruceJia commented 3 years ago

Hi,

Thanks for your great work (It is really fast!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!). I really appreciate it.

I used the following codes and wanted to show the output.

import cv2
import numpy as np
from fast_slic import Slic
from PIL import Image
from skimage import io, color

with Image.open("test.jpg") as f:
   image = np.array(f)

image = cv2.cvtColor(image, cv2.COLOR_RGB2LAB)
slic = Slic(num_components=35, compactness=10)
assignment = slic.iterate(image)  # Cluster Map
out = color.label2rgb(assignment, image, kind='avg', bg_label=-1)
cv2.imshow("superpixels", out)
cv2.waitKey(0)

But it seems that the image cannot be shown. Is there any solution to this?

Best,

Shuyue