Log in

View Full Version : medianblur 0.84 a variable radius spatial/temporal median blur filter


tsp
29th October 2004, 17:51
The filter should be fully functional now. Get it here (http://www.tsp.person.dk/medianblur084.zip).
You can follow the development in this (http://forum.doom9.org/showthread.php?s=&threadid=83883) thread.

From the readme:


medianblur 0.84


medianblur is a spatial median blur filter with a variable radius.
If you want to use it with radius 1 consider using removegrain(mode=4) instead.
medianblurcw is a centerweighted medianblur filter with a variable radius.
medianblurb is binary medianblur filter. It will take advantage of integer SSE if present.
medianblurt is a temporal-spatial median blur filter with optional motion compensation using Manaos MVTools.
If you want to use it with a temporal and spatial radius of 1 consider using DeGrainMedian(limitY=255,limitUV=255,mode=0)

ML3Dex means extended multilevel 3 Dimensional filtering. This filter should cause less artifact compared to medianblurt while removing the same amount of noise. This filter can also use MVTools for motion compensation. The filter is based on the description in: MOTION PICTURE RESTORATION. by Anil
Christopher Kokaram. Ph.D. Thesis. May 1993 (http://www.mee.tcd.ie/~ack/papers/a4ackphd.ps.gz) (Fizick thanks for finding this ;-) )



Usage:

medianblur(clip,int radiusy,int radiusu,int radiusv,bool calcborder)

radiusy,u & v: specify the radius to use. Default is 2. If the supplied radius is between -1 and -255
the plane is set to -radius. If the the radius is 0 the plane is copied unaltered. If the radius is
less than -255 the plane isn't processed at all.

calcborder: if true (default) the borders of the frame is filtered too. If false then the border is copied from the source clip.

for the centerweighted version:



medianblurcw(clip,int radiusy,int radiusu,int radiusv,int weighty,int weightu,weightv, bool calcborder)

weighty,u & v: specify the centerweight = number of times the centerpixel should be replicated. Default 1.



binary mask version:

medianblurcw(clip,int radiusy,int radiusu,int radiusv,int thresholdy,int thresholdu,thresholdv, bool calcborder)

thresholdy,u & v: specify the threshold to use to make the mask. Afterwards the mask is medianblured. Default 127.


temporal medianblur:


medianblurt(clip,int radiusy,int radiusu,int radiusv,int temporalradius, bool mc, bool calcborder,bool markscenechange,int blksize,int pel,int lambda, int thSCD1, int thSCD2,bool spfull,bool bsfull)

radiusy,u & v: same as medianblur with the small difference that radius can be set to 0.
This disable spatial blurring. If you want to copy the plane set it to -1

temporalradius: Number of frames to search before and after current frame. Default 2.

mc: Use Motion Compensation. This is achieved using Manaos MVTools. It's has only been tested with version 0.9.8.1 .
Get it in this thread: http://forum.doom9.org/showthread.php?s=&threadid=84770&perpage=20&pagenumber=1 or here http://manao4.free.fr/MVTools-v0.9.8.1.zip
Don't use version 0.9.8.0. This version would cause an error. Default is false.

markscenechange: If set to true there will be a red square in the upper left corner when MVTools detects a scenechange.
If this happens to often the temporal filtering will be decreased. Increase thSCD1 or thSCD2. Default false.

blksize,pel,lambda,thSCD1,thSCD2,searchparam: Parameters to control MVTools. for the meaning of each parameter see MVTools documentation.
Defaults:blksize 4, pel 1, lambda 1000,thSCD1 200,thSCD2 175,searchparam=1

bsfull,spfull: If set to true the blocksize(bsfull) and/or searchparam(spfull) are applied to the frames before the current frame and the frames after.
If set to false then they are only applied to the frames before the current frame. This speeds the motion compensation up but decrease the posible noise reduction.
Defaults are false,false.


extended Multi Level 3Dimensional:

ml3dex(clip,bool mc, int Y, int U, int V,bool markscenechange, int blksize, int pel, int lambda, int thSCD1, int thSCD2,bool spfull,bool bsfull)

good values for cartoons are ml3dex(blksize=4,searchparam=60,lambda=0,thSCD1=1000)

mc: Use Motion Compensation. This is achieved using Manaos MVTools. It's has only been tested with version 0.9.8.1 and 0.9.8.4.
Get it in this thread: http://forum.doom9.org/showthread.php?s=&threadid=84770&perpage=20&pagenumber=1 or here http://manao4.free.fr/MVTools-v0.9.8.1.zip
Don't use version 0.9.8.0. This version would cause an error. Default is false.

markscenechange: If set to true there will be a red square in the upper left corner when MVTools detects a scenechange.
If this happens to often the filter can't remove scratches and larger defects as efficient. Increase thSCD1 or thSCD2. Default false.

blksize,pel,lambda,thSCD1,thSCD2,searchparam: Parameters to control MVTools. for the meaning of each parameter see MVTools documentation.
Defaults: blksize 8, pel 1, lambda 1000,thSCD1 200,thSCD2 200,searchparam=1


Y,U,V: Controls which planes the filter is applied to. If set to 3 the plane will be filter, if 2 the plane will be copied from the source,
if 1 the plane will be ignored and from 0 to -255 the plane will be assigned the absolute value. Default Y 3,U=2, V=2


mc: Use Motion Compensation. This is achieved using Manaos MVTools. It's has only been tested with version 0.9.8.1 and 0.9.8.4.
Get it in this thread: http://forum.doom9.org/showthread.php?s=&threadid=84770&perpage=20&pagenumber=1 or here http://manao4.free.fr/MVTools-v0.9.8.1.zip
Don't use version 0.9.8.0. This version would cause an error. Default is true.

blksize,pel,lambda,thSCD1,thSCD2: Parameters to control MVTools. for the meaning of each parameter see MVTools documentation.
Defaults: blksize 4, pel 1, lambda 1000,thSCD1 200,thSCD2 175

bsfull,spfull: If set to true the blocksize(bsfull) and/or searchparam(spfull) are applied to the frames before the current frame and the frames after.
If set to false then they are only applied to the frames before the current frame. This speeds the motion compensation up but decrease the posible noise reduction.
Defaults are false,false.



changelog:

Version 0.1 First version. Really slow and buggy. Used a modified bubblesort to find the median causing the filter to be extremely slow with large radii.

Version 0.2 Changed the sort algorithm to radix sort resulting in a great speed improvement especially for large radii. Also fixed a couple of bugs.

Version 0.3 optimized the sort algorithm even more. Also added the ability to process the borders.

version 0.31 bugfix. Should make the same output as tmedianblur except for the borders.

version 0.4 Added medianblurcw a centerweighted median blur

version 0.5 Added medianblurb and medianblurt.

version 0.6 Fixed a couple of bugs and added iteger SSE optimization for medianblur for radius below 4. This results in a 85-400% speed increase

version 0.65 More bugs removed. Added assembler optimization resulting in 30-60% speedincrease for medianblurcw, medianblurt and medianblur(for radius >3)

version 0.7 Added support for motion compensation in medianblurt using manaos MVTools.

version 0.8 Added ML3Dex a multilevel temporal medianblur filter that can use MVTools for motion compensation.

version 0.81 Bugfixes and added an option to show when mvtools detects a scenechange.

version 0.82 fixed a bug that caused a access violating in medianblurt and ml3dex

version 0.83 fixed a bug causing a memory leak with motion compensation. Now calls MVTools with named arguments. This should increase support of different versions of MVTools.

version 0.84 Added the option searchparam bsfull and spfull to ml3dex and medianblurt.

sourcecode released under GPL se copying.txt

Thanks to Manao for creating MVTools.

Mug Funky
31st October 2004, 17:19
weeeee! thanks, tsp. temporal median looks like it'll be very useful for removing spots and stuff.

tsp
14th November 2004, 20:06
Updated to version 0.6.

Mug Funky
15th November 2004, 16:50
temporal median works well for heavily scratched stuff. now i've just got to nut out how to protect the stream from the massive artefacts i get on motion, while keeping the removed spots removed.

thanks for this plugin :)

tsp
15th November 2004, 21:43
well the plugin don't have any motion compensation. Maybee MVTool or Depan can be used.

krieger2005
19th November 2004, 15:54
Please correct the Documentation:

temporal medianblur:


medianblurcw(clip,int radiusy,int radiusu,int radiusv,int temporalradius, bool calcborder)


should be

temporal medianblur:


medianblurt(clip,int radiusy,int radiusu,int radiusv,int temporalradius, bool calcborder)


Thanks for your work

tsp
20th November 2004, 17:52
Thanks for finding that little error. Should be fixed now.

tsp
21st November 2004, 22:11
version 0.65 released. Contains some assembler optimization of the critical functions. This causes a 20-60 % speed increase. I'm not really impressed by the compiler. Thought it would be better to optimize the code.

Fizick
21st November 2004, 22:25
tsp,
Have you any plans to include multi-level median filter? ;)
It must produce less blur.

tsp
22nd November 2004, 18:37
Originally posted by Fizick
tsp,
Have you any plans to include multi-level median filter? ;)
It must produce less blur.

