Can you calculate how far away an object was from a photo?

Asked 5/26/2011

5 views

2 answers

0

If you know the camera sensor size, focal length, and the size of the object as it appears in the image, can you estimate the distance from the camera to that object? For example, if I photograph a windmill on the horizon, what additional information would I need, and what formula would I use?

Originally by Photography Stack Exchange contributor. Source · Licensed CC BY-SA 4.0

Photography Stack Exchange contributor

15y ago

2 Answers

48

The only other factor you need is the height of the object in real life (otherwise you could be photographing a model which is much closer to the camera).

The maths isn't actually that complex, the ratio of the size of the object on the sensor and the size of the object in real life is the same as the ratio between the focal length and distance to the object.

To work out the size of the object on the sensor, work out it's height in pixels, divide by the image height in pixels and multiply by the physical height of the sensor.

So the whole sum is:

$$ \textrm{Distance to object}(mm) = \frac{f(mm)\,\times\, \textrm{real height}(mm)\,\times\, \textrm{image height}(pixels)} {\textrm{object height}(pixels)\,\times\, \textrm{sensor height}(mm)} $$

Let's sanity check this equation.

If we keep everything else constant and increase the focal length then the distance increases (as focal length is on the numerator). This is what you would expect, if you have to zoom your lens to make one object the size another equally sized object used to be, the first object must be further away.

If we keep everything else constant and increase the real height of the object then again the distance increases as if two objects of different real heights appear the same height in the image the taller one must be further away.

If we keep everything else constant and increase the image height, then the distance increases, as if two objects (of the same size, remember we're keeping everything else constant) appear the same pixel size in a cropped and uncropped image then the object in the uncropped image must be further away.

If we keep everything else constant and increase the object height in pixels then the distance decreases (we're on the denominator now): two equally sized objects, one takes up more pixels, it must be closer.

Finally if we keep everything else constant and increase sensor size, then distance decreases: two equally sized objects have the same height in pixels when shot with a compact (small sensor, where 20mm is a long lens) and shot with a DSLR (large sensor where 20mm is a wide lens), then the object in the DSLR image must be further away (because it appeared the same size but with a wide lens).

Originally by user1375. Source · Licensed CC BY-SA 4.0

user1375

15y ago

0

AI Answer

Generated from our catalog & community — verify before relying on it.

Yes — but only if you also know the object’s real-world size (for example, the actual height of the windmill). From a single photo alone, distance and subject size are ambiguous.

Using the pinhole-camera approximation:

x / f = X / d

where:

  • x = object size on the sensor
  • f = focal length
  • X = real object size
  • d = distance to the object

So:

d = f × X / x

To find x, measure the object’s height in pixels, divide by the image height in pixels, and multiply by the physical sensor height:

x = (object pixels / image pixels) × sensor height

Combining those gives:

distance = (focal length × real object height × image height in pixels) / (object height in pixels × sensor height)

Use consistent units for each pair (for example, mm for sensor/object-on-sensor and meters or mm for real size/distance).

Important limits:

  • You must know the object’s actual size.
  • This is an estimate; lens distortion, cropping, focus breathing, and uncertainty in the object’s exact size will reduce accuracy.
  • For very distant subjects, the approximation is generally reasonable.

UniqueBot

AI

15y ago

Your Answer