Calculate Distance or Size
of an Object in a photo image

This is rather specialized, but people do ask how to determine or measure the distance or size of an object or subject 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.

Similar calculators (with similar math) are Field of View, Depth of Field, and blur trails of stars when using a fixed tripod.

This calculator can find distance or size of an object in a photo, but you must know the following things about the situation:

Describe the camera:

  1. The lens focal length that the camera image used, in mm.
  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 size (pixels) of the actual Object in the image. Can be width or height.
  5. 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. The result will only be as accurate as this estimate.

    You can use any units (feet or meters), but do be consistent (distance and size must be in the SAME units). Results will be in those same units. Focal length and sensor size are always in mm.

  6. The distance to that object from camera, in same units as size.

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. 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
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
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.

Width and Height means in the rotated photo. If camera is rotated up on end to portrait orientation, then reverse sensor width and height here. If you are using Width as Height then use sensor Width, and call it photo Height.

The options will compute and change the appropriate field, where the Pink background will appear. Any value already in the field you are finding will be ignored and replaced (by computing with all of the other fields). So when it has already computed once, clicking Compute again without change can only compute the same matches, with no visible change then, until you change something.

Example: The calculator initial defaults match this photo example. The tape on the floor in the image measures 30 feet, which is the correct result to compare. 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 data says this Focus distance was 3.76 meters, which is 12.33 feet (when it was in fact actually measured to be 30 feet, so don't trust that number. Zoom lenses and/or internal focusing change internal things.) The focus point was on the door knob, center of the frame. And this was a 60 mm lens, not even a zoom lens. Cameras don't know distance, they only know how much the lens focus is rotated, but with zoom and internal focus changing everything internally, sometimes calibration must be hopeless, and the cameras distance report can be a real crap shoot (often worse than useless). If you're going to rely on the distance in the Exif, I suggest you first verify the accuracy of your lens, at least at both moderate and distant focus, and at both wide and telephoto zoom (see more details of my complaining about this. I don't care that the number is inaccurate, I can ignore it, but my complaint there is that the camera metering system can actually use that number to override correct TTL BL direct flash exposure).

The door measures 80 inches tall, 6.67 feet (or the size of some 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 (at ranges of at least a few feet).

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


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 really should be the original image from the camera. If you cheat on the calculator, it will cheat on you. :)

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:


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-2018 by Wayne Fulton - All rights are reserved.

Previous Menu