Conditional Temporal Median Filter

This filter is designed to remove temporal noise in the form of small dots and streaks found in some videos. A common cause of this is dirty VHS heads but I have also seen small black or white streaks in broadcast material.

An AviSynth 2.5 and MJPEG Tools is available.

The AviSynth version requires my C API Plugin available at kevin.atkinson.dhs.org/avisynth_c/.

The MJPEG Tools version has been tested using GCC 3.2, GCC 3.3, and Intel's C++ compiler for Linux. It uses some library routines from the MJPEG Tools distribution. You can find MJPEG Tools at http://mjpeg.sourceforge.net/

I spent a decent amount of time optimizing the filter so it should be fairly effect. It is integer SSE optimized using either GCC or Intel MMX/SSE builtins. Unfortually Gcc versions before 3.3 does not use them very well. There for it is recomended that either GCC 3.3+ or Intel's compiler is used. Non SSE optimized versions are also included in the source.

This filter reads in a yuv4mpeg stream from stdin and write a yuv4mpeg stream to stdout.

The filter works as follows:

1) Find pixes that are different from its neighbors by at least P1.

1b) Enlarge outliers based on P2.

2) Determine the size of the specks and reject all those
   larger than PWIDTHxPHEIGHT

3) Find moving areas of an image by simply comparing each
   pixel to the previous frame and considering all those which
   are greater than MTHRES.

3b) Remove pixels determined as noise from the motion map.

4) Denoise the motion map by diffusing and then diluting.  This is
   probably the most important step.

5) Only remove the specks in which there was no motion in
   the current or the next frame.
The filter can also be configured to work as follows (by setting mode to median)
1) Find moving areas of an image by simply comparing each
   pixel to the previous frame and considering all those which
   are greater than MTHRES.

2) Denoise the motion map by diffusing and then diluting.  This is
   probably the most important step.

3) Apply a simple temporal median filter on the non-moving areas of
   the image.


Here is a before and after picture. Pay particular attention to the orange area near the bottom.

Here is a 3 sec video (XVid, 2.4 M): Before, After

Here is another video, this one is not resized but cropped to only show part of the lower left corner (MJPEG 345 K): Before, After


And Finally Here is the filter:

It is Copyright 2003 by Kevin Atkinson under the GPL version 2.


Last modified: 2003-08-12

To My Home Page