Log in

View Full Version : Clay - Denoising script


Pages : 1 [2]

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.

anton_foy
17th October 2023, 08:42
Finally got my new computer and need to set up avs+ and vapoursynth.

I was reading some older posts about masking with levels and Didée pointed out that mt_lut is 4x faster than levels. So I tried to modify his YLevels function as such:


#...clay function above

mask = dark.Ymask(lo=lo, mid=mid, hi=hi, lift=0, mix=mix)

mt_merge(dark, bright, mask, luma=true, u=uv, v=uv)
return last
}​

function Ymask(clip clp,
\ int "lo", float "mid", int "hi",
\ int "lift", int "mix")
{
lo = Default(lo, 0)
mid = Default(mid, 1.0)
hi = Default(hi, 255)
lift = Default(lift, 0)
mix = Default(mix, 255)

c = extractY(clp)

lev = "x " +string(lo)+ " - " +string(hi)+ " " +string(lo)+ " - / 1 " +string(mid)+
\ " / ^ " +string(mix)+ " "+string(lift)+" - * "+string(lift)+" +"

return c.mt_lut(Yexpr = lev, U=1,V=1, scale_inputs="allf")
}


Would this be faster than the original masking technique or has internal levels been optimized lately?

EDIT:
Now the comp is up and runnin' and Ymask is slower than using levels.
Going to try ClayDTL in a moment.

DTL
5th April 2024, 23:40
After looking into MRecalculate function: It looks current thSAD param for MRecalculate equal to DthSAD for MDegrainN is too high for making MVs refining. It cause running of MRecalculate in the MVs interpolation mode but not performing refining search for many MVs. This makes better fps performance but may cause more details blurring where MVs passed to MDegrainN with significant errors. So to make quality possibly higher (with visible performance hit) it may be recommended to set thSAD for MRecalculate to much lower value (setting to 0 will cause all MVs refining). As I see in SMDegrain script it is hardcoded to thSAD(MDegrain)/2 but it may be also not very low if user will set too high thSAD.

anton_foy
7th April 2024, 08:50
After looking into MRecalculate function: It looks current thSAD param for MRecalculate equal to DthSAD for MDegrainN is too high for making MVs refining. It cause running of MRecalculate in the MVs interpolation mode but not performing refining search for many MVs. This makes better fps performance but may cause more details blurring where MVs passed to MDegrainN with significant errors. So to make quality possibly higher (with visible performance hit) it may be recommended to set thSAD for MRecalculate to much lower value (setting to 0 will cause all MVs refining). As I see in SMDegrain script it is hardcoded to thSAD(MDegrain)/2 but it may be also not very low if user will set too high thSAD.

Thank you DTL I will try that!