Log in

View Full Version : degraining "Predator"


vooyeq
11th September 2006, 12:10
Hi,

I'm trying to figure out how to get rid of the grain from the movie.
I came across SeeSaw, LimitedSharpen, fft3dfilter solutions tried to apply them but they did not yield satisfactory results. As im writing this post it's preety obvious i wasnt also able to fine tune them.
I ended up either with too blurry or too noisy output. What seemed to look good was quickly spoiled by xvid compression.

This is the best solution I came up with so far:

SetMemoryMax(256)
LoadPlugin("D:\_PREDATOR_XVID_\x32\avs\dgdecode.dll")
LoadPlugin("D:\_PREDATOR_XVID_\x32\avs\mvtools.dll")
LoadPlugin("D:\_PREDATOR_XVID_\x32\avs\masktools.dll")
LoadPlugin("D:\_PREDATOR_XVID_\x32\avs\removegrainsse2.dll")
LoadPlugin("D:\_PREDATOR_XVID_\x32\avs\repairsse2.dll")
LoadPlugin("D:\_PREDATOR_XVID_\x32\avs\removedirtsse2.dll")
LoadPlugin("D:\_PREDATOR_XVID_\x32\avs\fft3dfilter.dll")
LoadPlugin("D:\_PREDATOR_XVID_\x32\avs\vaguedenoiser.dll")
LoadPlugin("D:\_PREDATOR_XVID_\x32\avs\fluxsmooth.dll")
LoadPlugin("D:\_PREDATOR_XVID_\x32\avs\deen.dll")
LoadPlugin("D:\_PREDATOR_XVID_\x32\avs\LimitedSupport_09Jan06B.dll")
LoadPlugin("D:\_PREDATOR_XVID_\x32\avs\colormatrix.dll")

import("D:\_PREDATOR_XVID_\x32\avs\SeeSaw.avs")
import("D:\_PREDATOR_XVID_\x32\avs\LimitedSharpenFaster.avs")
import("D:\_PREDATOR_XVID_\x32\avs\noisy.avs")

function RemoveTempGrain(clip input, int _mode)
{
rg = RemoveGrain(input, mode=_mode)
return TemporalRepair(rg, input)
}

function RemoveDirt(clip input, int limit, int rgrain, bool "_grey")
{
_grey = default(_grey, false)
_dgr1 = 0.35+rgrain*0.3
_dgr2 = 0.45+rgrain*0.4
repmode = 1
clensed = Clense(input, grey=_grey, cache=4)
restore = input.FluxSmoothST(3+3*rgrain,rgrain)
restore = Repair(restore, input, mode=repmode, modeU= _grey ? -1 : repmode)
restore = rgrain==0 ? restore.RemoveGrain(1) : \
restore.VagueDenoiser(threshold=_dgr1, chromaT=_dgr1, nsteps=7, percent=75).RemoveGrain(1)
alt = input.VagueDenoiser(threshold=_dgr2, chromaT=_dgr2, nsteps=7, percent=100).RemoveGrain(5)
return RestoreMotionBlocks(clensed, restore, neighbour=input, alternative=alt, pthreshold=4+2*rgrain, cthreshold=6+2*rgrain, gmthreshold=40, dist=1, dmode=2, debug=false, noise=limit, noisy=12, grey=_grey)
}

global idx_c = 25

function RemoveNoiseMC(clip,int "rdlimit", int "rgrain", int "denoise", float "csharp", bool "_grey")
{
rdlimit = default(rdlimit,11)
rgrain = default(rgrain,2)
denoise = default(denoise,8)
csharp = (rgrain>2) ? default(csharp,0.28) : (rgrain>1) ? default(csharp,0.25) : \
(rgrain>0) ? default(csharp,0.23) : default(csharp,0.13)
_grey = default(_grey,false)
_dgr = 0.45+rgrain*0.4
dummy = clip.BlankClip(length=0)
global idx_c = idx_c+1
cbs = 4
ccf = cbs*cbs/64
cpn = (denoise>12) ? 50*ccf : (denoise>8) ? 58*ccf : (denoise>5) ? 66*ccf : 72*ccf
csh = (rgrain<1) ? 1 : 0
bvec2 = clip.MVAnalyse(isb=false, blksize=cbs, delta=2, pel=2, sharp=csh, overlap=0, truemotion=true, pnew=cpn, idx=idx_c)
bvec1 = clip.MVAnalyse(isb=false, blksize=cbs, delta=1, pel=2, sharp=csh, overlap=0, truemotion=true, pnew=cpn, idx=idx_c)
fvec1 = clip.MVAnalyse(isb=true, blksize=cbs, delta=1, pel=2, sharp=csh, overlap=0, truemotion=true, pnew=cpn, idx=idx_c)
fvec2 = clip.MVAnalyse(isb=true, blksize=cbs, delta=2, pel=2, sharp=csh, overlap=0, 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=csharp, Szp=12, SdampHi=20, bias=40)
return clp
}

