Find the diameter of the parts in an image processing?

Hello,
Does anybody have any idea how can I calculate the average diameter of the parts attached here? The white parts ar cylinders actually with diameters in Nano size.
Would you please help me to write a code such that I can catch the diameters?
12.PNG
Thanks

Answers (1)

One approach would be:
  1. First, you need to segment the objects you want using any segmentation function, for example imbinarize, or a manual threshold.
  2. Then, Using regionprops you can obtain the perimeter of each segmented object
  3. Finally, to obtain the diameters is just:
diameter = perimeter/pi

6 Comments

For a perfect circle, indeed . For an image of a circle, with imperfections I wouldn't rely on this formula. You would be better off using the area which will be more faithfull to the true circle, so . In fact, that's exactly, what regionprops use for its property EquivDiameter, so you could just get that out of regionprops.
Instead of regionprops, you could also use imfindcircles. Its second output is the circle radii.
Of course, if you want the diameter in physical units, you need to have calibrated your imaging system to know the scale of the images. If you haven't done that, then you're wasting your time.
Comment by Torkan mistakenly posted as an answer:
Thanks all
First I have a problem. I wrote this code:
A = imread('12.png');
imshow(A)
%radiusRange = [150 220];
%[centers,radii] = imfindcircles(A,radiusRange) ;
%viscircles(centersBright, radiiBright,'Color','b');
Rmin = 1;
Rmax = 2;
[centersBright, radiiBright] = imfindcircles(A,[Rmin Rmax],'ObjectPolarity','bright');
The MATLAB mostly gives empty centersbright and radiiBright. I don't know
which number should I define based upon my scale?
Warning: You just called IMFINDCIRCLES with a large radius range. Large radius ranges reduce algorithm accuracy and increase
computational time. For high accuracy, relatively small radius range should be used. A good rule of thumb is to choose the
radius range such that Rmax < 3*Rmin and (Rmax - Rmin) < 100. If you have a large radius range, say [20 100], consider breaking
it up into multiple sets and call IMFINDCIRCLES for each set separately, like this:
[CENTERS1, RADII1, METRIC1] = IMFINDCIRCLES(A, [20 60]);
[CENTERS2, RADII2, METRIC2] = IMFINDCIRCLES(A, [61 100]);
Warning: You just called IMFINDCIRCLES with very small radius value(s). Algorithm accuracy is limited for radius values less
than or equal to 5.
You may want to perform the first step described by Alex before calling imfindcircle: binarise the image.
"which number should I define based upon my scale?"
The radius you pass to imfindcircle is in pixels. So look at the typical pixel radius of the circles in your image and pass a range around that value. Use imtool or imshow to look at your image.
If the image you've posted in your question is the actual size of your images, you have a problem. The resolution is extremely small, most of the circles are actually squares of only a few pixel because of the low resolution and magnification and there's hardly any variation in size. You either need a much higher resolution camera or a much higher optical magnification.
If it is indeed the resolution of your images, then I'd recommend using regionprops instead of imfindcircles. But again, the measurement error will be very high.
Thank u
The scale is actual actually in the figure!
How can I see the pixels?
Torkan's answer converted to comment:
I used stats = regionprops('table',BW,'Centroid','MajorAxisLength','MinorAxisLength') and it gives nothing for major and minor axis. It seems that as you said the resolution makes problem.
As I said, use imtool or imshow to look at the image.
resolution is a bit of an overloaded word. You have the optical resolution, i.e. physical unit/pixel (in your case ) which you can determine by measuring the length of the line in your image (not the most accurate method but of it's all you have...). Resolution is also used for the size of the image in pixels. If your images are only 170x315, then that's a very low resolution. In that image your white cylinders are only 2 or 3 pixels in diameter, so an error of meaurement of one pixel is a 50 % mesurement error. The only way to reduce that error is to have a sensor with more pixels or increase the optical magnification so that the cylinders take more pixel. An error of 1 pixel for a cylinder of diameter 20 pixels drops the measurement error to 5 %.

Sign in to comment.

Categories

Asked:

on 10 Jan 2020

Commented:

on 10 Jan 2020

Community Treasure Hunt

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

Start Hunting!