opencv / opencv_contrib

Repository for OpenCV's extra modules
Apache License 2.0
9.21k stars 5.73k forks source link

SuperPixelSLIC accepts both 32F and 8U images but does not scale parameters accordingly #2061

Open oor001 opened 5 years ago

oor001 commented 5 years ago
System information (version)
Detailed description

When using the SuperPixelSLIC class to generate superpixels for an RGB image I have encountered the following phenomenon:

Code:

cv::Ptr<cv::ximgproc::SuperpixelSLIC> spixel = cv::ximgproc::createSuperpixelSLIC(rgb, cv::ximgproc::SLIC, 15, 50.0);
spixel->iterate();
cv::Mat cv_labels_32SC1;
spixel->getLabels(cv_labels_32SC1);    

Using the above code, I get two different results based on the format of the input image:

a) If 'rgb' is a CV8UC3 (0-255) then I get a desired result. Superpixels conforming to the shapes within the image. b) If 'rgb' is a CV32FC3 (0-1) then I get a slightly perturbed grid as a result.

This leads me to believe that whatever code is weighting the image structure vs compactness within the function is not taking into account the scale of the image. It is fine if this is the case, but possibly enforcing/documenting the incoming image format would reduce confusion here.

cbalint13 commented 5 years ago

@oor001 ,

https://docs.opencv.org/trunk/df/d6c/group__ximgproc__superpixel.html