how to find the radius of a circle from an image
Mostra commenti meno recenti
I want to fit a circle just like the black line drawn in the figure and trying to find its radius. below is the code i am writing but not getting anything significant. kindly help me how to approch this kind of problems.
clear all
clc
% read the image
img = imread('gra.png');
% convert the image to grayscale
img_gray = rgb2gray(img);
% perform edge detection using the Canny algorithm
edge_img = edge(img_gray, 'sobel');
% perform hough transform to detect circles
[centers, radii] = imfindcircles(edge_img, [10 50000],'ObjectPolarity','bright','Sensitivity', 0.95);
% find the largest circle
[max_r, max_i] = max(radii);
max_center = centers(max_i, :);
% plot the results
figure;
imshow(img);
hold on;
viscircles(max_center, max_r, 'EdgeColor', 'b');

Risposta accettata
Più risposte (2)
Aditya
il 28 Feb 2023
0 voti
Hi,
I think you can reduce/simplify the problem statement to finding the enclosing circle around a collection of points.
To solve this problem, you can try out multiple algorithms depending on your requirements:
- The simplest could be to find the 2D Bounding box of the points. The radius of the enclosing circle would be the diagonal of the bounding box.
- The above solution, however, would not guarantee you the tightest/minimum enclosing circle. You can find the minimum enclosing circle using Welzl's Algorithm. You can read more about the Smallest Circle problem.
You can check out implementations at File exchange: Exact minimum bounding spheres and circles - File Exchange - MATLAB Central (mathworks.com)
Image Analyst
il 28 Feb 2023
0 voti
Please attach 'gra.png' so we can run your code. So I see small red circles and a large black circle. Do you have the coordinates of the centers of the red circles? If you want the min bounding circle you can use
Otherwise if you want to fit just some of the more "outer" red circles then you need to somehow define the radius that defines ones you want to include in the fit and those inner ones that you want to exclude from the fit.
6 Commenti
Devargya chakraborty
il 28 Feb 2023
Image Analyst
il 28 Feb 2023
OK, fine, but what about my questions. Do you want the bounding circle of the outer circle, or the "fitted" circle? And if fitted, what two radii do you want to include in those determining the fit?
Devargya chakraborty
il 28 Feb 2023
Image Analyst
il 28 Feb 2023
Modificato: Image Analyst
il 28 Feb 2023
Define "most"? 90%? 51%? 99%? And define what determines if a circle (white or red) is "at the boundary" or in the interior.
Devargya chakraborty
il 28 Feb 2023
Image Analyst
il 1 Mar 2023
If you want to minimize the number of atoms outside the circle then you want the min bounding circle so that the number outside will be zero. For this you can use John's function in the link I gave you. Will you try it? Just pass your max_center array into his function. Or if you want no part outside, then pass in the coordinates of your binary image you get with find() into his function.
Categorie
Scopri di più su Image Transforms in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
