## Motorized bellows

**Moderators:** rjlittlefield, ChrisR, Chris S., Pau

From data below for a thin lens of 100mm (pink) and 50mm (blue) where d is distance from subject to lens and i is distance from image to lens, f is focal length

For 100mm thin lens, when d changes by 10mm, the i changes from 600mm to 433mm, a 167mm difference, and magnification changes from 5x to 3.33x. Since the lens is fixed, the change in d means different part of subject is in focus. Lets say it is not a problem constructing a 600mm long below, but change in magnification from 5x to 3.33x probably pose a challenge for stacking software.

For 50mm thin lens, when d change by 10mm, the i changes from 277mm to 169mm, still a whopping 108mm change, but look at the magnification change -- from 4.55x to 2.38x.

I have ordered a bunch of parts from eBay and Thorlabs so I will be building the set up soon. Theory is great but actually trying it has some value too!

It is interesting that the variation is only a factor of 2 - that is less than I would have guessed. I will do some calculations of more scenarios.

Very deep stacks at high mag are likely to be problematic no matter what, so eventually it will fail.

It is interesting that the variation is only a factor of 2 - that is less than I would have guessed. I will do some calculations of more scenarios.

Very deep stacks at high mag are likely to be problematic no matter what, so eventually it will fail.

nathanm

I myself have written a stacking software in about a month and it works fine. Having said that, from my experience of it, when you align images, you first build a transformation matrix that maps one image to another and you can do so progressively (ie, image by image) but eventually you will end up with a matrix mapping the first and final image. Take 100mm lens for example, image acquired at 5x and 3.33x will have different FOV by a factor of 1.5, so that final matrix will have to reflect this, so something has to give.

Sure this "loss" of information might not cause too much trouble for final perceived image quality, the "loss" is there, however.

Say we use 50mm lens and combining aperture etc, it has DOF of 50um, and to make sure we have enough overlap, we can make the increment of 25um, so to cover 10mm depth of field, we need to do 400 images. Then we can feed this information to thin lens model to get the "i" for each "d" . In this case we probably do not even care if the step of "i" is linear or not, just calculate it and we will have 400 points for "i"

just a thought

Peter

So I just did a calculation of the number of frames various ways.

As a concrete example, take a Canon 100mm macro lens, which will focus from 1X to infinity. Suppose we are shooting an object that has the nearest point at 1X and the furthest point is farther out.

If the far point is at 0.5 (meaning it is ~100mm from the near point), then if we assume that we stack with different step sizes in focus then it needs 500 steps if each step overlaps the ones in front and behind it by 25%.

If we use a constant step size then it is 1123 steps.

This assumes the lens is at f/4.5, which gives an effective f-stop of 9 at 1X.

If we set f/9 as the threshold for the effective f-stop, then we can do slightly better by changing both the aperture and the step size together. This gives us 415 steps.

So it is about a factor of 2.25X differences between constant and variable, and a factor of 2.7 if we include aperture.

If instead we go from 1X to 0.1X - which is an object that is 1.1 meters long, with its nearest point at 1X, then optimal including f/stop change is 755 steps. Constant aperture, variable step size is 1226 steps, and constant step size would take 10102 steps.

Going from 0.01x to 1x (that has everything in focus out to 10.6 meters)makes the numbers crazy. The optimal steps including aperture are 832 steps (which seems feasible), with constant aperture it is high but maybe possible at 1470, but constant step size would be an impossible 111,112 steps.

Note that the number of steps is independent of whether you move the back of the bellows or the front.

In the case of the Canon lens you could do this with the focus ring.

So the value of having non-constant step sizes depends on the magnification range.

As a concrete example, take a Canon 100mm macro lens, which will focus from 1X to infinity. Suppose we are shooting an object that has the nearest point at 1X and the furthest point is farther out.

If the far point is at 0.5 (meaning it is ~100mm from the near point), then if we assume that we stack with different step sizes in focus then it needs 500 steps if each step overlaps the ones in front and behind it by 25%.

If we use a constant step size then it is 1123 steps.

This assumes the lens is at f/4.5, which gives an effective f-stop of 9 at 1X.

If we set f/9 as the threshold for the effective f-stop, then we can do slightly better by changing both the aperture and the step size together. This gives us 415 steps.

So it is about a factor of 2.25X differences between constant and variable, and a factor of 2.7 if we include aperture.

If instead we go from 1X to 0.1X - which is an object that is 1.1 meters long, with its nearest point at 1X, then optimal including f/stop change is 755 steps. Constant aperture, variable step size is 1226 steps, and constant step size would take 10102 steps.

