Wednesday, April 17, 2019

Deep Focus Photography: User Guide for ML Get Brackets Script

Warning this is a longer and more detailed post than usual!

The above script (as usual accessible on the RHS of this site) has been written to support ‘deep focus’ photography and specifically capturing focus brackets that seamlessly cover the depth of field from infinity down to a near object of interest.

It is ‘best’ used with wide angle lens, but can be used at any focal length, with care!

Most times deep focus can be handled by focusing at, or ideally, just beyond, the hyperfocal, ie for focus insurance. If focused at the hyperfocal distance (H), the depth of field is, by definition, from H/2 to infinity.

In this case the accepted ‘focus quality’ will go from H/2 to infinity, and is mainly influenced by two dominant ‘blurs’, usually taken together in quadrature. That is, the so-called circle of confusion (CoC) criterion that you have decided to use to cover the lens defocus blur, that varies through the scene and is only zero in the plane of focus; and the diffraction blur, which is essentially the same throughout the scene, only changes with aperture and is never zero.

For Full Frame (FF) cameras the ‘accepted’ defocus CoC, ie without taking account of diffraction, is usually stated as 29 microns, so let’s call this 30 for convenience. This 30 microns CoC is based around an arm’s length viewing of a 10in print, by a person with normal eyesight. Closer scrutiny, ie by judges, and larger prints viewed close-up in gallery, will require CoCs less than 30. A billboard 30m away, less.

As for a sensible minimum defocus blur (CoC) to use; well you can’t squeeze a line pair/dot (one black + one white line) into less than two sensor pixels: so let’s pragmatically accept an absolute lower CoC of two sensor pixels, ie around 12 microns on my 5D3. Both numbers being adjusted by the crop of the camera, ie 1.6 on a Canon APS-C camera, or 12/1.6 to 30/1.6.

Accounting for diffraction complicates the above a little, but, as we will see, we can ignore diffraction if we sensibly select the defocus (Coc) blur in Magic Lantern, ie between 30 and 12 on my 5D3.

To help inform your photography, and focus bracketing, it is useful to remember the ‘Rule of 10’, which says that the hyperfocal (H) in meters (sic) is simply the focal length (FL) in mm divided by 10, IF you are at an aperture of f/10 and you assume your CoC (in microns) is the FL (in mm). As an example, assume a lens with a focal length of 16mm at an aperture of f/10. The ROT says H is simply 16/10 = 1.6m (with a CoC of 16 microns).

In general, for any lens with a focal length of, say, 30mm or less, the ROT will always give a higher quality focus than the usual hyperfocal tables; that assume a fixed 29-30 microns. Thus, shooting with a WA lens, ie less than or equal to 30mm, means that, at f/10, the depth of field will go from FL/20 to infinity, with an infinity blur (defocus CoC) of FL in microns, if you focus at the ROT-based H, ie FL/10 in meters. Also, the wider the lens, the higher the focus quality, ie the lower the infinity blur, will be using the ROT approach: all other things being equal, which there’re not , of course!

Of course, knowing the ROT (at a CoC of the FL in microns) allows one to simply adjust the ROT to account for other apertures. For example, the 16mm ROT H above, at 1.6, will be 0.8m at f/20 or 3.2m at f/5, ie ROT*(10/N), where N is the aperture. Likewise to adjust the ROT to account for different defocus CoCs, all one has to do is do some simple maths: ROT*((FL in mm)/(required CoC in microns)). Thus, our 16mm example, with a ROT H of 1.6m at a CoC of 16 microns, would have a hyperfocal of 3.2m if we used a CoC of 8 microns, ie 1.6*16/8.

Finally, we can use H, from the ROT or a table or a calculation, to estimate the number of focus brackets required to cover from our point of focus (x) to H, where x = H/m, and m is an integer between 3 and infinity. The number of brackets is simply (m + 1)/2. For example, if we need to cover a depth of field that covers from H/9 to H, ie to infinity, then m = 9 and the number of ‘perfect’ brackets would be 5 = (9 + 1)/2. If we then decided to increase the near field from H/9 to H/19, the number of brackets just double to (19 + 1)/2 = 10.

The key thing to take away from the above is: know your H and know how to use the ROT.

Let’s now assume you are focusing at less than H/2 and you still require to cover focus to infinity, ie you can’t use a single image. In this case you have various options.

You could naively follow the advice some photographers give and focus 2/3 into the scene. But then you will likely be disappointed with your result. The ‘2/3 rule’, ie depth of field is split 1/3 in front of the point of focus and 2/3 behind, is only true at H/3. So, please don’t use this ‘rule’.

