1

I was wondering if there is a function, preferably in openCV, to find the largest circle fitting into a pointset. Maybe some kind of circle growing algorithm.

What I have:

std::vector<std::vector<Point> > contours;
cv::findContours(binary,contours, RETR_EXTERNAL, CHAIN_APPROX_NONE);
cv::minEnclosingCircle(cnts[0],res_center,res_radius);
Mat backtorgb;
cv::cvtColor(binary,backtorgb,cv::COLOR_GRAY2RGB);
cv::circle(backtorgb,res_center,res_radius,Scalar(0,0,255),2);

But this works more or less like a shrinking circle (red). I need a growing one(green).

minEnclosingCircle

What I want:

desired result

Original:

original binary

Dženan
  • 3,329
  • 3
  • 31
  • 44
Pj Toopmuch
  • 115
  • 10

1 Answers1

0

@beaker pointed me to the right solution.

I had to add floodfill and adjust the distanceTransform parameters. For the sake of completeness the adjusted code:

cv::Mat img = cv::imread("original.png", IMREAD_GRAYSCALE);
cv::Mat im_floodfill = binary.clone();
cv::floodFill(im_floodfill, cv::Point(0,0), Scalar(255));
cv::Mat inv=Mat(im_floodfill.size(), im_floodfill.type());
cv::bitwise_not(im_floodfill,inv);
cv::Mat1f dt;
cv::distanceTransform(inv, dt, cv::DIST_L2, DIST_MASK_PRECISE,cv::DIST_LABEL_PIXEL);
double max_val;
cv::Point max_loc;
cv::minMaxLoc(dt, nullptr, &max_val, nullptr, &max_loc);
cv::Mat3b out;
cv::cvtColor(img, out, cv::COLOR_GRAY2BGR);
cv::circle(out, max_loc, max_val, cv::Scalar(0, 255, 0));

result:

enter image description here

Pj Toopmuch
  • 115
  • 10