Going from 0.01x to 1x (that has everything in focus out to 10.6 meters)makes the numbers crazy. The optimal steps including aperture are 832 steps (which seems feasible), with constant aperture it is high but maybe possible at 1470, but constant step size would be an impossible 111,112 steps.

Note that the number of steps is independent of whether you move the back of the bellows or the front.

In the case of the Canon lens you could do this with the focus ring.

So the value of having non-constant step sizes depends on the magnification range.

nathanm

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

You may be using the same formulas that I do, but you're applying them in some completely different way that is yielding a crazy result.nathanm wrote:As a concrete example, take a Canon 100mm macro lens, which will focus from 1X to infinity. Suppose we are shooting an object that has the nearest point at 1X and the furthest point is farther out.

...

each step overlaps the ones in front and behind it by 25%.

...

Going from 0.01x to 1x (that has everything in focus out to 10.6 meters)makes the numbers crazy. The optimal steps including aperture are 832 steps (which seems feasible), with constant aperture it is high but maybe possible at 1470, but constant step size would be an impossible 111,112 steps.

...

I should add that the calculations above are based on Rik's wave optics formula for depth of field, assuming 550 nm light.

Following is the way I would work this problem, for a lens with fixed focal length 100 mm.

Notice that I'm doing all of my thinking & working in terms of the

*image*and rear extension. Magnification is involved only as it determines min & max rear extension. I'm not concerned about step size at the subject at all.

**Key formula: TDF = lambda/NA^2 = lambda*4*f_eff^2**

This is for total depth of focus (TDF) in the image plane, with effective aperture f_eff and wavelength lambda, using the wave optics criterion of quarter-lambda wavefront error.

**--- Case 1: constant step size in rear bellows extension, lens set to f/4.5 ---**

At 0.01x, an f/4.5 lens has f_eff = 4.5*(1+0.01) = 4.545 .

The corresponding depth of focus at lambda = 550 nm is TDF = 0.00055*4*4.545^2 = 0.045445455 mm.

Then, to get your 25% overlap, we'll multiply by 75% to get step size = 0.75 * 0.045445455 = 0.034084091. (Please excuse the plethora of digits. I'm including so many to make it simpler to confirm the calculation.)

Now, a 100 mm lens focused at m=0.01x has total rear extension = 100*(1+0.01) = 101 mm. When focused at m=1x, total rear extension = 100*(1+1) = 200 mm.

The number of steps will be the total difference of rear extension, divided by the step size,

so (200-101) / 0.034084091 =

**2905 steps**(rounded up).

**--- Case 2: variable step size, still keeping the lens fixed at f/4.5 ---**

The first step from 101 mm rear extension will be the same size as for case 1, so 0.034084091 mm.

After that, larger steps can be used, in proportion to f_eff^2, recognizing that f_eff keeps rising in proportion to the total rear extension.

My spreadsheet enumeration based on this principle shows that, starting at 101 mm of total rear extension,

200 mm of total rear extension is reached at

**1469 steps**.

**--- Case 3: constant step size, adjusting lens aperture so as to retain fixed f_eff = f/9.0 ---**

This is just like case 1, with the exception that the step size is now increased by roughly a factor of 4, to 0.75*0.00055*4*9^2 = 0.13365 mm.

The total number of steps required is then (200-101)/0.13365 =

**741 steps**.

By these calculations, using variable steps with fixed lens aperture reduces the number of steps by a factor of 2904 / 1468 = 1.98X, and using variable lens setting to maintain constant f_eff puts us back to constant step size but with larger steps, saving another 1468 / 741 = 1.98X .

I don't know what process you've done to get your numbers.

I suggest seeing if you can understand what I've done, and relate that to whatever you've done. At least one of us -- quite possibly both -- is getting the wrong answer.

I look forward to getting this discrepancy resolved.

--Rik

It is really helpful that you took the time to work the example!

First, I did not describe the overlap correctly - my steps overlap 25% to each adjacent step, so the total overlap is 50%.

By the way, what overlap % would you recommend Rik?

Second, I did have a bug in my calculations. I will fix and re-post this evening.

First, I did not describe the overlap correctly - my steps overlap 25% to each adjacent step, so the total overlap is 50%.

By the way, what overlap % would you recommend Rik?

Second, I did have a bug in my calculations. I will fix and re-post this evening.

nathanm

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

