PDA

View Full Version : RemoveNoiseMC Function question.


rkalwaitis
30th October 2009, 09:52
Hello as listed below I have this older function. It does work well as is. My problem, which isnt really a problem is that it uses MVDenoise. Since Im trying to learn and many of you are the wealth of knowledge Ill ask my question and hope that I do not appear to stupid. My intent is to update this script to mvtools2 using Mdegrain. I can make simple scripts to get both of these denoisers to work. However they are of course different. So I guess my real problem deals with the settings of the denoisers. So which settings of mdegrain would be comparible to the mvdenoiser settings used below. Im really having problems with is the thmv function and its comparable counterpart in Mdegrain. Or does mdegrain not have such a comparible setting. I have read the readme's for both, but I may have missed it or am not clever enough to recogize it as I read it.

function RemoveNoiseMC(clip,int "rdlimit", int "rgrain", int "denoise", bool "sharp", float "csharpen", bool "_grey")
{
rdlimit = default(rdlimit,11)
rgrain = default(rgrain,2)
denoise = default(denoise,8)
sharp = (rgrain<1) ? default(sharp,true) : default(sharp,false)
csharpen = (rgrain>2) ? default(csharpen,0.17) : (rgrain>1) ? default(csharpen,0.15) : default(csharpen,0.13)
csharpen = sharp ? csharpen : csharpen+0.08
_grey = default(_grey,false)
_dgr = 0.45+rgrain*0.4
dummy = clip.BlankClip(length=0)
global idx_c = idx_c+1
cbs = 8
cov = (cbs>4) ? cbs/4 : 0
ccf = cbs*cbs/64
cpn = (denoise>12) ? 50*ccf : (denoise>8) ? 58*ccf : (denoise>5) ? 66*ccf : 72*ccf
csh = sharp ? 1 : 0
bvec2 = clip.MVAnalyse(isb=false, blksize=cbs, delta=2, pel=2, sharp=csh, overlap=cov, truemotion=true, pnew=cpn, idx=idx_c)
bvec1 = clip.MVAnalyse(isb=false, blksize=cbs, delta=1, pel=2, sharp=csh, overlap=cov, truemotion=true, pnew=cpn, idx=idx_c)
fvec1 = clip.MVAnalyse(isb=true, blksize=cbs, delta=1, pel=2, sharp=csh, overlap=cov, truemotion=true, pnew=cpn, idx=idx_c)
fvec2 = clip.MVAnalyse(isb=true, blksize=cbs, delta=2, pel=2, sharp=csh, overlap=cov, truemotion=true, pnew=cpn, idx=idx_c)
backw1 = rdlimit>13 ? \
rdlimit>20 ? \
clip.MVFlow(bvec1, idx=idx_c).Deblock(quant=22, aOffset=6, bOffset=6) : \
clip.MVFlow(bvec1, idx=idx_c).Deblock(quant=16, aOffset=4, bOffset=4) : \
clip.MVFlow(bvec1, idx=idx_c)
forw1 = rdlimit>13 ? \
rdlimit>20 ? \
clip.MVFlow(fvec1, idx=idx_c).Deblock(quant=22, aOffset=6, bOffset=6) : \
clip.MVFlow(fvec1, idx=idx_c).Deblock(quant=16, aOffset=4, bOffset=4) : \
clip.MVFlow(fvec1, idx=idx_c)
clp = interleave(backw1,clip,forw1)
clp = clp.RemoveDirt(rdlimit,rgrain,_grey)
dnc = denoise==0 ? clp.RemoveTempGrain(rgrain).SelectEvery(3,1) : dummy
clp = clp.SelectEvery(3,1)
dnc = denoise==0 ? dnc : \
clp.MVDenoise(bvec2, bvec1, fvec1, fvec2, thT=denoise, thSAD=190+15*denoise, thmv=40, thSCD1=230+5*denoise)
vid_mo = dnc.VagueDenoiser(threshold=_dgr, chromaT=_dgr, nsteps=7, percent=75)
vid_mo = rgrain==1 ? vid_mo.RemoveGrain(1) : vid_mo.RemoveGrain(5)
dnc = dnc.ConditionalFilter(dnc, vid_mo, "(YDifferenceFromPrevious()+YDifferenceToNext())/AverageLuma()", "<", "0.3")
clp = clp.SeeSaw(dnc, Sstr=csharpen, Szp=12, SdampHi=20, bias=40)
return clp
}

thanks K

