Home‎ > ‎

## Measuring Plant Dimensions

a web-report by Steve Sullivan and Walter Siegmund

The photos on this page can be measured by clicking on the photo.  This starts the Photo Measure Tool in a new tab.  The Photo Measure Tool allows you to zoom in on a portion of a photo by clicking and dragging.  You measure by clicking at the start and end points of a line.  You zoom out with the "All" button or the negative magnification symbol.

This balsamroot image was taken with a Casio EX-Z75 camera.

This broomrape image (courtesy of Yan Soucie) was taken with a Sony DSC-TF1 camera.
The length of the hairs on the flower can be measured.

This Mimulus alsinoides image was taken with a Canon EOS DIGITAL REBEL XSi camera using a EF100mm f/2.8L Macro IS USM lens. Photo courtesy of Walter Siegmund. The hairs in the throat of the flower can be measured.

## Theory Behind Measuring Photos

In order to take length measurements from a photo image the following conditions must be met.  The camera must record the distance between the camera and the plane of focus.  The depth of focus must be small.  The measurement must be made on objects that are in focus and at a right angle to a line from the camera to the object.  These conditions are shown in the following diagram.

In this diagram the parameter being measured is the size of the flower.  The flower faces the camera and is within the depth of field of the camera.  The camera records the distance to the flower.  In a simplified calibration step (that is not shown) a ruler replaces the flower while the camera records the same distance to the object.  The scale of the ruler in the calibration photo is then used to measure the size of the flower in the flower photo.  In a more typical calibration step a ruler is photographed at many distances and interpolation is used to find the scale of the ruler at the same distance from the camera as the object being measured.

#### Recording the distance between the camera and the plane of focus

Only some cameras record the distance to the plane of focus.  Those that do record this distance do so in a number of ways.  What is important for accuracy is that the distance is measured repeatably and that the depth of focus is relatively small.

Cameras record metadata, i.e., non-image information such as the shutter speed that is related to an image, in the Exif data block of the image JPEG file. There is a place for the distance to the plane of focus in the Exif data block.  But the cameras that we have examined have the distance in the MakerNote block.  The MakerNote block of data is a place where the camera manufacture can place any information they wish.  It seems that the information in the MakerNote area is used by the camera manufacture to help them debug their software and hardware.  Having the focus distance in the MakerNotes probably helps them debug their focus software and helps them find defective cameras during production test.

The more expensive Canon and Nikon cameras have the focus distance in the MakerNotes and these notes have been decoded and published (but probably not by the manufacture).  This also seems to be true for the less expensive Casio cameras.  However, Casio no longer manufactures these cameras.  I examined the MakerNotes for a Sony DSC-TX10 camera that I own and could not find a field that related to the focus distance.  But I did find such a field for the new Sony DSC-TF1 camera.  In this case the field seemed to be the lens position rather than the distance to the object but a simple transformation changes that to the focal distance.

The Canon DSLR cameras may use the subject distance to help set the flash intensity.  The distance in the MakerNotes has enough resolution for setting the flash.  But the cameras seems to have the ability to measure the subject distance with even more resolution.

#### Sources of Error (A Quick Discussion)

Depth of Field:  As the distance to the object becomes large, the separation of the lower and upper focus limit increases.  At the hyperfocal distance the upper focus limit is infinity. When the depth of field becomes large, the measurement error also becomes large.  In macro (or closeup) photography, e.g., a flower, an insect, the grain of a rock or details of a stem, the depth of field is narrow and the uncertainty in focus distance may contribute an error of only a few percent.  More distant subjects, e.g., trees, large bushes and fields, can not be measured accurately. It is possible to use the information recorded in the JPEG image to provide an estimate of the error due to the depth of field and to prevent measurements when this error source is large.

Focal Distance Resolution:  The electronic focusing mechanism may have a limited number of setting or the auto-focus algorithm may only determine the focus at a limited number of focus distances.  Generally, the focus settings must overlap so that objects at all distances can be brought into focus.  This suggests that this source of error will be less than the depth of field error.