rjlittlefield wrote:Then, to get your 25% overlap, we'll multiply by 75%

I don't see the inconsistency. When step size is multiplied by 0.75, the first 1/4 of each step is overlapped by the last 1/4 of the previous step, and the last 1/4 of each step is overlapped by the first 1/4 of the next step. This sounds to me the same as what you're saying: total overlap 1/4 plus 1/4 = 50% . If that's not what you intend, then please explain more fully.nathanm wrote:I did not describe the overlap correctly - my steps overlap 25% to each adjacent step, so the total overlap is 50%.

Mostly I listen to what other people tell me works well for them. Step sizes from 2/3 to 3/4 of the nominal DOF are commonly mentioned, but some people use much more overlap.By the way, what overlap % would you recommend Rik?

The requirement depends on both the nature of the subject and the criteria applied.

A good way to think about the subject issue is how quickly the subject surface transitions from one focal plane to the next. If transitions are slow, occurring over a span of 10's of pixels or larger, then less overlap is required because it is simpler for the software to make good decisions. As transitions become more rapid, more overlap is better because it gives more insurance against imperfect decisions by the software.

At high magnifications, there is the additional issue that subject features may "wiggle around" laterally as focus is changed. See http://www.photomacrography.net/forum/v ... 187#149187 for an illustration at 50X NA 0.55 . In such cases, using a very fine step size can produce better rendering, especially of linear structures, which are particularly sensitive to lateral wiggling. The nominal DOF at NA 0.55 is 1.8 microns, but I have seen cases where people chose to shoot at 0.5 or even 0.25 microns because they saw better results with their subjects.

There is a strong element of subjectivity in the decision. At http://www.photomacrography.net/forum/v ... 108#104108, I show DMap images from a 40X NA 0.50 objective, using step sizes as small as 1/16 micron. The calculated DOF in this case is 2.2 microns (quarter lambda at 550 nm). What I wrote in my evaluation was that

But another colleague wrote to me offline that he considered the differences obvious down to much smaller step sizes, with (barely) detectable improvement even between the two smallest step sizes.I think the results are pretty clear. From 1/16 to 1 micron, the images are indistinguishable. At 1.5 microns, there are tiny detectable difference, but I surely wouldn't see them without the flashing. At 2 microns, the differences are larger and more widespread, but again that I think that most people would not see those without the flashing. At 2.5 microns, there's definite blurring in some areas, and it gets worse from there on out.

I don't know any way to get around the issues of subject dependence, both in the thing being photographed and the person doing the viewing.

--Rik

So, here is a place where we differ.

I used the formula from http://janrik.net/MiscSubj/2014/Defocus ... ns_v01.pdf

Which says that

TDOF_qlwe = lambda*4*(f_eff*f_eff)/(m*m)

This is on page 1 of the document.

Meanwhile in the post above you use

I think the one from the document TDOF_qlwe is correct, because it is numerically almost exactly the same as the geometric optics formula given here https://en.wikipedia.org/wiki/Depth_of_field in terms of magnification due to Laramore (1965) if you setting the circle of confusion c as

c = 2*lambda*f_eff

Which makes some intuitive sense. At very low magnification the two formulas disagree by a small amount - about 3% at m = 0.001 and 0.03% at m = 0.01.

Given the formula that I used, we have

TDOF_qlwe (lambda = 0.00055mm, m=1, f/4.5) = 0.1782 mm

TDOF_qlwe (lambda = 0.00055mm, m=0.01, f/4.5) = 5.39055 mm

Where f/4.5 means the lens is set to that value, not f_eff.

The distance from the lens (in thin lens formula anyway) to the subject is 200mm at m = 1. At m = 0.01, the distance is 101* 100 = 10,100 mm, or about 10 meters.

The distance across the shot on the subject side of the lens is 10100 - 200 =9900 mm

So that means 55,556 steps to move 9900 mm with the lens set at constant stated aperture, with ZERO overlap.

I made a mistake with the overlap, your approach is correct. With each step at 75% of DOF steps that would be 740742 steps.

This may not be correct, but at least it explains what I get (modulo the errors!) for the constant aperture case.

I used the formula from http://janrik.net/MiscSubj/2014/Defocus ... ns_v01.pdf

Which says that

TDOF_qlwe = lambda*4*(f_eff*f_eff)/(m*m)

This is on page 1 of the document.

Meanwhile in the post above you use

This differs by the factor of 1/m^2, which doesn't matter at m = 1, but does matter a lot at other magnifications.Key formula: TDF = lambda/NA^2 = lambda*4*f_eff^2

