www.scantips.com

Calculate Distance or Size
of an Object in a photo image

This is rather specialized, but people do ask how to determine the distance or size of an object in a photo image. The DSLR camera Exif data may tell you Focus Distance, except you should realize that the focus distance reported is often seriously incorrect, especially for zoom lenses. You surely want to verify what actual focus distance is required for this lens to report that distance at that zoomed value. And the focus distance might not even be the distance of interest.

The calculator here can determine distance or size, but you must know the following things about the situation:

  1. The lens focal length that the camera image used.
  2. The sensor size in the camera, in mm.
  3. The sensor size in the camera, in pixels (image size)

    And then, two of these next three, to compute the other:

  4. The distance to that object from camera.
  5. The size (pixels) of the actual Object in the image, width or height.
  6. The real life size of the Object, the actual or approximate estimated Width or Height size dimension, in feet or meters. Not necessarily the "subject", but some known object there. Its distance and size must be in the same units (feet or meters).

The calculator will compute # 4, 5, or 6 from the other five values.

You need the original digital image. It won't work from a cropped image or a paper print (but it could be a resampled image). See some notes below about determining values.


Calculate Distance or Size of an Object in an Image

  First select the options to be used:

Find Distance to object
Find Size of object (feet or meters)
Find Size of object (pixels)

 Size Dimension used: Height   Width

 Enter One of these sensor size options:
Sensor size H mm
Crop factor and
  Aspect Ratio
  Width:Height
Lens Focal Length mm
H size of sensorpixels
H of Object in imagepixels
H of real ObjectF
Distance to ObjectF
 

Numbers only. A NaN result will mean an input is Not A Number. Decimal points are OK.

Please report ( Here ) any problem with the calculator, or with any aspect of any page. It will be appreciated, thank you.

You can use object size or distance in feet or meters, cubits, whatever... Be consistent, both will be in the same units. Sensor size and focal length are always in mm.

If camera is rotated up on end to portrait orientation, then reverse sensor width and height here. You are using Width as Height then (use sensor Width, call it Height).

The options will compute and change the appropriate field, where the Pink background appears. Any value already in the field you are finding will be ignored and replaced (by computing with all of the other fields). So when one of the three options has already computed the matching numbers, the other options with same numbers without change can only compute the same matches. No visible change then, except perhaps the slightest rounding differences (we have to round to one pixel). But each option is recomputing and overwriting its own result goal.


Example: The calculator initial defaults match this photo example. The tape on the image floor measures 30 feet, which will be the correct result. If any doubts, you can repeat a similar test.

Nikon D800 DSLR camera: Sensor 35.9 x 24 mm. 7360x4912 pixels. 60 mm f/2.8 D lens.

The Exif says this Focus distance was 3.76 meters, which is 12.33 feet (when it was in fact actually measured to be 30 feet). The focus point was on the door knob, center of the frame. And this was a 60 mm lens, not even a zoom lens, so sometimes the cameras distance report is a real crap shoot (often worse than useless).

The door measures 80 inches tall, 6.67 feet (or the size of many things might be reasonably estimated). In the original full size image, the cropped door is 2724 pixels tall (crop it, then look at image size).

So computing distance, the calculator input specified 24 mm sensor height, 60 mm lens, 4912 pixel sensor height, 2724 pixel object height, and 6.67 feet estimated real object height.

The tape on the floor measures 30 feet, and the calculator computes 30.07 feet (within 0.2%). That 0.07 foot is 0.8 inches. This distance is computed to the Thin Lens node somewhere in the lens, not really known (but this calculated value here is to it, and Not to the focal plane mark at rear of camera). I guessed the node was at the middle of lens, so that could be an inch error. Still, the accuracy seems very adequate.

The focal length in the EXIF says 59.9 mm, which calculates 30.02 feet (0.07%).

Notes:

If using a simple compact or smart phone camera, or camcorder, you may not know all of the numbers, like maybe not the correct size of the sensor in mm. Knowing crop factor can substitute for it.

The image used cannot be cropped. because we lose the sensor size in mm. It cannot be printed, because we lose the object size in pixels. It should be the original image from the camera.

However, the small resampled image copy which is shown here is 450x300 pixels, and it can work too (only because the image is still full frame view, NOT cropped at all).

