My HDR function to avisynth

Forum covering all aspects of small gauge cinematography! This is the main discussion forum.

Moderator: Andreas Wideroe

Post Reply
MattiasN
Posts: 66
Joined: Thu Jun 13, 2013 10:57 pm
Real name: Mattias Norberg

My HDR function to avisynth

Post by MattiasN »

Hi im new here i did post allready my HDR function here http://forum.videohelp.com/threads/3567 ... R-function becuse i did not manage to get a account here but now when i have so i post it here to :)

i have done a function for hdr that works very good when i use it for my 8mm transfer heh it did take me many many hours to find the right method or that did work very good for me anyway here it is

clip a_stab=normal exposure or low exposure Ex on my vision camera 1/217 sec
clip b_stab=High exposure EX on my vision camera 1/38 sec

and you need HDRAGC from http://strony.aster.pl/paviko/hdragc.htm

Code: Select all

function hdr(clip a_stab,clip b_stab)
{
ab=overlay( b_stab,a_stab,x=0,y=0,mask=b_stab,opacity=0.5,greymask=true,mode="Multiply",pc_range=true)
t=a_stab.coloryuv(autowhite=true).TurnLeft().HDRAGC(max_gain = 3.0,min_gain=0.5,coef_gain=2.0,coef_sat=2.00,MODE=1,shadows=true,protect=1,corrector=0.8).TurnRight()
ab1=overlay(a_stab,b_stab,x=0,y=0,mask=a_stab,opacity=0.5,greymask=true,mode="hardlight",pc_range=true)
l=overlay(ab,ab1,x=0,y=0,mask=ab,opacity=1.0,greymask=true,mode="blend",pc_range=true).coloryuv(autowhite=true)
last=overlay(l,t,x=0,y=0,mask=ab,opacity=1.0,greymask=true,mode="blend",pc_range=true).TurnLeft().HDRAGC(max_gain = 1.5,min_gain=0.1,coef_gain=2.0,coef_sat=0.90,MODE=1,shadows=true,protect=1,corrector=0.8).TurnRight()
return last
}
Here is some photos of my telecine diy but on does pictures i did not use this function for HDR it was a older function that was not so good and little to much sharpening to hehe http://www.flickr.com/photos/94271811@N03/
MattiasN
Posts: 66
Joined: Thu Jun 13, 2013 10:57 pm
Real name: Mattias Norberg

Re: My HDR function to avisynth

Post by MattiasN »

When i run the two exposure on my projector they are not in aling to aling them i have a avisynth script for that to that i did get from here http://forum.doom9.org/showthread.php?t=152109&page=3 post nr #41 but i did have to tweek it little to work even beter but it´s very slow :/ but it works very very good :) for my setup anyway

uncomment #return c_ref to tweek a_cont and b_cont odd and even picture look about the same

Code: Select all

a=ImageSource("F:\Reel1\N\pgm\bmp\image%d.bmp",start=1,end=32429,fps=18).ConvertToYV12()
b=ImageSource("F:\Reel1\E\ppm\bmp\image%d.bmp",start=1,end=32429,fps=18).ConvertToYV12()

c = Interleave(a, b)

a_cont=6.45
b_cont=1.15

a_ref = a.NonlinUSM(1.2,2.6,6.0,8.5).HighlightLimiter(1,true,1,true,100).tweak(cont=a_cont).MT_binarize(threshold=80).greyscale().invert()
b_ref = b.NonlinUSM(50.2,2.6,6.0,8.5).HighlightLimiter(1,true,1,true,100).tweak(cont=b_cont).MT_binarize(threshold=25).greyscale().invert()

c_ref = Interleave(a_ref, b_ref)
#return c_ref     #USE this to see that odd and even picture  look about the same

mdata = DePanEstimate(c_ref,trust=1.0,dxmax=10,dymax=12)
c_stab = DePanInterleave(c, data=mdata)

b_stab = c_stab.SelectEvery(6, 2)
a_stab = c_stab.SelectEvery(6, 1)

