Sunday, May 19, 2019

Focus on Flax

As I mainly post about technical stuff, I thought I’d upload an image of a field of flax near where we live. It was taken with my 5D3 and a Sigma 12-24mm at 12mm. 

The exposure was set via Magic Lantern ETTR at 1/200s. I had Dual-ISO switched on at 100/1600 and the aperture was set at f/8. 

I set the lens to the minimum focus distance of 280mm and let my auto focus bracketing script do the rest. 

After processing the Dual-ISO in Lightroom, I sent three images over to Photoshop and used layer masks to blend the images, after first auto aligning. 

After returning to Lightroom, I finished off the image, including selectively using the new texture slider both positively, for the field, and negatively, for the sky. 

Tuesday, May 14, 2019

Multi-image, Deep Focus Photography: Magic Lantern Helper Script

For those that seek to achieve ‘deep focus’ in their photography, ie from very near to infinity, you know that wide angle lenses are your friend. For example, an IRIX 11mm lens on a Full Frame camera, with an aperture set to f/10, with have a hyperfocal distance (H) of around 1.1m, at an infinity defocus blur of 11 microns. This follows from the Rule of Ten, where the hyperfocal is simply FL/10, when the circle of confusion, in microns, is the focal length (FL) in mm and the aperture is f/10.
Such a single image set up will provide a very high-quality focus over a deep focus field, ie less than 11 micron defocus blur, between 550mm (H/2) and infinity

But what if there was a feature you needed to include in the focus at, say, 150mm? The simple answer is you couldn’t achieve this in a single image and maintain focus quality through the scene.

This is where multi-image, deep focus techniques come into play, ie focus bracketing.
One of the challenges with multi image focus bracketing, apart from the wind, is knowing where to focus from image to image.

At the simplest level, for perfect focus bracketing, one would focus at H, H/3, H/5, H/7 etc. Thus, with four images, where H/7 being the shortest with a near and far depth of field at H/8 and H/6, the merged, focus stacked, depth of field will cover from H/8 to infinity. 

Thus, in the example above, with an H of 1.1m, focusing at 1100/7, ie at about 157mm, will achieve a four image depth of field from 1100/8 to infinity, ie from 137mm to infinity.

But notice how the near depth of field collapses with each image. For example, when focused at H, the near depth of field for that image was some 550mm behind the point of focus, ie at H/2. In the fourth image, taken at H/7, the near depth of field, ie relative to the point of focus, is H/56, some 20mm!!!!! In other words, you must really want that extra 20mm to do multi-image deep focus photography.

Of course, knowing distances in theory is fine on paper, but not much help in the field. So, as usual, Magic Lantern to the rescue; all assuming, of course, your lens reports focus distance etc. If it doesn’t, you are out of luck!

Over the years I’ve experimented with various ways of getting focus feedback using ML. I’ve tried automatically moving the lens, which has got better as Lua has matured (thanks to a1ex at ML); plus I’ve tried various Focus Bar arrangements that provide visual feedback to the user.

Although I like my latest focus bar (DoFBar), the down side is its (LV) readability in the field, especially without a hood/shade in bright sunlight. Plus, I (over)loaded it with features: that is, it’s just too complicated.

Last month I released my latest auto focus bracketing script (GFBS), which, IMHO, runs well: at least on my 5D3. Today, I’m releasing the latest version of my focus bar, that I’ve simplified, and targeted 100% towards deep focus photography and in-field (LV) viewing.

I’m calling this script the Bracketeer; and you can download it from the link on the right.
I believe the Bracketeer does three things rather well:

  • First it continuously shows you the defocus blur at infinity, the diffraction blur and the total blur at infinity, ie the defocus and diffraction blurs taken in quadrature. In addition to this blur information in microns, the script displays a simple traffic light system as an aid to focusing: 
    • Red: focus is less than H (H being based on the blur as set in the ML CoC, which is used as the overlap defocus blur) 
    • Yellow: focus is between H and 2*H, ie infinity defocus blur between the overlap blur and half of the overlap blur 
    • Green: focus is between 2*H and 4*H, ie overlap_blur/2 to overlap_blur/4
    • Orange: focus is greater than 4*H and less than ‘infinity’, ie you are now over focusing, but still based on camera distance information 
    • White: focus is at ‘infinity’, ie there is no distance information to be gained from the camera
  • Second it provides a continuous estimate of the number of focus bracket estimate from the current point of focus to the current hyperfocal; 

  • Thirdly, the killer feature, is the visualisation of the image to image focus overlap, ie between the current point of focus and the last image captured. The visualisation is prioritised to show the amount of overlap or the overlap gap.

