Set each pixel in the output image to the mean RGB color of the superpixel region

I’m working on image segmentations where need to calculate image superpixels. I have calculated, and displayed the image superpixel successfully but unable to color each pixel in the output image to the mean RGB color just as it’s done using MATLAB.

Full URL for more understanding of my question from MATLAB
https://www.mathworks.com/help/images/ref/superpixels.html

are you asking about opencv’s implementation, or matlab’s
(which would be somewhat off-topic here)

I’m asking of opencv implementation but need a result similar to what is contained in the link I shared

what if you try it yourself ?

you only get a “contours mask” for each superpixel,
but mean() will give you the value (for the region in th mask),
and setTo() lets you recolor it (again using that mask)

Yes, I was able to achieve the first part using the documentation you just shared the link but couldn’t achieve the second part which is the reason am seeking for assistance here.