# Find the actual distances in an image.

2 views (last 30 days)

Show older comments

##### 2 Comments

Adam
on 15 Apr 2016

### Accepted Answer

Mohammad Abouali
on 15 Apr 2016

Similar approach to this should work:

I=imread('P3290337.JPG');

I=padarray(I,[1 1 0],0);

thresh = 15;

mask = ~(I(:,:,1) < thresh & I(:,:,2) < thresh & I(:,:,1) < thresh);

xProj = any(mask);

xMin = find(xProj,1,'first')-0.5;

xMax = find(xProj,1,'last');

yProj = any(mask,2);

yMin = find(yProj,1,'first');

yMax = find(yProj,1,'last');

imshow(I);

hold on

plot([xMin xMin],ylim,'r','LineWidth',2)

plot([xMax xMax],ylim,'r','LineWidth',2)

plot(xlim,[yMin yMin],'r','LineWidth',2)

plot(xlim,[yMax yMax],'r','LineWidth',2)

##### 4 Comments

Mohammad Abouali
on 19 Apr 2016

Edited: Mohammad Abouali
on 19 Apr 2016

If you need to know the real world coordinates then you need your image to be geo-referenced. Have a look at pix2map() function.

another easy solution is that if you know how wide are each pixel then you can multiply the Euclidiean distance in pixel unit by the size of each pixel and you get the distance in your requested unit. However, this is only good for short distances, If your image is covering large areas you can not use this method to compute the distance and you should use other methods. For example, if you are measuring the distance between to cities located in two different state you should not do this. Also this requires your image to be corrected for distortions so that all pixels do have same size.

### More Answers (1)

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!