I think it may be interesting to preprocess the image before using @Melago's approach.
This permits to get rid of the 0.98
coefficient.
One may say that the following preprocessing introduces a new "magic" coefficient (erosionRadius = 30
), but this new coefficient is less critical than the 0.98
.
img00 = Import["https://i.sstatic.net/kUebf.jpg"]
img01 = MorphologicalBinarize[img00]
erosionRadius = 30;
img02 = Erosion[img01, DiskMatrix[erosionRadius], Padding -> 0]
m = Dilation[img02, DiskMatrix[erosionRadius]]
Note that the top and the bottom are slightly flattened. This should not have effect on the extracted "BoundingDiskRadius"
Beyong this point, @Melago's approach is used :
circ = Flatten[{#[[1]], (* 0.98 : Removed *) #[[2]]} & /@
ComponentMeasurements[m, {"Centroid", "BoundingDiskRadius"}][[All,
2]], 1];
Show[img00, Graphics[{Red,Thick,Circle[circ[[1]], circ[[2]]]}]]
Related