Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 22nd August 2017, 01:00   #41  |  Link
burfadel
Registered User
 
Join Date: Aug 2006
Posts: 2,234
I did adjust the noise alteration, do you prefer the new one or old one? I was thinking about the going back to 8 bits, how do you detect the source bit depth so you can go back to it?
burfadel is offline   Reply With Quote
Old 22nd August 2017, 01:23   #42  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,173
Quote:
Originally Posted by burfadel View Post
how do you detect the source bit depth so you can go back to it?
BitPerComponent
MysteryX is offline   Reply With Quote
Old 22nd August 2017, 01:39   #43  |  Link
burfadel
Registered User
 
Join Date: Aug 2006
Posts: 2,234
The non-detail spatial noise reduction has also changed, it's now removegrain (21), was 17. Any of 2, 12, 13, 14, 17, 21 could be suitable due to how it's applied, it's figuring which one is more suitable. I can continue to adjust the renoise feature as well before going on to the next feature.
burfadel is offline   Reply With Quote
Old 22nd August 2017, 03:30   #44  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,173
Quote:
Originally Posted by burfadel View Post
I did adjust the noise alteration, do you prefer the new one or old one?
Honestly, the old one gives a more natural feel.
MysteryX is offline   Reply With Quote
Old 22nd August 2017, 06:43   #45  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,173
Something else I'm thinking about. Adjusting denoising strength with THSAD doesn't actually change the strength, but rather the width of areas being affected. It's a ON/OFF denoiser where you only select where to draw the line. Renoise allows for this subtle adjustment of strength, on top of allowing for stronger denoising than would normally be acceptable. It thus has at least 2 benefits.

You can also test whether converting Luma to Linear Light makes any difference.

Last edited by MysteryX; 22nd August 2017 at 07:37.
MysteryX is offline   Reply With Quote
Old 22nd August 2017, 12:21   #46  |  Link
burfadel
Registered User
 
Join Date: Aug 2006
Posts: 2,234
That true about THSAD .

I've made test script with two new options for the testing only. To set the renoise variation there's options ver=1 through to ver=6. There is also spatial noise reduction option 'sn' that allows to specify any specific Removegrain mode, default 21, but 2, 4, 7, 9, 10, 17, 18 may also be worth testing. The different 'ver' settings will affect not only still images but how they look in motion, which can make it hard to tell. The intent is to have it look good in both still images and motion, whilst not causing excessive bitrate increase. Test script is YV12/YUY2/RGB32 only.

Separate question, how do you specify a script to return back to the original colour space if conversion occurs during the script? I know you can find the pixel type with the pixteltype() function, but there doesn't seem to be any way to actually use that information? Basically most filters require for instance, a planar format like YV12 or YV24. Ideally if in YV12 it can stay in YV12 (fine), what about RGB32 input? You would convert to YV24 which will (mostly) keep the chroma resolution, and convert back again, but how do you tell the script to automatically convert back to RGB32 or whatever the source was in, without guessing? Sure, you can get the pixeltype, and run the 'if' operator for every colour type based on the pixel format, but that's a considerable number of lines!

Test script for renoise variations and spatial clean type.

Note: Function mCleanT
Code:
# mClean Test Scipt
# Not for any other use than to test Renoise variations
# Function is mCleanT, T for Test.

# TEST ONLY!!!
# ver (renoise type) range 1 to 6
# sn (spatial noise reduction) test recommended values 2, 4, 7, 9, 10, 17, 18, 21 (default)


