Log in

View Full Version : Median2 - function that gives median of 5 clips


g-force
13th August 2008, 17:59
Function Median2(clip "input_1", clip "input_2", clip "input_3", clip "input_4", clip "input_5", string "chroma")
{# median of 5 clips from Helpers.avs by G-force

chroma = default(chroma,"process") #default is "process". Alternates: "copy first" or "copy second"

#MEDIAN(i1,i3,i5)
Interleave(input_1,input_3,input_5)
chroma == "process" ? Clense(reduceflicker=false) : Clense(reduceflicker=false,grey=true)
m1 = selectevery(3,1)

#MAX(MIN(i1,i3,i5),i2)
m2 = input_1.MT_Logic(input_3,"min",chroma=chroma).MT_Logic(input_5,"min",chroma=chroma).MT_Logic(input_2,"max",chroma=chroma)

#MIN(MAX(i1,i3,i5),i4)
m3 = input_1.MT_Logic(input_3,"max",chroma=chroma).MT_Logic(input_5,"max",chroma=chroma).MT_Logic(input_4,"min",chroma=chroma)

Interleave(m1,m2,m3)
chroma == "process" ? Clense(reduceflicker=false) : Clense(reduceflicker=false,grey=true)
selectevery(3,1)

chroma == "copy first" ? last.MergeChroma(input_1) : chroma == "copy second" ? last.MergeChroma(input_2) : last

Return(last)
}

Here is a function I wrote that is proving very handy in mo-comped noise removal scripts, and is miles faster than MedianBlurT(0,0,0,2). Hope someone else finds it useful.

-G

AVIL
14th August 2008, 23:10
Awesome script, thanks. I've prepared a version that accept yuy2 input also (renamed to median5_yuy2). Here is:

Function Median5_yuy2(clip "i1", clip "i2", clip "i3", clip "i4", clip "i5", string "chroma")
{# median of 5 clips from Helpers.avs by G-force

chroma = default(chroma,"process") #default is "process". Alternates: "copy first" or "copy second"


i1p=i1.interleaved2planar()
i2p=i2.interleaved2planar()
i3p=i3.interleaved2planar()
i4p=i4.interleaved2planar()
i5p=i5.interleaved2planar()

#MEDIAN(i1,i3,i5)
Interleave(i1,i3,i5)
chroma == "process" ? Clense(reduceflicker=false) : Clense(reduceflicker=false,grey=true)
m1 = selectevery(3,1)

#MAX(MIN(i1,i3,i5),i2)
m2 = i1p.MT_Logic(i3p,"min",chroma=chroma).MT_Logic(i5p,"min",chroma=chroma).MT_Logic(i2p,"max",chroma=chroma).planar2interleaved()

#MIN(MAX(i1,i3,i5),i4)
m3 = i1p.MT_Logic(i3p,"max",chroma=chroma).MT_Logic(i5p,"max",chroma=chroma).MT_Logic(i4p,"min",chroma=chroma).planar2interleaved()

Interleave(m1,m2,m3)
chroma == "process" ? Clense(reduceflicker=false) : Clense(reduceflicker=false,grey=true)
selectevery(3,1)

chroma == "copy first" ? last.MergeChroma(i1) : chroma == "copy second" ? last.MergeChroma(i2) : last

Return(last)

}

g-force
15th August 2008, 17:00
Cool! any chance you could rename it to Median2_yuy2 just to avoid confusion. I debated a long time if I should call it Median5 or Median2, and finally decided upon Median2 since it is in keeping with the whole "temporal radius" conventions of Mo-comped scripts.

BTW, here is my current favorite denoiser:

source = last
temp = source.TemporalSoften(4,255,255,25,2).Repair(source,9).MinBlur(1)

bw_vec1 = temp.MVAnalyse(isb=true, delta=1,pel=2,sharp=1,overlap=4,plevel=0,idx=1)
fw_vec1 = temp.MVAnalyse(isb=false,delta=1,pel=2,sharp=1,overlap=4,plevel=0,idx=1)
bw_vec2 = temp.MVAnalyse(isb=true, delta=2,pel=2,sharp=1,overlap=4,plevel=0,idx=1)
fw_vec2 = temp.MVAnalyse(isb=false,delta=2,pel=2,sharp=1,overlap=4,plevel=0,idx=1)

