The Application of macro DoF calculations

A forum to ask questions, post setups, and generally discuss anything having to do with photomacrography and photomicroscopy.

Moderators: rjlittlefield, ChrisR, Chris S., Pau

orac
Posts: 11
Joined: Wed Dec 30, 2015 10:31 am

The Application of macro DoF calculations

Post by orac »

Hi, I have been loitering for some time one and off and thought that this would be a good place to ask a few questions about applying DoF calculations.

I have build myself an electronic macro rail, not dissimilar to the stack shot as I found out after completing it. It is based around a PICAXE 28X2 processor. It drives a 4 line display, a TB6465 micro step driver for the stepper motor and a micro mega 32 bit FPU.

I found some calculations here :http://www.tirpor.com/macro/macro_DOF.htm
These seemed to be fine for things like reversed lenses and extension tubes. However after using a nikkor 40mm micro, and just purchasing a sigma 105 macro lens for my Nikon D7100 I have found that the sums don't add up to the magnification reading on the lenses.

The lens mounted on camera the image distance should be around 166.5 (sensor plane to mounting ring of F mount is 46.5mm, lens mounting ring to first element is around 120mm).
from the above site indicate
Mag = (Id-f)/f = (166.5-105)/105 = 0.5857.

Once the magnification is calculated, the DoF is calculated and the distance the camera need to be moved to allow a 30% image overlap is calculated. But with incorrect magnification, the DoF is wrong. The FPU can do as complex a calculation as you like, providing I can either programme into the PICAXE or load it as a function directly onto the FPU it can be done.

The user has input the camera data before a shooting sequence is calculated, this information is:
Focal length
F stop
Lens mounting ring to front element length
Shutter time

The system ask for some information on first start up:
Sensor type (it has the crop factors stored and CoC stored)
Mount ring to sensor plane distance

The rail itself is capable of some impressive feats of tiny movement. The micro step controller is set for 64 micro step per a single full step of the bipolar stepper motor, giving a 12800 step per rotation. the motor is couple to a 4mm pitch ball CNC style ball thread giving a theoretical 0.0003125mm minimum step size. although practically due to thing like back lash and tolerance in the motor makes this distance unlikely. However it would be nice to be able to make use of some extension tubes and start getting magnification number up, and applying the right maths is the only way that this can be achieved.

I have seen some other sums on here most notably
http://www.photomacrography.net/forum/v ... hp?t=28814
but I am struggling to see how to apply these calculation to my situation.

Here's a link to complete project thread over on the PICAXE forum
http://www.picaxeforum.co.uk/showthread ... macro-Rail

rjlittlefield
Site Admin
Posts: 23625
Joined: Tue Aug 01, 2006 8:34 am
Location: Richland, Washington State, USA
Contact:

Post by rjlittlefield »

orac, welcome aboard!

Calculating magnification and DOF are two of of my favorite topics, but I have bad news: trying to do it accurately based on lens specifications is an exercise in futility because published specifications never include the information that you would need to get it right.

All the standard formulas are derived from simple models that assume things like thin lenses, fixed focal length, pupil factor 1, focusing entirely by extension, and where the f-number refers to a mechanical ring setting, not adjusted by the camera. Those are reasonable approximations for an enlarging lens on bellows, but they are not even close for a modern macro lens mounted on a Nikon body.

In theory more complicated formulas can be used that work properly for thick lenses with variable focal length, pupil factor different from 1, and so on, but then the formulas require knowing parameters like placement of principal planes, which are never part of the published specifications. Those parameters can be measured using DIY techniques, but the methods are not simple to understand or to carry out correctly.

As a matter of practice, the only reliable way to determine magnification is to measure it. Fortunately that process is simple: photograph a ruler and divide sensor width by field width.

That still leaves the challenge of determining an accurate f-number. For your Sigma 105 mounted directly on your Nikon D7100, most likely the number that you set on the camera is the effective f-number, already adjusted by the camera and lens as necessary to compensate for focusing extension and change in focal length with focus. But if you add extension tubes, something different may happen depending on exactly what tubes you have. If your camera were Canon, then what appears to be the same number would usually produce a different physical aperture, because on Canons the value is always just the lens's nominal f-number, not adjusted to compensate for extension etc.

