Log in

View Full Version : Film dirt removal script


Floatingshed
3rd June 2014, 20:08
I use the following script (stolen from here years ago!)to very effectively remove film dirt and it has served me well. However, I have several clips consisting of hybrid 50i video and 25p film and I'd like to apply the filter on just the film sections.

I need help to either make the script work with multiple calls or somehow ignore the 50i sections, but this worries me as often you find the film sections are out of phase and "look" interlaced as the film frame changes between fields.

Any help much appreciated. Thanks.

function Dirt(clip clap,int "limit")
{
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\mvtools v1.11.4.5\mvtools.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\Mask tools v2.0.36.0\mt_masktools-26.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\Mask tools v1.5.1.0\MaskTools.dll")


_grey=false
limit = default(limit,60)


bvec = clap.MVAnalyse(isb=false, blksize=8, delta=1, pel=2, truemotion=true, idx=4)
fvec = clap.MVAnalyse(isb=true, blksize=8, delta=1, pel=2, truemotion=true, idx=4)
backw = clap.MVFlow(bvec)
forw = clap.MVFlow(fvec)
clt = interleave(backw,clap,forw)
clt = clt.RemoveDirt(limit)

return clt.SelectEvery(3,1)

}


function RemoveDirt(clip input, int limit)
{
clensed=input.Clense(grey=false, cache=4)
alt=input.RemoveGrain(2)
return RestoreMotionBlocks(clensed,input,alternative=alt,pthreshold=4,cthreshold=6, gmthreshold=40,dist=1,dmode=2,debug=false,noise=limit,noisy=12,grey=false)
}

manono
3rd June 2014, 23:20
...but this worries me as often you find the film sections are out of phase and "look" interlaced as the film frame changes between fields.
You could use TFM on the whole thing first, before the dirt removal. Set PP=0 so the real interlaced sections don't get post-processed.

I need help to either make the script work with multiple calls...
That's easy enough to accomplish. I use ReplaceFramesSimple for such things. It's part of stickboy's RemapFrames filter. Here's an example of its use:

A=Last
B=A.Dirt()#or however you call the filter
ReplaceFramesSimple(A,B,Mappings="[1000 2000] [4000 5000] [8000 10000]")#the beginning and end frame numbers each time it's called.

Floatingshed
4th June 2014, 10:07
ReplaceFramesSimple sounds just the thing, I'll give it a try. Thanks.

Floatingshed
5th June 2014, 00:23
ReplaceFramesSimple worked a treat, thanks for the suggestion.
Using TFM completely messed up the interlaced parts, so I'm guessing I had it set wrong...

manono
5th June 2014, 03:19
ReplaceFramesSimple worked a treat, thanks for the suggestion.
You're welcome. I use it a lot myself for 'selective filtering'.
Using TFM completely messed up the interlaced parts, so I'm guessing I had it set wrong...
Wrong field order, maybe? Or maybe I was just plain wrong about suggesting its use on a mix of pure interlace, phase shifted, and progressive material, and expecting it not to do anything to the interlaced and progressive sections, even with 'PP=0' set.

Floatingshed
5th June 2014, 19:50
Setting order=1 and AssumeTFF (it is TFF) and Separatefields after gives 4 forward fields and one backward field on the interlaced parts and exactly what you would expect on the film parts.
So TFM doesn't seem to be the way to go here. But ReplaceFramesSimple has solved my problem. Thanks.

manono
5th June 2014, 20:48
Sorry then. I should have tested first. You could always try and isolate the phase-shifted parts and use TFM together with ReplaceFramesSimple on them alone. But it might be too much work to be worth it for you.