you need this two functions to

Code: Select all

function HighlightLimiter(clip v, float "gblur", bool "gradient", int "threshold", bool "twopass", int "amount", bool "softlimit", int "method")
{

gradient = default (gradient,true) #True uses the gaussian blur to such an extent so as to create an effect similar to a gradient mask being applied to every area that exceeds our threshold.
gblur = (gradient==true) ? default (gblur,100) : default (gblur,5.0) #The strength of the gaussian blur to apply. 
threshold = default (threshold,150) #The lower the value, the more sensitive the filter will be.
twopass = default (twopass,false) #Two passes means the area in question gets darkened twice. 
amount = default (amount,10) #The amount of brightness to be reduced, only applied to method=2
softlimit = default (softlimit,false) #If softlimit is true, then the values around the edges where the pixel value differences occur, will be averaged.
method = default (method, 1) #Method 1 is multiply, the classic HDR-way. Any other method set triggers a brightness/gamma approach.

amount = (amount>0) ? -amount : amount

darken=v.Tweak(sat=0).mt_lut("x "+string(threshold)+" < 0 x ?")
blurred= (gradient==true) ? darken.gaussianblur(gblur).gaussianblur(gblur+100).gaussianblur(gblur+200) : darken.gaussianblur(gblur)
fuzziness_mask=blurred.mt_edge(mode="prewitt", Y=3, U=2, V=2).mt_expand(mode="both", Y=3, U=2, V=2)
multiply = (method==1) ? mt_lut(v,"x x * 255 /") : v.Tweak(bright=amount)
multiply = (method==1) ? eval("""(twopass==true) ? mt_lutxy(multiply,v,"x y * 255 /") : multiply""") : eval("""(twopass==true) ? multiply.SmoothLevels(gamma=0.9,smode=2) : multiply""")

merged=mt_merge(v,multiply,blurred)
fuzzy= (softlimit==true) ? mt_merge(merged,mt_lutxy(v,merged,"x y + 2 /"),fuzziness_mask) : merged
return fuzzy
}
this function did help to get all edge in the pictures to pop up more it did help more to aling maby some other sharpening function can to the same

Code: Select all

function NonlinUSM(clip o, float "z", float "pow", float "str", float "rad", float "ldmp")
{
z   = default(z,   6.0)  # zero point
pow = default(pow, 1.6)  # power
str = default(str, 1.0)  # strength
rad = default(rad, 9.0)  # radius for "gauss"
ldmp= default(ldmp, 0.001) # damping for verysmall differences

g = o.bicubicresize(round(o.width()/rad/4)*4,round(o.height()/rad/4)*4).bicubicresize(o.width(),o.height(),1,0)

mt_lutxy(o,g,"x x y - abs "+string(z)+" / 1 "+string(pow)+" / ^ "+string(z)+" * "+string(str)+
 \                        " * x y - 2 ^ x y - 2 ^ "+string(ldmp)+" + / * x y - x y - abs 0.001 + / * +",U=2,V=2)

#interleave(o,last) # just for visualisation, you don't want the function to do this

return(last)
}
Will2
Senior member
Posts: 1983
Joined: Mon Sep 26, 2005 12:18 am
Real name: Will Montgomery
Location: Dallas, TX
Contact:

Re: My HDR function to avisynth

Post by Will2 »

The results are amazing, much like Fred's.

What I don't understand is why software like Resolve doesn't incorporate similar functions without having to write a script? Seems like this would be a perfect addition to some higher end software packages and if freeware can do it, why not them?
MattiasN
Posts: 66
Joined: Thu Jun 13, 2013 10:57 pm
Real name: Mattias Norberg

Re: My HDR function to avisynth

Post by MattiasN »

thanks :)
i did use fred´s script on two of the pictures here http://www.flickr.com/photos/94271811@N03/ Fred´s script is very good but i did use little to much sharpening on does pictures
MattiasN
Posts: 66
Joined: Thu Jun 13, 2013 10:57 pm
Real name: Mattias Norberg

