Tuesday, May 30, 2017

Focus Stacking using the Focus Bar

In previous posts I introduced the focus bar, which is a Magic Lantern add-on via a Lua script.

This post is all about a new feature that helps with manual (sic) focus stacking.

Landscape focus stacking is more complicated than ‘simple’ macro focus stacking, where the near and far depths of field are very small, eg of the order of a millimetre, and symmetric about the plane of focus.

In landscape focus stacking we need to keep track of the near and far depths of field, which are not symmetric about the plane of focus, and that vary with focus, focal length and aperture.

Assuming you have the focus bar script up and running (download FOCUS on the right), you will have a new tool to do manual landscape focus stacking. Before discussing the workflow, it is worth a reminder on how the focus bar works, which for this post is put into Depth of Field mode, option -1. Also the focus bar diffraction is set to OFF and the ML diffraction set to ON, which maximises the amount of information that is presented on the Live View screen.

With the above setting you should see this:

Where: ODoFN is the optical only near DoF distance, ie zero diffraction is assumed (the blur used is that set in the ML setting); ODoFF is the optical only far DoF distance; TDoFN (left green dot) is the total near DoF with diffraction accounted for; TDoFF (right green dot) is the total far DoF with diffraction accounted for; and FP (red dot) is the focus plane (point). The ODOF distances are shown on the focus bar and the TDOF distances are shown at the bottom of the LV screen, just above the focus plane distance (assuming you have set Diffraction aware in the ML menu. Thus, with the focus bar set up this way, you have all the info you require to make informed decisions about your focus.

Note you can set the ML and focus bar DoFs independently according to your preferences. The useful combinations being:

  • ML = diffraction aware : Focus bar = diffraction off
  • ML = simple : Focus bar = diffraction on [My preference]
Because the focus bar is in its DoF mode, the grey shows the focus field. Black indicates where the (total) focus blur is equal to the ML set total blur (ie CoC) criterion, eg, say, 30 microns on a full frame (or whatever blur total you have set; remembering that total blurs should fall between, say, 30 (OK for on screen) and around half that (say 15 for quality printing), according to your final presentation needs. White indicates a blur of zero, which can only occur at the plane of focus and with zero diffraction.

Now we understand what we are looking at, let’s look at the generic situation, ie before we look at the workflow landscape focus stacking.

The focus stacking info is available once you take an image. As you capture an image the focus bar script registers the total near and far DoFs for that image. These reference DoFs are then used as you refocus to show the amount of focus overlap between the last image taken and any refocusing you are doing. The following chart (FB = diffraction OFF and ML = Diffraction aware) is illustrative:

The middle focus bar shows the status of the bar when the last image was captured. The focus bar at the top illustrates what you will see if you refocus towards the macro end; and the focus bar at the bottom illustrates what you will see if you refocus towards the infinity end.

In both cases the magenta area shows the focus overlap, ie the overlap between the total DoFs of the last image captured and the focus state you are in. The magenta area dynamically changes as you refocus, giving you full feedback on the focus overlap state relative to the last captured image.

One thing to note is that, as you refocus, you will observe that EOS lenses (Canon or not) do not have infinitely varying focus, ie they tend to refocus in steps, ie as you rotate the lens focus ring. Plus these steps vary across the focus range of the lens. Thus you will need to ‘play around’ with focus to ensure you have a suitable magenta area. Too much magenta means you are ‘wasting’ focus (see above), ie overlapping too much; no magenta showing means you have zero or less overlap.

In the illustration above, it is clear to see that the we have too much overlap, ie we are wasting focus; as, in a perfect world, the TDoFs (last to current) should be ‘just’ overlapping. But you will not see this condition very often, because of the lens-focus control. Thus you should be aiming for something like this, ie with the smallest magenta area relative to the green dots, ie the total DoF deltas:

The magenta between the total DoF (green dots) and the end of the focus bar, simply shows the difference between the current optical-only DoF, relative to the last image captured total DoF, ie with diffraction. Note this changes if you set the focus bar to show diffraction corrected focus field. Then things would look like this (which is what I personally prefer):

Whether you have the focus bar showing the optical focus field or the total, is a personal choice. For most, once you have played around with the optical presentation, you will likely switch the focus bar to showing the total DoFs, as these are the ones you are interested in. But note, in doing this, we are duplicating the information on the LV, ie the focus bar DoFs are the same as the ML DoFs; unless you switch these around ;-)

[Note at the time of posting the ML DoFs are ‘broken’; however, as the FOCUS script is now independent of ML calculated DoF info, the ML ‘problem’ can be ignored. The ML focus menus are still OK to use, ie to set DoFs to ‘simple’ or ‘diffraction aware’, ie FOCUS uses these menus.]

Now we understand how the focus overlap feedback works, let’s see it in action in a landscape still, photography example. As stated above, let’s assume we are on a tripod, composed and the exposure is optimally set; and that we wish to maximise what is in ‘high quality’ focus, ie from infinity down to close in the near field, and closer than we could capture in a single image.

In this scenario it is usually best to start focus bracketing at infinity. Thus, using the focus bar, all we need to do is focus towards infinity until the focus bar switches into infinity mode, where the near and far DoF distances switch to showing the near DoF distance that matches the infinity blur, and the far DoF shows the total blur at infinity. Also note that for the near DoF you can have the focus bar report the DoF distance based on the total blur at infinity, or twice this: your choice. This x2 option is only really of value if you are not focus stacking, and you wished to be reassured that your near DoF is going to cover the things of interest in the near field. Because we will likely be seeking out an infinity blur that is less than the blur criterion, we can afford, in the near field, to use a 2 x total blur as our criterion, ie for a single image capture.

The focus bar at infinity (assuming set to show total DoFs, ie green dots at the end of the focus bar) will look like this:

Here we see that we have focused to a point where the total blur at infinity, for the far DoF, is at 16 microns. This implies a high quality focus. Note, you should not over focus at infinity. It is best to focus until the infinity total blur doesn’t change, then back of until you see a change.

At this point we would take our first image; at which time the focus bar registers the total DoFs.

We now simply refocus towards away from infinity until we see the minimum amount of magenta. For example things would look like this:

We can repeat the above as many times as we wish. However, for the sake of this post, we will stop here and note that, after post processing the two focus brackets, say in Helicon Focus or Photoshop, we will have a final image that has a high quality depth of field from YYY to infinity.

Finally, here is an actual screen grab, showing the focus bar in its DoF and focus stacking mode, and following an image capture, ie showing the magenta overlap zone. In this screen capture we see the focus bar in optical mode and the ML info (at the bottom) in diffraction aware mode.

Bottom line: the latest focus bar’s ability to give you focus overlap information is a very powerful way of taking control of focusing. Once again, Magic Lantern shows us what cameras should be able to do: if only manufactures open their minds.

Friday, May 19, 2017

Update to EOSM Toggler

Now I have the focus bar up and running, I needed to tweak the EOSM Toggler to ensure script-2-script compatibility in the UI.

The EOSM Togger was written specifically for the EOSM, ie this version is not a generic Toggler.

You can download the updated Toggler on the right.

The EOSM Toggler and focus bar look like this:

In the above screen dump we see the focus bar and the Toggler in its interactive mode, showing that the ML state currently selected (ready to change to) is AutoETTR. 

If you select this state (read the script's intro), then the Toggler will change the  ML Menus you have selected for that state and exit interactive mode. 

In interactive mode, you can go backwards and forwards through your Toggler states and have as many as you like.

The EOSM Toggler also works without the focus bar.

As usual I welcome feedback.

Focus Bar for Magic Lantern

A simple post to say I've rationalised the focus bar script and it now runs in the background, and controllable from the ML FOCUS menu.

I have cleaned up the UI and it now blends into the overall ML UI.

The focus bar script (FOCUS) on the right has extensive info built in.

The overall functionality follows from previous versions, eg:
  • I decided to keep the visualization of the focus field to a linear representation. I personally get more out of it this way. 
  • In addition to 'seeing' the focus field, and the fp and dofs, you can decide if you wish to see the near and far distance info shown below the bar.
  • For landscape photography, once the far dof is greater than 'infinity' the focus_bar distance reporting switches to total blur units (optical and diffraction in quadrature) at infinity for the far; and the dof distance based on the total infinity blur for the near dof.
  • Blur reporting at infinity is green if above the sensor limit (2xsensor pixels) and red below (make sure you set the correct sensor info for your camera).
  • The multiplier allows you to see the focus field beyond the far dof.
  • A multiplier of -1 switches the focus bar into dof mode. Note in all modes the focus bar functions during Canon zoom. Hint: this may help portrait photographers or videographers looking to 'ensure' the focus field is 'right', ie use Canon zoom and focus on the eyes (say) and check the focus field, ie front vs back focus.
  • A multiplier of 0 switches the focus bar into fp mode, ie see the focus field from zero to the fp.
  • I think it 'best' to have ML diffraction aware on (diffraction impacted green dots showing dofs) and switch diffraction off in the focus bar. This way you can see the impact of diffraction in the focus field. The focus field is black at unity blur (optical or with diffraction if selected). Unity blur is defined as the calculated blur divided by the ML set blur (CoC).
Finally, as always, I welcome any feedback.

Monday, May 15, 2017

FOCUS Tutorial

With the first (full) release of my new FOcus COmpanion Script (FOCUS, downloadable on the right), I thought I would write a short tutorial on one of the use cases, namely landscape focusing.

Before doing so, it is worth highlighting the core functionality of FOCUS:

  • It runs within the Magic Lantern Lua environment;
  • It runs continuously, unless you switch it off;
  • By default it is enabled in DoF (depth of field) mode, which we will discuss below;
  • The other modes are interactive mode, which allows you to direct the lens to the hyperfocal distance point, with various aperture options (we will cover this in a later tutorial); and a mode that provides more infinity focus info.

Before discussing how to use FOCUS, it is worth a reminder as to why focusing is not as easy as one would think.

First, modern AF lenses are great at what they do: auto focus. However, when it comes to manual focus, these lenses can be a challenge, eg no hard stop at infinity (to cover glass temperature variations and IR focusing) and, more importantly, very poor correlation between the lens markings and focusing distance, especially when you approach infinity, which, on a wide angle lens, favoured by landscape photographers, is not that far into the field.

Luckily, most modern lenses, even if they are not auto focus, report focus distance, which Magic Lantern gives us on screen and access to in Lua: in addition to aperture and focal length etc. In other words we have all the properties we need to do some interesting stuff.

Another reason that lenses are not ‘easy’ to focus is that their response is not linear. To see this all you need to look at is the focus info on the lens. For example, an x degree rotation of the lens at the macro end is not the same as an x rotation towards the infinity end.

Finally, the depth of field of a lens, ie the zone that to our eyes appears ‘sharp’ is not a simple function through the scene. For instance this chart shows a 24mm lens at F/8 focused at the hyperfocal distance. The green curve show the effect of diffraction, while the blue curve is ‘just’ the optical response. Unity is where the blur is just at our selected acceptable limit, ie around 30 microns here.

Around the plane of focus the difference is clear to see.  In the far field the curves asymptotically approach our set limit, 30 microns in this case; whereas in the near field’, focus collapses rather quicker and towards infinity blur. 

The above curve illustrates a key property of (non-macro) lenses, ie the near and far field responses are radically different: in a true macro lens the near and far depths of field are very small and ‘symmetrical’ about the plane of focus.

So how does the above insight and access to FOCUS help us?

The ‘secret’ of getting the sharpest landscape images, ie from the near to infinity, is to not (sic) use the hyperfocal distance, as, by definition, at infinity the focus is only just acceptable. See my previous posts for more information on HFD vs infinity focusing.

FOCUS brings you a new way to do landscape focusing, through access to three pieces of information: the total blur at infinity, a visual feedback on the optical focus field, ie without diffraction, and the 'usual ML' information about the near and far depths of field with diffraction.

OK, I appreciate some of you may have stopped reading, so lets show the Live View screen when FOCUS is running in its DOF mode.

Here we see the focus bar from FOCUS and, because we are in DOF mode, the left and right hand edges of the focus bar show the near and far depth of field points, ie the green dots (note the distances (within rounding limits) are the same as ML is reporting at the bottom). 

The red dot is the plane of focus, clearly illustrating the bias towards the near field. The focus bar shows the blur as it varies from 0 (white), at the plane of focus, to the ML set total acceptable blur (black), or Circle of Confusion if you prefer.

Clearly the above, random, starting position is not much good for our landscape, so let’s focus towards infinity until we see ML reporting that the far DoF is at infinity. 

The following image shows that we are at now at the HFD, a distance on 71cm, as ML is reporting the far DoF at infinity: as is the focus bar, which is telling us that the total blur is in fact around 28 microns, ie we have (manually) slightly ‘over focused’.

The key thing to note is that throughout the focus field, the acceptable focus is virtually fixed, ie the same level of grey (note the focus bar only shows optical focus blur, ie not diffraction). In this case black equals 30 microns. A total blur of 30 microns would be OK for screen representation, but not for high quality printing, where you would like to see a total blur of, say, half this.

But remember, although we are at the hyperfocal distance, we are in fact only focusing at about 71cm! What if we carried on, say, to the lowest total blur that we can get at infinity. This image next shows that state.

We have now moved focus to 4.25m and the total blur is reported as 12 microns. This is practically the lowest we can achieve with a 5D3, ie below this we are ‘breaching’ the 2xsensor limit, as the 5D3 sensor pitch is about 6.3 microns. Also note the focus bar greyness has shifted towards white, indicating that the optical blur across the field is about as low as you can get it.

So what have we gained by focusing beyond the HFD?

Well we have achieved about double the ‘total focus quality’, ie 12 microns vs 30 microns; which equates to doubling the print (lp/mm) quality. But what have we lost?

In this case, with a 12mm focal length, the acceptable near depth of field has reduced from 34cm at the HFD, to 1.1m using the infinity blur focusing approach. 

Note: the left hand of the focus bar reports the total (optical & diffraction) near depth of field if the far depth of field is less than infinity, ie at the HFD. Once the far depth of field is greater than infinity, the left hand end of the focus bar reports the depth of field that meets the infinity total blur, ie which will be different to the ML reported near DoF (1.1mm vs 55cm in the above example, ie the ML DoFs use the ML set total blur criterion, eg 30 microns in this example.

Clearly it is up to you to decide whether the above is acceptable, eg near field depth of field. But note you have a lot of information to use, eg:

  • A total blur at infinity of 12 microns, as good as you can hope to get;
  • A near DoF, based on 12 microns, of 1.1m;
  • A near DoF, based on 30 microns, of 55cm.

So let’s sum up.

With the new FOCUS approach to focusing we have the advantage of visually ‘seeing’ the focus field, as well as gaining access to some critical information at infinity. These new pieces of information, together with the ML supplied info, represents a new and enhanced way to control focus in your images.

In future posts I will provide more ‘case studies’ related to FOCUS, as well as illustrating additional functionality.

I hope you find this new approach as useful as I have; and, as usual, I welcome any feedback.

Saturday, May 13, 2017

Introducing the 'The Focus Bar'

In previous posts I introduced a 'new', Magic Lantern based, approach to landscape focusing; based on the idea of monitoring the optical, diffraction and total blurs at infinity.

This approach is simplicity itself, as all one needs to do is monitor the blur (provided in microns) and stop focusing when your blur criterion is reached.

For example, for full frame landscape photographers a total blur of, say, 30 microns is OK for screen presentation. If, however, you are seeking the best quality for printing, then a total blur goal at infinity of, say, 15 microns may be a better goal. But note blurs are related to image size and viewing distance.

Once your blur-focus condition at infinity is met, the script provides info on the near field depth of field position, that also meets the total blur criterion. Thus you know you have achieved your focus criterion from the near distance to infinity.

In this post I'm introducing (in beta) a new feature: a focus bar (see image below):

This 5D3 screen dump shows the landscape focus helper, with the new focus bar.

This version 'only' provides a visual feedback on the optical blur through the scene: although I plan to add in diffraction, ie so you can visualize total blur, in a later release.

The focus bar provides you a visual impression of the blur through the field, the red dot being the point of focus. This is important information for those seeking high quality images, as, unlike diffraction, optical blur changes through the depth of field.

The left hand distance is set at the HFD/4: as this script is for landscape photographers, ie unlikely to be seeking focus below HFD/4.

The right hand distance is a user variable and adjusted by a multiplier (from the script's menu). The multiplier is based on sensor-limited 'infinity' (which the script calculates), ie the distance where the optical (sic) blur is the same as the sensor pitch, or the size of single sensor site. That is about 6.3 microns on my 5D3.

The colours provide info on the optical blur through the scene, based on a menu selected 'unity blur', eg 30 microns was used above. The colours provide the following info:
  • Black: an optical blur equal or greater than the unity blur x a multiplier (1-9)
  • Grey: the blur between Black (above) and a unity blur (white)
  • Green: a blur between the unity value, eg 30 microns above, and half this
  • Yellow: a blur of less than half the unity blur, eg less than, say, 15 microns
  • The red dot is the focus point and this varies from HFD/4 to the limit identified above. If focus goes beyond the set limit, the red dot will be shown outside the focus bar, providing another piece of info to be used.
The script is available from the download area (right), ie HFD3. Currently this is a beta release and I welcome feedback.

Wednesday, May 10, 2017

To Infinity…but not beyond!

Modern lens are technical marvels and simple to focus via their Auto Focus (AF) feature. However, this simplicity hides some complexes: take infinity focus.

On older manual lenses there tended to be a hard infinity, ie the lens stopped focusing at infinity. These lenses were usually ‘calibrated’ by the manufacturer; thus one could set infinity focus in the dark, ie rotate the lens focus ring until it stopped. They also tended to have rather impressive markings on the lens to find specific distances, eg the hyperfocal distance.

With a modern AF lens, scales are rather ‘difficult’ to read and infinity is rather confusing, as you can focus beyond infinity, ie you are in the dreaded lazy L zone.

The lens manufacturers say that the Lazy L is there mainly to account for temperature variations in the glass and when you need to focus at Infra-Red frequencies.

OK, this sounds rather nice, but for the majority of photographers, the lazy L zone is rather wasted, eg how do you know by how much to adjust the infinity at a given glass temperature.

Because of the ‘confusion’ over infinity and the lazy L, I’ve decided to add a working-infinity feature into my Landscape Focusing Helper Script (see HFD2 on the right).

For those interested in the ‘simple, ie arm-waving, science’, the logic goes like this:

  • The human eye can only resolve details down to a certain limit. For someone with ‘normal’ eye sight it is said that one can resolve 5 line pairs per millimetre (lp/mm) at about 250mm away (10 inches);
  • The camera’s sensor has thousands of pixels, eg on my 5D3 the pixel pitch is about 6.3 microns. Thus, on the sensor, a lp is about 13 microns, ie 2 x 6.3 microns, equivalent to about 80 lp/mm on the sensor;
  • It is reasonable to consider a ‘focus blur’ (some may prefer to call this a circle of confusion) on the sensor as having a minimum that relates to this sensor-blur limit, ie about 13 microns;
  • The total (system) blur that we record is an amalgam of many sub-blurs. Once again, simplifying  things we may reduce the sub-system blurs down to two main ones: the optical blur that the lens creates, and that varies over the depth of the scene, and the diffraction blur, that is flat across the scene;
  • For the optical blur, we will simplify things even more and assume the lens is symmetrical;
  • We now have a way of defining a working-infinity, which we will define as a focus distance that creates a specified optical blur on the sensor. From the above, we can sensibly say that this blur can not be less that one pixel on the sensor, so let’s use that as our blur criterion;
  • The focus distance at which a specified blur (on the sensor) gives a specific value at infinity can be estimated (sic) by:
  • Where fd is the focus distance, f the focal length, k is the blur criteria and N the aperture number. Of course, the above calculates the HFD if you use that blur criterion, eg 30 microns;
  • As an example, at a focal length of 12mm, an aperture of f/10 and a blur criterion of 6.3 microns (our sensor pitch or size), infinity comes out at about 2.3m! Bluntly, focusing beyond this distance will not provide any more 'infinity detail' or in-focusness or 'acceptable out of focusness'.

Pulling all this together, how would I use the landscape infinity focus helper script on my 5D3? That is using Magic Lantern and my script

Here’s how, ignoring all the other ‘stuff’ like exposure and composition:

  • First, decide on the blur criterion you wish to use at infinity, remembering that on a full frame 5D3, a total blur of, say, 30 microns is ‘OK’, ie good enough for an HD monitor presentation (but worry about that 8K monitor you will buy in the future), and ‘OK’ for looking at a 10x6 (in) image at arms length - about a 5 lp/mm result on the print. For gallery and/or competitions, consider a total blur criterion at infinity of half the above, say, 15 microns: ie taking a hit on the near field DoF distance;
  • Ensure the ML settings are OK, ie diffraction aware on and DoF visible in LV;
  • Switch to Live View (LV) and look at the script’s info box. Let’s assume we are using a 12mm lens at f/8;
  • Focus towards infinity until the total (system) blur is around 15 microns. To illustrate things, here is a screen dump from my 5D3:

  • At the bottom we see that ML is reporting that the lens is focused at about 1.51m, giving an ML reported DoF from 46cm to infinity (based on a set 29 microns total blur in ML);
  • The script is showing additional info, ie that the infinity is anything beyond about 2.7m (!!!), and that a total blur (RMS of diffraction (11) and optical (12)) is about 16 microns at infinity, giving a near DoF of 64cm. That is we have achieved enhanced focusing (15 micron total blur) from 64cm to infinity;
  • As we haven't yet reached the lazy L zone, let's keep focusing towards the lazy L infinity zone;
  • The first thing that occurs (above) is the total blur turns red, warning us that the total blur is now less than the sensor limit, ie about 13 microns on the 5D3. This means that it is not really 'worth' focusing any more towards infinity. Remember, the more you focus towards infinity, the more DoF you lose in the near field (note we are now at 1.1m). But let's keep going, as the lens allows us to keep moving towards the lazy L zone. The optical blur (the centre blur reported above) turns red (below), warning that we are now focusing at or beyond an optical blur of zero;
  •  Going beyond this means we are over focusing. Note that our near DoF is reporting 1.6m: and we still could go on!
Bottom line: If using my script, good practice is to ensure there are no red warnings. Once you decide on your infinity total blur, eg between 15 and 30 microns on a full frame camera, getting the optimum landscape 'infinity focus' is simplicity itself. There is no need to worry about 'where is infinity'.

A final word of warning: appreciate the 'limitations' of the script, ie it is suited for 'shortish' lenses, ie don't expect to use the script on your 70-200; use it on your wide angle lenses.

As usual, I welcome any feedback on this post and any ideas to make this approach to landscape focusing better.