Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the diameter of a line in an image?

Tags:

image

matlab

line

as you know I am working on images, at this moment I am facing the following problem, I do not know how to measure the diameter of the line that is observed in the image that I attached, I could apply a little the theorem of Pythagoras, but I do not know if it is possible to do it in an image, for example in this case the image has a thick line, but in case the line is thinner than can be done?

Example image

I would like to know the diameter when the line is alone, because it is obvious that when there is a cross the diameter will change, I show it in the next image.

diameter

like image 826
AlexZ Avatar asked Oct 30 '22 07:10

AlexZ


2 Answers

Here are simple hacks for when the resolution and thickness are "large enough":

at a given point on the line where you want to estimate the thickness you can do one of 2 things:

1) span out a line from that point at every angle between 0 and 180 and find the line that results in the shortest overlap with your original line, it will be the thickness

2) span out a circle from that point, whenever the circle is not overlapping anymore with the line, re-center it to have full overlap. When it is impossible to re-center it anymore such that you have full overlap, then the diameter where you still managed to have an overlap is your best estimate of line thickness

like image 112
Stack Player Avatar answered Nov 15 '22 09:11

Stack Player


One way to display an estimate of the line thickness is to use bwdist to calculate the distance to the nearest edge for each point in the line, then use imdilate to smooth the maximum values (running along the center of the line) out across the width of the line. You can then select a point on the line to see its approximate diameter (which will be off a bit near transitions between diameters, like at joins). Here's an example:

img = imread('qGs5t.png');            % Load RGB image
bw = ~im2bw(img);                     % Convert to black and white and invert
bw = imclose(bw, strel('disk', 3));   % Morphological close to remove noise
distImage = bwdist(~bw);              % Distance transform
maxDist = double(max(distImage(:)));  % Find maximum distance measure
diamImage = 2.*bw.*imdilate(distImage, strel('disk', floor(maxDist)));  % Dilate and mask

imagesc(diamImage);            % Display image
colorbar;                      % Display color bar
dcmObj = datacursormode(gcf);  % Create data cursor object...
set(dcmObj, 'Enable', 'on');   % ... and enable to select points

And here's the image with a point selected (the "Index" value is the approximate diameter):

enter image description here

like image 33
gnovice Avatar answered Nov 15 '22 10:11

gnovice