I would like to use scikitimage to segment an image into rectangles (where each rectangle color would be the mean color of the pixels composing this rectangle), it would look to something like this:
In Scikit-Image, there is the slic segmentation function that uses k-mean clustering, i.e, it will cluster all pixels that are neighbours and that are of similar color.
Here is an example with the corresponding code:
from skimage.segmentation import slic
from skimage.data import astronaut
from skimage.color import label2rgb
plt.figure(figsize=(15,15))
astronaut = astronaut()
# Applying Simple Linear Iterative
# Clustering on the image
# - 50 segments & compactness = 10
astronaut_segments = slic(astronaut,
n_segments=50,
compactness=10)
plt.subplot(1,2,1)
plt.imshow(astronaut)
plt.subplot(1,2,2)
# Converts a label image into
# an RGB color image for visualizing
# the labeled regions
plt.imshow(label2rgb(astronaut_segments,
astronaut,
kind = 'avg'))
So, my question is: Is there a way to use one of the segmentation techniques offered by scikit-image to obtain this rectangle segmentation ? I have tried to see if one could change the slic function parameters in order to do that, but I could not find.
Best
Aymeric