Didée
30th October 2009, 10:43
There's no way to do a 1:1 conversion to MVTools2. MVDegrain and MVDenoise are (were) two different methods. MVDG weights pixels according to block SAD. MVDenoise (did) weight pixels according to block SAD, vector length, and absolute pixel difference. ("Hard threshold" principle for the latter, as in TemporalSoften.) - Since MVDenoise isn't anymore in MVTools2, you can't make a true conversion. Sure, you could just replace MVDenoise with MDegrain using some reduced thSAD, but it's not the same anymore.

There are a few amusing things in that function. From using MVFlow (not wrong in itself, but ~Compensate usually is more suited for denoising than ~Flow), over deblock()'ing the Flow'ed interpolations (Flow should not be blocky per methodology, and even less so when used with overlapping, as is here), up to childly-usage of SeeSaw (which would benefit a lot from mo'comp - it doesn't use it on its own because of too much overhead, but here it is already in the context of another MV-application, and could be rather easily integrated to make use of that. But instead, it's just copy/pasted as a final touch ... with subliminal strength, because the blackbox usage won't safely allow for more.)

To me, it's a patchwork denoiser.


"In order to solve a problem, the problem needs to be understood."

For a good lesson, don't start with any of those existing scripts. Instead, start from scratch, perhaps with a basic MDegrain() script. Then one by one, proceed this list:

1.) What is a problem that remains?
2.) Figure a dedicated way to avoid /or/ to work around that problem.
3.) Goto #1

This way is much more educational. Juggling around with cut-pieces of already existing scripts, so long until by chance it happens to "look nice", is neither effective nor efficient in getting oneself understanding the roots of problems.

So, start at the roots.

rkalwaitis
30th October 2009, 10:48
Thanks Didee, Ill Start from scratch. As always your input is respected and not to be ignored. It does make sense to learn from the begining. With all of these great scripts like MC_Spuds and MCTemporalDenoise, I get lazy and work off of someone elses knowledge (i.e the script above was from another thread here on doom). I do need to be more resourceful and make my own scripts.

K

Didée
30th October 2009, 11:13
Well, the above comment surely is bursting for fatalism. There's nothing wrong with benefitting from prior research & experience.
But still, understanding the stripped-down problems helps a lot. When faced with code snipplets, seeing that other scripts do things like "this" or like "that", it's very helpful to understand *why* things are done like that*). Otherwise you're just looking at a blackbox, and often end with puzzle-scripts that use chains of blackboxes in varying order.

*) This assumes that an original script creator really was aware what he's doing ... which is not always the fact.

There were quite a few times where I've been bugged by "modds" of some of my scripts, where some random "but I like it like so" stuff was added, without following the "red line" of the basic methodology (sometimes even contradicting the red line). Or, lots of minor stuff was added, the vast majority being rather unimportant, without touching the really problematic sections. Or, I used a surrogate operation as a shorthand for "the real thing", and some time later there's a "modd" that offers a confusing ninety-seven more parameters and options, but the cheapo shortcut was still the same...

Perhaps I'm just too rigorous to childplay in the sandbox. Well possible.

rkalwaitis
30th October 2009, 12:18
I did not mean to sound negative, but I took your comments as more of a motivational thing. I should no more about these things. I can learn from others scripts to, but I should still take time to learn more about things before jumping right in. Which I think is a good thing and as a result of your words of inspiration, im reading the avisynth scripting language now and am learning plenty. ex.. I didn't know that there was a sharp command for avisynth that did not require me to load a plugin or use a script. Im playing with it now along with temporalsoften and spatialsoften, which I always assumed were plugins too. So what was read as fatalism was infact motivation on my part.

K

Didée
30th October 2009, 13:21
Oh ... only now I see that my phrasing was a bit unlucky. The wording should've been "my above comment", not just "the" ...

... i.e. I was pulling my own leg. Not yours. ;)

18fps
30th October 2009, 15:01
I have used that script with a DVD that had a strong film grain (which I wanted to retain) but that had a lot of white a black dots from a slightly damaged film negative, and I loved how it kept the detail and the texture, while repairing most of the holes. Of course I can't understand the script, even less what can be wrong with it. It would be interesting to see you tackling with it!

rkalwaitis
30th October 2009, 15:17
I think does do a good job on heavy noise too. Im by no means a scripter, but Didee has motivated me to learn more and Ill will be taking his advise on this and starting from the one block of the process. Hopefully he will not get tired of my questions. Hopefully I can ask some good ones.

canuckerfan
30th October 2009, 17:17
it is an excellent despotter that retains quite a bit of detail while removing the nasty stuff. but it can struggle during high motion, creating artifacts, so watch out for that.