Calibration Error:  Calibration consists of taking a number of photos of a ruler, graph paper or some other object with known dimensions.  These photos make it possible to determine the pixel size at the different focus distances.  Each photo will contain the errors previously mentioned.  However, by taking many photos with many focus distances some of the resolution and depth of field errors can be averaged out.

Incorrect Focus:  In using the inexpensive Casio camera it seems that the largest error source is due to incorrectly focusing on the object to be measured.  Objects seemed to measure 10 to 20% too large.  I suspect that this is because the camera regularly focused 10 to 20% behind the object to be measured.  I predict that this will often be a problem when an auto-focus mode is used.

The auto-focus algorithm takes a small photo at many focus settings.  It checks each photo for the visual texture.  When the camera is out of focus the image has a smooth visual texture.  An in-focus image will often have a rough visual texture.  However, flowers often have a fairly smooth visual texture.  On the other hand, grass, sand and small leaves often have a rough visual texture.  In many photos of flowers the camera focuses on the ground or other objects behind the flower.  Often, it seems that when the flower appears to be in focus the camera has still focused behind the flower.

It seems likely that manually focusing with a more expensive camera will overcome this error source.  Experiments to demonstrate this have not yet been performed.

Lens Distortion:  The Casio EX-Z75 camera reduced the size of objects in the corners of the image when taking macro photos.  This distortion could cause objects in the corners to measure 5 to 10% too small.  The Sony DSC-TF1 was much better than the Casio.  DSLR macro lenses typically have very low distortion.

Incorrect Orientation:  When an object is not perpendicular to the line of sight, the measurement will be too small.

## Cameras Tested

#### Casio EX-Z75

Steve purchased this 2007 camera used because Jason Hollinger, who uses a similar Casio camera, has been posting photos in Flickr that have a scale.  He explained in an e-mail that he uses the subject distance, provided by the camera, to set the scale that he inserts into his photos.

The following plot was generated by taking photos of a ruler in sunlight at various distances.  The vertical axis is the size of a pixel (in microns) determined by examining the ruler in Photoshop.  The horizontal axis is the subject distance provided by the camera and placed in the MakerNotes in the JPEG images.

When I examined photos of plants that also contained a ruler I found that the ruler typically measured 10 to 20% too large.  The most likely explanation for this is that when taking photos of flowers the auto-focus typically focuses behind the flower but when taking photos of just a ruler the auto-focus does focus on the ruler.

Because this camera is old and because it does not have an outstanding marco ability I would not recommend this camera for making measurements of plants.

#### Sony DSC-TF1

Steve's wife recently purchased this camera for about \$205 (including memory for a few hundred photos).  She wanted this camera because of the very short focus distance (of about 1 cm) that allows it to take photos with more magnification that most other point-and-shoot cameras.  The camera is also waterproof to 10 meters making it a good choice for a wet climate.  Unlike similar, previous Sony cameras, this camera does not use a touch screen.  We view this as an improvement.

The MakerNotes for this camera includes the lens position (instead of a focus distance).  The following plot was generated by taking photos of graph paper at various distances.  The vertical axis is the the number of pixels per mm.  The horizontal axis is the lens position number.  (Both axis are the reciprocal of the axis shown in other calibration plots.)

Measurement errors were typically less than 10% when the object being measured occupied a significant portion of the photo and the focus mode was "Center AF."  Report on Measurement Errors

This camera has much better magnification than the Casio and is considerably more rugged.  It may be one of the better choices for a lower cost field camera.

#### Canon DIGITAL REBEL T3 with EF-S 18-55mm IS II lens

This is currently the least expensive Digital SLR by Canon.  This camera body and lens costs about \$500 with a spare battery.  The camera puts both the upper and lower focal distance into the MakerNotes data included in the JPEG image file.