I think the one from the document TDOF_qlwe is correct, because it is numerically almost exactly the same as the geometric optics formula given here https://en.wikipedia.org/wiki/Depth_of_field in terms of magnification due to Laramore (1965) if you setting the circle of confusion c as

c = 2*lambda*f_eff

Which makes some intuitive sense. At very low magnification the two formulas disagree by a small amount - about 3% at m = 0.001 and 0.03% at m = 0.01.

Given the formula that I used, we have

TDOF_qlwe (lambda = 0.00055mm, m=1, f/4.5) = 0.1782 mm

TDOF_qlwe (lambda = 0.00055mm, m=0.01, f/4.5) = 5.39055 mm

Where f/4.5 means the lens is set to that value, not f_eff.

The distance from the lens (in thin lens formula anyway) to the subject is 200mm at m = 1. At m = 0.01, the distance is 101* 100 = 10,100 mm, or about 10 meters.

The distance across the shot on the subject side of the lens is 10100 - 200 =9900 mm

So that means 55,556 steps to move 9900 mm with the lens set at constant stated aperture, with ZERO overlap.

I made a mistake with the overlap, your approach is correct. With each step at 75% of DOF steps that would be 740742 steps.

This may not be correct, but at least it explains what I get (modulo the errors!) for the constant aperture case.

nathanm

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

Right underneath the key formula above, it says "This is for total depth of focus (TDF) in thenathanm wrote:So, here is a place where we differ.

I used the formula from http://janrik.net/MiscSubj/2014/Defocus ... ns_v01.pdf

Which says that

TDOF_qlwe = lambda*4*(f_eff*f_eff)/(m*m)

This is on page 1 of the document.

Meanwhile in the post above you use

This differs by the factor of 1/m^2, which doesn't matter at m = 1, but does matter a lot at other magnifications.Key formula: TDF = lambda/NA^2 = lambda*4*f_eff^2

**image**plane" (emphasis added), that is,

**at the sensor**.

In the pdf that you reference, it says "TDOF_qlwe is the total DOF, front to back, measured

**at the subject**" (emphasis added).

The key difference is sensor versus subject. The effective aperture on the camera side is narrower by a factor of m, compared to effective aperture on the subject side. In both cases, the governing formula is TDF = lambda/NA^2 = lambda*4*f_eff^2, but because the respective effective apertures are different by a factor of m, the corresponding DOF's ("depth of

**field**" at the subject, "depth of

**focus**" at the sensor) are different by a factor of m^2.

Both formulas are correct when interpreted as described.I think the one from the document TDOF_qlwe is correct

--Rik

[Edit: correct typo, "narrower" versus "wider"]

Ok, great, my calculation is on the subject side of the lens.

The number of steps has to be the same regardless of whether we count them in the subject side or the sensor side.

In this case our subject has a portion near the camera which is 200 mm away from the lens (thin lens center) and thus will be imaged at 1X and a portion that is 10100 mm away from the lens (i.e. imagine an object 9.9 meters long).

My previous DOF numbers are on the subject side

TDOF_qlwe (lambda = 0.00055mm, m=1, f/4.5) = 0.1782 mm

TDOF_qlwe (lambda = 0.00055mm, m=0.01, f/4.5) = 454.455 mm

So, we get the answer that constant step size, will have to be the smaller of those two DOF, and with constant lens aperture give us 74075 steps - there is a typo in my post above where I omitted the decimal point - sorry!

If we now move to the case of constant lens aperture, with variable step size, we have the DOF sizes above, times 0.75 for overlap.

My code steps through them and get the result that it will take 1470 steps. That works out to a factor of about 50.4 fewer steps.

The difference between the largest step and smallest step is huge - a factor of 2550. But the differences narrow so overall we get the factor of 50X fewer steps.

If we then try variable step size, with variable lens aperture (attempting to maintain constant effective aperture <= f/9), I get 832 steps, at lens settings from f/8 to f/4.5. The largest step size occurs at m=0.01, f/8 which is 1436.3 mm.

Note that this assumes we can only set aperture at 1/3 stop intervals. You would do better with a continuous aperture variation.

The total reduction in step count is a factor of 89. The largest step is 8060 times bigger than the smallest step.

Admittedly this is a very deep subject.

Here is a more realistic case for a deep subject. Consider the 14 mm Laowa lens that will focus from 1X to infinity. Consider the same range of m = 0.01 to m = 1.