Re: My HDR function to avisynth

Post by MattiasN »

Here is some example of the hdr function i have done no color correction just the function

HDR 1 Low Exposure(1/217 Sec Exposure)
Image

HDR 1 High Exposure(1/38 Sec Exposure)
Image

HDR 1 Low+High Exposure(1/217 Sec + 1/38 sec Exposure)
Image


HDR 2 Low Exposure(1/217 Sec Exposure)
Image

HDR 2 High Exposure(1/38 Sec Exposure)
Image

HDR 2 Low+High Exposure(1/217 Sec + 1/38 sec Exposure)
Image


HDR 3 Low Exposure(1/217 Sec Exposure)
Image

HDR 3 High Exposure(1/38 Sec Exposure)
Image

HDR 3 Low+High Exposure(1/217 Sec + 1/38 sec Exposure)
Image


HDR 4 Low Exposure(1/217 Sec Exposure)
Image

HDR 4 High Exposure(1/38 Sec Exposure)
Image

HDR 4 Low+High Exposure(1/217 Sec + 1/38 sec Exposure)
Image
Will2
Senior member
Posts: 1983
Joined: Mon Sep 26, 2005 12:18 am
Real name: Will Montgomery
Location: Dallas, TX
Contact:

Re: My HDR function to avisynth

Post by Will2 »

So you do a two exposure pass on the telecine and use that script to line up each frame perfectly and do an HDR function? Brilliant. This could work with any telecine.

To do the alignment do you have to see the sprockets or does it work from all elements in the frame?
MattiasN
Posts: 66
Joined: Thu Jun 13, 2013 10:57 pm
Real name: Mattias Norberg

Re: My HDR function to avisynth

Post by MattiasN »

yes it´s from all elements in the frame i use extrem sharpnes to it puch all the edge in the picture to pop up better :)

i show the HDR 4 ref of the low and high exposure so you can see they must look about the same i do have a script that only use the sprocket hole but that i only use to get stabel vertical jitter so i can crop the frame easyer at the end :)

here are the ref a and b



LowRef exposure (even frame a_ref)
Image


HighRef exposure (odd frame b_ref)
Image


you can see that low and high exposure look about the same you adjust it with a_cont=6.45 b_cont=1.15 use the return c_ref so see or you can use return a_ref and after return b_ref
maby you can use return StackHorizontal(a_ref,b_ref) to i think :)
aj
Senior member
Posts: 3556
Joined: Thu Oct 02, 2003 1:15 pm
Real name: Andre
Location: Netherlands
Contact:

Re: My HDR function to avisynth

Post by aj »

Do you know if AviSynth is also being used to do automated process of still images?

I.e. process a set of scanned negatives and do a grain reduce on all and possibly a bit of sharpening?
Kind regards,

André
MattiasN
Posts: 66
Joined: Thu Jun 13, 2013 10:57 pm
Real name: Mattias Norberg

Re: My HDR function to avisynth

Post by MattiasN »

hmm sorry do not know if it can about negatives
i use it like this input image sequence and it can output image sequence to like this

Code: Select all

#input image sequence example image1.bmp image2.bmp image3.bmp and so on to  image32429.bmp
ImageSource("F:\Reel1\N\pgm\ppm\image%d.bmp",start=1,end=32429,fps=18)

#here you can have all noise and sharpening 

#output image sequence must be first converted to rgb32 or rgb24 this output example output image0.tga image1.tga image2.tga and so on to the last frame that is image32428.tga
ConvertToRGB32()
imagewriter(file="H:\reel1\HDRstab3\image%d.tga",start=0,end=0,type="tga")
you open then that .avs fil in some player like mediaplayer classic :) and let it play now it outputs image sequence to the output destination
the output can be .tga .bmp .tiff .jpg and some other you can see here more info http://avisynth.org/mediawiki/ImageWriter

i use this to edit avisynth scrips http://avisynth.org/qwerpoi/
Post Reply