You could use the depth of field scale on your lens. But many new lenses don’t have such scales and if they do, they’re not usable (an example of a useable scale on a modern, high quality lens, is the one that Irix use: BTW my 11mm Irix appears to be calibrated around a defocus CoC of the FL in microns, ie it’s a ROT scale!). Some old, manual lenses do have good depth of field scales, but you will need to calibrate/confirm they are still OK or, simply manually focus, ignoring the focus scale reporting on the lens, and then use the depth of field scale to focus bracket from your point of focus.

If you have an AF lens, and are running Magic Lantern, you could use my DoF Bar script to give you the required manual feedback for focus bracketing.

Finally, if you have an AF lens, and are running Magic Lantern, you now have the ultimate focus bracketing tool: my Get Focus Brackets script.

Once loaded in the normal way, ie turn on auto start, this script may be switched on and off under its ML Focus menu. There are three options:

  • Script ON+Bookends plus place dark image bookmarks at the start and end of the bracketing sequence, to help delineate the bracket set in post. This is the default and recommended setting;
  • Script ON will simply create the focus brackets, ie no bookmarks;
  • Script OFF means just that and that the button that runs the script is usable in its normal mode.
The script will only run if the lens is an AF one and you are in LV. If running the only feedback from the script is displayed in the top right ML bar. Here you will see one of two ‘B number’ presentations:
B=n, where n >= 3: showing the estimated number of brackets the script will take (for n>3, B = +/- 1);
B=0 means the script will not run: for whatever reason ;-) 

B=666 means diffraction is dominating, so open up the aperture

The script watches for camera changes, ie in AF setting, focal length, aperture etc.

Once you see B=n, where n >= 3, you should be confident the script will run.

The speed the script runs at is camera dependent. On my 5D3 it’s ‘zippy’ but not super fast. But IMHO, if you are on a tripod and doing land/city-scape, deep focus, photography, you should be relaxing and enjoying life. OK, if the capture is really slow, then you may have to deal with a little bracket to bracket movement – but such is life, ie it’s not perfect :-)

If you are focused beyond H/3, ie B=3, don’t worry about fine tuning focus, as the script will always take three brackets at/around H/3, H and 3*H. The 3*H shot being the infinity focus shot, generating an infinity blur of the ML CoC/3. Hence if you have an ML CoC set at 30 microns (ie full frame and less by the crop on an APS-C camera), the infinity blur will be around 10 microns = 30/3.

The script is sensitive to the ML depth of field diffraction setting as it uses the ML set hyperfocal. So, if you wish to increase the focus quality through the scene, switch on diffraction aware, however, be warned: the number of brackets needed to cover the depth of field will increase. Set diffraction aware on and play around with aperture to see the impact on B.

An alternative approach is to switch off the ML diffraction aware, ie use the Simple option, and explicitly adjust the CoC under your direct control. If you wish the brackets to overlap at 2/3 of the CoC, ie at 20 micons as opposed to the normal 30, then dial this in to the ML depth of field menu: but remember to select Simple. The following illustrates what overlap means, ie it is a fraction of the 'normal' CoC = the CoC you dial into ML:


To use the script, put the camera in M mode and Live View, and simply focus on the nearest point of interest in your scene that you wish to see in focus, ie the front of that object, using any focusing method you wish: doing this means you will have a little insurance in front of the focus.

As an aside if you are focused at a fraction of the hyperfocal, ie x = H/m, where m >= 1, the near depth of field in front of x can be estimated from H/(m.(m+1)) and behind the point of focus as H/(m.(m-1)). Thus, say, with an H of 1000mm and focused at, say, 200mm, ie m = 5, the depth of field behind the focus (ie towards the camera) is about 1000/(5*6) = 33mm; whereas in front of the point of focus, ie towards infinity, it is 1000/(5*4) = 50mm. That is, as we know, depth of field collapses as you move towards the camera and below H, and at high m the two depth of field, either side of the point of focus, converge to about H/(m^2).

Next review the B number and confirm it is acceptable, ie not too large.

Assuming composition and exposure are OK, now press the script’s trigger key. The default is the RATE key, but you can easily change this in the script. On the 5D3 the RATE key works well for me. Once running and useable, ie not switched off, this trigger key is hijacked, ie it won’t be usable in normal mode. To access it in standard mode, simply switch off the script in its menu.

