Monday, February 15, 2016

In-Camera Focus Stacking Helper

I hope this post and script helps others who are learning/struggling to become Magic Lantern 'scripters'.

I couldn't have got this far without the help of David Milligan and others, who have provide feedback. So thank you David.

Although learning Lua scripting is easier than trying to code in ML C, Lua still requires some effort to learn, especially while the 'user manual' is being developed. For instance helps, but there are still areas where the user is left 'guessing'.

As a scripting newbie, I have spent tens of hours experimenting and trying to divine what my various coding errors mean. I have also educated myself on event driven programming and now have a reasonable looking, and simple, script to offer the Canon Magic Lantern user community.

This script's only purpose is to provide in-camera feedback to aid landscape (sic) focus stacking, ie NOT macro focus stacking.

The caveats are the lens must report focus distance and Depth of Field, and Live View must be on. Also you must have the latest ML nightly that has the Lua module.

Before using the script it is best to check if the ML DoF is set up correctly, eg I recommend switching on the diffraction aware option.

I have positioned the script in the Audio menu (my preference), but you can reposition elsewhere by changing parent = "Audio"

Here is the script, which you should put in a text file with a .lua extension and place this file in the ML script folder.

 Manual Landscape bracketing helper script
 Version 0.3.3
 Garry George Feb 2016
 First focus at nearest bracket in focus stack then move towards infinity. 
 Try using ML follow focus to control lens, as opposed to rotating lens by hand.
 Yellow means move more towards the infinity end, Red means move more towards macro end, 
 Green means at the sweet spot. If Green not seen, move to just being in the Yellow from being in the Red.
 * Must be in liveview! *
a1 = lens.dof_near
b1 = lens.dof_far
c1 = 0
fp = lens.focal_distance
inf = 1000000
started = false

event.keypress = function(key)
 if keymenu.submenu["Turn On/Off"].value == "Off" then started = false end
 if fp ~= 0 then
  b1 = lens.dof_far -- in mm
  fp = lens.focal_distance -- in cm
  if keymenu.submenu["Bracket to bracket overlap"].value == "20%" then
  factor = .2
  elseif keymenu.submenu["Bracket to bracket overlap"].value == "10%" then
  factor = .1
  factor = .05
  c1 = b1 - (b1 - fp*10)*factor
  started = true
    name = "Landscape Stacker Info",
    value = "",
    priority = 100,
    update = function(this)
    this.value = ""
 if fp == 0 then
 this.value = ""
    if keymenu.submenu["Turn On/Off"].value == "On" 
    if started then
   a2 = lens.dof_near
   this.value = ""
   if a2 > b1 then 
   this.background = COLOR.RED
   elseif a2 < c1 then 
   this.background = COLOR.YELLOW 
   this.foreground = COLOR.BLACK
   this.background = COLOR.GREEN1 
   if lens.dof_far >= inf then 
   this.value = "Inf"
   this.value = "   "
 this.value = ""

keymenu =
 parent = "Audio",
 name = "Landscape Stacking Helper",
 help = "First focus at nearest point in bracket set",
 help2 = "and take first picture",
 depends_on = DEPENDS_ON.LIVEVIEW,
 submenu =
   name = "Turn On/Off",
   help = "Switches the script on/off",
   depends_on = DEPENDS_ON.LIVEVIEW,
   choices = {"Off","On"},
   name = "Bracket to bracket overlap",
   help = "Amount to overlap each bracket",
   help2 = "% of FP-2-DoF(far) distance",
   choices = {"20%","10%", "5%"},

The script, by default, is not running. To switch it on, go to the ML Audio menu and switch to 'on'.

Also change the bracket to bracket overlap %. The default is 20%, but you can reduce this to 10% or 5%. The % represent the % of the distance between the current bracket's DoF(far) and the focal_distance. According to the lens you may not see the effect of this variable.

Do a half shutter press to get rid of the script's menu and, of course, ensure you are displaying the ML top and bottom bars of information, ie if not seen press INFO a few times (in LV).

To use the script, once switched on, position the lens at the first (closest) bracket and take the first picture. You will then see a helper flag (coloured block) come on.

The coloured block has the following meaning:
* Yellow = move the lens towards the infinity end
* Red = move the lens towards the macro end
* Green, if seen, means the lens is in the 'sweet spot', according to the % overlap criterion

If you don't see green, but just yellow or red, simply move the lens into the yellow position just before it goes red.

Consider using the ML follow focus to move the lens, as this is more controllable than trying to manually position the lens.

Each time you take a picture move the lens closer to the infinity end until you see INF in the coloured block. This means the DoF-far has reached infinity: you may wish to take an insurance shot beyond this.

To take a new set of brackets, simply reposition the lens to a new closest image and take a picture to reset the bracketing sequence. Consider grabbing a bookend image to separate your bracket sequences, eg an image of your hand: this will help in post processing, especially if you are not recomposing.

Bottom line: I have tested the script on my 5D3 and 24-105 F/4L and it works for me. I hope it does for you - remember the lens must report DoF and position. As usual I welcome feedback on this script. Also note that my next project is an automated version of this, but I can't finish this until the next Lua update is pushed out, eg fixing the lens control by Lua.

No comments:

Post a Comment