I have tried to find some way to make superpixels in Processing.
I need it to be a bit configurable, the more features, the better, as resolution and numbers of superpixel will change. Important is a possibility to fill the superpixel with the average color.
I found the super nice library boofcv which is even available for Processing . But it looks like there are only some features implemented. I could not find a way to fill the superpixel with the average color.
It can be done in Java though. But I could not convert it to Processing. Seems to need a ton of libraries and the BufferedImage conversion drama…
How do you want to do this? Do you want the avg r, acg g, avg b of all pixels? Or are you looking for something perceptual?
A boofcv SimpleImageSegmentation uses a boofcv.abst.segmentation.ImageSuperpixels. That stores integers per region. You could calculate all average colors in one pass by keeping four indices–r/g/b/count – and looping over the pixels, adding to the total rgb and incrementing the count on the corresponding index. When done, divide the rgb of each index by its count to solve the “average” color. Now that you have an index of average colors (one per region), you can draw them all in one pass – loop over the pixels again and write the average color for each lookup index to that pixel.
Unfortunately, the BufferedImage conversion drama is hard to escape – the simplest path might be to convert the ImageSuperpixels from GrayI32 to a simple primitive integer array and then do everything described above on PImages. (untested)
Thank you for your answer,
yes I just would like to fill it with the average color (mean Color). As far as I understood these values should be already calculated as it is needed for the Superpixel algorithm.
"
// Computes the mean color inside each region
ImageType type = color.getImageType();
ComputeRegionMeanColor colorize = FactorySegmentationAlg.regionMeanColor(type);
" From Java Example BoofCV
It makes the image look like a comic strip. Like in the java example.
Interesting as there are not a lot of segmentation and even less Superpixel examples made in Processing to be found.
Will have to look in BoofCV Java Library as I think it wont work with the Processing version of BoofCV.
If I cant get it done, I could scan the Superpixel Image, which has no mean color for the borders and calculate the mean color inside the borders. It just seems odd an complicated as it is somehow accessable in the Superpixel algorithm.
A bit late to the conversation, but if there’s a feature that’s missing that you would like to have make a request on Github. https://github.com/lessthanoptimal/BoofProcessing I don’t update it too often but it does get updated.