In that case the m = 1 end is 28 mm from the lens center (thin lens formula might be stretching things here...) the m = 0.01 end is 1214 mm away. So it is a much less deep subject, but spanning the same magnifications.

Constant steps with f_eff <= f/9 takes 10371 steps. Variable steps but constant aperture takes 208 steps, varying aperture and steps takes 119 steps.

Note that all of these calculations are independent of whether you move the front or the back of the bellows. Since we want to tile the subject side with DOF thick steps (and some overlap) the count has to be the same.

The main difference is that if we move the front of the bellows for these long stacks, we will introduce more parallax. Which does not matter

Note also that we will see the subject distorted by the large magnification difference from front to back. In conventional (i.e. non-macro) photography that is called "wide angle distortion" or "perspective distortion" but that is because one does not think in terms of magnification. The same thing can happen with any lens if you can focus across a large range of magnifications.

The number of steps has to be the same regardless of whether we count them in the subject side or the sensor side.

In this case our subject has a portion near the camera which is 200 mm away from the lens (thin lens center) and thus will be imaged at 1X and a portion that is 10100 mm away from the lens (i.e. imagine an object 9.9 meters long).

My previous DOF numbers are on the subject side

TDOF_qlwe (lambda = 0.00055mm, m=1, f/4.5) = 0.1782 mm

TDOF_qlwe (lambda = 0.00055mm, m=0.01, f/4.5) = 454.455 mm

So, we get the answer that constant step size, will have to be the smaller of those two DOF, and with constant lens aperture give us 74075 steps - there is a typo in my post above where I omitted the decimal point - sorry!

If we now move to the case of constant lens aperture, with variable step size, we have the DOF sizes above, times 0.75 for overlap.

My code steps through them and get the result that it will take 1470 steps. That works out to a factor of about 50.4 fewer steps.

The difference between the largest step and smallest step is huge - a factor of 2550. But the differences narrow so overall we get the factor of 50X fewer steps.

If we then try variable step size, with variable lens aperture (attempting to maintain constant effective aperture <= f/9), I get 832 steps, at lens settings from f/8 to f/4.5. The largest step size occurs at m=0.01, f/8 which is 1436.3 mm.

Note that this assumes we can only set aperture at 1/3 stop intervals. You would do better with a continuous aperture variation.

The total reduction in step count is a factor of 89. The largest step is 8060 times bigger than the smallest step.

Admittedly this is a very deep subject.

Here is a more realistic case for a deep subject. Consider the 14 mm Laowa lens that will focus from 1X to infinity. Consider the same range of m = 0.01 to m = 1.

In that case the m = 1 end is 28 mm from the lens center (thin lens formula might be stretching things here...) the m = 0.01 end is 1214 mm away. So it is a much less deep subject, but spanning the same magnifications.

Constant steps with f_eff <= f/9 takes 10371 steps. Variable steps but constant aperture takes 208 steps, varying aperture and steps takes 119 steps.

Note that all of these calculations are independent of whether you move the front or the back of the bellows. Since we want to tile the subject side with DOF thick steps (and some overlap) the count has to be the same.

The main difference is that if we move the front of the bellows for these long stacks, we will introduce more parallax. Which does not matter

Note also that we will see the subject distorted by the large magnification difference from front to back. In conventional (i.e. non-macro) photography that is called "wide angle distortion" or "perspective distortion" but that is because one does not think in terms of magnification. The same thing can happen with any lens if you can focus across a large range of magnifications.

nathanm

If you keep aperture constant, doing things from two sides will not result in same number of steps though both are using equivalent quarter length wavefront error formula. This is because the relationship between the i and the d (distance to image "i" and distance to subject "d").The number of steps has to be the same regardless of whether we count them in the subject side or the sensor side.

Look at graph below, the orange graph changes drastically at both ends (m=0.01 and m=0.5), this means constant steps size obtained at higher magnification end will result a lot of waste when applied to the lower magnification end. Here is an example (constant step dd=0.1782mm 0r 0.0001782)

when d = 10m, i will be 0.10101010101 or 101.01mm

when d = 10 - 0.0001782, i will be 0.101010119, or 101.01010119mm

so the difference in i will be so small, it probably can be ignored. This means that step can be ignored.

However, when using variable step size and constant aperture, the result should be roughly the same, which I think they are and this is because variable step method counts the curvature in.

One more thought is, it is better to do it on image side as the range is limited (100 - 200) to cover infinity to 200mm on subject side [edit] WHEN USING CONSTANT STEP SIZE[/edit]