What do you men with multilevel? the center weighted version produces less blur if you use a high enough value for the weight (a little less than (radius*2+1)^2 would be fine).

Fizick
23rd November 2004, 00:23
http://www.mee.tcd.ie/~ack/papers/a4ackphd.ps.gz

tsp
28th November 2004, 23:30
updated to version 0.70. medianblurt can now use Manaos MVTools for motion compensation. This should please Mug Funky :) . Next project should be a multilevel median blur.

please note that this filter has only been tested with MVTools 0.9.8.1. 0.9.8.0 craches avisynth.

tsp
3rd December 2004, 20:40
version 0.80 ready. Now includes a multi-level median filter called ML3Dex, which also supports MVTools for motion compensation. Give it a try.

tsp
4th December 2004, 16:37
Forgot to enable assembler optimization. Fixed that and added an option to show when MVTools detects a scene change. Really useful with ML3Dex because this filter don't functions well if all frames are detected as scene changes. So get version 0.81.

Mug Funky
4th December 2004, 17:30
oh, i haven't been following this thread, but i should have been :)

will try that ml3d whatsit and report back. i've got a great clip to test it on - the "duck and cover" video from www.archive.org (it was posted in general discussion). so far i'm using MVtools, clense (like medianblurt(0,0,0,1) but faster), and degrainmedian/removedirt plus fft3dfilter by fizick. slow slow slow :) the results can only be described as "okay" at the moment. this is a very tough clip.

