Log in

View Full Version : How to Degrain in my Despot script?


papcom
31st October 2015, 11:53
I use a Despot Function based on RemovedirtMC, originally provided by johnmeyer. The result is good. Now I would like to have the Option to adjust the Degraining of my films.

I tried around but I could not get the desired result. The filmgrain remains. Can anyone give me a hint, which Parameter I have to adjust in order the grain is affected?

( a problem for me is to understand the section with the "RemoveDirt" - function... how is this called and is the code correct as it is? )

Here is the script:

function RemoveDirtMC(clip,int limit, bool "_grey")
{
_grey=default(_grey, false)
limit=default(limit,6)

prefiltered = fft3dfilter(clip,sigma=1,sigma2=2,sigma3=3,sigma4=5,bw=64,bh=64)
prefiltered = RemoveGrain(clip,2)
superfilt = MSuper(prefiltered, hpad=32, vpad=32,pel=2)

super=MSuper(clip, hpad=32, vpad=32,pel=2)

bvec = MAnalyse(superfilt,isb=true, blksize=16, overlap=2,delta=1, truemotion=true)
fvec = MAnalyse(superfilt,isb=false, blksize=16, overlap=2,delta=1, truemotion=true)

# Increase thSAD if moving objects are being removed!! default is 100
bvec_re = Mrecalculate(super,bvec,blksize=4, overlap=0,thSAD=160)
fvec_re = Mrecalculate(super,fvec,blksize=4, overlap=0,thSAD=160)

backw = MFlow(clip,super,bvec_re)
forw = MFlow(clip,super,fvec_re)

clp=interleave(backw,clip,forw)
clp=clp.RemoveDirt(limit,_grey)
clp=clp.SelectEvery(3,1)
return clp
}

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

StainlessS
31st October 2015, 15:20
A spot is usually a single isolated blob, eg some kind of mark/stain on film, grain/noise are entirely different.
(EDIT: a spot usually exists on a single frame)
If you dont know what it is you are trying to get rid of then best post at least an image, better upload to eg PhotoBucket.com
and paste link into your post so as to avoid delay waiting for moderator approval.
A short clip is sometimes required which includes an amount of movement (cut from original source and not re-encoded, audio
can be omitted).

Judging by the script you provided, the only candidate for modification is 'Limit' it defaults to 6 in RemovedDirtMC.

Here is a Degrain script by Didée
http://forum.doom9.org/showthread.php?p=1508289#post1508289

EDIT: Call with frame of 1 -> 3 (3 most powerful).

papcom
31st October 2015, 15:49
Explanation:

I use this despot script to remove spots and dirt from my films, and this works satisfying well.

Now I have the idea to add a section where I can reduce the grain additionally to the despoting.

When I look at the script there is a section "RemoveDirt" where there is a line with "alt=input.RemoveGrain(2)".

I do not really understand this line. So I thought perhaps anyone can explain me this part and perhaps this line can be useful to remove grain on my film.

Otherwise there is perhaps another way to achive my goal in reducing the grain of my film in addition to the despotting

johnmeyer
31st October 2015, 16:24
The scripts by VideoFred (and my modifications to those scripts) show you how to do this. RemoveDirt is good for removing isolated dirt spots that exist on one frame, as StainlessS already pointed out. The VideoFred scripts use MDegrain2, which is part of MVTools2, to reduce the film grain. The code you need is in those scripts. I advise that you don't do much of this because reducing the grain makes the end result look very artificial and "weird." A very small amount of reduction sometimes make it look better.

Less is more.

papcom
31st October 2015, 17:49
The scripts by VideoFred (and my modifications to those scripts) show you how to do this. RemoveDirt is good for removing isolated dirt spots that exist on one frame, as StainlessS already pointed out. The VideoFred scripts use MDegrain2, which is part of MVTools2, to reduce the film grain. The code you need is in those scripts. I advise that you don't do much of this because reducing the grain makes the end result look very artificial and "weird." A very small amount of reduction sometimes make it look better.
Less is more.

@JMH - As You have contributed on the "despotter script" I use, would You be so Kind to explain me the section with the second function with "RemoveDirt"...? --- NOT the one with the"RemoveDirtMC" !!

Why is this second function in this despotter script?

Isn't there a typing error in RemoveDirt(clip input, int limit, bool _grey). Shouldn't this be RemoveDirt(clip input, int limit, bool "_grey")???