The first time the script runs after every camera start up, it carries out a short calibration test to check the lens motor’s chirality, ie what direction does the lens move in when Lua lens.focus() is called. This is all transparent to the user.

Assuming all is OK, the script will then either take the first image and then refocusing and take the next etc, or first move to H/3 and then take the first image and refocus etc. At the end of the bracketing the lens will be repositioned to about where it was at the start, ie there may be small differences according to where you start the lens.

Once captured, ingest the images into your post processing environment, I’ll assume Lightroom in this post, and you will clearly see your bracketing sequences, ie delineated by bookends.

For those that like seeing data, you can then get a feel (sic) for where each image was focused, by exploring the makers data in the image’s EXIF. This can be accomplished several ways, eg using the EXIF plug in from http://regex.info/blog/lightroom-goodies/metadata-viewer or with EXIFToolsGui at http://u88.n24.queensu.ca/exiftool/forum/index.php/board,7.0.html.

Interpretation of the focus position from the EXIF is not straightforward, as Canon decided to write out two numbers: FocusDistanceUpper and FocusDistanceLower, rather than Focus. Also, there appears to be some debate as to what these Canon EXIF data mean. Until someone says something else to correct me, I suggest you assume (sic) that the focus position is in the middle of the upper and lower numbers.

Once ingested in LR you then need to merge the focus brackets. Unfortunately, you can’t do this only within LR at the moment, ie without a little help. Personally, I use one of three round trips routes:

  • LR to PhotoShop and back to LR
  • LR to Helicon Focus and back to LR
  • LR to Zerene Stacker and back to LR
For example, in Helicon Focus, which I use most of the time, I find Method B works well with the script’s seamlessly created focus brackets; and it’s pleasing to see Method B unfold in front of you, ie first the depth map, followed by the detail being added in.

You may, however, find you need to adjust some of the images, ie to remove bracket-2-bracket movement artifacts. Each of the above allows you to do this, eg via adjusting masks or clone from one image to the composite.

This post has a lot of words: so let’s finish with a test image I just took in my garden, with my 5D3 and 12-24mm Sigma lens at 19mm, with a aperture of f/11..


The camera was in M mode and I had Dual-ISO switched on. I ML ETTRed to get 1/13s. The script indicated 4 brackets would be taken, ie B=4, but remember the +/- 1 for the B number. 


I used ExifToolGui to establish the four focus distances, ie lower and upper in meters: (0.28/0.28), (0.39/0.41), (0.93/1.16) and (1.51/2.19). I had diffraction aware on in ML and the CoC was set at 30 microns.  ML stated the resultant hyperfocal was 1.27m.

Finally, the latest version of the script will always be here: https://gist.github.com/pigeonhill/d02e5d5a88516c67e929397d74af0142

Monday, April 8, 2019

Landscape Bracketing Script: Update

Because I was not content with its stability, I've withdrawn and rewritten my original CHDK Landscape Focus Bracketing script.

I've written some background on the new script here.

In addition, the link on the right of this page now points to the new script.

Here are a couple of test images I took at the weekend with the new script, using my G7X:




Saturday, March 23, 2019

Further 645 Experiments

Over the past few weeks I've been 'perfecting' my 645 workflow, using my RhinoCam and a Sekor 35mm lens. The lens is a second hand one and exhibits a little 'softness' in one corner/edge, however, it's manageable, as this isn't my prime system. Afterall, If I want sharpness over the entire image I'll use my 5D3 with my 24mm TSE lens.

To help with the infield workflow, I wrote a new script which I'm calling the Cycler, whose job is to help manage the EOSM's rather limited button UI, as I need to change camera states a few times.

The script should work on any EOS camera running Magic Lantern. To use the script simply press the [PLAY] button twice, eg [PLAY]+{<1000ms}+[PLAY] = cycle to next programmed ML state. In the script as downloaded the states that are cycled through ETTR, Auto-Bracket, Zoom, Dual-ISO.

Pressing [PLAY] and waiting will result in the top ML bar moving through various options, eg BOOK, <<>> and PLAY. BOOK will set a dark frame exposure, <<>> will change cycler direction and PLAY will result in the [PLAY] button acting as normal.

Taking an image with BOOK set results in the shutter being reset to the exposure before the bookmark image was taken.

As for the RhinoCam, this allows a 645 digital image to be taken with the Canon EOSM, ie 8 sensor brackets, creating a 645 image that is about 12500x9900.

