Here is my script for automatic HDR
--[[
@title AutoHDR
@param a Black Level
@default a 25
@param b White Level
@default b 230
@param c Percentage of histogram
@default c 1
--]]
proptable=...
if a<0 then
a=0
elseif a>20 then
a=20
end
-- define black level
blacklevel=a
if b<220 then
b=220
elseif b>255 then
b=255
end
-- define white level
whitelevel=b
if c<1 then
c=1
elseif c>10 then
c=10
end
-- percentage of histogram
level=c
-- ---------------------------------------------------------------
function howmanypixelsareunder(upperlimit)
m=0
r=0
r=md_detect_motion(36, 27, 1, 300, 100, 255, 0, m, 0, 1, 1, 1, 1, 0, 1, 301)
numbers=0
for i=1, 36 do
for j=1, 27 do
r=md_get_cell_diff(i, j)
if r < upperlimit then
numbers=numbers+r
end
end
end
numbers=numbers*100/(36*27)
return numbers
end
function setexposure(exposure)
set_prop(proptable.EV_CORRECTION_1, exposure*32)
set_prop(proptable.EV_CORRECTION_2, exposure*32)
--- half press to set correct exposition
press("shoot_half")
repeat
until get_shooting() == true
return exposure
end
function takeashut(success)
--- take the zero shot
press("shoot_full")
repeat
until get_shooting() == true
release("shoot_full")
repeat
until get_shooting() == false
release("shoot_half")
repeat
until get_shooting() == false
return success
end
--- opening
x=get_prop(proptable.EV_CORRECTION_1)
y=get_prop(proptable.EV_CORRECTION_2)
-- initiating
-- exposure in 1/32e ... 3 means 1 ev
exposure=setexposure(0)
--- how many pixels are underexposed
underexpose=howmanypixelsareunder(blacklevel)
--- how many pixels are overexposed
overexpose=100-howmanypixelsareunder(whitelevel)
--- take the initial shut
success=takeashut(1)
--- while overexposed and exposure >= -9
while overexpose > level and exposure >= -9 do
exposure=setexposure(exposure-3)
--- how many pixels are still overexposed
overexpose=100-howmanypixelsareunder(whitelevel)
--- take the under exposure shot
success=takeashut(1)
end
--- reset to zero exposure
exposure=setexposure(0)
--- while underexposed and exposure <= +9
while underexpose > level and exposure <= 9 do
exposure=setexposure(exposure+3)
--- how many pixels are still underexposed
underexpose=howmanypixelsareunder(blacklevel)
--- take the over exposure shot
success=takeashut(1)
end
--- reset to zero exposure
exposure=setexposure(0)
--- closing
set_prop(proptable.EV_CORRECTION_1, x)
set_prop(proptable.EV_CORRECTION_2, y)