It is very far from clear what is the best way to deal with all these uncertainties and variations. What I've done for the DOF tables published at http://zerenesystems.com/cms/stacker/do ... romicrodof is to divide the world into 3 general situations, then use some reasonable approximations to calculate optical DOF ignoring sensor limitations, following the strategy discussed at http://www.photomacrography.net/forum/v ... hp?t=19756. Perhaps something in there could be useful to you also.

The TIRPOR page has a comment that's worth noting: "You can get bogged down in theory - s the way I work is to use these values as a starting point and then check what happens in practise."

It is good advice.

--Rik

orac
Posts: 11
Joined: Wed Dec 30, 2015 10:31 am

Post by orac »

Thanks for the reply.

It seems that experimentation is needed for each setup.
Nikon do adjust their F-stop with magnification, so if I start at F2.8 in infinity focus and then draw right back to 1:1 focus I end up at F5.6.

luckily my rail can be set to move as little as 0.001mm each step (running Its current software). using the quick way to check DoF (the slanted ruler through the focus area) I know that the DoF is around 0.5mm.

The thing that I have just noticed though, the spread sheet I have written to check the values given by the rail (used during development) gives a DoF of 0.516mm if I feed it an f-stop of 2.8.

It looks like the sums need the nominal f-stop, and not what the camera (or at least Nikon cameras) read out

as an idea.
image distance is 166.5
correct F stop 5.6
results in:
M = 0.5857
Effective aperture = 8.88
DoF = 1.032
30% overlap = 0.7

this stack doesn't work so well, given a 70% overlap, with a 0.031mm the stack works.

now with uncorrected data
image distance = 166.5
F stop = 2.8
results in:
M = 0.5857 (same as before)
EA = 4.44
DoF = 0.5163
30% overlap = 0.3614

I don't know if the stack works with entering uncorrected data. But simply knowing that I should be entering uncorrected instead of what the camera tell me is helpful in its self.

I do have an old lens (nikkor 35-80mm) with an aperture ring which I use with a reverser ring. part of me sometimes think that the old ways were much simpler.

Time for some experimenting I think

rjlittlefield
Site Admin
Posts: 23625
Joined: Tue Aug 01, 2006 8:34 am
Location: Richland, Washington State, USA
Contact:

Post by rjlittlefield »

orac wrote:It looks like the sums need the nominal f-stop, and not what the camera (or at least Nikon cameras) read out
That's correct. In the standard formula that "Symmetrical DOF = 2FC((m+1)/(m^2))" (as written on tirpor.com), it's the factor of (m+1) that corrects from nominal f-stop to effective f-stop, under the assumption of pupil ratio 1.

--Rik

orac
Posts: 11
Joined: Wed Dec 30, 2015 10:31 am

Post by orac »

This is stack of 37 images taken with the second set of settings, its not perfect, I am not sure what happen on the front left corner, and I should have start further back.

its a piece of quartz illuminated with a red LED
Image

orac
Posts: 11
Joined: Wed Dec 30, 2015 10:31 am

Post by orac »

I have done a little more work on this. Starting to get better results, and now I know were the issues lies it time to start thinking about a more permanent solution.

I found this on the subject of extension tubes.
http://photo.stackexchange.com/question ... be-will-be

The tubes I have allow for the camera to alter the aperture and have full electrical connection in them.

I quick few test shows that the lens is at 1:1 magnification before attaching a 20mm extension tube. Width of view after is about 19mm (down from 23.6 for 1:1) resulting in 1.24:1 magnification, which sound fine enough. If I use the sums in the above posted site (with the lens @ 1:1 magnification) the results is 1.19:1 - which is pretty close and would most likely work. There is about the same variation in the F stop and a 0.01mm difference in DoF.

Using the measured magnification DoF is 0.2234...mm, and the Effective aperture matches that given by the camera. however the camera does not make any changes to the aperture read out when an extension tube is applied even though the maths indicates that it should change to around the 6.2 mark.

