Inscribed and circumscribed circle of a contour

Hello,
I want to calculate the inscribed and circumscribed circle of a contour. The contour is those of this image of plant stem section :
leaflet.jpg_8

by circumscribed circle I mean smallest circle outside the contour and by inscribed circle I mean largest circle inside the contour
Thank you
Bets regards

the outer one is minEnclosingCircle() , for the inner one you might try to fit a circle to the convexity defect points

thank you very much !

inner: peak of distance transform

I’d also just go with circle fit through convexity detects. cheaper to compute and should be mathematically the same or within tolerance of noise.

I don’t understand, for circumscribed circle I succeeded but for inscribed circle not, and I don’t think convexity detects. could works

then use the peak of the distance transform

I don’t know what is it, have you a piece of code or tutorial on this please ?

I finally succeeded by this code :
Circle cercleInscrit(std::vectorcv::Point contour,Size imgSize) {
Mat dist_map;
double* minVal=new double;
double* maxVal=new double;
Point* minLoc=new Point;
Point* maxLoc=new Point;
//création d’une image binaire avec le contour rempli de blanc
Mat mask = Mat::zeros(imgSize, CV_8UC1);
//remplissage
vector<vector> polygones;
polygones.push_back(contour);
fillPoly(mask, polygones, Scalar(255));
//imwrite(“mask.jpg”, mask);
distanceTransform(mask, dist_map, DIST_L2, DIST_MASK_PRECISE);
minMaxLoc(dist_map, minVal, maxVal, minLoc, maxLoc);
Circle res(*maxVal, *maxLoc);
free(maxVal);
free(maxLoc);
free(minVal);
free(minLoc);
return res;
}

2 posts were split to a new topic: Can not create contours using numpy array #23230