View Full Version : Median of an arbitrary number of clips
thewebchat
5th October 2009, 17:01
If I have n clips of the same length, size, and colorspace, is there a way to return a new clip where each pixel is the median value of all the corresponding pixels in the n input clips? I know that the Average plugin can generate the mean of these clips, but what about the median? Is there a way to hack this in? Perhaps using a lot of recursion and mt_lutxy? If not, could someone (please) write a filter that does this? It only has to work in YV12 space.
Didée
5th October 2009, 18:38
MedianBlur (http://avisynth.org/warpenterprises/#MedianBlur) by tsp.
The # of clips has to be odd, the median isn't (well-) defined for even # of elements.
interleave( c1,c2,...,cN)
MedianBlurT( 0,0,0, (N-1)/2 )
SelectEvery( N, (N-1)/2 )
Beware, this will be slow.
If any plugin-coder happens to be bored: MedianBlur cries for optimisation - in particular the temporal part. (The "T" version gets r.i.d.i.c.u.l.o.u.s. slow for radii >2 ...)
For 3 elements, use Clense() instead of MedianBlurT.
For 5 elements, use the Median2 function (http://forum.doom9.org/showthread.php?t=140282) of g-force.
g-force
5th October 2009, 23:50
For 5 elements, use the Median2 function (http://forum.doom9.org/showthread.php?t=140282) of g-force.
Never found a great use for the median of 5 clips. Definitely not as useful as the median of 3.
-G
here's how to do median of 3 as Didée suggested:
Function Median1(clip input_1, clip input_2, clip input_3, string "chroma")
{# median of 3 clips from Helpers.avs by G-force
chroma = default(chroma,"process") #default is "process". Alternates: "copy first" or "copy second"
Interleave(input_1,input_2,input_3)
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)
}
thewebchat
6th October 2009, 01:03
With Median2, I am getting the error "Clense does not have a named argument 'reduceflicker'". The version I am using is from RemoveGrainT 1.0 pre-release. Is there an equivalent syntax I can use?
Didée
6th October 2009, 01:44
Yes, that's definetly possible. Find documentation, then go figure how to handle the recursion slots correctly. :)
(For my old senile brain that's too complicated, reason I stick with the older v0.9-style version...) :p
g-force
6th October 2009, 03:27
RemoveGrain... can't live with it, can't live without it.
Best switch to v1.0 beta or v0.9. Kassandro may not have implemented "reduceflicker" in the pre-release (which has no official documentation), as it was never documented in v1.0 beta either.
-G
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.