All in all the best option is going to be using a ruler to obtain magnification. Just need to get a ruler with a slightly higher resolution for more accurate readings.

Looking at your sums in a little more detail is up next Rik, then its off to update the software the rail runs.

austrokiwi1
Posts: 350
Joined: Sun Sep 14, 2014 10:53 am

Post by austrokiwi1 »

I Am somewhat challenged by the maths used for calculating DOF. There are two calculators available through this web site but I found I was using them blindly with no feel for what the maths was doing. I developed my own DOF calculator that uses Maths I understand much better: Pythagoras

I mounted a Microscope calibration slide at a 45 degree angle. {I found I had to back the slide with white tape to see the scale easily} All I do is set up the camera, bellows and lens combination I want to use. I then measure how much is in focus on the calibration slide. I square that result next divide by two and then take the square root to get the DOF.

The maximum magnification I use is around 12 times( and at that level infrequently) so my DOF calculator performs well for me, but may not be so accurate at higher magnifications
Still learning,
Cameras' Sony A7rII, OLympus OMD-EM10II
Macro lenses: Printing nikkor 105mm, Sony FE 90mm F2.8 Macro G, Schneider Kreuznach Makro Iris 50mm , 2.8, Schnieder Kreuznach APO Componon HM 40mm F2.8 , Mamiya 645 120mm F4 Macro ( used with mirex tilt shift adapter), Olympus 135mm 4.5 bellows lens, Oly 80mm bellows lens, Olympus 60mm F2.8

ChrisR
Site Admin
Posts: 8671
Joined: Sat Mar 14, 2009 3:58 am
Location: Near London, UK

Post by ChrisR »

I square that result next divide by two and then take the square root
You could just divide by Sqrt(2)?
Chris R

rjlittlefield
Site Admin
Posts: 23625
Joined: Tue Aug 01, 2006 8:34 am
Location: Richland, Washington State, USA
Contact:

Post by rjlittlefield »

orac wrote:I found this on the subject of extension tubes.
http://photo.stackexchange.com/question ... be-will-be
There's a lot of doubt expressed on that page. Let me see if I can clear up some of that.

There's a really simple relationship between changing extension and changing magnification:

NewMagnification = OldMagnification + AddedExtension/LensFocalLength

This formula is valid for any lens, zoom or not, at any position of the lens focus ring, as long as you don't change the zoom or move the focus ring.

The biggest wrinkle with applying this formula is that a lot of lenses change focal length as they focus closer. When its ring is set at 1:1, a typical macro lens will reduce focal length to around 70% of its length at infinity.

Fortunately, measuring the actual LensFocalLength is simple. Just measure the magnifications with two different extensions, then apply this rearrangement of the previous formula:

LensFocalLength = AddedExtension / (NewMagnification - OldMagnification)

Once you know the LensFocalLength, you can re-apply the earlier formula to calculate magnification for any other extension, again assuming that the lens zoom and focus settings are not changed.

There is a similarly simple formula for change in working distance as you change magnification.

The trick is to focus your attention on changes. If you try to calculate the absolute magnification or working distance, starting from published lens specifications, then you run into the problem of needing parameters like locations of the principal planes, which are very seldom published.

The effect on aperture can also be calculated, but that's a bit more difficult and requires that you know something about the entry/exit pupil sizes of the lens. See
FAQ: What is "pupil ratio" and why would I care? for a full discussion of that.
The tubes I have allow for the camera to alter the aperture and have full electrical connection in them.
...
however the camera does not make any changes to the aperture read out when an extension tube is applied even though the maths indicates that it should change to around the 6.2 mark.
That sounds reasonable, and from the above discussion you can probably see the difficulty. In order to make that adjustment the calculation would have to know the actual focal length of the lens, the length of the extension, and the pupil ratio of the lens. One can imagine that the lens and each extension tube would have some conversation with the camera to provide that information, and then the camera could do the calculation, but I've never heard that the comm protocols on those electrical connections are fancy enough to do that. I'd guess that the extension tubes are just blindly passing along whatever signals would otherwise go directly from lens to camera, and nothing in the system is electrically aware that the tubes are in place.

