When taking photographs for reference purposes it good to be able to see the size of what is being photographed. Often people add an object of known size. A similar idea is to put a ruler or grid in the photo, but that is not as easy. An alternative is to add a scale during image editing, all one needs to know is the magnification of the image. In other words how many pixels per millimetre there are; then generate a bitmap of the correct size and paste it into the image.
Typical macro lenses offer 1:1 magnification, the image on the sensor is the same size as the object being photographed. From the camera sensor data one can calculate the pixels per millimetre. Just as easy one can photograph a scale at any magnification. Then set the lens to that magnification - macro lenses usually have magnifications visible on the manual focus adjusting mechanism - when taking photos.
This is only sensible because in the macro lens regime the depth of field, the distance in focus, is typically a couple of millimetres along the axis to and from the camera. If something is in focus, its distance from the camera is known precisely and so is the magnification.
This is simple, but it relies on setting the lens magnification before taking the photo and then remembering it. Better to read the magnification from the Exif data embedded in the image file, then generate the required scale and add it to the image.
I have a Nikon D5200 and a Nikon AF-S DX Micro-Nikkor 40 mm f/2.8G lens. The Nikon specification says the sensor covers 23.5 x 15.6 mm or 6000 x 4000 pixels, giving a resolution of 255 pixels per millimetre.
In the Nikon NEF RAW files, there are two likely Exif tags 'Focus Distance' and 'Exit Pupil Position'. All that matters is that these have a reliable relationship to the magnification. It turns out that at small distances the 'Focus Distance' and at large distances the 'Exit Pupil Position' values vary little. Ideally one should use the 'Exit Pupil Position' at small distances and the 'Focus Distance' at large ones.
Using Exiftool I read the values for these two tags for all my photographs (3000+). I found only these 17 values:
The first number is the 'Exit Pupil Position' in millimetres and the second the 'Focus Distance' in metres.
To be continued...