Motenai Yoda
26th February 2011, 14:13
Yo Guys, I need some help, this function should sharp with some limits. Can be optimized?
function BSharp(clip c, float "strength", float "lim", float "lim2", int "tlim",int "tlim2", bool "debug")
{
#~ v20f
strength = default( strength, 1.0 )
lim = default( lim, 10.0 )
lim2 = default( lim2, lim)
tlim = default( tlim, 16)
tlim2 = default( tlim2, 64)
debug = default( debug, false)
tlim= (tlim<0.0) ? 0.0 : tlim
tlim2= (tlim2<tlim) ? tlim + 2.0 : tlim2
stre=string(strength)
slim=string(lim)
slim2=string(lim2)
b1=c.removegrain(11,-1)#blur 1px radius
b2=b1.removegrain(11,-1)#blur 2px radius
b3=b2.removegrain(11, -1).removegrain(11,-1)#blur 4px radius
#use an inverted sigmoid curve to reduce sharp at noise level (lim2)
l1 = mt_lutxy(c, b1, yexpr = "x y - abs 1 < x - y "+slim2+" 4 < x y - x y - y x - "+slim2+" 2.0 / / exp x y - "+slim2+" 2.0 / / exp - y x - "+slim2+" 2.0 / / exp x y - "+slim2+" 2.0 / / exp + / abs * ? ? 0.5 * 128 +" , U = 1, V = 1)
l2 = mt_lutxy(c, b2, yexpr = "x y - abs 1 < x - y "+slim2+" 2 < x y - x y - y x - "+slim2+" / exp x y - "+slim2+" / exp - y x - "+slim2+" / exp x y - "+slim2+" / exp + / abs * ? ? 128 +" , U = 1, V = 1)
l3 = mt_lutxy(c, b3, yexpr = "x y - abs 1 < x - y "+slim2+" 1 < x y - x y - y x - "+slim2+" 2.0 * / exp x y - "+slim2+" 2.0 * / exp - y x - "+slim2+" 2.0 * / exp x y - "+slim2+" 2.0 * / exp + / abs * ? ? 0.5 * 128 +" , U = 1, V = 1)
sharped=mt_adddiff(l1,l2, U = 1, V = 1).mt_adddiff(l3, U = 1, V = 1)#.RequestLinear(rlim=5,clim=5)
#use a sigmoid curve to reduce sharp at edge level (lim)
limitstring=slim+" 0 == x 128 - x 128 - "+slim+" x 128 - / exp 1.0 "+slim+" x 128.0 - / exp / - "+slim+" x 128.0 - / exp 1.0 "+slim+" x 128.0 - / exp / + / abs * ?"
#use a composite function (parabola+parabola) to reduce sharp at dynamics edge (16=0,235=0,128=1.0)
parabola="x y 128 - x 128 == 1.0 x 16 <= 0.0 x 235 >= 0.0 x 128 < x 15.0 - x 2 ^ 256.0 / - 49.0 / x 256.0 * 4935.0 - x 2 ^ - 11449.0 / ? ? ? ? * +"
#use a motion mask to stabize sharp like soothe (tlim,tlim2)
tlimited=mt_lutxy(sharped, c.mt_motion(thy1=tlim, thy2=tlim2,thT=10, u=1,v=1) , yexpr = "x 128 == 128 "+limitstring+" 255.0 y - 255.0 / * "+stre+" * 128 + ? ", U = 1, V = 1)
return (debug) ? mt_lutxy(c,tlimited,parabola,u=128,v=128) : mt_lutxy(c,tlimited,parabola,u=2,v=2)
}
:thanks:
function BSharp(clip c, float "strength", float "lim", float "lim2", int "tlim",int "tlim2", bool "debug")
{
#~ v20f
strength = default( strength, 1.0 )
lim = default( lim, 10.0 )
lim2 = default( lim2, lim)
tlim = default( tlim, 16)
tlim2 = default( tlim2, 64)
debug = default( debug, false)
tlim= (tlim<0.0) ? 0.0 : tlim
tlim2= (tlim2<tlim) ? tlim + 2.0 : tlim2
stre=string(strength)
slim=string(lim)
slim2=string(lim2)
b1=c.removegrain(11,-1)#blur 1px radius
b2=b1.removegrain(11,-1)#blur 2px radius
b3=b2.removegrain(11, -1).removegrain(11,-1)#blur 4px radius
#use an inverted sigmoid curve to reduce sharp at noise level (lim2)
l1 = mt_lutxy(c, b1, yexpr = "x y - abs 1 < x - y "+slim2+" 4 < x y - x y - y x - "+slim2+" 2.0 / / exp x y - "+slim2+" 2.0 / / exp - y x - "+slim2+" 2.0 / / exp x y - "+slim2+" 2.0 / / exp + / abs * ? ? 0.5 * 128 +" , U = 1, V = 1)
l2 = mt_lutxy(c, b2, yexpr = "x y - abs 1 < x - y "+slim2+" 2 < x y - x y - y x - "+slim2+" / exp x y - "+slim2+" / exp - y x - "+slim2+" / exp x y - "+slim2+" / exp + / abs * ? ? 128 +" , U = 1, V = 1)
l3 = mt_lutxy(c, b3, yexpr = "x y - abs 1 < x - y "+slim2+" 1 < x y - x y - y x - "+slim2+" 2.0 * / exp x y - "+slim2+" 2.0 * / exp - y x - "+slim2+" 2.0 * / exp x y - "+slim2+" 2.0 * / exp + / abs * ? ? 0.5 * 128 +" , U = 1, V = 1)
sharped=mt_adddiff(l1,l2, U = 1, V = 1).mt_adddiff(l3, U = 1, V = 1)#.RequestLinear(rlim=5,clim=5)
#use a sigmoid curve to reduce sharp at edge level (lim)
limitstring=slim+" 0 == x 128 - x 128 - "+slim+" x 128 - / exp 1.0 "+slim+" x 128.0 - / exp / - "+slim+" x 128.0 - / exp 1.0 "+slim+" x 128.0 - / exp / + / abs * ?"
#use a composite function (parabola+parabola) to reduce sharp at dynamics edge (16=0,235=0,128=1.0)
parabola="x y 128 - x 128 == 1.0 x 16 <= 0.0 x 235 >= 0.0 x 128 < x 15.0 - x 2 ^ 256.0 / - 49.0 / x 256.0 * 4935.0 - x 2 ^ - 11449.0 / ? ? ? ? * +"
#use a motion mask to stabize sharp like soothe (tlim,tlim2)
tlimited=mt_lutxy(sharped, c.mt_motion(thy1=tlim, thy2=tlim2,thT=10, u=1,v=1) , yexpr = "x 128 == 128 "+limitstring+" 255.0 y - 255.0 / * "+stre+" * 128 + ? ", U = 1, V = 1)
return (debug) ? mt_lutxy(c,tlimited,parabola,u=128,v=128) : mt_lutxy(c,tlimited,parabola,u=2,v=2)
}
:thanks: