HDR Assist script, multi-series, fully adjustable (LUA) - Completed and Working Scripts - CHDK Forum

HDR Assist script, multi-series, fully adjustable (LUA)

  • 19 Replies
  • 22311 Views
HDR Assist script, multi-series, fully adjustable (LUA)
« on: 26 / August / 2009, 15:16:56 »
Advertisements
Since I've been in a LUA scripting mood lately, here's one more:  :D

HDR Assist script

Here is a script to assist in setting up exposure stacks to create HDR images.  It also allows to run more than one series with the same settings (eg to assist in mirror-ball light probe HDRs where two series are taken from perpendicular angles)

Features
- Select #shots (per series)
- Select #series
- Select start delay (each shot per series taken immediately after one another)
- Pre-focus ON/OFF (pre-focus once per series, focus locked for subsequent shots)
- #shots, #series, pre-focus adjustable on-the-fly
- Script pauses before each HDR series to allow for camera positioning
- Select start shutter speed on-the-fly*
- Select end shutter speed on-the-fly*
- Script progresses from start to end shutter speeds evenly by # shots
- Select/adjust Av on-the-fly*

*To change start Tv, end Tv and Av, camera should be in Manual mode (or Tv mode if not adjusting Av).  When prompted close the <alt> menu (script pauses) and adjust the Tv/Av to the desired, then reopen <alt> menu (script should resume where it was) and press any key to resume.  Script then reads in the user selected value.

EG, for start/end Tv:
- select adjust start Tv,
- select the bottom (underexposed) limit of the desired series
- resume script
- select adjust end Tv,
- select the top (overexposed) limit of the desired series
- resume script

Written in LUA, so save as a .lua file

Please try it and give feedback on errors or feature change/requests.  All comments welcome.

*Script in follow-up message (in 2 parts again due to length, add both parts to .lua file in order)*
« Last Edit: 26 / August / 2009, 15:19:39 by barberofcivil »

Re: HDR Assist script, multi-series, fully adjustable (LUA)
« Reply #1 on: 26 / August / 2009, 15:18:03 »
PART 1:
Code: [Select]
--[[
rem Author: barberofcivil

@title HDR Assist
@param d No.Shots
@default d 1
@param e No. Series
@default e 1
@param f Start Delay (s)
@default f 0
@param g Pre-focus: 0=off, 1=on
@default g 1
--]]

if e<1 then e=1 end
if d<1 then d=1 end
if f<0 then f=0 end
if g<0 then g=0 end
if g>1 then g=1 end

function ShutterCalc (k)
  local l=(k/384)*384
  if k<0 then l=l-384 end
  local n=(k-l)
  local j=(((((((((30*n^3)/384)*n)/384)*n)/384)*243)/384)*7)
  local j=j-(((((((30*n^3)/384)*n)/384)*254)/384)*4)
  local j=j+(((((30*n^3)/384)*227)/384)*9)
  local j=j+(((9210*n^2)/384)*3)
  local j=j+(25500*n)
  local m=16^(l/384+2)
  local o=((((((j/18000+1)/2)+96)*m)/12288+1)/2)
  local q=((4915200/((((j/18000+1)/2)+96)*m)+1)/2)
  if m<1 then
    mm=16^(-l/384-2)
    q=((((491520000/(((j/18000+1)/2)+96))/100)*mm+1)/2)
  end
  if k<=-660 then q=q/60 end
  local r=q/100
  local s=(q-r*100)/10
  local t=q-r*100-s*10
  return o,r,s,t
end

function AVCalc (x)
  local l=(x/192)*192
  local m=2^(l/192)
  local n=(x-l)
  local j=(n^3)+650*(n^2)+360000*n
  local q=((j/100000+1005)/10)*m
  local r=q/100
  local s=(q-r*100)/10
  local t=q-r*100-s*10
  return r,s,t
end