bw1 = source.MVCompensate(bw_vec1,idx=2,thSAD=400)
fw1 = source.MVCompensate(fw_vec1,idx=2,thSAD=400)
bw2 = source.MVCompensate(bw_vec2,idx=2,thSAD=400)
fw2 = source.MVCompensate(fw_vec2,idx=2,thSAD=400)

Median2(temp,bw1,bw2,fw1,fw2)

last.ContraMC(source,bw1,fw1,3)


Function ContraMC(clip denoised, clip orig, clip bw1, clip fw1, int "overshoot")
{#

overshoot = default(overshoot,0)

pmax = orig.MT_Logic(bw1,"max").MT_Logic(fw1,"max")
pmin = orig.MT_Logic(bw1,"min").MT_Logic(fw1,"min")

Interleave(denoised,denoised.RemoveGrain(12,-1),denoised.RemoveGrain(4,-1))
Clense(reduceflicker=false,grey=true)
SelectEvery(3,1)

MT_MakeDiff(last,last.RemoveGrain(12,-1))
MT_LUTxy(denoised,last,"y 128 - 1.5 * x +",chroma="copy first")
MT_Clamp(last,pmax,pmin,overshoot,overshoot,chroma="copy first")

Return(last)
}

AVIL
16th August 2008, 12:18
Here it is:

Function Median2_yuy2(clip "i1", clip "i2", clip "i3", clip "i4", clip "i5", string "chroma")
{# median of 5 clips from Helpers.avs by G-force

chroma = default(chroma,"process") #default is "process". Alternates: "copy first" or "copy second"


i1p=i1.interleaved2planar()
i2p=i2.interleaved2planar()
i3p=i3.interleaved2planar()
i4p=i4.interleaved2planar()
i5p=i5.interleaved2planar()

#MEDIAN(i1,i3,i5)
Interleave(i1,i3,i5)
chroma == "process" ? Clense(reduceflicker=false) : Clense(reduceflicker=false,grey=true)
m1 = selectevery(3,1)

#MAX(MIN(i1,i3,i5),i2)
m2 = i1p.MT_Logic(i3p,"min",chroma=chroma).MT_Logic(i5p,"min",chroma=chroma).MT_Logic(i2p,"max",chroma=chroma).planar2interleaved()

#MIN(MAX(i1,i3,i5),i4)
m3 = i1p.MT_Logic(i3p,"max",chroma=chroma).MT_Logic(i5p,"max",chroma=chroma).MT_Logic(i4p,"min",chroma=chroma).planar2interleaved()

Interleave(m1,m2,m3)
chroma == "process" ? Clense(reduceflicker=false) : Clense(reduceflicker=false,grey=true)
selectevery(3,1)

chroma == "copy first" ? last.MergeChroma(i1) : chroma == "copy second" ? last.MergeChroma(i2) : last

Return(last)

}

Only a futurible question ¿What about median of seven clips?

Edit about your denoiser.

Its similar to scripts I use.
In my case contraMC has rendered discrete results, better look but more artifacts.
It increases present (but less noticeable) aliasing.

I use the median clip as input for a mvdegrain wich uses the same vector clip calculated
before (used to obtain the median).

yup
19th August 2008, 17:07
Hi g-force & AVIL!
Good script I try find median2 for YUY2 colorspace for my analog capture. Before I use clense function from last version RemoveGrainT, but with temporal radius 1.
How Your scripts work with pulse noise? I try this at tommorow.
yup.

g-force
20th August 2008, 19:11
I'm still working on Median of 7. It doesn't lend itself as easily to the tricks used in Median of 5 (Median2). Stay tuned.

-G

g-force
11th September 2008, 15:39
Well, I haven't had any progress on median of 7. It really is just too computationally expensive.

Anyone had any luck using this with mo-comped scripts?

-G

yup
11th September 2008, 16:43
g-force!
Anyone had any luck using this with mo-comped scripts?
Yes. I use median2 script for my analog capture, very good result. But I use mask based on MVMask(vectors,kind=1,ml=100,Ysc=255) for all 4 vectors.

yup.