#
Median

Author V. C. Mohan
Date Dec 2016
All my plugins are available for free download from "here".

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. This Median filter can suppress impulsive noise with 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 distortion such as excessive thinning or thickening of object boundaries.
" unquote

This function works in All color formats and bit depths supported by avisynth+ . It is thread safe MT_NICE_FILTER
In RGB color spaces, all 3 color values are processed. In case of YUY2 or Planar filtering of Luma Y, or chroma U or chroma V is optional.

Details of parameters
Description | Name | Type | Limits | Default
Input clip |  | clip |  | none
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

    Median()
    a = converttoYUY2()
    Median(a, maxgrid=7, yy = false, uu = true, vv = true)
    # following script produced the images below
    converttoRGB32()
    adm1 = Median(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 loadmodPlus plugin To Avisynth