The script uses the ML-set circle of confusion as the overlap (defocus) blur criterion. For a full frame I recommend this be set around 20-30 microns, and crop scaled on an APS-C camera. The script can be tweaked for IR, ie use a frequency in the script of 0.850, say, compared to 0.550 for a visible band camera.

The script has a simple menu, ie its either on or off; and it can be used in any direction, ie near to far or far to near. 

Once running the script continuously displays the three pieces of focus information. If the script is running alongside the auto bracketing script, the auto bracketing script will deconflict itself, ie you can’t have both scripts running at the same time. However, I recommend these two scripts be loaded as a pair; but note the auto bracketing script requires an AF lens, whereas the Bracketeer doesn’t.

The following illustrate the UI and show traffic lights in action.

In the above we see the point of focus moving through the red, yellow to green states of focus. We also see the blur information changing. The final yellow traffic light warns us that we are now focusing past 4*H. If we were it infinity, this traffic light would show white.

The full focus bracketing (bar) feedback only kicks in once an image has been taken. Before an image has been captured the top and bottom bars show the current focus info relative to the focus state at the script’s start up, ie time zero. 

After an image is captured, the top bar will show the last image’s depth of field, whereas the lower bar will always show the current point of focus’s depth of field. 

The following screen captures illustrate the two bars in action. The red ‘zone’ showing a focus gap. The left hand side of the bar display is positioned at the minimum of the two near depths of field. The right hand side is positioned at either H, if one of the bars far depth of field is greater than H, or at the maximum of the two bars’ far depth of field if both are less than H.

Finally, here is a test image I took with using the Bracketeer script; running on my IR converted EOSM. The focal length was 11 mm, the ISO 100, the aperture was set to f/6.3 and the shutter was at 10s. Using the Exif-tool GUI, we see that the Canon recorded (upper) focus information of the images taken, at: 0.19m, 0.25m, 0.40m, 1.54m and 3.84m.

Rather that drone on about the script, I will leave those with a curious mind to try it out (remove any of my old/legacy scripts). As usual I welcome feedback of any kind, especially how to make the script better.

Sunday, May 12, 2019

Late Spring Cleaning

As Magic Lantern Lua has evolved, alongside my Lua scripting skills, some of the scripts I wrote a while ago are now out of date. 

For this reason I’ve tidied up the list of scripts on the right, both ML and CHDK, and put a single link to the legacy ones, ie the ones I don’t support or recommend. 

Saturday, April 27, 2019

Continuing the Deep Focus story

In this post I'm publishing the latest version of my Magic Lantern Lua script to achieve deep focus.

As we know, lenses are very complex things, for example, here is a cross section through the Canon 24-105 F/4L lens, showing the various individual lens element.

As can be imaged, light rays will follow a complex path, ie as exemplified by the following illustration from an arbitrary lens:

As photographers, or, more correctly, as photographers who wish to play around with a few equations, we usually make use of a few simplifying assumptions. For example, the so-called Thin Lens Model:

The simplicity of the lens equation hides some real power. For example, using various solutions, eg introducing the ideal of reproduction magnification, ie  (Image size)/(Object size) = M, we can show, using similar triangles, that the v and b distances can be stated in terms of the magnitude and the focal length and the object to image distance (x), ie:

Also photographers make use of other useful equations, like the hyperfocal equation (H), which tells us where to focus to achieve a depth of field between H/2 and infinity; and where the focus quality, in terms of (microns) of blur will be never be worse than the so-called circle of confusion (CoC).

