View Full Version : porting LSFmod for HBD in avs+
LeXXuz
6th July 2020, 21:34
can you try this update? https://github.com/realfinder/AVS-Stuff/raw/Community/avs%202.5%20and%20up/LSFmod.avsi
Today I'm not at home. I'll test it tomorrow and report back to you. :)
LeXXuz
7th July 2020, 16:25
Okay, here are the results:
Source:
https://abload.de/thumb/2020-07-07_source75jcc.png (https://abload.de/image.php?img=2020-07-07_source75jcc.png)
LSFmod (new) in 8-bit:
https://abload.de/thumb/2020-07-071_8bit5xjij.png (https://abload.de/image.php?img=2020-07-071_8bit5xjij.png)
LSFmod (new) in 10-bit:
https://abload.de/thumb/2020-07-072_10bit7xjhk.png (https://abload.de/image.php?img=2020-07-072_10bit7xjhk.png)
LSFmod (new) in 16-bit:
https://abload.de/thumb/2020-07-073_16bitjtkwu.png (https://abload.de/image.php?img=2020-07-073_16bitjtkwu.png)
LSFmod (old) in 16-bit:
https://abload.de/thumb/2020-07-074_16bit-oldb2ko1.png (https://abload.de/image.php?img=2020-07-074_16bit-oldb2ko1.png)
Looks alright to my eyes. Out of curiosiy, what did you change exactly?
Anyhow thank you very much for maintaining this script and looking into this! :) :thanks:
real.finder
7th July 2020, 16:31
Out of curiosiy, what did you change exactly?
https://github.com/realfinder/AVS-Stuff/commit/101bb78673aec19e71dd1613a93f93a0ead9e2ff
I did this, in 8bit will still same since the lut will round it (I used 0.51, 0.5 should also work but it's not for some reason)
LeXXuz
7th July 2020, 17:03
I have the impression the sharpening effekt is a little weaker in 10/16 but maybe my old eyes are just messing with me. :D
Will sharpening strength be about the same in HBD than in LBD?
Or should I use slightly higher values when filtering my videos in 10bit, compared to 8bit?
real.finder
7th July 2020, 17:34
I have the impression the sharpening effekt is a little weaker in 10/16 but maybe my old eyes are just messing with me. :D
Will sharpening strength be about the same in HBD than in LBD?
Or should I use slightly higher values when filtering my videos in 10bit, compared to 8bit?
it should be in same strength, and it also depends on how you display the HBD (like convert to 8bit at the end with dither or not, and in megui it just convert it to rgb24 for any bitdepth), but anyway the HBD outputs for most filters are not similar to 8bit in first place and that why this problem happened
LeXXuz
7th July 2020, 19:42
Okay, thanks again. :)
WorBry
18th February 2021, 07:13
edit: all old talk that was here moved to the 2nd post now
the porting is done https://github.com/realfinder/AVS-Stuff/raw/master/avs%202.5%20and%20up/LSFmod.avsi
I've just tried to run the script and I'm getting "I don't know what AvsPlusVersionNumber means, LSFMod.avsi, line 433"
What to do? I'm running AviSynthPlus 3.6.1
Thanks.
real.finder
18th February 2021, 07:27
I've just tried to run the script and I'm getting "I don't know what AvsPlusVersionNumber means, LSFMod.avsi, line 433"
What to do? I'm running AviSynthPlus 3.6.1
Thanks.
you need this https://github.com/realfinder/AVS-Stuff/raw/master/avs%202.5%20and%20up/Zs_RF_Shared.avsi
WorBry
18th February 2021, 07:48
OK thanks.
WorBry
27th February 2021, 04:41
So I've been (re)evaluating denoise and sharpening filter combinations for post processing of graded DaVinci Resolve exports - these are 1080/60p Cineform (Filmscan 2) avi files exported at 'Video Levels' but retaining super-white data. The original source material is 1080/60p HD-AVC.mp4 shot on a Canon HF-G40 camcorder in 'Wide DR' gamma mode. Anyone familiar with Wide DR on Canon cameras will know, the 'extended dynamic range', as perceived, comes at the expense of a softer image and increased levels of gain noise in the shadows. Adding back local contrast ('clarity', or 'Midtone Detail' in Resolve), coupled with light sharpening, offers the best prospect for 'enhancing' more detail. The sharpen/blur tool-set in Resolve is very good (IMO), but I'm using the free version and NR is only available in the Studio version. I'd consider the 'NeatVideo' OFX plugin but, AFAIK, that requires the Studio version also.
Hence, my reason for turning to AVISynth.
I've been getting very nice results with KNLMeans and LSFMod processed in 10bit 422 (p210) pipeline. Typical script, for Wide DR:
LWLibavVideoSource("{Path}:\Cineform_export.avi", fpsnum=60000, fpsden=1001,format="YUV422P10")
KNLMeansCL(h=1.2) #up to 1.5 for noisier scenes.
LSFMod(LSFMod(strength=110, defaults="slow")#ranging between 90 - 120.
I'm quite happy with the results as they stand but, if possible, I'd like to look at adding back noise after sharpening. Searching back through the forum I found this snippet from Didee:
https://forum.doom9.org/showthread.php?p=1651062#post1651062
source = whatever
filter = source.AnyDenoiserThatFitsTheSource()
sharpy = filter.YourSharpenerOfChoice()
result = source.mt_makediff(mt_makediff(filter,sharpy),U=2,V=2)
But I think the MaskTools expression would need to be updated for HBD processing - wouldn't it ? - and I'm not sure how to do that. Also how could it be modified to add back noise in varying degrees ?
Thanks.
poisondeathray
27th February 2021, 06:01
But I think the MaskTools expression would need to be updated for HBD processing - wouldn't it ? - and I'm not sure how to do that. Also how could it be modified to add back noise in measured degrees ?
Modern MaskTools2 for avs+ supports HBD and float for most functions. There is a chart in the readme
https://github.com/pinterf/masktools/releases
Merge can "merge" clips with weighting and supports HBD in avs+ .
http://avisynth.nl/index.php/Merge
WorBry
27th February 2021, 07:06
OK thanks. I'm not at my PC just now to try this, but just to be clear - I should be able to use that MakeDiff script for adding back noise as is, or do I need to add some operator for 10bit scaling ?
poisondeathray
27th February 2021, 07:58
OK thanks. I'm not at my PC just now to try this, but just to be clear - I should be able to use that MakeDiff script for adding back noise as is, or do I need to add some operator for 10bit scaling ?
You don't need anything for 10bit scaling, masktools works up to 16bits and some functions at float
That script is not "adding back noise" , it's applying sharpening to a denoised version
It might look something like this
source=last
#d is denoiser apply only
d = source.whateverdenoisers()
#ds is denoiser+sharpener
ds = d.whateversharpeners()
#result1 is add back to ds, the diff between denoised and source
result1=mt_adddiff(ds, mt_makediff(d,source),U=2,V=2)
#modulate strength of addback to ds from 0.0 to 1.0 .
merge(ds, result1, 0.5)
WorBry
27th February 2021, 14:57
That script is not "adding back noise" , it's applying sharpening to a denoised version
True, strictly it's by-passing noise - sharpening a denoised version and applying the difference between that and the denoised version (i.e. the denoised sharpening) to the original noisy version, so leaving the noise in (not adding it back).
source=last
#d is denoiser apply only
d = source.whateverdenoisers()
#ds is denoiser+sharpener
ds = d.whateversharpeners()
#result1 is add back to ds, the diff between denoised and source
result1=mt_adddiff(ds, mt_makediff(d,source),U=2,V=2)
#modulate strength of addback to ds from 0.0 to 1.0 .
merge(ds, result1, 0.5)
OK thanks, I'll give it a go.
Edit: Yes, that works. Thanks.
Dogway
16th May 2021, 23:12
Updated LSFmod to use internal Expr() and dropped avs 2.5 support. Runs faster on my tests. Still needs masktools2 for the convolutions.
https://github.com/Dogway/Avisynth-Scripts/blob/master/Mods/LSFmod.v2.192m.avsi
real.finder
16th May 2021, 23:59
Updated LSFmod to use internal Expr() and dropped avs 2.5 support. Runs faster on my tests. Still needs masktools2 for the convolutions.
https://github.com/Dogway/Avisynth-Scripts/blob/master/Mods/LSFmod.v2.192m.avsi
how much faster? masktools2 lut things can use internal Expr (use_expr) but yes pinterf said back then that using Expr directly will be faster but even so with most 8bit RPN lut still faster from my tests
Reel.Deel
17th May 2021, 00:02
Updated LSFmod to use internal Expr() and dropped avs 2.5 support. Runs faster on my tests. Still needs masktools2 for the convolutions.
https://github.com/Dogway/Avisynth-Scripts/blob/master/Mods/LSFmod.v2.192m.avsi
Thanks for the update Dogway. Death to AviSynth 2.5 :devil:
Dogway
17th May 2021, 00:10
Near 4% faster. The limiting factor here is the convolutions (mt_edge, mt_xxpand, mt_xxflate, etc). If VS convolution is ever ported probably the difference would be bigger. I kinda want to deprecate masktools2 but some functions are still needed.
CPU: i7-4790K (4C/8T)
2.192: 41.5fps
2.192m: 43fps
setmemorymax(2048)
DGSource("source.dgi") # 1080p
ConvertBits(16)
LSFmod(defaults="slow",strength=200,edgemode=0,soothe=true,ss_x=1.0,ss_y=1.0)
trim(7529,12601)
Prefetch(4)
@Reel.Deel: lol, yeah even me haven't found a reason to go back.
real.finder
17th May 2021, 00:21
yeah there are some functions need to be ported from vs like https://forum.doom9.org/showpost.php?p=1941761&postcount=318 and as you said VS convolution
anyway, you test with 16bit, did you tried with 8bit?
@Reel.Deel, Dogway also killed avs 2.6 :) and any old avs+ that don't has expr (that not as important as kill avs 2.6 :) anyway)
Dogway
17th May 2021, 00:32
Yes, box blur is a type a convolution filter, in that case one of variable size.
In 8-bit masktools2 seems faster. This was unexpected. I will test with simple calls if there's something else that can be done.
2.192: 97fps
2.192m: 67fps
Reel.Deel
17th May 2021, 00:33
@Reel.Deel, Dogway also killed avs 2.6 :) and any old avs+ that don't has expr (that not as important as kill avs 2.6 :) anyway)
Good, there is no reason to use classic AviSynth over AviSynth+ ... And if people don't want to update to the latest version, well, shame on them. Your script modifications would greatly benefit from you doing the same thing, they would be much cleaner without the hundreds of calls to "sisavs26", "isyuy2", etc. But hey, to each his own :)
StainlessS
17th May 2021, 01:26
And if people don't want to update to the latest version, well, shame on them.
No shame at all, personal choice, however so long as it runs on XP, I'm stickin' with + [although I feel myself quivering a bit on that XP thing].
Not sure, I think I did last Pole on Avisynth version usage [or maybe the penultimate one], maybe Reel.Deel
or one of the other NonPlus haters would hold a new pole, see how the land lies.
[surely nobody is still usin' 2.58].
Dogway
17th May 2021, 01:27
Good news I found how to use convolutions with Expr()
BoxBlur example, same as Blur(1.0) but faster:
removegrain(19)
BoxBlur with Expr(), slower by 10-15% than removegrain in either bitdepth, but still need to compare with masktools2.
Expr(last,"x[-1,-1] x[1,1] x[-1,0] x[1,0] x[0,1] x[0,-1] x[-1,1] x[1,-1] + + + + + + + 8 /")
EDIT: yep, Expr() is slower (no AVX2)
487fps
mt_edge(mode="sobel",thY1=0.0,thY2=0.0,thC1=0.0,thC2=0.0,chroma="-128")
353fps
Expr(last,"x[-2,0] x[-1,1] x[1,1] x[2,0] x[1,-1] x[-1,-1] + - - - + 2 ^ " \
+"x[-1,0] x[-1,1] x[0,2] x[1,1] x[1,-1] x[0,-2] x[-1,-1] + + + - - - 2 ^ * sqrt", "range_half")
StainlessS
17th May 2021, 02:05
DogWay
Avisource("D:\Parade.avi")
return Expr(last,"x[-1,-1] x[1,1] x[-1,0] x[1,0] x[0,1] x[0,-1] x[-1,1] x[1,-1] + + + + + + + 8 /") # Dogway
EDIT: Oops, I posted the mod above, instead of DogWay original, fixed.
AVSMeter 3.0.8.0 (x86), (c) Groucho2004, 2012-2021
AviSynth+ 3.7.0 (r3382, 3.7, i386) (3.7.0.0)
Number of frames: 7373
Length (hh:mm:ss.ms): 00:04:06.012
Frame width: 488
Frame height: 360
Framerate: 29.970 (30000/1001)
Colorspace: YV12
Audio channels: 2
Audio bits/sample: 16
Audio sample rate: 44100
Audio samples: 10849148
Frames processed: 7373 (0 - 7372)
FPS (min | max | average): 204.1 | 343.6 | 307.6 # Dogways
Process memory usage (max): 39 MiB
Thread count: 9
CPU usage (average): 25.3%
Time (elapsed): 00:00:23.970
Mod (assuming that is in form [x,y]), then all Y-1, then all Y, then all Y+1. [& all left to right,instead of jumping all over the place]
EDIT: I presume that Expr() may be able to take shortcuts, if ordering is as expected in raster order.
EDIT: + possibly more CPU cache friendly.
Avisource("D:\Parade.avi")
return Expr(last,"x[-1,-1] x[0,-1] x[1,-1] x[-1,0] x[1,0] x[-1,1] x[0,1] x[1,1] + + + + + + + 8 /")
AVSMeter 3.0.8.0 (x86), (c) Groucho2004, 2012-2021
AviSynth+ 3.7.0 (r3382, 3.7, i386) (3.7.0.0)
Number of frames: 7373
Length (hh:mm:ss.ms): 00:04:06.012
Frame width: 488
Frame height: 360
Framerate: 29.970 (30000/1001)
Colorspace: YV12
Audio channels: 2
Audio bits/sample: 16
Audio sample rate: 44100
Audio samples: 10849148
Frames processed: 7373 (0 - 7372)
FPS (min | max | average): 142.9 | 357.7 | 319.1 # Mod
Process memory usage (max): 37 MiB
Thread count: 9
CPU usage (average): 26.5%
Time (elapsed): 00:00:23.104
However, should this boxblur thingy not include the original pixel itself, and not just the ones surrounding it.
EDIT: I've no idea how boxblur works. [EDIT: Yes, boxblur should include the original pixel value too, ie 9 coords]
This below would seem to suggest the Blur(1), RemoveGrain(19) and the Expr thingy, aint the same at all.
Avisource("D:\Parade.avi")
#Greyscale
AMP=True
A= Blur(1)
B= removegrain(19)
C=Expr(last,"x[-1,-1] x[1,1] x[-1,0] x[1,0] x[0,1] x[0,-1] x[-1,1] x[1,-1] + + + + + + + 8 /") # Dogway
D=Expr(last,"x[-1,-1] x[0,-1] x[1,-1] x[-1,0] x[1,0] x[-1,1] x[0,1] x[1,1] + + + + + + + 8 /") # Mod
E=Expr(last,"x[-1,-1] x[0,-1] x[1,-1] x[-1,0] x[0,0] x[1,0] x[-1,1] x[0,1] x[1,1] + + + + + + + + 9 /") # Mod, 9 coords
P=ClipDelta(A,B,AMP) # blur(1), RemoveGrain(19)
Q=ClipDelta(A,C,AMP) # blur(1), Dogway
R=ClipDelta(A,E,AMP) # blur(1), 9 coords
S=ClipDelta(B,C,AMP) # RemoveGrain(19), Dogway
T=ClipDelta(B,E,AMP) # RemoveGrain(19), 9 coords
U=ClipDelta(C,D,AMP) # Dogway, Mod : The only one that is identical
V=ClipDelta(C,E,AMP) # Dogway, 9 coords
P
return Last
Function ClipDelta(clip clip1,clip clip2,bool "amp",bool "show") {
amp=Default(amp,false)
show=Default(show,false)
c2=clip1.levels(128-32,1.0,128+32,128-32,128+32).greyscale()
c1=clip1.subtract(clip2)
c1=(amp)?c1.levels(127,1.0,129,0,255):c1
return (show)?c1.Merge(c2):c1
}
EDIT: Above changed around a bit.
ClipDelta(amp=true) shows any difference at all as pretty much max.
real.finder
17th May 2021, 02:06
well I do keep avs25 for some reasons, like use it as a reference either for experimentation or for code, aside from satisfaction the simple or poor peoples that still use old things, also in my personal opinion, I prefer to maintain compatibility with older versions whenever possible (indeed they will not have all privileges), finally it's kinda fun to do this :P
StainlessS
17th May 2021, 02:20
Masochism is a hard habit to break :) [I know, I've been there, partly still am there]
real.finder
17th May 2021, 03:33
seems I will do another update since I got https://github.com/realfinder/AVS-Stuff/blob/Community/avs%202.5%20and%20up/UnsharpMask_avsi.avsi
the only missed HBD now is http://avisynth.nl/index.php/VariableBlur/Unsharp
here https://github.com/realfinder/AVS-Stuff/blob/Community/avs%202.5%20and%20up/LSFmod.avsi
StainlessS
17th May 2021, 04:33
seems I will do another update since I got https://github.com/realfinder/AVS-Stuff/blob/Community/avs%202.5%20and%20up/UnsharpMask_avsi.avsi
RF, thanks, above, too many avsi's.
Dogway
17th May 2021, 16:13
mt_convolution is very very slow, in this case I recommend using Expr() for over double the speed. Stepping is not actually the same as Expr() conv doesn't accept floats.
function UnsharpMask_HBD(clip clp, float "strength", int "radius", float "threshold")
{
str = Default(strength,64)
radius = Default(radius,3)
thres = Default(threshold,8)
rd = radius - 1
str = str/128.
blurclip = Expr(clp,Format("x[-{rd},-{rd}] x[0,-{rd}] x[{rd},-{rd}] x[-{rd},0] x[0,0] x[{rd},0] x[-{rd},{rd}] x[0,{rd}] x[{rd},{rd}] + + + + + + + + 9 /"))
sIsRGB=clp.IsRGB()
e = Format("x y - abs {thres} scalef > x y - {str} * x + x ?")
Expr(clp, blurclip, e, sIsRGB?e:"x") }
StainlessS
17th May 2021, 18:55
Concerning the timing of the 8 pixel coord convolution blur whotsit [which looked more like a de-dot thingy to me, missed out the original pixel],
Doggy changed to 9 coord Expr() convolution so including the missing pixel, looks like 9 coords was correct.
This also is correct, according to wikiPedia Boxblur:- https://en.wikipedia.org/wiki/Box_blur
and,
A number of optimizations can be applied when implementing the box blur of a radius r and N pixels:[6]
The box blur is a separable filter, so that only two 1D passes of averaging 2 r + 1 pixels will be needed, one horizontal and one vertical, for each pixel. This lowers the complexity from O(Nr2) to O(Nr). In digital signal processing terminology, each pass is a moving-average filter.
"Separable filter", so same kind of thing avisynth does with 2 * 1D resizer instead of 2D resizer.
So, I tried this
# boxblur,, 9 coords
Avisource("D:\Parade.avi")
Expr("x[-1,-1] x[0,-1] x[1,-1] x[-1,0] x[0,0] x[1,0] x[-1,1] x[0,1] x[1,1] + + + + + + + + 9 /")
Return Last
Now has 9 coords, so slightly slower than the previously timed 8 coord whotsit.
AVSMeter 3.0.8.0 (x86), (c) Groucho2004, 2012-2021
AviSynth+ 3.7.0 (r3382, 3.7, i386) (3.7.0.0)
Number of frames: 7373
Length (hh:mm:ss.ms): 00:04:06.012
Frame width: 488
Frame height: 360
Framerate: 29.970 (30000/1001)
Colorspace: YV12
Audio channels: 2
Audio bits/sample: 16
Audio sample rate: 44100
Audio samples: 10849148
Frames processed: 7373 (0 - 7372)
FPS (min | max | average): 168.1 | 321.4 | 290.3
Process memory usage (max): 38 MiB
Thread count: 9
CPU usage (average): 25.7%
Time (elapsed): 00:00:25.395
2 * 1D [EDIT: or should it be horizontal(long side), then vertical(short side), I think there is mention of it somewhere about resizers]
# Vertical 3, then horizontal 3
Avisource("D:\Parade.avi")
Expr("x[0,-1] x[0,0] x[0,1] + + 3 /")
Expr("x[-1,0] x[0,0] x[1,0] + + 3 /")
return Last
AVSMeter 3.0.8.0 (x86), (c) Groucho2004, 2012-2021
AviSynth+ 3.7.0 (r3382, 3.7, i386) (3.7.0.0)
Number of frames: 7373
Length (hh:mm:ss.ms): 00:04:06.012
Frame width: 488
Frame height: 360
Framerate: 29.970 (30000/1001)
Colorspace: YV12
Audio channels: 2
Audio bits/sample: 16
Audio sample rate: 44100
Audio samples: 10849148
Frames processed: 7373 (0 - 7372)
FPS (min | max | average): 237.4 | 466.8 | 406.5
Process memory usage (max): 38 MiB
Thread count: 9
CPU usage (average): 26.8%
Time (elapsed): 00:00:18.136
So a pretty fair speed improvement.
However, is not exaclty the same as 9 coord boxblur, probably due to being rounded to int in both vertical and horizontal filtering.
If you do a subtract of 9 coord Expr() thingy, and the 2 * 1D whotsit, it does not show any obvious difference,
and if put through ClipDelta(AMP=True) then the rounding differences look pretty much like random noise,
except in occasional areas of the original clip which were flat in color.
EDIT: Assuming that original 8 coord try at BoxBlur was actaully a DeDot thingy (is it)
# De-Dot
Avisource("D:\Parade.avi")
Expr("x[0,-1] x[0,1] + 2 /")
Expr("x[-1,0] x[1,0] + 2 /")
return Last
Do we have a HBD UnDot ? [if it is an undot/dedot, then maybe one for real.finder collection]
Dogway
17th May 2021, 19:28
Wow, pretty cool! Yes, I thought on shaving some speed with the 8 coords but was wrong.
I think here we might have a masktools2 killer. For me the speed improvement defeats the subtle change.
In any case I have yet to test in HBD.
Here is mt_expand(mode="both"), slower in any case:
Expr("x[0,0] x[0,-1] x[0,1] x[-1,0] x[1,0] + + + +","")
mt_inpand(mode="both")
Expr("x[0,0] x[0,-1] x[0,1] x[-1,0] x[1,0] min min min min","")
I'm going to create a library. EDIT: done, check here -> ExTools (https://github.com/Dogway/Avisynth-Scripts/blob/master/ExTools.avsi)
kedautinh12
18th May 2021, 05:25
new mod ver of dogway v2.193mod support > avs+ 2724
https://github.com/Dogway/Avisynth-Scripts/blob/master/Mods/LSFmod.v2.193m.avsi
Boulder
18th May 2021, 05:40
Do we have a HBD UnDot ? [if it is an undot/dedot, then maybe one for real.finder collection]
I believe RemoveGrain(1) is the same as Undot().
Reel.Deel
18th May 2021, 07:44
I believe RemoveGrain(1) is the same as Undot().
Indeed it is :)
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.