[edit]

wow! i mean wow!

even at defaults ml3dex gives a good result. nice work. now to try it with motion compensation...

[edit 2]

motion compensation is nice too :) this is the best christmas ever :D

it gets pretty blocky in parts though. are there any parameters to ml3dex apart from the MC related ones?

[edit 3]

i get an access violation when i do it this way:
odd=separatefields().selectodd().ml3dex()
even=separatefields().selecteven().ml3dex()
interleave(odd,even).weave()


i'm going to bed now :)

Fizick
4th December 2004, 20:37
tsp,
thanks for filter and ml3dex!

And you may thanks me for info also :D

tsp
4th December 2004, 22:30
Originally posted by Fizick
tsp,
thanks for filter and ml3dex!

And you may thanks me for info also :D

Sure thing if you implement the 2DAR model (chapter 5) for jitter correction ;)

Mug Funky I didn't have any problems with blocky parts yet. Is it a heavy compressed source? Maybe Deblock from MVTools can help. you can try this:

c=last
vfw = c.mvanalyse(pel=1, isb=false, blksize=8)
vbw = c.mvanalyse(pel=1, isb=true, blksize=8)
interleave(c.mvcompensate(vfw, thSCD1=1000),c,c.mvcompensate(vbw, thSCD1=1000)).Deblock(40,16,16).ml3dex(false).selectevery(3,1)

If it helps I will implement it in the next version.

Fixed the bug that caused a access violation. It was caused by different pitch in some of the source frames. Get version 0.82 above.

I also discovered a memory leak with MC=true. I think it's caused by MVTools combined with env->Invoke. It doesn't happend when using the above script so until it's fixed use the above script instead if you want motion compensation for more than 1000 frames.

Mug Funky
5th December 2004, 03:43
thanks. no more access violation :)

it seems MC is true by default in this new release...