As an aside, I'll mention that teleconverters have a simpler problem. A 2X teleconverter always loses exactly 2 stops, no matter what optics are stuck on front. So it's relatively simple for a chipped teleconverter to adjust aperture numbers to account for its own effect.
All in all the best option is going to be using a ruler to obtain magnification. Just need to get a ruler with a slightly higher resolution for more accurate readings.
Search eBay for "stage micrometer". 1 mm x 0.01 mm (100 marks) can be purchased now for less than $10, shipping included.

--Rik

orac
Posts: 11
Joined: Wed Dec 30, 2015 10:31 am

Post by orac »

It seems that the formula on the other page, while simplistic do conform to your equations

the formula in its simplest form
NewMag = (focal * OldMag + Extension) / focal

OldMag is the magnification before extension tube, this will have to measured, or known (ie scale on lens), relies on no changes to lens zoom or focus.
Focal is the focal length of the lens without extension - reported to camera
extension is the length of extension tube

this means that the only thing that is changed is the extension

if I use focal of 105, F2.8, OldMag of 1, NewMag of 1.25421053 (19mm field of view, and extension of 20mm:-
final Mag = 1.19047619
E A = 6.133
Dof = 0.220700842mm

all the extension tubes I have seen, are "dumb" in the fact they just pass information without telling the camera its there

Off to eBay to hunt out a couple stage micrometres. Then to think about applying some new found knowledge.

Thanks for your help, I am sure I will be back when something doesn't go quite right

rjlittlefield
Site Admin
Posts: 23625
Joined: Tue Aug 01, 2006 8:34 am
Location: Richland, Washington State, USA
Contact:

Post by rjlittlefield »

orac wrote:Focal is the focal length of the lens without extension - reported to camera
...
if I use focal of 105, F2.8, OldMag of 1, NewMag of 1.25421053 (19mm field of view, and extension of 20mm:-
final Mag = 1.19047619
E A = 6.133
Dof = 0.220700842mm
The formula is correct. My concern about "a lot of doubt expressed on that page" refers to people dithering about whether it does or does not apply with zoom lenses etc. It does apply -- but only with the warning that you have to use the actual lens focal length, which may be much different from whatever is written on the lens or reported to the camera.

That's where I don't follow your calculation.

It looks to me like you have computed final Mag = 1.19047619 by running the calculation as

NewMag = (focal * OldMag + Extension) / focal = NewMag = (105* 1 + 20) / 105

I don't see where you have used the observed "NewMag of 1.25421053" at all.

I would do it like this...

Assuming OldMagnification=1, AddedExtension=20, and NewMagnification=1.25421053, then I would calculate

LensFocalLength = AddedExtension / (NewMagnification - OldMagnification) = 20 / (1.25421053 - 1) = 78.6749471 mm

From there, I would use that focal value of 78.6749471 to calculate the expected magnification for other values of AddedExtension. (Of course it will also work for 20 mm of added extension, since that's what we used to calculate it.)

--Rik

orac
Posts: 11
Joined: Wed Dec 30, 2015 10:31 am

Post by orac »

that's correct.

the first sum does not make use of new magnification, its the reason I decided earlier today that I would be using the calculation that makes use of the new mag and calculates focal length for the final result.

The hard part is figuring out how to best to get the information into the rail system. It has to be able to operate in the field as well as in the comfort of home.

orac
Posts: 11
Joined: Wed Dec 30, 2015 10:31 am

Post by orac »

Here's a quick screen shot of the spread sheet for checking the data the rail produces. On the right is the new calculations, quite a difference from the old ones on the left.

If extension is set to 0, field width (measured after installing extension) is ignored and the focal length is used (in this case 105). Lens field is the measured field of view of the lens without extension tubes. aperture is the nominal value and not the corrected value shown by Nikon (and maybe others) cameras.

Image

I have ordered a couple of stage micrometres so I can confirm that this is at least close

Post Reply Previous topicNext topic