AdaptiveMedian


Author V. C. Mohan
Date Sep 14, 2005/ Dec 12, 2006, Mar 9, 2009 15 Aug 2014
All my plugins are available for free download from "here".

AdaptiveMedian plugins for Avisynth 2.5 and 2.6 versions, are free and the author does not give any guarentee for its operation. It may be downloaded and used at the users risk.

This is an adaptive Median Filter for eliminating certain types of noise. It uses local statistics (minimum, maximum and median values) of a moving local grid, and changes grid size depending on local statistics.

Rules implemented for processing.
starting value of grid is 3 i.e. 3x3 pixels.
Compute max, min and median of the grid
1. if median is more than minimum and less than maximium:-
 if the grid center value is greater than minimum and less than maximum,the value is not changed
 Otherwise center value of grid is replaced by median.
2 else:-
 if grid size is less than maxgrid, it is increased to next step and process repeated.
 Otherwise center value is unchanged.

As per theory
Quote "Ordinary median filters perform well as long as the spatial density of impulsive noise is small. Adaptive Median filter can handle impulsive noise having larger probablity. An additional benefit is this seeks to preserve detail while smoothing nonimpulse noise something that the traditional median filter does not do.

The algorithm described has three purposes.
1.To remove salt and pepper (impulse) noise.
2.To smooth other noise which may not be impulsive
3.To reduce distortionsuch as excessive thinning or thickening of object boundaries.
" unquote

This plugin works in All color formats supported by avisynth version selected. In RGB color spaces, all 3 color values are processed. In case of YUY2 or Planar filtering of any plane is optional.


Details of parameters
Description Name Type Limits Default
Input clip clip none
Starting frame number to process sf integer within clip 0
End frame number to process ef integer within clip and not less than sf last frame
Maximum size to which grid can be increased maxgrid integer 3 to 9 5
Whether Y plane is to be processed (not for RGB formats) yy bool true, false true
Whether u plane is to be processed (not for RGB formats) uu bool true, false false
Whether v plane is to be processed (not for RGB formats) vv bool true, false false

Usage examples
AdaptiveMedian()
a = converttoYUY2()
AdaptiveMedian(a, maxgrid=7, yy = false, uu = true, vv = true)
# following script produced the images below
converttoRGB32()
adm1 = AdaptiveMedian(yy = true, uu = true, vv = true, maxgrid = 7)
last + adm1 + subtract(last, adm1 ).Levels(125,1,135,0,255)

Input :-

output :-

difference being noise removed ;-
To my index page down load plugin To Avisynth