But as we know, the Thin Lens model is hardly representative of a real lens. A better model would be to use a Thick Lens model, which may be seen as a Thin Lens model pulled apart.

However, although lens manufacturers tell us some lens specifications, eg maximum magnification, what they don't report is where the lens principal planes sit; and although there are procedures to estimate these positions, they are rather fiddly, and hence, in this script we will continue to assume a thin lens.

Typically, for viewing a 10in print from a full frame camera, at 10in away, the CoC is stated at around 30 microns. Less than this if on a crop camera, ie CoC = (CoC-FF)/Crop. 

Of course, a CoC of 30 microns is often not enough, ie because of closer scrutiny by judges; and can be more, ie web image on Facebook!

As for a minimum blur, pragmatically two sensor pixels is a reasonable limit, ie around 12 microns on my 5D3.

Knowing the CoC, the focal length and the aperture then allows us to estimate the near and far depths of field.

But as we are coding up our solution, we will seek out the ‘correct’ forms for the depths of field.

Thus the near (n) and far (F) depths of field may be written as:

For focus stacking we are seeking solutions when the far depth of field of the current image is the same as the near depth of field of the next image, as shown below:

We thus need to solve for d (note: not the same d in the Thick Lens model above), the amount to move from the current focus position, namely d in this expression:

Some would give up at this point, as it looks difficult to solve for d. However, help is at hand in the form of Wolfram Alpha, which means we can say that d is:

We now seem to have everything we need: we know our focus position (x), thanks to Canon and Magic Lantern; we know the aperture and the focal length; and we know what overlap blur we want.

So there is no confusion, we have not really solved our problem. That is we know the focus position relative to the sensor, and we know the hyperfocal, near depth of field and far depth of field, relative to the lens front principal plane. What we don't know is the position of the front principal plane relative to the sensor.

So the best we can do is assume our thin lens estimate, ie the only principal plane sits at b.

The final step is to code the above up as a ML Lua script: which I have done and which you can down load from the right, in the script list area: ML Get Focus Bracketing Script.

All you need to do is to register your lens in the script, ie name, minimum focus distance and maximum focal length (ie if it is a  zoom).

The script is a so-called Lua simple script, in that it doesn’t have a menu. To run it, simply go to the ML Scripts menu and select run.

The default script assumes a Thin Lens model, however, by commenting in one line you can experiment with using the script in a Thick Lens mode.

I have also written a help script that allows you to press one key to jump you to the ML Scripts menu. I use the RATE key on my 5D3.

The script uses the ML CoC as the required overlap (defocus) blur and to explicitly calculate H. The script does not use the ML depth of field estimates or worry about diffraction.

The script will carry out a calibration step, ie checking what direction the lens moves in, some go left and some go right when command to move towards infinity.

Once the calibration is complete, the script will pause and tell you how many brackets it estimates (+/- 1ish) it will take. At this point you can adjust the focus, aperture and focal length. You can also ETTR, assuming you have selected the ETTR SET option, ie not a long (2+ seconds) half shutter press: the text will change colour to green to indicate you are ready to stack.

The UI shows you the estimated number of brackets, the defocus, diffraction and total blurs at infinity (in microns).

You can ETTR (via SET) when the UI is being shown.

Doing a half shutter press will initiate the image capture phase and pressing any other key, will exit the script. But that key will also function as normal. On my 5D3 I exit with the RATE key.

At each focus the script can also capture exposure brackets, using the ML Advanced Bracketing. Note you can also turn on Dual ISO mode. The script will switch both of these off when it takes the bookend images (see below).

[Note: at the moment this will fail if the Advanced Bracketing chooses (sic) to use BULB mode: sorry, this is a problem in ML that I can’t fix. So, if this does occur, ensure the slowest bracket is fast enough not to trigger the BULB mode.]

The script will also take two (dark) bookend images, to help differentiate the bracketing sequence in post.

So there you have it: perfect focus and exposure bracketing, thanks to Magic Lantern Lua and making a few simplifying assumptions.

In future posts I’ll provide further insight into the script’s use and limitations, and show how to process the images in post.