What is the following line good for?
alt=input.RemoveGrain(2)

johnmeyer
31st October 2015, 20:50
I don't know where you got that script. The versions I've posted do not contain that typo. Either you, or someone else, introduced that error. The "alt" variable is used by the RestoreMotionBlocks function.

StainlessS
31st October 2015, 20:56
Isn't there a typing error in RemoveDirt(clip input, int limit, bool _grey). Shouldn't this be RemoveDirt(clip input, int limit, bool "_grey")???


Putting quotes around _grey would make _grey optional, and it is not optional, ie there is no default value assigned to _grey within the function.

papcom
31st October 2015, 23:34
I don't know where you got that script. The versions I've posted do not contain that typo. Either you, or someone else, introduced that error. The "alt" variable is used by the RestoreMotionBlocks function.

Your post, check here: http://forum.doom9.org/showthread.php?t=59388&page=9 ===>>> #162


…and what is the correct typo?

StainlessS
1st November 2015, 00:13
…and what is the correct typo?

It is correct, there is no typo, see post #7.

EDIT: It would be best to wait until you can write scripts before attempting to correct other peoples scripts.

Groucho2004
1st November 2015, 00:17
It is correct, there is no typo, see post #7.
But what is a "correct typo"? Some inverse logic at work here or linguistic gremlins?

StainlessS
1st November 2015, 00:23
HeHeHeHe-He :D

papcom
1st November 2015, 01:03
It is correct, there is no typo, see post #7.

EDIT: It would be best to wait until you can write scripts before attempting to correct other peoples scripts.
i do not at all correct other peoples scripts ...I put a question because I am unsure. where is the misunderstanding?

StainlessS
1st November 2015, 01:11
where is the misunderstanding?

My apologies for being brusque.

johnmeyer
1st November 2015, 02:35
Well, I guess I'm the guilty party !!

I just did a quick check of all my scripts that use this function and I actually have it both ways. I have no idea how that happened. However, for the reasons StainlessS pointed out, it really doesn't matter for this situation because you are always going to be passing a value to this variable when using this function, so AVISynth will not complain, whether you include the quotes or not. Either way will work.

thescrapyard
1st November 2015, 06:45
I use this I altered to add, I think, grain filtering to the processing section of RemoveDirt and RemoveSpots so it uses the now degrained source as the prefilter for clense. Maybe somebody who can read the script fully can explain it



function RemoveSpots(clip clp, int "limit", bool "_grey")
{
_grey = Default(_grey, false)
limit = Default(limit, 16)

clmode = 17

clensed = Clense(clp, grey=_grey, cache=4)
sbegin = ForwardClense(clp, grey=_grey, cache=-1)
send = BackwardClense(clp, grey=_grey, cache=-1)

##### Uncomment ONE line below to use that filter to degrain #####

# alt = Repair(SCSelect(clp, sbegin, send, clensed, debug=true), clp, mode=limit, modeU = _grey ? -1 : limit).fluxsmoothst(5,5)
# alt = Repair(SCSelect(clp, sbegin, send, clensed, debug=true), clp, mode=limit, modeU = _grey ? -1 : limit).msmooth(threshold=5,strength=3,highq=true,chroma=false)
# alt = Repair(SCSelect(clp, sbegin, send, clensed, debug=true), clp, mode=limit, modeU = _grey ? -1 : limit).convertToYUY2().peachsmoother(100).convertToYV12()

restore = Repair(clensed, clp, mode=limit, modeU = _grey ? -1 : limit)
clp = RestoreMotionBlocks(clensed, restore, neighbour=clp, alternative=alt, gmthreshold=70, dist=1, \
dmode=2, debug=false, noise=10, noisy=12, grey=_grey)

return clp
}