function mCleanT(clip c, int "thSAD", int "blksize", int "blksizeV", int "overlap", int "overlapV", int "enh", int "rn", int "sn", int "ver", int "cpu")
{
    defH        = Max (C.Height, C.Width/4*3)     # Resolution calculation for auto blksize settings
    thSAD       = Default (thSAD, 450)     # Denoising threshold
    blksize     = Default (blksize, defH<360 ? 8 : defH<750 ? 12 : defH<1200 ? 16 : defH<1600 ? 24 : 32)     # Horizontal block size for MDegrain2
    blksizeV    = Default (blksizeV, blksize)     # Vertical block size for MDegrain2, default same as horizontal
    overlap     = Default (overlap, blksize>4?(blksize/4+1)/2*2:0)     # Horizontal block overlap
    overlapV    = Default (overlapV, blksize>4?(blksizeV/4+1)/2*2:0)     # Vertical block overlap
    enh         = Default (enh, 20)     # Detail enhancement (detail orientated sharpen) strength
    rn          = Default (rn, 0)     # ReNoise strength from 0 (disabled) to 20
    sn          = Default (sn, 21) # Spatial noise type *****For TESTING ONLY*****
    ver         = Default (ver, 0) # Renoise variation *****For TESTING ONLY*****
    cpu         = Default (cpu, 4)     # Threads for fft3dfilter

    Assert(enh>=0 && enh<=102, """mClean: "enh" ranges from 0 to 102""")
    Assert(rn>=0 && rn<=20, """mClean: "rn" ranges from 0 to 20""")
    bits = bitspercomponent(c)
    c = convertbits(c, 16)

# Spatio/temporal chroma noise filter
filt_chroma  =  fft3dfilter (c, bw=blksize*2, bh=blksizeV*2, ow=overlap*2, oh=overlapV*2, sharpen=0.12, bt=3, ncpu=cpu, dehalo=0.3, sigma=2.35, plane=3)

# Temporal luma noise filter
super     =  c.MSuper (chroma=false,hpad=16, vpad=16)
bvec2     =  MAnalyse (super, chroma=false, isb = true, delta = 2, blksize=blksize, blksizeV=blksizeV, overlap=overlap, overlapV=overlapV, search=5, searchparam=5)
bvec1     =  MAnalyse (super, chroma=false, isb = true, delta = 1, blksize=blksize, blksizeV=blksizeV, overlap=overlap, overlapV=overlapV, search=5, searchparam=3)
fvec1     =  MAnalyse (super, chroma=false, isb = false, delta = 1, blksize=blksize, blksizeV=blksizeV, overlap=overlap, overlapV=overlapV, search=5, searchparam=3)
fvec2     =  MAnalyse (super, chroma=false, isb = false, delta = 2, blksize=blksize, blksizeV=blksizeV, overlap=overlap, overlapV=overlapV, search=5, searchparam=5)
clean     =  c.MDegrain2 (super, bvec1, fvec1, bvec2, fvec2, thSAD=thSAD, plane = 0)

# Masks for spatial noise reduction and noise independent detail enhancement
noised    =  mt_makediff (clean, c, u=1, v=1)
noise     =  mt_binarize (clense(mt_makediff(mt_binarize(noised, u=1, v=1), mt_edge(sharpen(clean, 0.85), "prewitt", u=1, v=1), u=1, v=1), grey=true), u=1, v=1)

# Spatial luma denoising
clean2    =  mt_merge (clean, removegrain(clean, sn, modeU=-1, modeV=-1), noise, u=1, v=1)

# Unsharp filter for spatial detail enhancement
clsharp   =  (enh>0<=100) ? mt_adddiff (mt_makediff(clean, blur(clean, 0.80*(enh/100), 0.50*(enh/100)), u=1, v=1), clean2, u=1, v=1) : clean
clsharp   =  (enh>=101<=102) ? mt_adddiff (mt_makediff(clean, gblur(clean, enh-100), u=1, v=1), clean2, u=1, v=1) : clsharp

# If selected, combining ReNoise
renoise   = (ver==1) ? tweak(clense (blur(noised,1), grey=true), cont=1.010+(0.020*(rn/20)), bright=1.01+(0.04*(rn/20))) : nop
renoise   = (ver==2) ? tweak(clense (noised, grey=true), cont=1.010+(0.020*(rn/20)), bright=1.01+(0.04*(rn/20))) : renoise
renoise   = (ver==3) ? tweak(temporalsoften (noised, 3, 128, 0, scenechange=0, mode=2), cont=1.010+(0.020*(rn/20)), bright=1.01+(0.04*(rn/20))) : renoise
renoise   = (ver==4) ? tweak(temporalsoften (noised, 4, 128, 0, scenechange=0, mode=2), cont=1.010+(0.020*(rn/20)), bright=1.01+(0.04*(rn/20))) : renoise
renoise   = (ver==5) ? blur(tweak(temporalsoften (noised, 3, 128, 0, scenechange=0, mode=2), cont=1.010+(0.020*(rn/20)), bright=1.01+(0.04*(rn/20))), 1) : renoise
renoise   = (ver==6) ? blur(tweak(temporalsoften (noised, 4, 128, 0, scenechange=0, mode=2), cont=1.010+(0.020*(rn/20)), bright=1.01+(0.04*(rn/20))), 1) : renoise


clean2    =  (rn>0<=20) ? mergeluma (clean2, mt_adddiff(clean2, renoise, u=1, v=1), 0.3+(rn*0.035)) : clean2

# Combining spatial detail enhancement with spatial noise reduction using prepared mask
filt_luma =  mt_merge (clean2, clsharp, mt_invert(mt_convolution(noise, u=1, v=1), u=1, v=1), u=1, v=1)

# Combining result of luma and chroma cleaning
mergechroma (filt_luma, filt_chroma)

return last.convertbits(bits, dither=1)
}
Renoise 'rn' is now much stronger as a minimum, seeing as it was far too weak in the lower numbers to actually be beneficial, and fractionally stronger effect at rn=20 than the previous rn=20. I can tweak that down slightly as well if found to be necessary!

