Log in

View Full Version : Bloom filter for film look


Pages : 1 [2]

raffriff42
3rd September 2013, 17:21
Works great StainlessS! Thank you! Nicely formatted too, which helps if you want compare calls to see what's changed. Still scratching my head over what I done wrong...

This thing is super useful because of the wide variety of possible bloom/fog/whiteout/neon effects, and what looks great for one source looks so-so on another. (EDIT so-so? How about frikin' unwatchable?) Stepping through the script, you can find an effect you like within seconds, then look up the frame number in the logfile and paste the args into a call to C.SoftBloom_B(...)

(One thing: the float args should be formatted as something like String(X,"%5.2f"), not String(X,"%3.0f"), which turns them into ints)
:thanks:
EDIT didn't see the note about 0 and 1 showing twice...but it doesn't matter for our purposes.
Since the log is being written as frames are served, there's no guarantee of monotonicity or other big words like that there.
If I wanted one-and-only-one line per frame, in ascending order, I would use the Sort function in TextPad, or another similar text editor - if one exists ;)

StainlessS
3rd September 2013, 17:34
Ooooops, fixed floats.

The amended script at end using RT_TxtWriteFile() fixes the double frame 0,1 output, can change G_args to local.


EDIT:

you can find an effect you like within seconds, then look up the frame number in the logfile and paste the (...)

I did something similar with the Sinclair QL Beep command years ago where I managed to find a
single Beep command that sounded like a complete tune that was written by a human, but very badly
off-key (was very funny, lasting several minutes)
{Brits ONLY:- Reminds me of Les Dawson playing piano. Non Brits, Google "Les Dawson Piano"}

Gavino
3rd September 2013, 19:12
This works but I dont really like the use of Global G_args (cant remember if there is an alternative way).
Since the function is already running inside ScriptClip(), you can use WriteFileStart() instead of WriteFile(), and this will evaluate its arguments immediately.
/* write frame number + tab char + statement to logfile. */
# G_Args can now be local
C.WriteFileStart(g_logpath,"current_frame","Chr(9)","G_Args")

StainlessS
3rd September 2013, 19:26
Thank you Gavino, also needed 'append=true'. Post #50 fixed. (I've used exact same solution before, but forgot)

StainlessS
3rd September 2013, 19:37
/* write frame number + tab char + statement to logfile. */
C.WriteFileStart(g_logpath,"current_frame","Chr(9)","G_Args")

Oops, needed a bit more than 'append=true'. ("current_frame" produces '-1' output)
Fixed again as here:

WriteFileStart(g_logpath,String(current_frame),"Chr(9)","args",append=True)