The following plot was generated by taking photos of graph paper at many distances.  The vertical axis is the size of a pixel (in microns) determined by examining the image in Photoshop.  The horizontal axis is the average focus distance provided by the camera.  The different colored dots represent different photo sessions.  The straight line shows a possible calibration curve.

The camera has a limited number of focal distances.  These focal distances are close together at the left side of the plot where the depth of field is narrow.  It is in this region where moderately accurate measurement can be taken from photo images.  The camera reports the focal distance which is used to find an estimate of the scale of the photograph.  In a test of this camera the measurements were typically within 8%.  You can read our report here.

Canon DIGITAL REBEL XSi EOS 450D with EF100mm f/2.8L Macro IS USM lens

## Thoughts on Implementing Photo Measurements

#### Web-based Photo Measure Tool

An initial implementation is demonstrated at the start of this web page.  Thumbnails of three plant photos are presented.  These photos are linked to a website that reads JPEG images and allows measurements to be made on the image.  This works well for photos posted in webpages.  Currently, this technique does not work for photos that have not been posted on the web since this program can only read and display web images.  The program could be improved to upload images from a computer but the upload can be slow and the process is complicated.  In addition, this scheme only works with images that have not been edited (by Photoshop, for example) because photo editors seem to remove the MakerNote data which is where the focus distance is kept.

The Photo Measure Tool which I have started resides at http://check.wildflowersearch.com/m.  The website takes the URL of a JPEG image and displays the image, allowing objects in the image to be measured. The image URL can be passed to the website when it is first called by using  http://check.wildflowersearch.com/measure?photo=URL.  This was done with the three example plant photos at the start of this webpage.

