2

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:

enter image description here

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:

enter image description here

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

RandomFellow
  • 317
  • 1
  • 9
  • 1
    you are looking for something like [split and merge](https://www.spiedigitallibrary.org/journalArticle/Download?urlId=10.1117%2F1.JEI.24.1.013007) – Bilal May 12 '22 at 13:35
  • @Bilal thanks, is there not an existing Python library for this ? – RandomFellow May 13 '22 at 07:31
  • I'm not sure, but there is an [answer](https://stackoverflow.com/a/14730467) in `C++` you might find useful. – Bilal May 13 '22 at 12:51

0 Answers0