function ADJUST()
  o1,r1,s1,t1 = ShutterCalc(Tv1)
  o2,r2,s2,t2 = ShutterCalc(Tv2)
  r3,s3,t3 = AVCalc(Av0)
  if v==1  then xx0=">Tv:"   else xx0=" Tv:" end           
  if o1>=4 then xx1="1/"..o1 else xx1=r1.."."..s1..t1 end
  if o2>=4 then xx2="1/"..o2 else xx2=r2.."."..s2..t2 end
  if Tv1>-660 then xe1="s" else xe1="m" end
  if Tv2>-660 then xe2="s" else xe2="m" end
  cls()

  if d==1 then
    print (xx0..xx1..xe1)
  else
    print (xx0..xx1..xe1.." to "..xx2..xe2)
  end
  if v==3 then
    print (">Av:"..r3.."."..s3..t3)
  else
    print (" Av:"..r3.."."..s3..t3)
  end
  if v==4 then
    print (">Shots:"..d)
  else
    print (" Shots:"..d)
  end
  if v==0 then BaseMenu()
  elseif v==1 then
    cls()
    if d==1 then
      print (xx0..xx1..xe1)
    else
      print (xx0..xx1..xe1.." to "..xx2..xe2)
    end
    print (" Av:"..r3.."."..s3..t3)
    print (" Shots:"..d)
    print ("Pause and select Tv1")
    print ("Any button to resume")
    wait_click()
    Tv1=(get_user_tv96()*32)
    v=0
  elseif v==2 then
    cls()
    if d==1 then
      print (xx0..xx1..xe1)
    else
      print (xx0..xx1..xe1.." to "..xx2..xe2)
    end
    print (" Av:"..r3.."."..s3..t3)
    print (" Shots:"..d)
    print ("Pause and select Tv2")
    print ("Any button to resume")
    wait_click()
    Tv2=(get_user_tv96()*32)
    v=0
  elseif v==3 then AdjustAV()
  elseif v==4 then AdjustShots()
  end
end

function BaseMenu()
  print ("L:Start  R:End  U:Av")
  print ("D:Shots   SET:Return")
  wait_click()
  if is_key("left")  then v=1 end
  if is_key("right") then v=2 end
  if is_key("up")    then v=3 end
  if is_key("down")  then v=4 end
  if is_key("set")   then v=-1 end
end

function AdjustShots()
  print ("L:-1 Shot R:+1 Shot")
  print ("D:Reset(1) SET:Return")
  wait_click()
  if is_key("left")  then d=d-1 end
  if is_key("right") then d=d+1 end
  if is_key("down")  then d=1   end
  if is_key("set")   then v=0   end
  if d<1 then d=1 end
end

function AdjustAV()
  print ("L:-1/3EV R:+1/3EV")
  print ("D:User SET:Return")
  wait_click()
  if is_key("left")  then Av0=Av0+32 end
  if is_key("right") then Av0=Av0-32 end
  if is_key("down")  then
    cls()
    if d==1 then
      print (xx0..xx1..xe1)
    else
      print (xx0..xx1..xe1.." to "..xx2..xe2)
    end
    print (">Av:"..r3.."."..s3..t3)
    print (" Shots:"..d)
    print ("Pause and select Av")
    print ("Any button to resume")
    wait_click()
    Av0=get_user_av96()
  end
  if is_key("set")   then v=0    end
  if Av0<0 then Av0=0 end
end

function DELAY()
  if g==0 then xx0="OFF" else xx0="ON" end
  if v==1 then xx1=">" else xx1=" " end
  if v==2 then xx2=">" else xx2=" " end

  cls()
  print (xx1.."Start delay: "..f.."s")
  print (xx2.."No.Series  : "..e)
  print (    " Pre-focus  : "..xx0)

  if v==0 then BaseMenu2()
  elseif v==1 then AdjustStartD()
  elseif v==2 then AdjustSeries()
  end
end

function BaseMenu2()
  print ("L:Start      R:Series")
  print ("D:Pre-focus  SET:Return")
  wait_click()
  if is_key("left")  then v=1   end
  if is_key("right") then v=2   end
  if is_key("down")  then g=1-g end
  if is_key("set")   then v=-1  end
end