also, if you want to see blocking, try fast moving anime with ml3dex(mc=true) and you'll probably see it. unless there's something wacky about it at my end (i'm not eliminating this possibility...). it'll show up on natural video as well, but anime is a sure way to screw up motion-compensation, and thus a good way to show blocking.

morsa
5th December 2004, 04:38
Is multilevel median the one which uses intead of a matrix first an X mask and then a cross one?

tsp
5th December 2004, 13:45
Is multilevel median the one which uses intead of a matrix first an X mask and then a cross one?

yes in fact it uses 5 mask. Finds the median of each of them and then returns the median of the medians. The 5 masks look like this:

prev frame . . . x +
current frame + x . . .
next frame . . . x +
.=center pixel x=diagonal mask +=crossmask

tsp
5th December 2004, 21:12
Mug Funky you are right about the blocky parts in anim. I don't think there is much to do about it. It's still better than not using motion compensation. Deblock only makes the artifacts worse at least in anims. A solution could be to have an option to only ably temporal bluring in area with suspected noise.

morsa
6th December 2004, 05:50
what you have described sounds more simillar to a Kuwahara filter than to an hybrid median, which was what I decribed above.....

tsp
6th December 2004, 17:27
Mug Funky:
I discovered that increasing the searchparam from the default 1 to about 40 or higher and setting the blocksize to 4 nearly all of the blocking artifacts disappear. Also because it's a median filter it's only necessary to apply this slow setting to one of the frames. This does however reduces the noise reducing ability of the filter some so I will include an option to use the searchparam with both the frame before and after or only one of them. Expect version 0.84 to be released shortly.




what you have described sounds more simillar to a Kuwahara filter than to an hybrid median, which was what I decribed above.....


Morsa remember that ML3Dex is a spatio-temporal filter so the matrix and mask used is 3d. Only the median is used so I think it qualifies as a median filter. Also the mask you describe is extended to 3D which makes it a multi level filter. This (http://www.ph.tn.tudelft.nl/~imap/library/wouter/kuwahara.html) homepage describes the Kuwahara filter and that's very far from what ML3Dex does. I don't know if it is the right definition of a Kuwahara filter though.

tsp
6th December 2004, 18:56
Version 0.84 ready. Adds searchparam and the option to use blocksize and/or searchparam on only the frames before the current frame instead of both the frames before and after. These increase speeds with a slight decrease in the noise reducing ability (while removing blocking artifacts compaired to a lower searchparam or higher blocksize).

A good starting value for cartoons is:

ml3dex(lambda=0,thSCD1=1000,searchparam=60,blksize=4)

Mug Funky
7th December 2004, 05:32
thanks muchly. i'll try it and edit this post :)

[edit]

much better. i think it needs some kind of artefact protection, nonetheless.

maybe using the SAD values that mvtools give? that'd probably be a lot of extra work, so don't feel an obligation - i'll make a wrapper function for this for the moment, and try to limit big changes. hehe... the main headache with pixel change limiting is that no matter how it's done, it's going to let through a lot of the splotches that it was trying to remove.

tsp
7th December 2004, 15:39
Mug Funky what kind of artifact are you getting. I downloaded the duck and cover clip(mpeg 244 MB) so if you can find somewhere in that clip you're getting artifact I will see what i can do to improve it and how it looks.
The problem is to detects these because it's difficult to tell if the pixel is change by a large amount because there is a sparkle or a error in the motion compensation.

zilog jones
19th February 2005, 16:01
Thanks for recommending ml3dex to me for my crappy old bad reception VHS captures. I'm getting great results, but I'm having trouble with scene changes. I try putting thSCD1=900 and it detects about half of them, but with the ones it doesn't detect the frame before the scene change goes all dark. It also detects any large movement or fades as a scene change too, which messes things up. If I set it to 1000 it will only detect actual scene changes, but not a lot of them.

Anything else I should try changing? How should I set thSCD2? Or since most of what I'm capturing is just ad's, would I get better results just doing ApplyRange with the filter on each scene?

Didée
14th July 2007, 14:00
Bump, with a long-standing issue:

MedianBlurT is really really slow: e.g. with 720x576 as input, MedianBlurT(0,0,0,2) gives like 1.5~2.0 fps.

Must be something on the side of implementation ... median filtering is time-consuming, sure, but not *that* much.

Any chance to improve this?

tsp
14th July 2007, 21:28
it should be posible. Now I only need the time to do it.

Eastermeyer
18th August 2007, 18:06
I am getting http://img441.imageshack.us/img441/4312/zwischenablage01bf4.jpg using your recommended Cartoon settings with ml3dex after a few Frames. Same Issue with the GPU version.

What can i do ?