In addition to the sensor bracketing, I also focus bracket in the same image. The approach is to set the lens to F/16 and focus at about 3.5m for the top four brackets; then take the bottom four brackets at a distance of 1.2m. Using these distances results in an infinity blur of about 22 microns, compared to a 'normal' CoC-based blur of about 45microns on a 645.

In this test image I also used Dual-ISO, once again accessed vi the Cycler. BTW this image is scaled by 50% in pixel space.


Sunday, March 3, 2019

Bad weather = self development


Looks like a miserable day weather-wise, so I decided to refine my workflow associated with my visible band & IR band digital (EoSM) backs on my 645 Vizelex RhinoCam system.

The RhinoCam allows me, via my Mamiya-Sekor 45mm lens, to create seamlessly flat large 645 image or a pano, ie no nodal points to worry about ;-)

In 645 mode, the EoSM is used in portrait mode, as below, and in pano mode it is used in landscape mode.





I've recently been exploring using an ML-based work flow, for the exposure, with an extended DoF technique, through using focus bracketing with the sensor bracketing.

Following composition setting, I first use ML’s ETTR to help me select a suitable base exposure for the highlights; and decide if I need to exposure bracket as well.

I then set focus using the 'Rule of 10', which says that if I use an aperture of F/10 and focus at 4.5m (45mm/10), I’ll be at the hyperfocal with a CoC of 45 microns, ie the FL in microns. Whereas a CoC of, say, 30 micron, is a good Full Frame starting point, 45 microns is the 645 equivalent.

From there I may adjust things as required. For example, I could add some background focus insurance and set the focus to, say, 6m, ie rather than the theoretical 4.5m.

Note that, because we are using a 645 format, I can also push the aperture more than we would with a 35mm format, ie extending the DoF. Thus I could go up to F/20 with my visible band EoSM back, but ‘only’ F/18 with my IR EoSM back; before diffraction started to dominate.

As the Vizelex RhinoCam system needs to take 8 images (two rows of 4 sensor brackets) with the EOSM in portrait mode, this gives me the opportunity to adopt two focus strategies. One for the top row and one for the bottom row.

That is I can focus bracket as well as sensor bracket in the same image. And, as mentioned above, if required, I could also exposure bracket at each sensor bracket, eg using a Zero-Noise bracket at, say, 4Ev for the shadows; that is if a single exposure wont hack it.

I then focus at 6m, in this case, and take the top four sensor bracket images (with exposure brackets if required).

Having then repositioned the RhinoCam system for the bottom row of sensor brackets, I then refocus the lens at the H/3 point, ie to extend the near DoF in the foreground from H/2 to H/4. For example, I refocus the lens to around 2m, ie 6/3, which will extend the near DoF from the 3m in the top row, ie 6/2, to 1m in the bottom row, ie (6/3)/2.

After ingesting into Lightroom, I simply use the LR Merge capability.

As an example (indoor) test shot, I used my visible band EoSM and ETTRed for the highlights, at ISO100 and at F/16. Giving a base exposure of 1.3s. I set the ML Auto bracketing to 2 images and +4Ev to create a single ‘zero-noise’ bracket for the shadows, ie at shutter of 20s. I focused the top row at 6m and the bottom row at 2m.

After ingesting into LR I tried to use the combined HDR-Pano merge in LR, but this failed with an ‘error’ of not enough matching images. I therefore resulted to doing a two-pass merge process in LR: HDR the two exposure brackets first, with auto stacking switched on; then do the pano merge in LR.

Finally, I tweaked the image for ‘a look’.

The resultant test image is a 283MB, 9367x8865 TIFF image, that, in the rendition below, is JPEGed down to 4Mb!


I hope some have found the above of interest and as usual I welcome any feedback.


Thursday, February 21, 2019

More Focusing & Stacking with CHDK

I've now updated the CHDK Landscape Focus Bracketing script and thought it worthwhile reminding readers what this script can do.

Being a CHDK Lua script, it runs on Canon Powershots. I've tested it on my S95, my G7X and my G1X.

In this post I show an example of what the script can do on a G7X, which has a minimum focus of 20cm.

The script can now work in a near full auto mode, using the Mac2Inf focus bracketing option. If this mode is selected, the script will automatically position the lens at the camera's minimum focus and, according to the infinity blur that you selected, will focus bracket from the minimum focus to the blur-defined infinity. Several bracket to bracket overlap strategies are covered, eg none, or at CoC/2, or at CoC/3 or at the diffraction corrected defocus CoC.

