# Measure the area of an object in an image by using fx and fy and given distance (distance between camera and object pixel-wise)

I want to measure the area of an object in an image. I have fx and fy of the camera and also since I am using depth camera I have the distance between camera and the object pixel-wise. Could you please let me know whether it is possible to measure the object area in mm?

You need to know what the focal length of the lens was for this image. You need to know distance camera-to-subject.

You need to know the dimensions of the image as projected by the lens. A ray trace of the image forming rays projected by the camera lens draws a triangle.

The height of this triangle is the focal length of the camera lens. Let’s say the camera lens setting was 50mm at the time of the exposure.

Next you need to know the height and width of projected image in millimeters (fx and fy).

For this example, set both fx and fy at 15mm.

Divide fx and fy into focal length. For this example, 50 ÷ 15 = 3.33 is the ratio of length to height for both values.

The object being imaged is 3 meters forward of the camera. 3 meters = 3000mm. The height and width of the object is 3000 X 3.33 = 9,990mm. The object’s dimensions are 9.99 meters by 9.99 meters. The area of this object is 9.99 X 9.99 = 99.8 square meters.

This method works because the light rays from the object-to-camera lens trace out a “similar” triangle to a triangle traced out inside the camera (image forming rays). Similar tringles --- all angles are identical; all dimensions of both triangles have the same ratio height-to-base.

One pitfall: The focal length of a lens is a measurement taken when the lens is imaging an object at infinity. A lens imagining objects closer than infinity will have a back-focus that is stretched. If the camera to subject distance is over 3 meters, the extra back-focus is likely moot. If closer than 3 meters, the focal length engraved on the lens barrel is wrong. As an example, a 50mm lens working at “unity” (life-size 1:1) has a working focal length of 100mm.

If the object is near to the camera, the back focus is used as the revised focal length.

What will be the back focus of a 50mm imaging an object 200mm forward of the lens?

One method of several will work this problem.

Convert focal length to diopter power. Convert subject distance to diopter power. Subtract these two values.

50mm to diopter units 1/50 X 1000 = 20d 200mm to diopter units 1/200 X 1000 = 30d Subtract 30 – 20 = 10d

Revised back focus is 1/10 X 1000 = 200mm Use 200mm as the focal length.

Hope this helps!

• Thanks you for your comprehensive explanation. I employ operates under the premise that each pixel's area in the real world can be determined by its depth from the camera. Specifically, the real-world area of a pixel is calculated by multiplying two ratios: the pixel's depth divided by the focal length in the x-direction (fx) and the same depth divided by the focal length in the y-direction (fy). This gives the area of a single pixel in square millimeters. Summing these areas for all pixels belonging to the object yields the total object area in real-world dimensions. Is it correct? Commented Mar 28 at 9:41
• Focal length is a measurement taken when imagining an object at infinity like a star. To focus on objects closer than infinity, we must increase lens to senor distanced. This increased back focus distance is trivial for most applications. When doing close-up work the working focal length elongates significantly. And this must be taken into account. Optics math is algebra with many approaches and substitutions. Commented Mar 28 at 14:01