How to assign the same weight to color and space proximity with the slic method for creating superpixels?

I’m trying to use this method for creating superpixels. The documentation says that the parameter compacteness “balances color proximity and space proximity. Higher values give more weight to space proximity, making superpixel shapes more square/cubic”. It can be found in this link:

However, I’m not sure how to assign the same weight to both, color and space proximity. Is it a matter of just assigning 1 to compactness?

Best regards.

Nominally, yes, assigning 1 assigns the “same” weight to colour and distance. However, note that the units and even the spaces/dimensions of “colour” and “space” are not comparable. Colour ranges from 0-255 or 0-1 depending on the data type of your image, while space is in pixels (or some other unit, if you use the spacing argument). So, in fact, the compactness weight can only ever be relative to the shape, size, and colour objects in your image — it does not have a strict interpretation.

You could try using slic_zero=True, which automatically determines the compactness locally according to the texture of the image.

Hi jni.
Thank you for clarifying this point.
I wondering if it would be possible to make changes in this method in a way that, before applying the clustering algorithm, it normalizes the color information and the space information, converting both to values between 0 and 1. After that, both kinds of information would have the same magnitude. This would make it easier to interpret the parameter compactness.

In the current version, this is not possible to do, right?

Best regards.