Currently, this Photo Measure Tool only works with the three cameras mentioned in the previous section.  The program can be improved to work with additional cameras.  It is unclear how many cameras include the focus distance within their JPEG images.  In e-mails with Ron Thomas (http://wildflowerlense.com/index.html) it seems that his Nikon D7000 camera with a 105mm Micro-Nikkor lens records the focus distance into the JPEG image.

To add a new camera to the Photo Measure Tool I would need a set of calibration photos.  This would consist of photos of a ruler (or graph paper) taken at many close-focus distances.  I also need to discover where the focus distance or subject distance is located in the JPEG image.  In order to do the job well, after adding a new camera to the Photo Measure Tool there should be a validation procedure.  This would consist of taking photos of plants while also carefully measuring dimensions of the plants.  Then the physical measurements are compared to the measurements made on the JPEG images.  Data from this procedure could be used by the Photo Measure Tool to provide a measurement uncertainty measure.

#### Local-Computer Photo Measure Tool

The web-based Photo Measure Tool is awkward to use on photos that have not been uploaded to the web.  In addition, performing any photo editing on a JPEG image seems to remove the information that is needed to make measurements.  These difficulties can be solved with a program that runs on the User's computer.  Such a program does not exists at this time.

A local-computer Photo Measure Tool would allow local photos to be measured.  In addition, the local tool can make a copy of the JPEG image while taking the focus distance from the proprietary Makernote area and inserting it into the more stable EXIF area.  The EXIF area has a subject distance field that could be used.  But an even better scheme would be to change the image resolution (which is often set to 72 dots-per-inch) so that it becomes the resolution of objects that are in focus.  The web-based Photo Measure Tool currently displays a value called "Photoshop resolution".  For the Mimulus alsinoides photo at the start of this webpage the "Photoshop resolution" is 1250 pixels/cm.  If you enter this resolution into Photoshop (or any other image editor) then measurements made by that editor will match the measurements made by the Photo Measure Tool.

(Currently, making measurements in Photoshop is awkward.  You first set the image resolution.  Then you make the info window visible.  Then you use the marque tool to draw a rectangle between the points you wish to measure.  The x and y dimensions of this rectangle appear in the info window.  Using a calculator you can compute the diagonal distance to find your measurement.)

Once the local Photo Measure Tool sets the image resolution the local Photo Measure Tool and the web-based Photo Measure Tool can make measurements on these even after an image has been edited.

#### Manufacture-based Photo Measurements

So far we have discussed programs that we can develop to allow distance measurements to be made on JPEG images.  If a camera manufacture decided to make a camera especially adapted for enabling measurements there are additional opportunities.   For example, Canon could add a feature that, when enabled, would automatically set the dots-per-inch photo resolution to match the dimensions of objects in focus.  Adobe could add features to Photoshop that utilize the camera focus distance and facilitate making measurements.

Most cameras that report the focus distance only provide enough resolution to focus the camera within the depth of field.  However, for making accurate measurements from the images it is desirable to have the subject distance measured with more accuracy and resolution than that needed to produce a clear image.  After a camera manufacture starts building cameras that enable measurements to be made on the images the next step for the camera manufacture would be to improve the range finding scheme so that the measurements are more accurate and work over a greater range of distances.

#### Focus Stacking for Improved Measurements (March 1, 2015)

Focus stacking is a scheme to improve depth of field.  For a static subject multiple images are recorded, each with a different focus position.  The different focus positions are chosen so that every feature of the subject is in focus in at least one of the images.  Then all of the images are combined to make a single image.  First, all of the images are aligned.  Then the highest resolution portions of each image are used to make the final image.

Making measurements on an image that has been developed with focus stacking poses some problems.  Objects that are close to the camera appear larger while object that are further from the camera appear smaller.  In addition, objects that are in focus now have a third dimension.

There is a measurement scheme that can compensate for these effects.  There are some requirements that must be met.  In each of the original images it must be possible to determine distances in the focal plane.  And it is necessary to know the change in distance of the focal plane between each image.  Then, the focus stacking software must keep track of operations that change the scale of an image (in order to line that image up with the final image).  When focus stacking has been completed the focus stacking software will make the following:  1)  The composite image that has a greater depth of field.  2) A source image that keeps track of where each pixel in the composite image came from.  For example, if the composite image was made by combining 9 orignal images the source image could contain the integers 1 thru 9.  In places where the first original image was used to make the composite image the source image would contain a "1".  In places where the second original image was used to make the composite image the source image would contain a "2".  Etc.  In this way it is possible to discover which original image was used to make any pixel in the composite image.  3)  A table that contains information about each of the original images.  This table would hold the "scale" and the "distance".  The "scale" is basically the size of each pixel for that image including any changes in the image needed to align it with the final composite image.  The "distance" is the distance of the focal plane of that image from the camera (or any other reference point).  This "distance" value makes it possible to compute the distance (towards the camera) between any of the original images.  All three types of data can be stored in a JPEG image so that the composite image can be viewed with ordinary image viewers.

Special measurement viewers can use the three types of information to make measurements on the composite image.  For example, to measure from point A to point B the measurement program will compute the x,y,z positions of both points and then compute the distance between those points.  The x and y positions are computed for point A by first determining which image that pixel came from.  Then the pixel size is found from the table.  Using the pixel size and pixel coordinates the x and y location can be found relative to the center of the image.  The z axis location is also found in the table.  In the same way the x,y,z location is found for point B.

It may be desirable to add a feature to the measurement program that helps show the user the Z axis value that is being used.  For example, consider measuring the diameter of a flower.  Point A and B are placed at the left and right edges of the flower.  Without focus stacking a 2D program will only use the X and Y values for point A and B and the measurement will be made correctly.  However, in a 3D program if point A is slightly outside the flower the Z axis value of point A will be the background behind the flower.  In this case the measurement will not be the flower diameter.  One way in which a measurement program could make the Z axis position visible is to adjust the contrast around point A and point B.  When point A is placed on the background the background layer would have normal contrast.  Other layers would have a reduced contrast.  For each pixel near point A the amount of contrast reduction might be related to the Z axis distance to the point A plane.  When point A is placed on the flower the flower near point A would have normal contrast but the background would have low contrast.  But when point A is placed on the background near the flower the flower would have low contrast.