Resamples: The "frame size in pixels" becomes the resampled size, but the sensor size in mm remains the same. Then (in this resampled smaller image) the cropped door is 168 pixels tall, full image height is 300 pixels tall (still representing 24 mm in camera), and calculator says 29.76 feet (0.8%). Less precision in a smaller image or object due to less possible cropping accuracy, one pixel is more then. Still, even this is very near 30 feet.

Note this 168/300 pixels or 2724/4912 pixels is simply computing the size is 56% of the 24 mm height of the camera sensor. Then knowing 56% of the camera sensor height in mm, and also the real life height, and the focal length distance in camera, it calculates distance to the subject.

Note that 16:9 movie images in a 3:2 or 4:3 still camera sensor is a resampled situation. The DSLR sensor might be 24 megapixels and 6000x4000 pixels, but the movie frame is resampled to 1920x1080 (2.07 megapixels) or 1280x720 pixels (0.92 megapixels). For such resampled images, use the resampled frame size in pixels, not the full sensor size in pixels. Movies in a still camera is also a cropped situation, but it's a bit special, if we assume the sensor width remains the same. Very few still cameras give the sensor area size in mm used for movies, but assuming full width is a good guess, unless otherwise specified.


People ask about the math. The math is similar triangles, just equal opposite angles, which are similar height/distance ratios.

The math the calculator uses is from this diagram:

FOV

Basics of lens optics:

Object height on sensor (mm) / focal length (f, mm) = Real Object height (feet) / Distance to Object (d, feet)

This is similar triangles in the diagram. The sensor size and focal length are both in mm, which is one ratio. The object distance and size are both in feet or meters, which is another. Both are same equal ratio, so we have an equation. The units work out OK, we simply rearrange and compute for the unknown. If we know three of the factors, we can solve for the fourth one. The calculator will do this, but it needs your accurate numbers.

If desired, of course substitute meters for feet. And/or substitute width for height if appropriate. Just be consistent, and solve for the unknown.

Size of an object image on the sensor: If we determine that the object size (in pixels, height or width) is say 12% of the sensor dimension (in pixels, height or width), then we know the object image is also 12% of the sensor mm dimension. The calculators initial default numbers compute it as (2724/4912) x 24 mm = 13.3 mm object height. Then we must know the focal length in mm, and have a reasonable estimate of the real object size. Then the highlighted formula is all that you need to compute distance. But for any accuracy, we really do need to know accurate focal length and accurate sensor size (mm).

You don't have to convert any units if consistent. These are two ratios. Since mm cancels out in the ratio inside the camera, and feet or meters cancels out in the ratio outside the camera, then it's two unit-less ratios, both equal (geometry says so), so we have an algebra equation. To make it be right angles (to make this all be true), we normally divide both heights on both sides by 2 (representing the angle marked above). However, these 2's also cancel out, so it's not necessary in the math (unless using trig, then we must divide both by 2). Trigonometry can do it another way, but trig is unnecessary, unless you want to compute the angle itself. But in geometry, the two opposite right angles are equal, so in trig, the tangents are equal, therefore the ratios of (opposite side / adjacent side) are equal. Just saying, not making anything up. :)

The easy way is as shown. This math couldn't be easier. Rearranged to find distance is:

Distance to Object (d, feet) = Real Object height (feet) x focal length (f, mm) / Object height on sensor (mm)

Or you can just use the calculator above. The calculator solves its example initial default case as 30.07 feet distance.

FWIW (bonus, informative fundamental). This same formula can be rearranged to be

Object height on sensor / Real object size = focal length f / Distance to Object d

This becomes obvious by definition when you recognize that it is similar sides of similar right triangles (then x 2 on both sides). Both of these ratios are "magnification" of the lens. In camera optics, lens magnification is of course (image size on sensor / image size in real life). Magnification is also f/d (if at 1:1, f and d are necessarily equal). These are obviously the same magnification, so these are obviously an equal equation, and we can solve for an unknown.

Assuming you want usable accuracy, the difficult part is determining accurate sensor dimensions and accurate focal length in the camera. I worry about your finding the right specifications, especially for compacts or phones. Vague questionable input gives vague questionable output. More bluntly, garbage in, garbage out. Read at the Field of View page for ideas about determining values. FOV is computed the same way, same equation of ratios.

Again, three points.

Menu of the other Photo and Flash pages here


Copyright © 2015-2017 by Wayne Fulton - All rights are reserved.

Previous Menu