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

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