how can measure diameter for circle image

9 次查看(过去 30 天)
i have an image that have circle shape and i want to measure diameter or distance between two point pleas help me in this regard. I take threshold and i use imtool() but it give pixals i want to measure in mm or cm . thank you all for support

回答(2 个)

Image Analyst
Image Analyst 2016-12-27
You forgot to include your image.
Basically segment your image to get just the circle(s) in a binary image. Then use regionprops() to get the equivalent circular diameter.
[labeledImage, numBlobs] = bwlabel(binaryImage);
props = regionprops(labeledImage, 'EquivDiameter');
allDiameters = [props.EquivDiameter];
See my Image Segmentation Tutorial for a full demo http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
Or you can do it manually with imdistline() like in my attached demo.
  6 个评论
Naja Najah
Naja Najah 2019-4-28
thnx but i'am beginner in matlab and i don't know where in this demo i will multply my distance ?
Image Analyst
Image Analyst 2019-4-28
If you look into the code you'll find a function called DrawLine(). In there, the crucial code is:
instructions = sprintf('Draw a line.\nFirst, left-click to anchor first endpoint of line.\nRight-click or double-left-click to anchor second endpoint of line.\n\nAfter that I will ask for the real-world distance of the line.');
title(instructions);
msgboxw(instructions);
subplot(1,2, 1); % Switch to image axes.
[cx,cy, rgbValues, xi,yi] = improfile(1000);
% Get the profile again but spaced at the number of pixels instead of 1000 samples.
hImage = findobj(gca,'Type','image');
theImage = get(hImage, 'CData');
lineLength = round(sqrt((xi(1)-xi(2))^2 + (yi(1)-yi(2))^2))
[cx,cy, rgbValues] = improfile(theImage, xi, yi, lineLength);
% rgbValues is 1000x1x3. Call Squeeze to get rid of the singleton dimension and make it 1000x3.
rgbValues = squeeze(rgbValues);
distanceInPixels = sqrt( (xi(2)-xi(1)).^2 + (yi(2)-yi(1)).^2);
distanceInRealUnits = distanceInPixels * calibration.distancePerPixel;
distanceInRealUnits is what you want.

请先登录,再进行评论。


Balakrishnan Sekar
Balakrishnan Sekar 2021-3-12
编辑:Balakrishnan Sekar 2021-3-12
Sir,
Thank you for the demo file. It is very useful. I wanted to measure diameter of a circle (hole) in the image. I have a doubt regarding the 'Enter real world units (e.g. microns):','Enter distance in those units:'. Sir, i want the final value in mm so that i shall the real world units in mm but i couldn't understand enter distance in those units. Could you explain what is that, Which value should i enter? Should i enter the value of the diameter of the circle? The actual diameter of the Circle (hole) is 10 mm, should i enter that value???
Please do explain and help me.
Thanks in advance.
  2 个评论
Image Analyst
Image Analyst 2021-3-12
Then when it asks you for the distance of the line you drew across the Circle (hole), you enter 10 for the distance and mm for the units.
But it looks like your image might be distorted since it does not look like a circle, but an ellipse. You might have to get a calibration factor for each direction, vertical and horizontal.
Balakrishnan Sekar
Balakrishnan Sekar 2021-3-12
No sir, it is actually a circle. But anyhow thank you so much sir. You gave a clear solution.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by