anton_foy
22nd September 2023, 13:10
Thank you - with importing that .avsi files and adding RgTools.dll it starts to work with all functions. Now with full 'pre' clip preparation I see it really not reach required denoise levels in 'auto' mode. Will look in debugger now.
After looking into debug:
After pre=cd.CCD(13).ex_median("IQMV",Y=3,UV=3).ex_sbr(2) the prefiltered clip gives very low average SAD - about 57 for 1 frame (after 0), without prefiltering it is about 180. So default static thSAD about 170 (for dark clip) is really very big for this prefiltered clip. Auto-thSAD simply selects lower thSAD for processing so create lower denoise effect. If you need equal to static 170 thSAD for provided test clip it is autp settings about
thSADA_a=3.5, thSADA_b=50
Though both static thSAD=170 and thSADA_a=3.5, thSADA_b=50 is too high th-settings and may cause more bad blocks blending and detail loss. Also too high thSADA_a param setting will close to disable th-variation proportional to nosie level and will be close to simply too high static thSAD setting.
So with such prefiltering settings you can start with auto settings of thSADA_a=3.5, thSADA_b=50 and tune thSADA_a slowly to lower values looking for still enough denoise with details saving balance. And try to check with another clip with different noise level if auto feature will track threshold better in compare with manual thSAD adjusting.
I start to see some difference in dark parts between static and auto-thSAD only with thSADA_a about 2.7 (with thSADA_b=50).
Test script with prefiltering:
LoadPlugin("mvtools2.dll")
LoadPlugin("masktools2.dll")
LoadPlugin("ffms2.dll")
LoadPlugin("LSMASHSource.dll")
LoadPlugin("vsdegrainmedian.dll")
LoadPlugin("RgTools.dll")
Import("DeblockPack.avsi")
Import("ExTools.avsi")
Import("SMDegrain.avsi")
Import("SharpenersPack.avsi")
function clayDTL(clip Input, clip "Preclip", clip "Superclip", clip "Darkclip", clip "Brightclip", int "DthSAD", int "DthSADC",
\ int "BthSAD", int "BthSADC", int "TR", int "BLKSize", int "Rb", int "Overlap", int "Pel", bool "Chroma",
\ float "VDTh", bool "TM", float "Falloff", int "UV", int "LO", int "HI", float "MID", int "MIX", bool "Fast", bool "Spat",
\ float "thSADA_a", float "thSADA_b")
{
DthSAD = default(DthSAD, 150)
DthSADC= default(DthSADC, 150)
BthSAD = default(BthSAD, 70)
BthSADC= default(BthSADC, 70)
_thSADA_a = default(thSADA_a, 0) #disabled
_thSADA_b = default(thSADA_b, 0) #disabled
TR = default(TR, 6)
BLKSize = default(BLKSize, 32)
Overlap = default(Overlap, 16)
Rb = default(Rb, 8)
Pel = default(Pel, 1)
Chroma = default(Chroma, true)
Tm = default(Tm, false)
Falloff = default(Falloff, 0.9)
VDth = default(VDth, 1.5)
Spat = default(Spat, true)
LO = default(LO, 60)
MID = default(MID, 0.57)
HI = default(HI, 127)
MIX = default(MIX, 230)
UV = default(UV, 3)
Fast = default(Fast, false)
Bt= BitLShift(1,input.BitsPerComponent - 8)
preclip = Default(preclip,input)
superclip = Default(superclip,input)
darkclip = Default(darkclip,input)
brightclip = Default(brightclip,input)
super = MSuper(superclip, pel=pel, hpad = 0, vpad = 0, chroma=chroma, mt=false, levels=1, sharp=1)
superB = MSuper(superclip.merge(input), pel=pel, hpad = 0, vpad = 0, chroma=chroma, mt=false, levels=1, sharp=1)
superfilt = MSuper(preclip, pel=pel, hpad = 0, vpad = 0, mt=false,sharp=1)
Multi_Vector = Superfilt.MAnalyse(Multi=True, Delta=tr, BLKSize=BLKSize, Overlap=Overlap, Chroma=Chroma, truemotion=tm, global=true)
vmulti2 = Mrecalculate(superfilt,multi_vector,thsad=Dthsad,truemotion=tm,tr=tr,blksize=rb,overlap=rb/2,mt=false,chroma=true)
mv_bw1=SelectEvery(multi_vector, tr*2, 0)
mv_fw1=SelectEvery(multi_vector, tr*2, 1)
mv_bw2=SelectEvery(multi_vector, tr*2, 2)
mv_fw2=SelectEvery(multi_vector, tr*2, 3)
dark = spat ? darkclip.MDegrainN(Super, vmulti2, TR, thSADA_a=_thSADA_a, thSADA_b=_thSADA_b, thSAD=DthSAD, thSAD2=Int(DthSAD*Falloff), thSADC=DthSADC, thSADC2=Int(DthSADC*Falloff)) :
\ darkclip.MDegrainN(Super, vmulti2, TR, thSADA_a=_thSADA_a, thSADA_b=_thSADA_b, thSAD=DthSAD, thSAD2=Int(DthSAD*Falloff), thSADC=DthSADC, thSADC2=Int(DthSADC*Falloff)).
\ neo_VD(VDTh, 1, 6, 90, UV=UV)
multi_2fixed=Interleave(mv_bw1, mv_fw1, mv_bw2, mv_fw2)
bright = Fast ? input : brightclip.MDegrainN(SuperB, multi_2fixed, 2, thSADA_a=_thSADA_a, thSADA_b=_thSADA_b, thSAD=BthSAD, thSADC=BthSADC)
mask=dark.extractY().levels(lo*bt, mid, hi*bt, 0, mix*bt)
mt_merge(dark, bright, mask, luma=true, u=uv, v=uv)
return last
}
LSMASHVideoSource("C0135.mp4")
#FFmpegSource2("C0135.mp4")
Crop(700, 540, 1000, 640)
propclearall()
convertbits(16)
Levels(0, 1, 255*256, 0, 235*256, coring=false)
converttoYUV444()
cd=convertbits(8,dither=-1).convertToYv12()
pre=cd.CCD(13).ex_median("IQMV",Y=3,UV=3).ex_sbr(2)
sup01=ex_unsharp(1.77,th=1.1,fc=width(),safe=true,UV=1)
staticthsad=ClayDTL(tr=7,dthsad=170,dthsadc=170,bthsad=100, thSADA_a=0, thSADA_b=0,preclip=pre,superclip=sup01,darkclip=vsdegrainmedian(),brightclip=last,chroma=true)
autothsad=ClayDTL(tr=7,dthsad=1700,dthsadc=1700,bthsad=1000, thSADA_a=2.7, thSADA_b=50,preclip=pre,superclip=sup01,darkclip=vsdegrainmedian(),brightclip=last,chroma=true)
Interleave(last.Subtitle("src"), staticthsad.Subtitle("static"), autothsad.Subtitle("auto"))
Convertbits(8,dither=1)
Prefetch(4)
Also I see with auto-thSAD enabled the thSADX values better to keep in range 100 or higher - setting to 17 looks like cause additional computing issues. So better to keep thSADX values as usual.
Great to see this kind of progress DTL! Have been utterly occupied with work so I will need a couple of days before I try it out. Lots of anticipation :)
Edit: also Im awaiting parts for a completely new computer with RTX 4070 card, AMD Ryzen 9 7950X 4.5 GHz, G.Skill 64GB (2x32GB) DDR5 6000MHz CL30 Trident Z5 etc. So very interested to know how this will perform.
After looking into debug:
After pre=cd.CCD(13).ex_median("IQMV",Y=3,UV=3).ex_sbr(2) the prefiltered clip gives very low average SAD - about 57 for 1 frame (after 0), without prefiltering it is about 180. So default static thSAD about 170 (for dark clip) is really very big for this prefiltered clip. Auto-thSAD simply selects lower thSAD for processing so create lower denoise effect. If you need equal to static 170 thSAD for provided test clip it is autp settings about
thSADA_a=3.5, thSADA_b=50
Though both static thSAD=170 and thSADA_a=3.5, thSADA_b=50 is too high th-settings and may cause more bad blocks blending and detail loss. Also too high thSADA_a param setting will close to disable th-variation proportional to nosie level and will be close to simply too high static thSAD setting.
So with such prefiltering settings you can start with auto settings of thSADA_a=3.5, thSADA_b=50 and tune thSADA_a slowly to lower values looking for still enough denoise with details saving balance. And try to check with another clip with different noise level if auto feature will track threshold better in compare with manual thSAD adjusting.
I start to see some difference in dark parts between static and auto-thSAD only with thSADA_a about 2.7 (with thSADA_b=50).
Test script with prefiltering:
LoadPlugin("mvtools2.dll")
LoadPlugin("masktools2.dll")
LoadPlugin("ffms2.dll")
LoadPlugin("LSMASHSource.dll")
LoadPlugin("vsdegrainmedian.dll")
LoadPlugin("RgTools.dll")
Import("DeblockPack.avsi")
Import("ExTools.avsi")
Import("SMDegrain.avsi")
Import("SharpenersPack.avsi")
function clayDTL(clip Input, clip "Preclip", clip "Superclip", clip "Darkclip", clip "Brightclip", int "DthSAD", int "DthSADC",
\ int "BthSAD", int "BthSADC", int "TR", int "BLKSize", int "Rb", int "Overlap", int "Pel", bool "Chroma",
\ float "VDTh", bool "TM", float "Falloff", int "UV", int "LO", int "HI", float "MID", int "MIX", bool "Fast", bool "Spat",
\ float "thSADA_a", float "thSADA_b")
{
DthSAD = default(DthSAD, 150)
DthSADC= default(DthSADC, 150)
BthSAD = default(BthSAD, 70)
BthSADC= default(BthSADC, 70)
_thSADA_a = default(thSADA_a, 0) #disabled
_thSADA_b = default(thSADA_b, 0) #disabled
TR = default(TR, 6)
BLKSize = default(BLKSize, 32)
Overlap = default(Overlap, 16)
Rb = default(Rb, 8)
Pel = default(Pel, 1)
Chroma = default(Chroma, true)
Tm = default(Tm, false)
Falloff = default(Falloff, 0.9)
VDth = default(VDth, 1.5)
Spat = default(Spat, true)
LO = default(LO, 60)
MID = default(MID, 0.57)
HI = default(HI, 127)
MIX = default(MIX, 230)
UV = default(UV, 3)
Fast = default(Fast, false)
Bt= BitLShift(1,input.BitsPerComponent - 8)
preclip = Default(preclip,input)
superclip = Default(superclip,input)
darkclip = Default(darkclip,input)
brightclip = Default(brightclip,input)
super = MSuper(superclip, pel=pel, hpad = 0, vpad = 0, chroma=chroma, mt=false, levels=1, sharp=1)
superB = MSuper(superclip.merge(input), pel=pel, hpad = 0, vpad = 0, chroma=chroma, mt=false, levels=1, sharp=1)
superfilt = MSuper(preclip, pel=pel, hpad = 0, vpad = 0, mt=false,sharp=1)
Multi_Vector = Superfilt.MAnalyse(Multi=True, Delta=tr, BLKSize=BLKSize, Overlap=Overlap, Chroma=Chroma, truemotion=tm, global=true)
vmulti2 = Mrecalculate(superfilt,multi_vector,thsad=Dthsad,truemotion=tm,tr=tr,blksize=rb,overlap=rb/2,mt=false,chroma=true)
mv_bw1=SelectEvery(multi_vector, tr*2, 0)
mv_fw1=SelectEvery(multi_vector, tr*2, 1)
mv_bw2=SelectEvery(multi_vector, tr*2, 2)
mv_fw2=SelectEvery(multi_vector, tr*2, 3)
dark = spat ? darkclip.MDegrainN(Super, vmulti2, TR, thSADA_a=_thSADA_a, thSADA_b=_thSADA_b, thSAD=DthSAD, thSAD2=Int(DthSAD*Falloff), thSADC=DthSADC, thSADC2=Int(DthSADC*Falloff)) :
\ darkclip.MDegrainN(Super, vmulti2, TR, thSADA_a=_thSADA_a, thSADA_b=_thSADA_b, thSAD=DthSAD, thSAD2=Int(DthSAD*Falloff), thSADC=DthSADC, thSADC2=Int(DthSADC*Falloff)).
\ neo_VD(VDTh, 1, 6, 90, UV=UV)
multi_2fixed=Interleave(mv_bw1, mv_fw1, mv_bw2, mv_fw2)
bright = Fast ? input : brightclip.MDegrainN(SuperB, multi_2fixed, 2, thSADA_a=_thSADA_a, thSADA_b=_thSADA_b, thSAD=BthSAD, thSADC=BthSADC)
mask=dark.extractY().levels(lo*bt, mid, hi*bt, 0, mix*bt)
mt_merge(dark, bright, mask, luma=true, u=uv, v=uv)
return last
}
LSMASHVideoSource("C0135.mp4")
#FFmpegSource2("C0135.mp4")
Crop(700, 540, 1000, 640)
propclearall()
convertbits(16)
Levels(0, 1, 255*256, 0, 235*256, coring=false)
converttoYUV444()
cd=convertbits(8,dither=-1).convertToYv12()
pre=cd.CCD(13).ex_median("IQMV",Y=3,UV=3).ex_sbr(2)
sup01=ex_unsharp(1.77,th=1.1,fc=width(),safe=true,UV=1)
staticthsad=ClayDTL(tr=7,dthsad=170,dthsadc=170,bthsad=100, thSADA_a=0, thSADA_b=0,preclip=pre,superclip=sup01,darkclip=vsdegrainmedian(),brightclip=last,chroma=true)
autothsad=ClayDTL(tr=7,dthsad=1700,dthsadc=1700,bthsad=1000, thSADA_a=2.7, thSADA_b=50,preclip=pre,superclip=sup01,darkclip=vsdegrainmedian(),brightclip=last,chroma=true)
Interleave(last.Subtitle("src"), staticthsad.Subtitle("static"), autothsad.Subtitle("auto"))
Convertbits(8,dither=1)
Prefetch(4)
Also I see with auto-thSAD enabled the thSADX values better to keep in range 100 or higher - setting to 17 looks like cause additional computing issues. So better to keep thSADX values as usual.
Great to see this kind of progress DTL! Have been utterly occupied with work so I will need a couple of days before I try it out. Lots of anticipation :)
Edit: also Im awaiting parts for a completely new computer with RTX 4070 card, AMD Ryzen 9 7950X 4.5 GHz, G.Skill 64GB (2x32GB) DDR5 6000MHz CL30 Trident Z5 etc. So very interested to know how this will perform.