Using Sobel on label's of DistanceTransform [closed]

asked 2015-04-06 17:15:25 -0600

MalcolmMaya gravatar image

I'm trying to use Sobel on the Distance Transform label as a way to only have Voronoi lines in the resulting map.

This is my code so far :

cv::Mat mat_test(heigh,width, CV_8UC3, cv::Scalar(0,0,0));
cv::circle(mat_test, cv::Point2d(0, 0), 1, cv::Scalar(255,255,255), -1);
cv::circle(mat_test, cv::Point2d(9, 9), 1, cv::Scalar(255,255,255), -1);
cv::circle(mat_test, cv::Point2d(0, 9), 1, cv::Scalar(255,255,255), -1);
cv::Mat result_ccomp;
cv::Mat other_result;
cv::Mat label;
cv::Mat label_pixel;

cv::cvtColor(mat_test, mat_test, CV_RGB2GRAY);
cv::threshold(mat_test, mat_test, 10, 255, CV_THRESH_BINARY_INV);
cv::Mat dist;
cv::distanceTransform(mat_test,result_ccomp, label, CV_DIST_L2, CV_DIST_MASK_PRECISE, CV_DIST_LABEL_CCOMP);
cv::distanceTransform(mat_test, other_result, label_pixel, CV_DIST_L2, CV_DIST_MASK_PRECISE, CV_DIST_LABEL_PIXEL);
cv::normalize(result_ccomp, result_ccomp, 0, 1., cv::NORM_MINMAX);
cv::normalize(other_result, other_result, 0, 100, cv::NORM_MINMAX);

cv::Mat sobelX;
cv::Mat sobelY;
cv::Mat sobel;
//int ddepth = CV_16S;
int scale = 1;
int delta = 0;
/// Gradient X

std::cout << "type : " << sobelX.type() << " type label : "<<label.type()<<std::endl;
cv::Sobel( label, sobelX, -1, 1, 0, 3, scale, delta, cv::BORDER_DEFAULT );

But when I try to run this little program I hit this error :

OpenCV Error: The function/feature is not implemented (Unsupported combination of source format (=4), and buffer format (=5)) in getLinearRowFilter, file /builddir/build/BUILD/opencv-2.4.9/modules/imgproc/src/filter.cpp, line 2857
unknown location(0): fatal error in "trying": std::exception: /builddir/build/BUILD/opencv-2.4.9/modules/imgproc/src/filter.cpp:2857: error: (-213) Unsupported combination of source format (=4), and buffer format (=5) in function getLinearRowFilter

I don't really understand what it means and how I got this error... Any help is appreciated.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2016-01-05 01:30:57.005580

Comments

3

it means, that the output from distanceTransform is not appropriate as input for Sobel.

try to convert to float: label.convertTo(label,CV_23F);

berak gravatar imageberak ( 2015-04-07 01:36:31 -0600 )edit
2

Thanks it solved my problem. But maybe you meant CV_32F ;)

MalcolmMaya gravatar imageMalcolmMaya ( 2015-04-07 04:49:11 -0600 )edit

^^ yea, typo, ofc. ;)

berak gravatar imageberak ( 2015-04-07 04:55:18 -0600 )edit

You should add your comment as an answer so I can accept it =)

MalcolmMaya gravatar imageMalcolmMaya ( 2015-04-07 06:25:36 -0600 )edit