Sunday, April 19, 2015

Customising Magic Lantern

As readers of this blog know, I’m a great believer in the power of Magic Lantern, however, up until now, changing and recompiling ML source code has been rather complicated.

Now, one of the ML team, see http://www.magiclantern.fm/forum/index.php?topic=14725.0, has found a easier way by creating a simple ‘compile in the cloud’ approach, so anyone, with a web browser can compile their own version of ML. At the moment the process is not 100% there, ie the Dual-ISO module doesn’t get compiled, but people are working to fix that.

Nevertheless, I thought this was a great opportunity to try out a few ML tweaks that I wanted to put in place, ie changes to ML functionality for my personal use.

The ‘test case’ I chose is to change the ML the depth of field (DoF) feedback, which, from previous posts you will know is a boon for landscape focus stacking.

Looking in the lens.c area of ML told me that the current ML code makes use of some reasonable assumptions, but does not account for diffraction.

Rather than bore the reader with reiterated ‘stuff’ that is freely available on the web, eg here http://toothwalker.org/optics/dofderivation.html, I will simply note that one can account for defocus and diffraction by combining the two in quadrature.

Where the diffraction term can be estimated, in the visible bands, as N/750, where N is the aperture number, ie 2.8 or 16, and the result is in microns. Thus, at, say, F/16, the term becomes just over 21 microns.

The total acceptable blur, ie the combined defocus and diffraction effects, is a function of viewing distance and the sensor: but for my 5D3 I usually use a total blur of between 25-30 microns.

Thus we can work out the defocus blur, accounting for diffraction and the total acceptable blur, from the above, noting that the minimum occurs when the defocus and diffraction blurs are the same.

Once we know the defocus blur we need to note a couple of ‘conditions’. First, if the diffraction blur is greater than the total blur, then we will say we have gone beyond the diffraction limit. Secondly, we should respect that a defocus blur that is less that, say, two sensor pixel widths is most probably not sensible, ie just over 12 microns on my 5D3.

From others, we know the near and far limits of depth of field can be found from the following:
Where u is the focus distance, f the focal length, N the aperture number, p the pupillary magnification, and c is out defocus blur. As many have found, other than for macro work, we can sensibly ignore the pupillary ratio, ie assume it is 1.

From the above we can calculate the hyperfocal distance, which, interestingly, is independent of pupillary magnification:
We now have everything thing we need. The final step is ‘simply’ changing the ML C code and recompiling ML for my personal use, which is what I did.

Bottom line: although not for the faint hearted, I hope this short post has alerted others to the fact that you can change the ‘base’ ML functionality for your own use. In the example above, I now have the ML reporting, diffraction corrected, near and far focus distances and accounting for diffraction limits, ie the near and far distances collapse to zero when diffraction conditions are reached.

No comments:

Post a Comment