MATLAB Answers

# How to find the distance between two points on an image using edge detection

42 views (last 30 days)
CHIRANJEEVI KANIKE on 22 Feb 2021
Commented: Image Analyst on 23 Feb 2021
Assume that, I have taken a picture of a catenoid structure with some radius of curvature and now I would like to find the distance between two rings or some random points on the image using edge detection. There is an error when both the image processd length and actual experimental are compared. Any fuctions which can help to find out the distace between some random points on the image.
a = imread('image.jpg');
a = im2bw(a);
%subplot(221);
imshow(a);
% measuring
h = imdistline(gca);
api = iptgetapi(h);
%
pause();
%
dist = api.getDistance();
u=menu('Choose Measuring unit','Pixels','Centimeters','Meters');
if (u==1)
fprintf('The distance is : %0.2f Pixels\n',dist)
elseif(u==2)
dist_cm=dist*0.02645;
fprintf('The distance is : %0.2f Cms\n',dist_cm)
else
dist_m=dist*0.02645/100;
fprintf('The distance is : %0.2f m\n',dist_m)
end
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Accepted Answer

Image Analyst on 22 Feb 2021
If the distance is wrong, then the spatial calibration factor of 0.02645 cm per pixel is not correct.
And obviously the spatial calibration factor will be different for diffferent numbers of pixels (720 or 256) spanning the same field of view.
For the 720 pixel field of view, the spatial calibration factor should be 0.02645 * 6 / 14 = 0.0113.
For the 256 pixel field of view, the spatial calibration factor should be 0.02645 * 6 / 5.12 = 0.0310.
##### 2 CommentsShowHide 1 older comment
Image Analyst on 23 Feb 2021
Sorry, no.

Sign in to comment.

### More Answers (1)

KSSV on 22 Feb 2021
Read about imdistline.
##### 3 CommentsShowHide 2 older comments
CHIRANJEEVI KANIKE on 22 Feb 2021
There is an option to drag a linear line to the required points up on the image generated. Which will calculate the distance interms of pixels.

Sign in to comment.

R2020b

### Community Treasure Hunt

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

Start Hunting!