Azzera filtri
Azzera filtri

Detecting circles in an image to measure inner and outer diameter

6 visualizzazioni (ultimi 30 giorni)
Any reason why this code won't detect the inner and outer diamter of the tube seen in the image below?
a = imread('E1-E2.jpg');
imshow(a);
% Center and radius
[centers,radii] = imfindcircles(a,[20 1000],'ObjectPolarity','bright', 'Sensitivity',0.95);
diameter = radii*2;
viscircles(centers, radii,'Color','b');

Risposta accettata

Image Analyst
Image Analyst il 19 Ago 2024
Yes. You're using the wrong lens. It needs to be a telecentric macro lens. Telecentric so that you don't see the sides of the tube. Macro so that the background gets blurred. If you have the proper lens and lighting, a simple intensity threshold would probably do the trick.
If you can't get a telecentric lens, then try different lighting setups, like overhead, or coming from down low all around so that maybe the tube walls will "glow" more brightly. But I'd really try to get a telecentric lens so that the light rays are parallel and you don't see the inside and outside walls of the tube.
I don't know what this thing is but there are other options, such as getting a 3-D height image with profilometry.
  1 Commento
Image Analyst
Image Analyst il 20 Ago 2024
@Matt J showed that if you manually locate some edge pixels, like with ginput,
[x, y] = ginput(5);
then you can fit an ellipse to the shape. To fit an ellipse to the points (you must have at least 5 points I believe) then you can use the code snippet in the FAQ:
See attached ellipse fitting function.
a = fitellipse(x, y)
% Note: a = [uCentre, vCentre, Ru, Rv, thetarad];
Since you probably have only a few dozen of these images or fewer, just doing the above to manually do it may be faster than spending days or weeks trying to come up with an automatic segmentation routine. And it may be more robust and just as accurate.
If you want, you can average the two elliptical semi-axis lengths to estimate a circular radius
Ru = a(3)
Rv = a(4)
radius = (Ru + Rv) / 2
equivalentCircularDiameter = 2 * radius

Accedi per commentare.

Più risposte (1)

Matt J
Matt J il 19 Ago 2024
Modificato: Matt J il 19 Ago 2024
Because of the angle of the camera, circular shapes like the ones you are looking for are imaged as ellipses. Since imfindcircles is looking for proper circles, this could confound it.
Below, I show the best circular (red) and elliptical (yellow) fit that I get when I manually sample the outer edge of the object. You can see that the circle misses the edges of the shape by up to 16 pixels in some places.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by