function mq_filter(clip c)
{
c=c.RemoveNoiseMC(rdlimit=5,rgrain=2,denoise=6)
c=c.fft3dfilter(sigma=2.2, sharpen=2, plane=4)
c=c.deen("a3d",rad=3,thrY=4,thrUV=7,min=0.25,tthY=2,tthUV=3,scd=7)
return c
}

mpeg2source("D:\_PREDATOR_XVID_\X32\pred.d2v")
ColorMatrix()
trim(95000,95150)

mq_filter(last)
crop(0,14,716,548)

Tweak(Sat=1.3,Coring=False)
Lanczos4Resize(704,368)


Here are some clips from the movie[VOBs]:
clip1 (http://k3310ph.amperpol.com/video/clip_16.vob) clip2 (http://k3310ph.amperpol.com/video/clip_45.vob) clip3 (http://k3310ph.amperpol.com/video/clip_86.vob) clip4 (http://k3310ph.amperpol.com/video/clip_94.vob)

What am I missing? Any hints appreciated.
Thanks.

Manao
11th September 2006, 13:00
I'm sure you want to read the rules and reformulate your first sentence.

*.mp4 guy
11th September 2006, 18:34
noisy = MPEG2Source("clip_94.d2v", cpu=0).Assumetff()

vf=noisy.mvanalyse(pel=2,blksize=8,isb=false,idx=1,overlap=4,sharp=2,truemotion=true)
vb=noisy.mvanalyse(pel=2,blksize=8,isb=true,idx=1,overlap=4,sharp=2,truemotion=true)
vf2=noisy.mvanalyse(pel=2,blksize=8,isb=false,idx=1,delta=2,overlap=4,sharp=2,truemotion=true)
interleave(\
mvcompensate(noisy,vf2,idx=1,thSCD1=800)\
, mvcompensate(noisy,vf,idx=1,thSCD1=800)\
, noisy\
, mvcompensate(noisy,vb,idx=1,thSCD1=800))
fft3dfilter(bw=48, bh=48, ow=24, oh=24, bt=4, sigma=0.75, sigma2=0.33, sigma3=1.5, sigma4=4, plane=4)
denoised=selectevery(4,2)
Denoised

FrFun7(0.8, 4, 4)

#Spline36resize(1024, 576)

LimitedSharpenFaster(Smode=3, Strength=80, Lmode=1, Overshoot=0)
Screneshot of Frame # 4 (http://img46.imageshack.us/img46/9145/predatorxm3.png)

vooyeq
12th September 2006, 12:27
Thanks for the idea. However as a single frame looks good a sequence of them visualize the noise which is still there.
Well for my eye it is neglectable as i prefer to have a little noise than too blurry picture, let's see what xvid thinks about it.
I hope 1/2DVD size will be sufficient to maintain the quality.
Damn jungle, every little leave is in motion. Im glad scenes do not involve any insects.
Cooperation of a horde of ants together with the noise would be an efficient bitrate killer ;)

*.mp4 guy
12th September 2006, 20:49
I wasn't trying to get rid of all the noise, that would make the picture look washed out, because there isn't much detail in a lot of scenes, you can get a perfectly clean picture just by raising sigma and sigma 2 a bit.

vooyeq
12th September 2006, 21:53
Yes, I (more less) know how to tune fft3dfilter, spent like a week trying to play with different settings. The problem is I tried to solve the issue from the wrong side. I had some good filtering results by myself but I wasnt able to obtain satisfactory xvid output. I thought that even a little noise kills compression. Well today there was a /major breakthrough for a noob/ and I've finally managed to configure xvid properly. Now filtered and compressed clips look awesome.