EDIT: Just changed the noise again for testing .

Last edited by burfadel; 22nd August 2017 at 16:53.
burfadel is offline   Reply With Quote
Old 22nd August 2017, 20:13   #47  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,173
Quote:
Originally Posted by burfadel View Post
Sure, you can get the pixeltype, and run the 'if' operator for every colour type based on the pixel format, but that's a considerable number of lines!
That's the way to do it. One line to store PixelType, and one line for conditional conversion back with ? and :
MysteryX is offline   Reply With Quote
Old 24th August 2017, 20:41   #48  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,173
mClean on its own doesn't work with AVS+ MT. Prefetch(2) works, Prefetch(4) crashes after a while and Prefetch(8) freezes on startup. (with 16-bit processing)

Even without MT, it doesn't work as a prefilter for FrameRateConverter, for some strange reason.

I was thinking of using Avisynth Virtual File System to feed the prefilter into the FrameRateConverter script, but AVFS doesn't work with Windows 10 x64, the folder C:\volumes stays empty.

So many bugs!!

As it stands, mClean isn't fast. It's too heavy to use as a 1080p prefilter.

Last edited by MysteryX; 24th August 2017 at 20:44.
MysteryX is offline   Reply With Quote
Old 24th August 2017, 21:58   #49  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,173
Just how necessary is 16-bit processing? Here are some comparison images (not using the latest version but the other one before)

Video: AOA - Like a Cat

- Original
- mClean(rn=12) # 8-bit
- ConvertBits(16).mClean(rn=12).ConvertBits(8, dither=0)
- KNLMeansCL(D=2, A=2, h=1.4, device_type="GPU")
- ConvertToYV24().KNLMeansCL(D=2, A=2, h=1.4, device_type="GPU", channels="YUV")



KNLMeansCL tends to give a plastic effect when applied on YUV planes. There is considerable difference between mClean 8 or 16 but it's subtle details.

ff3dfilter is simply applied on chroma plane and then merged back, it doesn't need to be convert to 16-bit. I did a test converting to 16-bit AFTER MDegrain2 and then converting back to 8-bit when merging luma and chroma. This will be considerably faster. Quality is good.


As for bit conversions, only convert to 16-bit and back if source is 8-bit

This modified version still crashes with Prefetch(8) saying "out of memory" on startup, so there's a bug that's not in MvTools2. I still can't use it as a prefilter with FRC.

Since your method works only on Luma and applies a simple FF3DFilter on chroma, it would be fair to compare with other filters with FF3DFilter on chroma.

KnlMeansCL with FF3DFilter. This one doesn't look very good.


With the changes converting to 16-bit only after MDegrain2, performance is good enough. Then there can be an option whether to dither back to 8-bit or stay in 16-bit. Since this runs at the beginning of the script, it makes sense to take a 8-bit input with 16-bit output.
Code:
FPS (min | max | average):      2.348 | 70862 | 9.560
Memory usage (phys | virt):     1264 | 1381 MiB
Thread count:                   34
CPU usage (average):            49%
Of the various denoiser I'm testing, I still like this one better, although it's not finished.

Last edited by MysteryX; 25th August 2017 at 02:12.
MysteryX is offline   Reply With Quote
Old 25th August 2017, 02:04   #50  |  Link
burfadel
Registered User
 
Join Date: Aug 2006
Posts: 2,234
I'll update the script tonight with that info (9.30 am here), thanks! Do you have a preference in terms of the renoise 'version' or spatial removegrain method 'sn' from the test script? There are very subtle differences.
burfadel is offline   Reply With Quote
Old 25th August 2017, 02:24   #51  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,173
As it is, it takes 15 minutes to encode the prefilter as lossless AVI using half the CPU (Prefetch(4)), which is very decent if I want to run a 3h encode with FRC Preset="slower". I just haven't found any way to run them both in the same script. Importing one script into the other doesn't work. AVFS doesn't work. Heck, MP_Pipeline also gives MRecalculate: wrong pixel type!!

The only kind of separation that allows it to work is to write to an interim AVI file.

Opening the AVI file with AviSource gives again "MRecalculate: wrong pixel type", but instead using LWLibavVideoSource works!?? This makes no sense

Last edited by MysteryX; 25th August 2017 at 02:54.
MysteryX is offline   Reply With Quote
Old 25th August 2017, 03:05   #52  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,173
I haven't tested those various versions. Right now I'm still testing your previous version. Subtle improvements over RemoveGrain but just slightly too sharp with default settings.

It would be a lot easier to test various settings if I could try different mClean settings without having to encode into an interim file.