function AdjustStartD()
  print ("L:-1s        R:+1s")
  print ("D:Reset(0)   SET:Return")
  wait_click()
  if is_key("left")  then f=f-1 end
  if is_key("right") then f=f+1 end
  if is_key("down")  then f=0   end
  if is_key("set")   then v=0   end
  if f<0 then f=0 end
end

function AdjustSeries()
  print ("L:-1         R:+1")
  print ("D:Reset(1)   SET:Return")
  wait_click()
  if is_key("left")  then e=e-1 end
  if is_key("right") then e=e+1 end
  if is_key("down")  then e=1   end
  if is_key("set")   then v=0   end
  if e<1 then e=1 end
end

Re: HDR Assist script, multi-series, fully adjustable (LUA)
« Reply #2 on: 26 / August / 2009, 15:18:54 »
PART 2:
Code: [Select]

Av0=get_user_av96()
Tv1=(get_user_tv96()*32)
Tv2=Tv1

done=0
while done==0 do
  v=0
  o1,r1,s1,t1 = ShutterCalc(Tv1)
  o2,r2,s2,t2 = ShutterCalc(Tv2)
  r3,s3,t3 = AVCalc(Av0)
  if o1>=4 then xx1="1/"..o1 else xx1=r1.."."..s1..t1 end
  if o2>=4 then xx2="1/"..o2 else xx2=r2.."."..s2..t2 end
  if Tv1>-660 then xe1="s" else xe1="m" end
  if Tv2>-660 then xe2="s" else xe2="m" end
  cls()
  if d==1 then
    print (" Tv:"..xx1..xe1)
  else
    print (" Tv:"..xx1..xe1.." to "..xx2..xe2)
  end
  print (" Av:"..r3.."."..s3..t3)
  print (" Shots:"..d.."    Series:"..e)
  print ("SET:proceed  MENU:adjust")
  print ("DISP:setup  other:cancel")
  wait_click()
  if is_key("menu") then
    while v>=0 do
      ADJUST()
    end
  elseif is_key("display") then
    while v>=0 do
      DELAY()
    end
  elseif is_key("set") then
    for h=1,e,1 do
      cls()
      print ("Series "..h.." of "..e)
      print ("Any button to proceed")
      wait_click()
      while f>0 do
        cls()
        print ("Series "..h.." of "..e)
        print ("Starting in "..f.."s...")
        sleep (1000)
        f=f-1
      end
      cls()
      if g==0 then
        print("Pre-focus OFF")
      elseif g==1 then
        print("Pre-focus ON")
        local focused = false
        local try = 1
        while not focused and try <= 5 do
          print("Pre-focus attempt " .. try)
          press("shoot_half")
          sleep(2000)
          if get_prop(18) > 0 then
            focused = true
            set_aflock(1)
          end
          release("shoot_half")
          sleep(500)
          try = try + 1
        end
        if not focused then print "Unable to pre-focus" else  print "Pre-focus complete" end
      end
      print ("Starting shots now...")
      for i=1,d,1 do
        cls()
        print ("Series "..h.." of "..e)
        print ("Shot   "..i.." of "..d)
        if d==1 then
          Tv0=Tv1
        else
          Tv0=(((Tv1*10+(((Tv2-Tv1)*(i-1)*10)/(d-1)))+5)/10)
        end
        o1,r1,s1,t1 = ShutterCalc(Tv0)
        r3,s3,t3 = AVCalc(Av0)
        if o1>=4 then xx1="1/"..o1 else xx1=r1.."."..s1..t1 end
        if Tv0>-660 then xe1="s" else xe1="m" end
        print ("Tv:"..xx1..xe1)
        print ("Av:"..r3.."."..s3..t3)
        if Tv0==0 then Tv0=1 end
        set_av96_direct(Av0)
        set_tv96_direct(Tv0)
        shoot()
      end
    end
    done=1
  else
    print ("Script cancelled")
    done=1
  end
end

Re: HDR Assist script, multi-series, fully adjustable (LUA)
« Reply #3 on: 28 / August / 2009, 07:58:32 »
I tried your script on my sx100is and it works  ;)

It's a simple script to use, I use "bracketing in continous mode" function included in chdk to do bracketing.

nice work  :D


