View Full Version : Having trouble sharpening Twister
Nightshiver
20th March 2010, 22:45
I'm having a spot of trouble trying to sharpen up the movie "Twister". Even the blu-ray is utterly lacking in this department. Whenever I try any kind of sharpening, it just brings out halo's and makes the odd film grain look horrible and the characters/scenery mushy. I so far haven't been able to find a way to combat this, and you can take a much better look in the 2 samples I've included. Any and all help is appreciated.
Sample 1: http://www.megaupload.com/?d=NO8IM56Z
Sample 2: http://www.megaupload.com/?d=NQKD0T1L
*.mp4 guy
22nd March 2010, 07:36
My god that's horrible... This should be interesting.
Nightshiver
22nd March 2010, 17:46
Oh goody, I got some help! And from .mp4 guy as well! Yes, I was a bit (understatement) disappointed with the source, but hopefully something can be done.
*.mp4 guy
23rd March 2010, 19:57
Well, this isn't great, it removes some detail, but the noise and halos are pretty much gone, and some sharpness has been put back into the Y dimension, which was really strongly lowpassed.
# Y'et A'nother H'alo R'educing script
function YAHR(clip clp)
{
b1 = clp.minblur(2).removegrain(11,-1)
b1D = mt_makediff(clp,b1)
w1 = clp.aWarpSharp(depth=32,blurlevel=2,thresh=0.5)
w1b1 = w1.minblur(2,1).removegrain(11,-1)
w1b1D = mt_makediff(w1,w1b1)
DD = b1D.repair(w1b1D,13)
DD2 = mt_makediff(b1D,DD)
clp.mt_makediff(DD2,U=2,V=2)
}
Function blurH(clip c, int "rad", Float "CW")
{
Rad = Default(rad, 1)
CW = Default(CW, 0.5)
Center = C
Left = C.PointResize(C.width, C.height, -rad, 0, C.width, C.height)
Right = C.PointResize(C.width, C.height, rad, 0, C.width, C.height)
Average(Center, CW/2, Left, (1-CW)/2, Right, (1-CW)/2, Center, CW/2)
Return(last)
}
Function BlurV(clip c, int "rad", Float "CW")
{
Rad = Default(rad, 1)
CW = Default(CW, 0.5)
Center = C
Down = C.PointResize(C.width, C.height, 0, -rad, C.width, C.height)
Up = C.PointResize(C.width, C.height, 0, rad, C.width, C.height)
Average(Center, CW/2, Down, (1-CW)/2, Up, (1-CW)/2, Center, CW/2)
Return(last)
}
Function Tblur4(Clip c, int "thresh")
{
Thresh = Default(Thresh, 8)
B1 = C.yahr
Mt_LutXY(C, b1, " X Y - abs X Y - abs * X Y - * X Y - abs X Y - abs * "+string(thresh)+" + / 128 +", u=1, v=1)
Mt_AddDiff(last, b1, u=1, v=1)
Return(last)
}
Function NLLV(Clip C, int "rad")
{
Rad = Default(Rad, 1)
B1 = C.BlurV(1*rad, 0.439)
B2 = C.BlurV(3*rad, 0.833)
B3 = C.BlurV(5*rad, 0.934)
B4= C.BlurV(7*rad, 0.983)
B1_D = Mt_Makediff(B1, C, u=1, v=1)
B2_D = Mt_MakeDiff(C, B2, u=1, v=1)
B3_D = Mt_MakeDiff(B3, C, u=1, v=1)
B4_D = Mt_MakeDiff(C, B4, u=1, v=1)
B2_DT = Mt_LutXY(B1_D, B2_D, " X 128 - Y 128 - X 128 - abs Y 128 - abs * 1 + * X 128 - abs Y 128 - abs * Y 128 - abs 1.915 * X 128 - abs - 0 > \
Y 128 - abs 1.915 * X 128 - abs - 0 ? X 128 - abs 0 > X 128 - abs -1 X 128 - abs 0 > X 128 - 1 ? / ^ 1 ? / 1 * + 1 + / + 128 + ", u=1, v=1)
B3_DT = Mt_LutXY(B2_DT, B3_D, " X 128 - Y 128 - X 128 - abs Y 128 - abs * 1 + * X 128 - abs Y 128 - abs * Y 128 - abs 2.025 * X 128 - abs - 0 > \
Y 128 - abs 2.025 * X 128 - abs - 0 ? X 128 - abs 0 > X 128 - abs -1 X 128 - abs 0 > X 128 - 1 ? / ^ 1 ? / 1 * + 1 + / + 128 + ", u=1, v=1)
B4_DT = Mt_LutXY(B3_DT, B4_D, " X 128 - Y 128 - X 128 - abs Y 128 - abs * 1 + * X 128 - abs Y 128 - abs * Y 128 - abs 2.077 * X 128 - abs - 0 > \
Y 128 - abs 2.077 * X 128 - abs - 0 ? X 128 - abs 0 > X 128 - abs -1 X 128 - abs 0 > X 128 - 1 ? / ^ 1 ? / 1 * + 1 + / + 128 + ", u=1, v=1)
Mt_AddDiff(B4_DT, C)
Return(last)
}
Function NLLH(Clip C, int "rad")
{
Rad = Default(Rad, 1)
B1 = C.BlurH(1*rad, 0.439)
B2 = C.BlurH(3*rad, 0.833)
B3 = C.BlurH(5*rad, 0.934)
B4= C.BlurH(7*rad, 0.983)
B1_D = Mt_Makediff(B1, C, u=1, v=1)
B2_D = Mt_MakeDiff(C, B2, u=1, v=1)
B3_D = Mt_MakeDiff(B3, C, u=1, v=1)
B4_D = Mt_MakeDiff(C, B4, u=1, v=1)
B2_DT = Mt_LutXY(B1_D, B2_D, " X 128 - Y 128 - X 128 - abs Y 128 - abs * 1 + * X 128 - abs Y 128 - abs * Y 128 - abs 1.915 * X 128 - abs - 0 > \
Y 128 - abs 1.915 * X 128 - abs - 0 ? X 128 - abs 0 > X 128 - abs -1 X 128 - abs 0 > X 128 - 1 ? / ^ 1 ? / 1 * + 1 + / + 128 + ", u=1, v=1)
B3_DT = Mt_LutXY(B2_DT, B3_D, " X 128 - Y 128 - X 128 - abs Y 128 - abs * 1 + * X 128 - abs Y 128 - abs * Y 128 - abs 2.025 * X 128 - abs - 0 > \
Y 128 - abs 2.025 * X 128 - abs - 0 ? X 128 - abs 0 > X 128 - abs -1 X 128 - abs 0 > X 128 - 1 ? / ^ 1 ? / 1 * + 1 + / + 128 + ", u=1, v=1)
B4_DT = Mt_LutXY(B3_DT, B4_D, " X 128 - Y 128 - X 128 - abs Y 128 - abs * 1 + * X 128 - abs Y 128 - abs * Y 128 - abs 2.077 * X 128 - abs - 0 > \
Y 128 - abs 2.077 * X 128 - abs - 0 ? X 128 - abs 0 > X 128 - abs -1 X 128 - abs 0 > X 128 - 1 ? / ^ 1 ? / 1 * + 1 + / + 128 + ", u=1, v=1)
Mt_AddDiff(B4_DT, C)
Return(last)
}
function Halomask1(clip c, int "Rad", float "SS")
{
SS = default(ss, 1.5)
Rad = default(rad, 7)
owidth = c.width
oheight = c.height
ssample = spline36resize(c, round((c.width*SS)/4)*4, round((c.height*SS)/4)*4)
mask1 = mt_lutxy(ssample, Xsharpen(ssample, 127, 255), "x y - abs 1 - 63 *", u=1, v=1)
mask2 = (rad >= 1) ? mask1.mt_expand(u=1, v=1) : mask1
mask2 = (rad >= 2) ? mask2.mt_expand(u=1, v=1) : mask2
mask2 = (rad >= 3) ? mask2.mt_expand(u=1, v=1) : mask2
mask2 = (rad >= 4) ? mask2.mt_expand(u=1, v=1) : mask2
mask2 = (rad >= 5) ? mask2.mt_expand(u=1, v=1) : mask2
mask2 = (rad >= 6) ? mask2.mt_expand(u=1, v=1) : mask2
mask2 = (rad >= 7) ? mask2.mt_expand(u=1, v=1) : mask2
mask2 = (rad >= 8) ? mask2.mt_expand(u=1, v=1) : mask2
mask2 = (rad >= 9) ? mask2.mt_expand(u=1, v=1) : mask2
mask2 = (rad >= 10) ? mask2.mt_expand(u=1, v=1) : mask2
mask2 = (rad >= 11) ? mask2.mt_expand(u=1, v=1) : mask2
mask2 = (rad >= 12) ? mask2.mt_expand(u=1, v=1) : mask2
mask2 = (rad >= 13) ? mask2.mt_expand(u=1, v=1) : mask2
mask2 = (rad >= 14) ? mask2.mt_expand(u=1, v=1) : mask2
mask2 = (rad >= 15) ? mask2.mt_expand(u=1, v=1) : mask2
mask2 = (rad >= 16) ? mask2.mt_expand(u=1, v=1) : mask2
mask3 = mt_lutXY(mask1, mask2, "y x - 63 - 1.5 *", u=1, v=1).spline36resize(owidth, oheight)
return(mask3)
}
Function NLHH(Clip C)
{
B1 = Average(C.BlurH(1, 0.833), 0.5, C.BlurH(2, 0.833), 0.5)
B2 = C.BlurH(3, 0.750)
B3 = C.BlurH(5, 0.944)
B4= C.BlurH(7, 0.981)
B1_D = Mt_Makediff(c, b1, u=1, v=1)
B2_D = Mt_MakeDiff(b2, c, u=1, v=1)
B3_D = Mt_MakeDiff(c, b3, u=1, v=1)
B4_D = Mt_MakeDiff(b4, c, u=1, v=1)
B2_DT = Mt_LutXY(B1_D, B2_D, " X 128 - Y 128 - X 128 - abs Y 128 - abs * 1 + * X 128 - abs Y 128 - abs * Y 128 - abs 0.75 * X 128 - abs - 0 > Y 128 - abs 0.75 * X 128 - abs - 0 ? X 128 - abs 0 > X 128 - abs -1 X 128 - abs 0 > X 128 - 1 ? / ^ 1 ? / 1 * + 1 + / + 128 + ", u=1, v=1)
B3_DT = Mt_LutXY(B2_DT, B3_D, " X 128 - Y 128 - X 128 - abs Y 128 - abs * 1 + * X 128 - abs Y 128 - abs * Y 128 - abs 2.25 * X 128 - abs - 0 > Y 128 - abs 2.25 * X 128 - abs - 0 ? X 128 - abs 0 > X 128 - abs -1 X 128 - abs 0 > X 128 - 1 ? / ^ 1 ? / 1 * + 1 + / + 128 + ", u=1, v=1)
B4_DT = Mt_LutXY(B3_DT, B4_D, " X 128 - Y 128 - X 128 - abs Y 128 - abs * 1 + * X 128 - abs Y 128 - abs * Y 128 - abs 6.75 * X 128 - abs - 0 > Y 128 - abs 6.75 * X 128 - abs - 0 ? X 128 - abs 0 > X 128 - abs -1 X 128 - abs 0 > X 128 - 1 ? / ^ 1 ? / 1 * + 1 + / + 128 + ", u=1, v=1)
Mt_AddDiff(B4_DT, C)
Return(last)
}
Function NLHV(Clip C)
{
B1 = Average(C.BlurV(1, 0.833), 0.5, C.BlurV(2, 0.833), 0.5)
B2 = C.BlurV(3, 0.750)
B3 = C.BlurV(5, 0.944)
B4= C.BlurV(7, 0.981)
B1_D = Mt_Makediff(c, b1, u=1, v=1)
B2_D = Mt_MakeDiff(b2, c, u=1, v=1)
B3_D = Mt_MakeDiff(c, b3, u=1, v=1)
B4_D = Mt_MakeDiff(b4, c, u=1, v=1)
B2_DT = Mt_LutXY(B1_D, B2_D, " X 128 - Y 128 - X 128 - abs Y 128 - abs * 1 + * X 128 - abs Y 128 - abs * Y 128 - abs 0.75 * X 128 - abs - 0 > Y 128 - abs 0.75 * X 128 - abs - 0 ? X 128 - abs 0 > X 128 - abs -1 X 128 - abs 0 > X 128 - 1 ? / ^ 1 ? / 1 * + 1 + / + 128 + ", u=1, v=1)
B3_DT = Mt_LutXY(B2_DT, B3_D, " X 128 - Y 128 - X 128 - abs Y 128 - abs * 1 + * X 128 - abs Y 128 - abs * Y 128 - abs 2.25 * X 128 - abs - 0 > Y 128 - abs 2.25 * X 128 - abs - 0 ? X 128 - abs 0 > X 128 - abs -1 X 128 - abs 0 > X 128 - 1 ? / ^ 1 ? / 1 * + 1 + / + 128 + ", u=1, v=1)
B4_DT = Mt_LutXY(B3_DT, B4_D, " X 128 - Y 128 - X 128 - abs Y 128 - abs * 1 + * X 128 - abs Y 128 - abs * Y 128 - abs 6.75 * X 128 - abs - 0 > Y 128 - abs 6.75 * X 128 - abs - 0 ? X 128 - abs 0 > X 128 - abs -1 X 128 - abs 0 > X 128 - 1 ? / ^ 1 ? / 1 * + 1 + / + 128 + ", u=1, v=1)
Mt_AddDiff(B4_DT, C)
Return(last)
}
Function TblurNL(Clip c, float "thresh", float "thresh2", float "thresh3", int "rad")
{
Rad = Default(Rad, 1)
B1 = C.NLLH(1*Rad)
B2 = B1.NLLV(1*Rad)
B3 = B2.NLLH(2*Rad)
B4 = B3.NLLV(2*Rad)
B5 = B4.NLLH(3*Rad)
B6 = B5.NLLV(3*Rad)
Thresh = Default(Thresh, 8)
Thresh2 = Default(Thresh2, Thresh/4)
Thresh3 = Default(Thresh3, Thresh/9)
Thresh1 = Thresh
Thresh2 = Thresh
Thresh3 = Thresh2
Thresh4 = Thresh2
Thresh5 = Thresh3
Thresh6 = Thresh3
Mt_LutXY(b5, b6, " X Y - abs 1 + X Y - abs 1 + * X Y - * X Y - abs 1 + X Y - abs 1 + * "+string(thresh6)+" + / 128 +", u=1, v=1)
Mt_AddDiff(last, b6, u=1, v=1)
b5 = last
Mt_LutXY(b4, b5, " X Y - abs 1 + X Y - abs 1 + * X Y - * X Y - abs 1 + X Y - abs 1 + * "+string(thresh5)+" + / 128 +", u=1, v=1)
Mt_AddDiff(last, b5, u=1, v=12)
b4 = last
Mt_LutXY(b3, b4, " X Y - abs 1 + X Y - abs 1 + * X Y - * X Y - abs 1 + X Y - abs 1 + * "+string(thresh4)+" + / 128 +", u=1, v=1)
Mt_AddDiff(last, b4, u=1, v=1)
b3 = last
Mt_LutXY(b2, b3, " X Y - abs 1 + X Y - abs 1 + * X Y - * X Y - abs 1 + X Y - abs 1 + * "+string(thresh3)+" + / 128 +", u=1, v=1)
Mt_AddDiff(last, b3, u=1, v=1)
b2 = last
Mt_LutXY(b1, b2, " X Y - abs 1 + X Y - abs 1 + * X Y - * X Y - abs 1 + X Y - abs 1 + * "+string(thresh2)+" + / 128 +", u=1, v=1)
Mt_AddDiff(last, b2, u=1, v=1)
b1 = last
Mt_LutXY(C, b1, " X Y - abs 1 + X Y - abs 1 + * X Y - * X Y - abs 1 + X Y - abs 1 + * "+string(thresh1)+" + / 128 +", u=1, v=1)
Mt_AddDiff(last, b1, u=1, v=1)
Return(Last)
}
Function TMed2(Clip C, int "thresh", int "rad", int "mode", int "kernel")
{
_Thr = Default(thresh, 256)
_Rad = Default(rad, 1)
Mode = Default(mode, 1)
THR = string(_Thr)
RAD = string(_Rad)
RAD2 = string(_Rad)
kernel = Default(kernel, 1)
Diff = Mode==0 ? MT_Luts(C, C, mode="med", pixels = "0 "+RAD+" "+RAD+" 0 -"+RAD+" 0 0 -"+RAD ,\
expr = "X Y - X Y - X Y - abs 1 + * X Y - abs 1 + "+THR+" 1 >= "+THR+" 0.5 ^ "+THR+" ? + / - 128 +", u=1,v=1)\
: MT_Luts(C, C, mode="med", pixels = "0 "+RAD+" "+RAD+" 0 -"+RAD+" 0 0 -"+RAD+" 0 0" ,\
expr = "X Y - X Y - X Y - abs 1 + * X Y - abs 1 + "+THR+" 1 >= "+THR+" 0.5 ^ "+THR+" ? + / - 128 +", u=1,v=1)
Diff = Kernel > 1 ? MT_Luts(C, C, mode="med", pixels = "-"+RAD2+" -"+RAD2+"-"+RAD2+" "+RAD2+" "+RAD2+" -"+RAD2+" "+RAD2+" "+RAD2+" 0 "+RAD+" "+RAD+" 0 -"+RAD+" 0 0 -"+RAD ,\
expr = "X Y - X Y - X Y - abs 1 + * X Y - abs 1 + "+THR+" 1 >= "+THR+" 0.5 ^ "+THR+" ? + / - 128 +", u=1,v=1) : Diff
MT_Makediff(C, Diff, u=2, v=2)
Return(Last)
}
Function MedSharp2(Clip C, int "thresh", int "rad", int "mode", bool "lp", bool "hp", bool "nr", float "str", int "kernel")
{
_Thr = Default(thresh, 256)
_Rad = Default(rad, 1)
Mode = Default(mode, 1)
str = Default(str, 1)
THR = string(_Thr)
RAD = string(_Rad)
RAD2 = string(_Rad)
lp = Default(lp, false)
hp = Default(hp, false)
nr = Default(nr, false)
kernel = Default(kernel, 2)
inputclipproperties = c
blank = BlankClip(length=inputclipproperties.framecount, width=inputclipproperties.width, height=inputclipproperties.height, pixel_type="rgb32", fps=inputclipproperties.framerate, fps_denominator=1, audio_rate=inputclipproperties.Audiorate, stereo=true, sixteen_bit=true, color=$828282).converttoyv12()
Lowpass1 = C.NLLV(rad=1).NLLH(rad=1)
Lowpass_Return = lp == true ? _Rad >= 2 ? Lowpass1 : C : C
Lowpass_NR_1 = Lowpass_Return.TMed2(rad=_Rad, thresh=_Thr, Kernel=1)
Lowpass_NR_2 = Lowpass_Return.TMed2(rad=_Rad, thresh=_Thr/4, Kernel=2)
Diff1 = MT_Luts(C, Lowpass_NR_1, mode="med", pixels = "0 "+RAD+" "+RAD+" 0 -"+RAD+" 0 0 -"+RAD+" 0 0" ,\
expr = "X Y - X Y - X Y - abs 1 + * X Y - abs 1 + "+THR+" 1 >= "+THR+" 0.5 ^ "+THR+" ? + / - 128 +", u=1,v=1)
Diff2 = MT_Luts(C, Lowpass_NR_2, mode="med", pixels = "-"+RAD2+" -"+RAD2+"-"+RAD2+" "+RAD2+" "+RAD2+" -"+RAD2+" "+RAD2+" "+RAD2+" 0 "+RAD+" "+RAD+" 0 -"+RAD+" 0 0 -"+RAD ,\
expr = "X Y - X Y - X Y - abs 1 + * X Y - abs 1 + "+THR+" 2 * 1 >= "+THR+" 2 * 0.5 ^ "+THR+" 2 * ? + / - 128 +", u=1,v=1)
mask1 = Mt_Lut(Diff1, " X 128 - 255 * ", u=1, v=1)#.NLLV().NLLH()
#mask2 = Mt_Lut(Diff2, " X 128 - 255 * ", u=1, v=1)#.NLLV().NLLH()
s1 = mt_merge(Diff2, blank, mask1).mt_Lut("X 128 - "+string(str)+" 2 / * 128 +")
s1b = s1.NLLV().NLLH()
s1s = mt_makediff(s1, s1b)
s2 = Diff1.mt_Lut("X 128 - "+string(str)+" * 128 +")
s2b = s1.NLLV().NLLH()
s2s = mt_makediff(s2, s2b)
out = MT_adddiff(C, s1s, u=2, v=2)
out = MT_adddiff(out, s2s, u=2, v=2)
out
Return(Last)
}
MPEG2Source("E:\twister1.demuxed.d2v", cpu=0, info=3).colormatrix(hints=true).crop(8, 56, -8, -56)
#sharpening
lanczosresize(704, 480, taps=7)
MV = Mt_LutXY(last.mt_convolution(horizontal=" 1 ", vertical=" 4 0 -10 0 42 -14 -14 168 -14 -14 42 0 -10 0 4 ", u=1, v=1), last, " X Y - Abs 64 * ", U=-128, V=-128)
Mt_Merge(last.mt_convolution(horizontal=" 1 ", vertical=" 4 0 -10 0 42 -14 -14 168 -14 -14 42 0 -10 0 4 ", u=2, v=2), last.NLHV.NLHV.tblur4(16), MV)
lanczosresize(704, 608, taps=7)
pointresize(704, height/2)
MedSharp2(str=3, rad=1, lp=true, hp=true, nr=true)
HaloMask = Halomask1(ss=1.25, rad=8).nllv().nllh()
MT_Merge(last.mt_convolution(horizontal=" 1 ", vertical=" -1 1 -5 70 -5 1 -1 ", u=1, v=1), Last.mt_convolution(horizontal=" 1 ", vertical=" 1 -1 5 50 5 -1 1 ", u=1, v=1), HaloMask).MergeChroma(last, 1)
#denoising
str=3
source = last
pred_ = source.fft3dfilter(bw=6, bh=6, ow=3, oh=3, bt=1, sigma=str, plane=4).fft3dfilter(bw=216, bh=216, ow=108, oh=108, bt=1, sigma=str/8, sigma2=str/4, sigma3=str/2, sigma4=str, plane=4).TblurNL(rad=2, thresh=4)
pred = pred_.hqdn3d(0.2, 0.2, 3, 3).gradfun2db(1.01)
w = source.width
h = source.height
backward_vec2 = pred.MVAnalyse(isb = true, delta = 2, pel = 4, overlap=4, sharp=2, idx = 1, truemotion=true, dct=5, chroma=false)
backward_vec1 = pred.MVAnalyse(isb = true, delta = 1, pel = 4, overlap=4, sharp=2, idx = 1, truemotion=true, dct=5, chroma=false)
forward_vec1 = pred.MVAnalyse(isb = false, delta = 1, pel = 4, overlap=4, sharp=2, idx = 1, truemotion=true, dct=5, chroma=false)
forward_vec2 = pred.MVAnalyse(isb = false, delta = 2, pel = 4, overlap=4, sharp=2, idx = 1, truemotion=true, dct=5, chroma=false)
maskp1 = source.mvmask(kind=1, vectors=forward_vec1, ysc=255).UtoY()
maskp2 = source.mvmask(kind=1, vectors=forward_vec2, ysc=255).UtoY()
maskp3 = source.mvmask(kind=1, vectors=backward_vec1, ysc=255).UtoY()
maskp4 = source.mvmask(kind=1, vectors=backward_vec2, ysc=255).UtoY()
maskf = average(maskp1, 0.25, maskp2, 0.25, maskp3, 0.25, maskp4, 0.25).spline36resize(w, h)
smooth = pred_.gradfun2db(1.01)
source2 = MT_Merge(Source, smooth, maskf)
source3 = source2.MVDegrain2(backward_vec1,forward_vec1,backward_vec2,forward_vec2,thSAD=800,idx=2)
source3.gradfun2db(1.01)
Sorry, no examples, my isp doesn't play nice with file hosting services. :rolleyes:
If you don't have a ton of ram, you might need to split the script into two sections for speed.
Nightshiver
23rd March 2010, 22:06
Just took a look. Extremely good results, thanks! Although, as you say, it does soften the image quite a bit. But a much better improvement over what I was doing.
*.mp4 guy
24th March 2010, 02:38
A lot of the softening is because of the noise removal section, if it bothers you, there might be a better script for that part, I'm not used to dealing with quite that much noise. iirc Didée made a script for 300 that might work well for the denoising.
Nightshiver
24th March 2010, 20:11
Yeah, I've got his 300 script, but he made that for the blu ray source.
o = last
fft = o.fft3dfilter(sigma=16,sigma2=10,sigma3=6,sigma4=4,bt=5,bw=16,bh=16,ow=8,oh=8)
# "srch" is a prefiltered clip on which the motion serach is done.
# Here, we simply use FFT3DFilter. There're lots of other possibilities. Basically, you shouldn't use
# a clip with "a tiny bit of filtering". The search clip has to be CALM. Ideally, it should be "dead calm".
srch = fft
# "spat" is a prefiltered clip which is used to limit the effect of the 1st MV-denoise stage.
# For simplicity, we just use the same FFT3DFilter. There're lots of other possibilities.
spat = fft
spatD = mt_makediff(o,spat)
# motion vector search (with very basic parameters. Add your own parameters as needed.)
b3vec1 = srch.MVAnalyse(isb = true, delta = 3, pel = 2, overlap=4, sharp=2, idx = 1)
b2vec1 = srch.MVAnalyse(isb = true, delta = 2, pel = 2, overlap=4, sharp=2, idx = 1)
b1vec1 = srch.MVAnalyse(isb = true, delta = 1, pel = 2, overlap=4, sharp=2, idx = 1)
f1vec1 = srch.MVAnalyse(isb = false, delta = 1, pel = 2, overlap=4, sharp=2, idx = 1)
f2vec1 = srch.MVAnalyse(isb = false, delta = 2, pel = 2, overlap=4, sharp=2, idx = 1)
f3vec1 = srch.MVAnalyse(isb = false, delta = 3, pel = 2, overlap=4, sharp=2, idx = 1)
# 1st MV-denoising stage. Usually here's some temporal-median filtering going on.
# For simplicity, we just use MVDegrain.
NR1 = o .MVDegrain3(b1vec1,f1vec1,b2vec1,f2vec1,b3vec1,f3vec1,thSAD=300,idx=2)
NR1D = mt_makediff(o,NR1)
# limit NR1 to not do more than what "spat" would do
DD = mt_lutxy(spatD,NR1D,"x 128 - abs y 128 - abs < x y ?")
NR1x = o.mt_makediff(DD,U=2,V=2)
# 2nd MV-denoising stage. We use MVDegrain.
NR2 = NR1x.MVDegrain3(b1vec1,f1vec1,b2vec1,f2vec1,b3vec1,f3vec1,thSAD=300,idx=3)
# contra-sharpening: sharpen the denoised clip, but don't add more to any pixel than what was removed previously.
# (Here: a simple area-based version with relaxed restriction. The full version is more complicated.)
s = NR2.minblur(1,1) # damp down remaining spots of the denoised clip
allD = mt_makediff(o,NR2) # the difference achieved by the denoising
ssD = mt_makediff(s,s.removegrain(11,-1)) # the difference of a simple kernel blur
ssDD = ssD.repair(allD,1) # limit the difference to the max of what the denoising removed locally.
ssDD = SSDD.mt_lutxy(ssD,"x 128 - abs y 128 - abs < x y ?") # abs(diff) after limiting may not be bigger than before.
NR2.mt_adddiff(ssDD,U=2,V=2) # apply the limited difference. (sharpening is just inverse blurring)
return(last)
Nevertheless, it's a viable option. I just tested it and it still super smooths motion a lot and scenery is better. I actually tried going back to my ugly simple way of things and wonder what you think of this:
MPEG2Source("D:\Movies\TWISTER\twist.d2v", cpu=0)
crop( 10, 56, -6, -58)
Spline36Resize(720,304)
YAHR()
source = last
vectors = source.MVAnalyseMulti(refframes=3, pel=2, overlap=4, sharp=1, idx=1)
b = source.MVDegrainMulti(vectors,thSAD=800,idx=1)
a = last
SeeSaw(a,b, NRlimit=4, NRlimit2=4,Sstr=1.5, Slimit=6, Sdamplo=8, Spower=5, Szp=16)
I suppose if I wanted even more degraining, I could always increase the refframes and the thSAD. I even tried just applying your approach to the sharpening, just the sharpening, and it still smoothed things out considerably, but I do honestly appreciate what you're doing, it's always good to have someone helping out :)
*.mp4 guy
25th March 2010, 00:57
After looking at what you did before, I can definitely say I prefer my script, but that's no surprise. I've never liked what sharpeners usually do to sources like this. Anyway, the detail loss is as I was afraid just the result of using mvdegrain on a source with very little temporal stability. It looks like the result of bad compression and some sort of temporal smoothing, possibly the smoothing is a result of compression aswell, I've seen it happen before.
I personally would probably use my "sharpening" and Didée's nr script, but replace his preprocessing with what I used, and maybe add in the masking of high SAD areas for spatial smoothing and replace his MVAnalyse arguments with what I used. however my computer isn't fast enough to handle that script, so there is no easy way for me to test it.
Nightshiver
25th March 2010, 20:51
Heck, it seems even my comp won't take it. 4gb of ram and quad core cpu and AvsP is always crashing. Was the hacked together script supposed to resemble something like this?
MPEG2Source("D:\Movies\TWISTER\twist.d2v", cpu=0)
crop( 10, 56, -6, -58)
source = last
#sharpening
lanczosresize(720, 304, taps=7)
MV = Mt_LutXY(last.mt_convolution(horizontal=" 1 ", vertical=" 4 0 -10 0 42 -14 -14 168 -14 -14 42 0 -10 0 4 ", u=1, v=1), last, " X Y - Abs 64 * ", U=-128, V=-128)
Mt_Merge(last.mt_convolution(horizontal=" 1 ", vertical=" 4 0 -10 0 42 -14 -14 168 -14 -14 42 0 -10 0 4 ", u=2, v=2), last.NLHV.NLHV.tblur4(16), MV)
lanczosresize(720, 608, taps=7)
pointresize(720, height/2)
MedSharp2(str=3, rad=1, lp=true, hp=true, nr=true)
HaloMask = Halomask1(ss=1.25, rad=8).nllv().nllh()
MT_Merge(last.mt_convolution(horizontal=" 1 ", vertical=" -1 1 -5 70 -5 1 -1 ", u=1, v=1), Last.mt_convolution(horizontal=" 1 ", vertical=" 1 -1 5 50 5 -1 1 ", u=1, v=1), HaloMask1).MergeChroma(last, 1)
#denoising
str = 3
o = last
fft = o.fft3dfilter(bw=6, bh=6, ow=3, oh=3, bt=1, sigma=str, plane=4).fft3dfilter(bw=216, bh=216, ow=108, oh=108, bt=1, sigma=str/8, sigma2=str/4, sigma3=str/2, sigma4=str, plane=4).TblurNL(rad=2, thresh=4)
srch = fft
spat = fft
spatD = mt_makediff(o,spat)
hqdn3d(0.2, 0.2, 3, 3).gradfun2db(1.01)
w = source.width
h = source.height
backward_vec2 = srch.MVAnalyse(isb = true, delta = 2, pel = 4, overlap=4, sharp=2, idx = 1, truemotion=true, dct=5, chroma=false)
backward_vec1 = srch.MVAnalyse(isb = true, delta = 1, pel = 4, overlap=4, sharp=2, idx = 1, truemotion=true, dct=5, chroma=false)
forward_vec1 = srch.MVAnalyse(isb = false, delta = 1, pel = 4, overlap=4, sharp=2, idx = 1, truemotion=true, dct=5, chroma=false)
forward_vec2 = srch.MVAnalyse(isb = false, delta = 2, pel = 4, overlap=4, sharp=2, idx = 1, truemotion=true, dct=5, chroma=false)
NR1 = o .MVDegrain2(backward_vec1,forward_vec1,backward_vec2,forward_vec2,thSAD=300,idx=2)
NR1D = mt_makediff(o,NR1)
DD = mt_lutxy(spatD,NR1D,"x 128 - abs y 128 - abs < x y ?")
NR1x = o.mt_makediff(DD,U=2,V=2)
NR2 = NR1x.MVDegrain2(backward_vec1,forward_vec1,backward_vec2,forward_vec2,thSAD=300,idx=2)
s = NR2.minblur(1,1) # damp down remaining spots of the denoised clip
allD = mt_makediff(o,NR2) # the difference achieved by the denoising
ssD = mt_makediff(s,s.removegrain(11,-1)) # the difference of a simple kernel blur
ssDD = ssD.repair(allD,1) # limit the difference to the max of what the denoising removed locally.
ssDD = SSDD.mt_lutxy(ssD,"x 128 - abs y 128 - abs < x y ?") # abs(diff) after limiting may not be bigger than before.
NR2.mt_adddiff(ssDD,U=2,V=2) # apply the limited difference. (sharpening is just inverse blurring)
spline36resize(w, h)
return(last)
*.mp4 guy
25th March 2010, 22:02
try this
str=3
o = last
fft = o.fft3dfilter(bw=6, bh=6, ow=3, oh=3, bt=1, sigma=str, plane=4).fft3dfilter(bw=216, bh=216, ow=108, oh=108, bt=1, sigma=str/8, sigma2=str/4, sigma3=str/2, sigma4=str, plane=4).TblurNL(rad=2, thresh=4)
srch = fft.hqdn3d(0.2, 0.2, 3, 3).gradfun2db(1.01)
# "spat" is a prefiltered clip which is used to limit the effect of the 1st MV-denoise stage.
# For simplicity, we just use the same FFT3DFilter. There're lots of other possibilities.
spat = fft.gradfun2db(1.01)
spatD = mt_makediff(o,spat)
# motion vector search (with very basic parameters. Add your own parameters as needed.)
b3vec1 = srch.MVAnalyse(isb = true, delta = 3, pel = 4, overlap=4, sharp=2, idx = 1, truemotion=true, dct=5, chroma=false)
b2vec1 = srch.MVAnalyse(isb = true, delta = 2, pel = 4, overlap=4, sharp=2, idx = 1, truemotion=true, dct=5, chroma=false)
b1vec1 = srch.MVAnalyse(isb = true, delta = 1, pel = 4, overlap=4, sharp=2, idx = 1, truemotion=true, dct=5, chroma=false)
f1vec1 = srch.MVAnalyse(isb = false, delta = 1, pel = 4, overlap=4, sharp=2, idx = 1, truemotion=true, dct=5, chroma=false)
f2vec1 = srch.MVAnalyse(isb = false, delta = 2, pel = 4, overlap=4, sharp=2, idx = 1, truemotion=true, dct=5, chroma=false)
f3vec1 = srch.MVAnalyse(isb = false, delta = 3, pel = 4, overlap=4, sharp=2, idx = 1, truemotion=true, dct=5, chroma=false)
# 1st MV-denoising stage. Usually here's some temporal-median filtering going on.
# For simplicity, we just use MVDegrain.
NR1 = o .MVDegrain3(b1vec1,f1vec1,b2vec1,f2vec1,b3vec1,f3vec1,thSAD=300,idx=2)
NR1D = mt_makediff(o,NR1)
# limit NR1 to not do more than what "spat" would do
DD = mt_lutxy(spatD,NR1D,"x 128 - abs y 128 - abs < x y ?")
NR1x = o.mt_makediff(DD,U=2,V=2)
# 2nd MV-denoising stage. We use MVDegrain.
NR2 = NR1x.MVDegrain3(b1vec1,f1vec1,b2vec1,f2vec1,b3vec1,f3vec1,thSAD=300,idx=3)
# contra-sharpening: sharpen the denoised clip, but don't add more to any pixel than what was removed previously.
# (Here: a simple area-based version with relaxed restriction. The full version is more complicated.)
s = NR2.minblur(1,1) # damp down remaining spots of the denoised clip
allD = mt_makediff(o,NR2) # the difference achieved by the denoising
ssD = mt_makediff(s,s.removegrain(11,-1)) # the difference of a simple kernel blur
ssDD = ssD.repair(allD,1) # limit the difference to the max of what the denoising removed locally.
ssDD = SSDD.mt_lutxy(ssD,"x 128 - abs y 128 - abs < x y ?") # abs(diff) after limiting may not be bigger than before.
NR2.mt_adddiff(ssDD,U=2,V=2).gradfun2db(1.01) # apply the limited difference. (sharpening is just inverse blurring)
return(last)
Blue_MiSfit
25th March 2010, 22:17
Give 64 bit AviSynth a whirl. There's been a lot of work recently on getting 2.5.8 MT a stable 64 bit build (and rebuilding many popular plugins as well).
Look in the AviSynth development thread.
I've had fantastic results, and for really RAM heavy scripts like this, 64 bit should actually complete the job instead of running out of RAM :)
Nightshiver
25th March 2010, 22:42
Mp4guy's script worked. Slowly. :P Here's some pics:
Source: http://img248.imageshack.us/img248/7157/sourcea.png
Didde + Mp4guy: http://img97.imageshack.us/img97/5575/dideemp4death.png
Oh and Misfit, I can't use 64bit avisynth because I don't have 64 bit OS :(
Didée
25th March 2010, 23:23
Here's some pics:
Source: http://img248.imageshack.us/img248/7157/sourcea.png
Didde + Mp4guy: http://img97.imageshack.us/img97/5575/dideemp4death.png
To my eyes, that looks not good, but rather poor.
Also, how comes "my name" into the game? I didn't give any recommendations for this particular case. Just because it uses some of "my" script snipplets, it's not a "Didée result". Imagine you would use FFT3DFilter with sigma=666, and would then call it a "Fizick result". :D
Nightshiver
26th March 2010, 00:02
Bah, I just thought of putting your name in there because it was your script that got used. I even misspelled your name :P And yes, I also think it doesn't look to good but I'm not sure if that can be helped much. Removing the noise seems to also smooth the video.
*.mp4 guy
26th March 2010, 03:52
Meh, that isn't great, I stand by the first part of the script, but I don't know what to do about the noise.
Didée
26th March 2010, 21:43
Okay, I tried something. The source is somewhat resistant against "make it look clean and and good". The script does a little of de-haloing, a little of de-graining, a little of sharpening and pimping .... Neither of the operations does a 200%-job - there's some halos left over, there's quite some grain left over, and so on. I did not try to remove {this} or {that} by all means and/or at any cost. Just tried to improve things, as in "make a visually pleasing result." Better to do a bit too little, than a bit too much. (Hopelessly over-filtering is for the script kiddies, but not for the adults.)
In exchange, the script runs at some "reasonable" frames-per-second speed, not at frames-per-hour. ;)
Screens:
http://img517.imageshack.us/img517/1730/twister0050src.th.jpg (http://img517.imageshack.us/i/twister0050src.jpg/) http://img696.imageshack.us/img696/7843/twister0050proc.th.jpg (http://img696.imageshack.us/i/twister0050proc.jpg/)
http://img185.imageshack.us/img185/61/twister0750src.th.jpg (http://img185.imageshack.us/i/twister0750src.jpg/) http://img404.imageshack.us/img404/7523/twister0750proc.th.jpg (http://img404.imageshack.us/i/twister0750proc.jpg/)
http://img7.imageshack.us/img7/4750/twister0900src.th.jpg (http://img7.imageshack.us/i/twister0900src.jpg/) http://img100.imageshack.us/img100/5369/twister0900proc.th.jpg (http://img100.imageshack.us/i/twister0900proc.jpg/)
http://img683.imageshack.us/img683/9527/twister1990src.th.jpg (http://img683.imageshack.us/i/twister1990src.jpg/) http://img408.imageshack.us/img408/3055/twister1990proc.th.jpg (http://img408.imageshack.us/i/twister1990proc.jpg/)
Script:
# LoadPlugin( RemoveGrain.dll
# Repair.dll
# MedianBlur.dll
# FluxSmooth.dll
# mt_masktools-25.dll
# MVTools.dll
#
# Import( LimitedSharpenFaster.avsi )
mpeg2source("twister2.demuxed.d2v")
crop(8,48,-8,-48,true)
o=last ox=o.width() oy=o.height()
mb2 = o.sharpen(.35).minblur(2)
mb2a = mb2.sbr()
e1 = mb2.mt_edge("prewitt",0,255,0,255).mt_inflate().mt_inflate().mt_expand().mt_inflate().mt_inflate().greyscale
e2 = e1.mt_edge("prewitt",0,255,0,255).mt_deflate().mt_expand().greyscale
e3 = mt_lutxy(e2,e2.mt_expand().mt_inpand(),"y x - 2 *").mt_inflate()
dh = o.mt_merge(mb2a.addgrainc(12),e2)
pre = mb2.sbr().fluxsmootht(4)
shrp = dh.mt_adddiff(mt_makediff(dh,dh.minblur(2).sbr()),U=2,V=2)
shrp = shrp.sharpen(.25).mt_merge(shrp,e2.mt_inflate().mt_inflate().removegrain(11).mt_logic(e3,"max"))
shrp = mt_lutxy(shrp,shrp.gaussresize(48,32,p=16).gaussresize(ox,oy,p=5),expr="x x y - abs 1 2.618 / ^ 0.618 * x y - 3 ^ x y - abs 3 ^ 1.618 + / * +",
\ yexpr="x x y - abs 1 2.618 / ^ 0.786 * x y - 3 ^ x y - abs 3 ^ 1.618 + / * +",U=3,V=3)
shrpD = mt_makediff(shrp,dh,U=3,V=3).sbr()
shrpDD = mt_makediff(shrpD,shrpD.removegrain(4),U=3,V=3)
shrpDD = mt_makediff(shrpDD,shrpDD.removegrain(11),U=3,V=3)
shrp = shrp.mt_adddiff(shrpDD,U=3,V=3)
shrp = shrp.minblur3()
presup = pre.msuper(pel=2,sharp=2)
shrpsup = shrp.MSuper(pel=2,levels=1)
bv3 = presup.manalyse(isb=true, delta=3,blksize=16,overlap=8,truemotion=false,search=4,searchparam=8)
bv2 = presup.manalyse(isb=true, delta=2,blksize=16,overlap=8,truemotion=false,search=4,searchparam=8)
bv1 = presup.manalyse(isb=true, delta=1,blksize=16,overlap=8,truemotion=false,search=4,searchparam=8)
fv1 = presup.manalyse(isb=false,delta=1,blksize=16,overlap=8,truemotion=false,search=4,searchparam=8)
fv2 = presup.manalyse(isb=false,delta=2,blksize=16,overlap=8,truemotion=false,search=4,searchparam=8)
fv3 = presup.manalyse(isb=false,delta=3,blksize=16,overlap=8,truemotion=false,search=4,searchparam=8)
dh.mdegrain3(shrpsup,bv1,fv1,bv2,fv2,bv3,fv3,thSAD=256)
limitedsharpenfaster(ss_x=1.0,ss_y=1.0,strength=24)
mergeluma(removegrain(11,-1).removegrain(20,-1).removegrain(11,-1),0.11)
crop(0,8,-0,-8)
stackvertical(last,o.crop(0,8,-0,-8))
return(last)
#======================================
function sbr(clip c) {
rg11D=mt_makediff(c,c.removegrain(11,-1))
rg11DD=mt_makediff(rg11D,rg11D.removegrain(11,-1)).mt_lutxy(rg11D,"x 128 - y 128 - * 0 < 128 x 128 - abs y 128 - abs < x y ? ?")
#rg11DD=mt_makediff(rg11D,rg11D.removegrain(11,-1)).mt_lutxy(rg11D,"x 128 - y 128 - * 0 < x y + 2 / x 128 - abs y 128 - abs < x y ? ?")
c.mt_makediff(rg11DD,U=2,V=2) }
# Nifty Gauss/Median combination
function MinBlur(clip clp, int r, int "uv")
{
uv = default(uv,3)
uv2 = (uv==2) ? 1 : uv
rg4 = (uv==3) ? 4 : -1
rg11 = (uv==3) ? 11 : -1
rg20 = (uv==3) ? 20 : -1
medf = (uv==3) ? 1 : -300
RG11D = (r==1) ? mt_makediff(clp,clp.removegrain(11,rg11),U=uv2,V=uv2)
\ : (r==2) ? mt_makediff(clp,clp.removegrain(11,rg11).removegrain(20,rg20),U=uv2,V=uv2)
\ : mt_makediff(clp,clp.removegrain(11,rg11).removegrain(20,rg20).removegrain(20,rg20),U=uv2,V=uv2)
RG4D = (r==1) ? mt_makediff(clp,clp.removegrain(4,rg4),U=uv2,V=uv2)
\ : (r==2) ? mt_makediff(clp,clp.medianblur(2,2*medf,2*medf),U=uv2,V=uv2)
\ : mt_makediff(clp,clp.medianblur(3,3*medf,3*medf),U=uv2,V=uv2)
DD = mt_lutxy(RG11D,RG4D,"x 128 - y 128 - * 0 < 128 x 128 - abs y 128 - abs < x y ? ?",U=uv2,V=uv2)
clp.mt_makediff(DD,U=uv,V=uv)
return(last)
}
function minblur3(clip c) {
rgD = mt_makediff(c,c.removegrain(3))
sbD = mt_makediff(c,c.sbr())
DD = mt_lutxy(rgD,sbD,"x 128 - y 128 - * 0 < x y + 2 / x 128 - abs y 128 - abs < x y ? ?")
c.mt_makediff(DD,U=2,V=2) }
*.mp4 guy
27th March 2010, 08:06
That looks pretty similar to what I got before I tried to kill all of the noise. Which it would appear is not really workable with this source. Also, I still like the first half of my script better. :p
The high radius sharpening is from the gaussresize? lol @ 1.618.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.