function RemoveSpotsMC_grain(clip clp, int "limit", bool "_grey", int "Vectors")
{
_grey = Default(_grey, false)
limit = Default(limit, 16)
Vectors = Default(Vectors, 1)

Vectors = (Vectors < 1) ? 1 : (Vectors > 3) ? 3 : Vectors

super = MSuper(clp, pel=2, sharp=2)
bvec3 = (Vectors == 3) ? MAnalyse(super, isb=true, delta=3, blksize=8, overlap=4, truemotion=true) : NullClip(clp)
bvec2 = (Vectors >= 2) ? MAnalyse(super, isb=true, delta=2, blksize=8, overlap=4, truemotion=true) : NullClip(clp)
bvec1 = MAnalyse(super, isb=true, delta=1, blksize=8, overlap=4, truemotion=true)
fvec1 = MAnalyse(super, isb=false, delta=1, blksize=8, overlap=4, truemotion=true)
fvec2 = (Vectors >= 2) ? MAnalyse(super, isb=false, delta=2, blksize=8, overlap=4, truemotion=true) : NullClip(clp)
fvec3 = (Vectors == 3) ? MAnalyse(super, isb=false, delta=3, blksize=8, overlap=4, truemotion=true) : NullClip(clp)
backw3 = (Vectors == 3) ? MFlow(clp, super, bvec3) : NullClip(clp)
backw2 = (Vectors >= 2) ? MFlow(clp, super, bvec2) : NullClip(clp)
backw1 = MFlow(clp, super, bvec1)
forw1 = MFlow(clp, super, fvec1)
forw2 = (Vectors >= 2) ? MFlow(clp, super, fvec2) : NullClip(clp)
forw3 = (Vectors == 3) ? MFlow(clp, super, fvec3) : NullClip(clp)

clp = (Vectors == 1) ? interleave(backw1, clp, forw1) : \
(Vectors == 2) ? interleave(backw2, backw1, clp, forw1, forw2) : \
interleave(backw3, backw2, backw1, clp, forw1, forw2, forw3)

clp = RemoveSpots(clp, limit=limit, _grey=_grey)

clp = (Vectors == 1) ? SelectEvery(clp, 3, 1) : \
(Vectors == 2) ? SelectEvery(clp, 5, 2) : \
SelectEvery(clp, 7, 3)

return clp
}


I also use a similiar altered version for heavier grain for RemoveDirt as well


function RemoveDirt(clip input, int limit, bool _grey)
{
clensed=input.Clense(grey=_grey, cache=4)

alt=input.removegrain(2)

##### Uncomment ONE line below to add extra grain removal #####

# alt=input.removegrain(2).fluxsmoothst(5,5)
# alt=input.removegrain(2).msmooth(threshold=5,strength=3,highq=true,chroma=false)

return RestoreMotionBlocks(clensed,input,alternative=alt,pthreshold=6,cthreshold=8, gmthreshold=40,dist=3,dmode=2,debug=false,noise=limit,noisy=4, grey=_grey)

# Alternative settings
# return RestoreMotionBlocks(clensed,input,alternative=alt,pthreshold=4,cthreshold=6, gmthreshold=40,dist=1,dmode=2,debug=false,noise=limit,noisy=12,grey=_grey,show=true)
# return RestoreMotionBlocks(clensed,input,alternative=alt,pthreshold=6,cthreshold=8, gmthreshold=40,dist=3,tolerance= 12,dmode=2,debug=false,noise=limit,noisy=12,grey=_grey,show=false)
}

function RemoveDirtMC(clip,int "limit", bool "_grey")
{
_grey=default(_grey, false)
limit = default(limit,6)
prefiltered = RemoveGrain(clip,2)
superfilt = MSuper(prefiltered, hpad=32, vpad=32,pel=2)
super=MSuper(clip, hpad=32, vpad=32,pel=2)
bvec = MAnalyse(superfilt,isb=true, blksize=16, overlap=2,delta=1, truemotion=true)
fvec = MAnalyse(superfilt,isb=false, blksize=16, overlap=2,delta=1, truemotion=true)
bvec_re = Mrecalculate(super,bvec,blksize=8, overlap=0,thSAD=100)
fvec_re = Mrecalculate(super,fvec,blksize=8, overlap=0,thSAD=100)
backw = MFlow(clip,super,bvec_re)
forw = MFlow(clip,super,fvec_re)
clp=interleave(forw,clip,backw)
clp=clp.RemoveDirt(limit,_grey)
clp=clp.SelectEvery(3,1)
return clp
}




I use either of these for very heavy grain usually for old childrens series or documentaries from the 1940's. It doesn't removal all grain/scratches but enough to make a big difference to the output. They may be overkill but dropping the filter settings down to remove just enough for your needs

To call RemoveSpots or RemoveGrain I use these :

Simply 'RemoveSpots()' does it for me with the defaults and additional grain filtering and also 'RemoveDirt(125,false)'

creaothceann
1st November 2015, 16:09
Please use the [code] tag...

/OT

thescrapyard
1st November 2015, 17:39
Edited, wondered how that was done !