Calculate the distance between two objects automatically using matlab.
199 views (last 30 days)
i am currently doing project on image processing in matlab, in which I'm assigned to calculate the Euclidean distance between two object automatically.here is the image link https://imageshack.com/i/pcUJ9tQgj i first converted the image to binary using 'im2bw', then i applied 'canny' edge detection method and obtained the edges, and by using 'find' function i got the corresponding pixel values. And i am not able to processed further, problem is i have to get array of pixel coordinates for object A and object B separately. and the code has to find which pixel coordinates is nearer between both objects and calculate the nearer distance. I'd very much appreciate your input.
Image Analyst on 25 Aug 2014
You forgot to attach your image, which people usually do when they want image processing advice. So I don't know if edge detection is what you want to do or not. Perhaps it is if you have something like phase contrast or DIC microscopy images, but if you have objects of one intensity on a background of a different intensity then you can probably use thresholding. That method is explained in my Image Segmentation Tutorial http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862 I find the blobs' centroids. From that you can find the distances between the centroids.
You didn't really explain your definition of distance clearly. I think you mean Euclidean /Pythagorean distance, but there's a chance you mean the Hausdorf distance. See this page to understand the Hausdorf distance: http://cgm.cs.mcgill.ca/~godfried/teaching/cg-projects/98/normand/main.html, though chances are you've never heard of it.
In my File Exchange there are also color segmentation methods. How you do your task really depends on what your images look like.
More Answers (6)
Ahmed Mehar on 1 Jul 2015
You Can calculate the Distance of multiple Objects of Center point by using this code:
k=2; for i=1:1:length(g)-1 x(i) = g(i).Centroid(1); y(i) = g(i).Centroid(2);
Vihan P on 23 Apr 2021
@Image Analyst I have been following the code you attached above 'test3' for finding the distance between two objects. I am unable to find the distance between the objects, instead I am able to find the distance between the boudary of the image to one of the objects. I am attaching the input as well as the output image that I am getting after applying your code, please help me find the minimum distance between these two bones.
Rhandrey Maestri on 17 Sep 2022
Edited: Rhandrey Maestri on 17 Sep 2022
Following this code. Can you tell me how to detect the bubble border(black region) and the tube wall(this black line near the bubble). And then calculate the distance between the border of the bubble and the closest wall pixel near this bubble?
Also if I know that the inside diameter is 15 mm. Can I have this distances in mm?