Reputation: 1
I try to use the implemented library slic from python on an RGB image. However, even if I set the multichannel to True, the output shape is (X, X), not (X, X, 3), and the saved image is simply a gray image with no color at all. The input image is here:
My code is as follows:
from skimage.segmentation import slic,mark_boundaries
from skimage import io
img = io.imread("luna.png", 0)
print("img shape: {0}".format(img.shape))
segments = slic(img, n_segments=10, compactness=10, start_label = 1, multichannel=True)
print("seg type:", type(segments))
print("seg shape: {0}".format(segments.shape))
print("seg max:", np.max(segments))
print("seg min:", np.min(segments))
seg_255 = (segments / np.max(segments)) * 255
seg_255 = seg_255.astype(np.uint8)
cv2.imwrite("luna_seg.png", seg_255)
The command line displays the following result:
img shape: (512, 512, 3)
seg type: <class 'numpy.ndarray'>
seg shape: (512, 512)
seg max: 34
seg min: 1
The output image is
Upvotes: 0
Views: 446
Reputation: 207748
If you ask for 10 segments, you will get back a single channel grey image with values 0..9 each value representing the segment number.
You can colour it however you like.
Upvotes: 0