At each focus position the script can take various exposures, eg:
  • two additional time based exposures at +/- or +/++ or -/-- (at 1, 2 or 3Ev)
  • one additional ISO bracket at either ISO 800 or ISO 1600, set according to the when your camera's ISO invariance zone kicks in
  • one zero-noise time bracket at 4Ev
In the tabletop example below, I positioned the flower a couple of inches away from the camera and used the Mac2Inf option, together with the zero-noise exposure bracket option.

This resulted in 17 focus positions, with two exposures at each focus station, ie 34 images.

The images were processed in Lightroom as HDRs and then exported, via a round trip, to Helicon Focus. Base exposure, for the highlights, was ISO 125, F/5.6 at 1/60s. The zero-noise exposure was at 1/4s.

Here is the resultant test image, albeit only lightly 'touched up' in Helicon Focus, ie I should have spent a few more minutes touching up around the petals. Nevertheless, I hope this example gives readers a flavour of the script's power.



As usual I welcome any feedback.

Wednesday, January 16, 2019

Update of Landscape Bracketing script

Just a short post to say I've updated the CHDK Lua script, that runs on Canon Powershot cameras.

The CHDK post about the script may be read here: https://chdk.wikia.com/wiki/Landscape_Focus_Bracketing_:_perfect_near_to_far_focus_brackets

You may also download the script from: https://gist.github.com/pigeonhill/10a43f5ba543bc758f1ce21d28981a89


Thursday, January 3, 2019

Landscape Focus Bracket Script for the G7X

In this post I'll be talking about my latest 'toy', the Canon Powershot G7X and in particular focus stacking with it.

As we know, macro focus stacking is rather 'easy' to undertake, albeit rather tedious. This is because the near and far depths if field (DoFs), ether side of the point of focus, are virtually symmetrical but very small. 

As soon, however, as we move away from the macro end, the near and far DoFs become progressively non-symmetric, until we reach the hyperfocal point (H), where the near DoF is, of course, H/2 and the far is at 'infinity'. Also the defocus blur field changes through the scene; being zero microns at the point of focus and the 'circle of confusion' set blur at the near and far DoFs.

However, it's relatively simple to estimate (sic) the bracketing that is required. That is, if I'm focused at Sn, where do I focus next (Sn+1) to ensure that my current far DoF is the same as my next near DoF, as illustrated here:


If we didn't explicitly calculate the correct Sn+1 focus position, and, say, only assume a fixed refocus delta, as we do in macro photography, we would end up with 'focus gaps', like this:



As it is near impossible to guarantee that the refocused position is a perfect match, we usually use an overlap 'insurance' to cover ourselves, like this:


With macro focus bracketing, which is usually indoors, we can either make use of rails or even try and move the lens in-camera. But for landscape photography, rails will not really work; plus we also we need to calculate the next focus position.

To date I've tried to solve the in-camera solution by Lua scripting on my EOS 5D3, using Magic Lantern. But I've now given up with that approach, as ML can not (yet) explicitly control the lens, ie drive it to an explicit position. Instead, on my EOS cameras I now use the DoF Bar to give me the required feedback, so I may manually adjust focus to the correct position.

With my 'new' G7X I'm pleased to report that everything just got brighter, as the CHDK environment does allow me to explicitly drive the lens; albeit with a little, but acceptable,  'jitter'.

The script below (a Lua CHDK script I've written that I call Landscape Bracketing) provides three user variables. The first is a simple delay to allow you to trigger the script on the tripod: the default is 3 seconds. The second input is whether you are requesting the script to create a start and end (dark) bookend frame, which helps identify the bracket set in post: the default is yes. The last input is the overlap logic that the script uses: the default is none, ie each bracket will link to the next using the CHDK CoC value. The other two options are 'some' and 'more'. Some will use a overap blur of CoC/1.25 and 'more' will use one of CoC/1.5.

In general the script captures the bracket set from near to just short of H. It then takes two more images: one at H and one at 2H.

As an example, here is a 7 bracket set (screen capture from Lightroom) that the script captured of my test scene:



Here is the near (1st image) showing the narrow DoF at that point:



Here is the last (7th Image), taken at 2*H, which insures our infinity focus quality



Here is the focus stacked image after a round trip to Helicon Focus, showing there are no focus gaps:



The script may be downloaded from the link on the right.

I must say, I'm impressed with the power of the CHDK Lua environment, which provides more functionality than Magic Lantern's Lua; but to be fair we are comparing apples and pears, ie a full frame DSLR to a point and shoot camera. Nevertheless, the G7X represents a great little travel companion for my pocket.