EDIT: Fixed again :(

Gavino
3rd September 2013, 21:54
Oops, needed a bit more than 'append=true'. ("current_frame" produces '-1' output)
Fixed again as here:
WriteFileStart(g_logpath,String(current_frame),"Chr(9)","args",append=True)

Argh! I forgot WriteFileStart had a different default for append, and that it sets current_frame to -1 (what on earth for (http://forum.doom9.org/showthread.php?p=1329748#post1329748)???).
Nice workaround, Mr S.

Perhaps instead I should just have suggested:
C.GWriteFile(g_logpath,"current_frame","Chr(9)","args", args="args")

MJLives12
17th September 2013, 23:51
Added Levels to fastgauss from Didée function to brighten blur in SoftGlow.

function FastGauss(clip clp, float rx, float ry)
{ ox=clp.width()
oy=clp.height()
clp.Levels (0, 0.1, 127, 0, 255, false).bicubicresize(m4(ox/rx),m4(oy/ry)).bicubicresize(ox,oy,1,0)
}
function m4(float x) {x<16?16:int(round(x/4.0)*4)}

And an improved version of SoftGlow

##################################
## SoftGlow with constrained inputs and resizing
## original @ http://forum.doom9.org/showthread.php?p=1642381#post1642381
#
Function SoftGlow (clip c, int "radius"
\ , int "min", int "max", int "threshold", int "blur", float "sat", int "cont", float "mul") {
c
## (limits are set based on guesswork; please adjust if needed)
radius = Min(Max(2, Default (radius, 2)), Width / 2)
edges = (radius % 4) == 0 ? radius : radius + 4 - (radius % 4)
threshold = Min(Max(16, Round (Default (threshold, 200) * 219 / 255.0) + 16), 255)
min = Min(Max(threshold+1, Default (min, 254)), 254)
max = Min(Max(min+1, Default (max, min+1)), 255)
blur = Min(Max(0, Default (blur, 24)), 768)
sat = Min(Max(0.0, Default (sat, 1.0)), 4.0)
cont = Min(Max(1, Default (cont, 0)), 256)
mul = Min(Max(0.0, Float(Default (mul, 1.0))), 1.0)

rmax_set=255.0
rwmax=last.width/blur
rhmax=last.height/blur
rmax= (rwmax <= rhmax) ? rwmax : rhmax

radius=(((rmax-1)*(radius-1))/(rmax_set-1))+1
b=radius-1
b=b*b*b
b=b*192/rmax/rmax/rmax

width=Round(last.width/blur)
height=Round(last.height/blur)

Mask = Merge (last
\ ,MT_lutxy (last
\ ,ConvertToRGB32 ().RGBLevelsG (min, 1.0, max, 0, 255).ConvertToYV12 ()
\ .Tweak (sat = sat)
\ .AddBorders (edges, edges, edges, edges)
\ .FastGauss (blur, blur)
\ .Crop (edges, edges, edges * -1, edges * -1)
\ .Levels (0, 1.0, threshold, 0, 255, false)
\ ,uexpr = " y 128 < x y * 128 /"
\ ,vexpr = " y 128 < x y * 128 /", Y = 4, U = 3, V = 3), mul)

White = MT_lutxy (BlankClip (Mask, color_yuv = $FF8080)
\ ,Mask.ColorYUV (cont_u = cont, cont_v = cont)
\ ,yexpr = "256 0 x - 256 y - * 256 / -", Y = 3, U = 4, V = 4)

MT_Merge (White, Mask, chroma = "process")

}

Optional SoftGlow Test


## SoftGlow: fuzz test input args
## just keep frame stepping, see if anything breaks
## (also a neat way to explore different effects)
## warning this video may cause seizures - do not play in real time

##################################
## SoftGlow: fuzz test input args
#
function SoftGlow_Test(clip C) {
C
## random inputs
a_radius=Rand(Width/2)
a_min=Rand(254)
a_max=Rand(255)
a_threshold=Rand(255)
a_sat=Rand(400)/100.0
a_cont=Rand(400)
a_mul=Rand(100)/100.0
a_blur=Rand(180)
args="radius=" + String(a_radius,"%3.0f")
\ + ", min=" + String(a_min,"%3.0f") + ", max=" + String(a_max,"%3.0f") + ", threshold=" + String(a_threshold,"%3.0f")
\ + ", blur=" + String(a_blur) + ", sat=" + String(a_sat) + ", cont=" + String(a_cont)

/* the following should be a valid Avisynth statement */
stat="SoftGlow(" + args + ")"
RT_Debug("SoftGlow","["+string(current_frame)+"]",args,false)
# RT_TxtWriteFile(String(current_frame)+Chr(9)+args,g_logpath,Append=true)
/* write frame number + tab char + statement to logfile...? */
WriteFileStart(g_logpath,String(current_frame),"Chr(9)","args",append=True)

return Eval(stat).ShowFrameNumber
}


C = last

global g_logpath = "C:\<dir>\logfile.txt"
C=C.WriteFileStart(g_logpath, """ "frameno" """, "Chr(9)", """ "args " """,append=false)
C=C.WriteFileEnd(g_logpath, """ "#end" """)

ScriptClip(c, "SoftGlow_Test(c)")


Also FastCross (Plus effect version of Didée FastGauss

function FastCross(clip clp, float rx, float ry)
{ ox=clp.width()
oy=clp.height()
Merge (clp.Levels (0, 0.1, 127, 0, 255, false).bilinearresize(m4(ox/rx),m4(oy)).bicubicresize(ox,oy,1,0)
\ ,clp.Levels (0, 0.1, 127, 0, 255, false).bilinearresize(m4(ox),m4(ry/ry)).bicubicresize(ox,oy,0,1),0.5)
}
function m4(float x) {x<16?16:int(round(x/4.0)*4)}

Function PGlow (clip c, int "radius"
\ , int "min", int "max", int "threshold", int "blur", float "sat", int "cont", float "mul") {
c
## (limits are set based on guesswork; please adjust if needed)
radius = Min(Max(2, Default (radius, 2)), Width / 2)
edges = (radius % 4) == 0 ? radius : radius + 4 - (radius % 4)
threshold = Min(Max(16, Round (Default (threshold, 200) * 219 / 255.0) + 16), 255)
min = Min(Max(threshold+1, Default (min, 254)), 254)
max = Min(Max(min+1, Default (max, min+1)), 255)
blur = Min(Max(0, Default (blur, 24)), 768)
sat = Min(Max(0.0, Default (sat, 1.0)), 4.0)
cont = Min(Max(1, Default (cont, 0)), 256)
mul = Min(Max(0.0, Float(Default (mul, 1.0))), 1.0)

rmax_set=255.0
rwmax=last.width/blur
rhmax=last.height/blur
rmax= (rwmax <= rhmax) ? rwmax : rhmax

radius=(((rmax-1)*(radius-1))/(rmax_set-1))+1
b=radius-1
b=b*b*b
b=b*192/rmax/rmax/rmax

width=Round(last.width/blur)
height=Round(last.height/blur)

Mask = Merge (last
\ ,MT_lutxy (last
\ ,ConvertToRGB32 ().RGBLevelsG (min, 1.0, max, 0, 255).ConvertToYV12 ()
\ .Tweak (sat = sat)
\ .AddBorders (edges, edges, edges, edges)
\ .FastCross (blur, blur)
\ .Crop (edges, edges, edges * -1, edges * -1)
\ .Levels (0, 1.0, threshold, 0, 255, false)
\ ,uexpr = " y 128 < x y * 128 /"
\ ,vexpr = " y 128 < x y * 128 /", Y = 4, U = 3, V = 3), mul)

White = MT_lutxy (BlankClip (Mask, color_yuv = $FF8080)
\ ,Mask.ColorYUV (cont_u = cont, cont_v = cont)
\ ,yexpr = "256 0 x - 256 y - * 256 / -", Y = 3, U = 4, V = 4)

MT_Merge (White, Mask, chroma = "process")

}

## PGlow: fuzz test input args
## just keep frame stepping, see if anything breaks
## (also a neat way to explore different effects)
## warning this video may cause seizures - do not play in real time

##################################
## PGlow: fuzz test input args
#
function PGlow_Test(clip C) {
C
## random inputs
a_radius=Rand(Width/2)
a_min=Rand(254)
a_max=Rand(255)
a_threshold=Rand(255)
a_sat=Rand(400)/100.0
a_cont=Rand(400)
a_mul=Rand(100)/100.0
a_blur=Rand(180)
args="radius=" + String(a_radius,"%3.0f")
\ + ", min=" + String(a_min,"%3.0f") + ", max=" + String(a_max,"%3.0f") + ", threshold=" + String(a_threshold,"%3.0f")
\ + ", blur=" + String(a_blur) + ", sat=" + String(a_sat) + ", cont=" + String(a_cont)

/* the following should be a valid Avisynth statement */
stat="PGlow(" + args + ")"
# RT_Debug("SoftGlow","["+string(current_frame)+"]",args,false)
# RT_TxtWriteFile(String(current_frame)+Chr(9)+args,g_logpath,Append=true)
/* write frame number + tab char + statement to logfile...? */
WriteFileStart(g_logpath,String(current_frame),"Chr(9)","args",append=True)

return Eval(stat).ShowFrameNumber
}


C = last

global g_logpath = "C:\Fraps\movies\logfile.txt"
C=C.WriteFileStart(g_logpath, """ "frameno" """, "Chr(9)", """ "args " """,append=false)
C=C.WriteFileEnd(g_logpath, """ "#end" """)

ScriptClip(c, "PGlow_Test(c)")

Manuel Settings:

PGlow (radius=2,min=200,max=235,sat=1.0,mul=0.5,cont=512,blur=24,threshold=127)


logfile of random settings

StainlessS
18th September 2013, 01:13
@MjLives12,
No real need for RT_Debug() in "Optional SoftGlow Test" (maybe), perhaps at least comment out. Nearly mentioned before but did not bother.
# unless debugging, handy for you, but not necessary to the script. Peace bro. :) (unless using RT_ elsewhere, dont think you do).

MJLives12
18th September 2013, 02:48
@MjLives12,
No real need for RT_Debug() in "Optional SoftGlow Test" (maybe), perhaps at least comment out. Nearly mentioned before but did not bother.
# unless debugging, handy for you, but not necessary to the script. Peace bro. :) (unless using RT_ elsewhere, dont think you do).

I haven't really tested out the RT_Debug and RT_TxtWriteFile
function, I get an error saying "there's no function named RT_Debug", also RT_TxtWriteFile when selected. I don't really use debugging (should've unchecked, but would worked for others who have the function)...I really use manual scripting but script is still useful. I'm such a noob.:o Peace.

StainlessS
18th September 2013, 15:39
RT_debug and RT_TxtWriteFile are functions from RT_Stats dll, runtime/compile time functions.
RT_Debug takes 1 or more strings, and outputs to debugview window so you can see debugging
information in real time.
DebugView from SysInternals, bought out by Microsoft, here:
http://technet.microsoft.com/en-gb/sysinternals/bb896647.aspx

Debugview is highly recommended if you develop scripts especially if you use either Scriptclip or GScript, you can see some example RT_Debug
output in post #50, 3rd code block, and the RT_Debug line in 1st code block of same post.

You can remove both RT_ funcs, as they are not now needed in your script.

MJLives12
18th September 2013, 18:14
RT_debug and RT_TxtWriteFile are functions from RT_Stats dll, runtime/compile time functions.
RT_Debug takes 1 or more strings, and outputs to debugview window so you can see debugging
information in real time.
DebugView from SysInternals, bought out by Microsoft, here:
http://technet.microsoft.com/en-gb/sysinternals/bb896647.aspx

Debugview is highly recommended if you develop scripts especially if you use either Scriptclip or GScript, you can see some example RT_Debug
output in post #50, 3rd code block, and the RT_Debug line in 1st code block of same post.

You can remove both RT_ funcs, as they are not now needed in your script.

Just downloaded the RT_Stats dll from Mediafire hyperlink, testing it out now with VirtualDub.:thanks:

C = last

global g_logpath = "C:\<dir>\logfile.txt"
C=C.WriteFileStart(g_logpath, """ "frameno" """, "Chr(9)", """ "args " """,append=false)
C=C.WriteFileEnd(g_logpath, """ "#end" """)

ScriptClip(c, "PGlow_Test(c)")



http://i.imgur.com/PwIJo0u.png?1

9047 radius=189, min=177, max=114, threshold= 64, blur=176, sat=3.560000, cont=240

PGlow (radius=189, min=177, max=114, threshold= 64, blur=176, sat=3.560000, cont=240)

MJLives12
26th December 2013, 03:32
Here's a faster version of using gaussian blur in realtime.

Function GBloom (clip c, int "radius", float "blur", int "w"
\ ,float "sat", float "cont", int "bright", "min", int "max", float "me") {
c
#Variable blur required http://forum.doom9.org/showthread.php?t=88645
#MVtools v2
#radius for BiCubicResize (higher radius use for speed up, 8)
#w for gaussian blur gfunc (set to 0 or 4 enhances lighting, luma and chroma)
#me luma gamma, set to 0.1 or up to 0.4 (brighter chroma and luma) and max to 250
#sat set to 0.5 if chroma is noisy and max to 250, me to 0.2

radius = Default (radius, Round (Width / 120.0))
blur = Default (blur, 1.0)
min = Default (min, 0)
max = Default (max, min +1)
me = Default (me, 0.1)
w = Default (w, 4)
sat = Default (sat, 1.0)
cont = Default (cont, 1.0)
bright = Default (bright, 0)

rmax_set=255
rwmax=last.width/radius
rhmax=last.height/radius
rmax= (rwmax <= rhmax) ? rwmax : rhmax
radius=(((rmax-1)*(radius-1))/(rmax_set-1))+1

old_wid = Width
old_hgt = height
new_wid = rwmax
new_hgt = rhmax

old_wid = Width
old_hgt = height
new_wid = rwmax
new_hgt = rhmax
new_wid = Min(Max(64, new_wid), old_wid / 2)
new_hgt = Min(Max(64, new_hgt), old_hgt / 2)
new_wid = new_wid + new_wid % 2
new_hgt = new_hgt + new_hgt % 2

Mask = BilinearResize(new_wid,new_hgt).ConvertToRGB32 ()
Mask = Mask.BLevels (min, me, max, 0, 255)
\ .GaussianBlur(blur,blur,gfunc=w,y=3,u=3,v=3)
\ .TweakRGB (sat=sat, cont=cont, bright=bright)
\ .ConvertToYV12 ().BilinearResize(old_wid,old_hgt)

MT_lutxy (Mask
\ ,yexpr = "248 256 x - 256 y - * 256 / -"
\ ,uexpr = " y 128 < x y * 128 /"
\ ,vexpr = " y 128 < x y * 128 /", U = 3, V = 3)

ColorYUV (levels="TV->PC")


}


function Blevels(clip c,
\ int input_low, float gamma, int input_high,
\ int output_low, int output_high)

{
c
LC = Levels(input_low, gamma, input_high
\ ,output_low, output_high, coring = true)


Overlay(LC,mode="blend")

}

function TweakRGB(clip last, float "cont", float "sat", int "bright") {

cont = Default (cont, 1.0)
sat = Default (sat, 1.0)
bright = Default (bright, 1)

ConvertToYV12().Tweak(sat=sat, bright=bright)
\ .ConvertToRGB32().RGBAdjust(cont,cont,cont,cont)


}



GBloom(radius=8,blur=6,me=0.4,max=250,sat=1.3,cont=0.8)