Re: HDR Assist script, multi-series, fully adjustable (LUA)
« Reply #4 on: 28 / August / 2009, 08:43:09 »
I tried your script on my sx100is and it works  ;)

It's a simple script to use, I use "bracketing in continous mode" function included in chdk to do bracketing.

nice work  :D

Thanks.

This one was made specifically with HDR in mind, not just bracketing.  In the past I have been experimenting with HDR imaging, especially creating full spherical light probe HDRs (from mirrorballs) for 3D rendering.  My original script was written to help me with this (do a series from X shutter to Y shutter), however with that one you can set the first shutter, but have to play with the steps to get the range.  I recently noticed that while a script is running, you can exit the <alt> mode, change your user settings and then resume <alt> and the script is still running and can read the new user set values.  By doing this, I can set the bottom shutter speed by adjusting is until I can actually see the underexposure level on-screen and same for the over exposure, then it just iterates between the 2 shutters.

One limitation on this one is that it is limited to usage with only available regular camera shutter speeds, not the CHDK override ones.  I suppose I could've added the adjustability as included in the other script, but I didn't want it getting too cluttered.

Re: HDR Assist script, multi-series, fully adjustable (LUA)
« Reply #5 on: 31 / August / 2009, 20:26:21 »
One limitation on this one is that it is limited to usage with only available regular camera shutter speeds, not the CHDK override ones.  I suppose I could've added the adjustability as included in the other script, but I didn't want it getting too cluttered.

creating spherical light probe HDR? wow! :o

the limitation is not a problem. It's quite unusual to do HDR with shutter greater than 15sec :)

Re: HDR Assist script, multi-series, fully adjustable (LUA)
« Reply #6 on: 28 / December / 2009, 00:07:25 »
Your script is fully working except I can't get start Tv and end Tv values to adjust. I'm using a SD790 IS with experimental firmware (which could be the reason) but I just press <Alt> to pause, adjust exposure within Canon's firmware, then press <Alt> again and unpause, correct? I should have override at Disable aswell, correct?
Thanks

EDIT: I got it working with a quick and dirty edit of the LUA (hard coded values), but automatic values aren't working.
« Last Edit: 28 / December / 2009, 01:20:42 by happyface »

Re: HDR Assist script, multi-series, fully adjustable (LUA)
« Reply #7 on: 16 / April / 2010, 16:55:31 »
 :) Wow this is great! I love how it keeps all the settings locked and just adjusts the shutter speed for the bracketed shots.

My only question then is how I best determine the spread of the shutter settings for maximum results! Typically a bracket will shoot exposure -2, 0, +2 How do I replicate that spread for instance with shutter speed adjustment?

Also, great job!!! I love how I can use this with my pano head and rotate between sets thank you thank you!! :)


Re: HDR Assist script, multi-series, fully adjustable (LUA)
« Reply #8 on: 12 / May / 2010, 14:02:24 »
One limitation on this one is that it is limited to usage with only available regular camera shutter speeds, not the CHDK override ones.  I suppose I could've added the adjustability as included in the other script, but I didn't want it getting too cluttered.

creating spherical light probe HDR? wow! :o

the limitation is not a problem. It's quite unusual to do HDR with shutter greater than 15sec :)

HI.. i know that have been pass some time from this post but a im interested in get the overrided value of TV instead of the standard of the camera, can you guide how i can modified the script to use that value.
Im using this script to do DeepField sky pictures and i need to take several shots with exposure time grater than 15 sec!. This script is almost perfect for that i need except for the limitation of the overrided values of TV :)
Note that i'm a complete newbie in LUA scripting, so... any help will be welcome :)

thanks and great job!!

Re: HDR Assist script, multi-series, fully adjustable (LUA)
« Reply #9 on: 02 / June / 2010, 21:49:50 »
I love this script, but it is very forgetful. If I inadvertently hit the shutter button, the start/end exposure values get lost, and I have to reset them again. Is there a way to make it remember these values permanantly?

Also, it seemed to me to take too many low light pictures (short exposures) and not enough bright ones. Is it easy to change the spacing between the steps?

 

Related Topics