but the fact that AviSource still gives the error means there's something obvious we're missing.
MysteryX is offline   Reply With Quote
Old 25th August 2017, 06:19   #53  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,173
ok, let's do some tests. First off, enh=20 is too strong. Without it it looks flat. I'd use enh=12.

Ver=1 to 6


Difference is too minor to see. I'd rather look at how it affects interpolation and encoding; but for that, I'd need to find a way to run both in the same script.

I can see the difference at 200% zoom.

1 is good.
2 is blurry.
3 is plastic.
4 is good, slightly better than 1.
5 is good but gives a slight plastic effect.
6 is good but gives a slight blur effect.

I'd go with 1 or 4.

sn
21 is good.
2 looks cheap.
4 looks good.
7 is very slightly blurrier than 4
9 is too sharp
10 is sharper but less than 9
17 is good, I like it.
18 is even better, my favorite.

This is my favorite (you can compare with ver=4 above for sn=21
MCleanT(rn=10, ver=4, sn=18, enh=12)

Last edited by MysteryX; 25th August 2017 at 06:47.
MysteryX is offline   Reply With Quote
Old 25th August 2017, 06:58   #54  |  Link
burfadel
Registered User
 
Join Date: Aug 2006
Posts: 2,234
I liked 18 myself, which is hardly ever used, so good to know it wasn't placebo! The noise enh setting i think depends on resolution, I'll have to look into that more. It can look good on HQ 720p and 1080p to have a higher enh setting, even 101. Version 4 is what i liked as well, the version 5 and 6 were just variations in case it was too sharp.
burfadel is offline   Reply With Quote
Old 26th August 2017, 05:47   #55  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,173
Here are some comparison of FrameRateConverter with

RemoveGrain(21) vs mClean(rn=10, enh=12, ver=4, sn=18)

It has especially great benefits on hair textures. I also suspect it will help the encoder pick more of the right details.









I suspect there will be additional benefits after encoding, getting ready to do my first encode with it.

Last edited by MysteryX; 26th August 2017 at 05:50.
MysteryX is offline   Reply With Quote
Old 26th August 2017, 16:59   #56  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,173
Encoding result

RemoveGrain(21) file size: 157,721,628
mClean(rn=10, enh=12, ver=4, sn=18) file size: 157,741,477
Nearly identical size with Q=23





Very considerable benefits!

Last edited by MysteryX; 26th August 2017 at 17:02.
MysteryX is offline   Reply With Quote
Old 26th August 2017, 17:35   #57  |  Link
burfadel
Registered User
 
Join Date: Aug 2006
Posts: 2,234
Yes, the difference is even more pronounced with some videos. For noisey sources the file size actually decreases . I've basically done the next update to the script, just need to work out the input/output pixel type conversions. The 8 to 16 and back to 8 bit conversion is only done for the luma process. You were saying there is no benefit to convert to 16 bit when in 10 or 12 bit? Would it make more sense then to convert from 8 bit to 10 or 12 bit, seeing as it would more computationally friendly?
burfadel is offline   Reply With Quote
Old 26th August 2017, 18:37   #58  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,173
10, 12, 14 and 16-bit all use the same Integer data type. Perhaps the only difference is that 10-12 bit may not need clamping and may have slightly better performance (not sure).

In my case, if I'm not using it as a prefilter, I'll give a 8-bit input and want a 16-bit output for doing further processing. Someone else may want a different output type, so it would make sense to expose that as a parameter. If outbits = 8, convert to 16-bit and back to 8-bit. If outbits > 8, convert to outbits and don't dither back.

For conversion, remember ConvertToYUV444 and ConvertToYUV420 which converts without regards to the bit depth.

Last edited by MysteryX; 26th August 2017 at 18:40.
MysteryX is offline   Reply With Quote
Old 26th August 2017, 19:51   #59  |  Link
burfadel
Registered User
 
Join Date: Aug 2006
Posts: 2,234
That's a good point, the output bits option is extremely easy to implement. Basically like most filters those used in the script require planar formats, it's probably only necessary to convert from and to RGB formats. Thanks to the work PinterF has done with FFT3Dfilter, Avisynth, Masktools, and MVTools, as well as VCMohan for Modplus, basically every planar format is natively supported unlike older versions of these.
burfadel is offline   Reply With Quote
Old 26th August 2017, 21:21   #60  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,173
Not sure it's worth auto-converting from RGB. You work on Luma. No point in supporting RGB for this method. If someone still wants it, they can convert to YUV manually.

Although... in terms of net result, it may still benefit those working in RGB space, so why not.
MysteryX is offline   Reply With Quote
Reply

Tags
cleaning, denoise, denoiser, mclean

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:49.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.