Filters (Spatial): Median

Jump to: navigation, search


The Median filter algorithm replaces a target pixel's value with the median value of the neighboring pixels. The designation of neighbor is determined by the size and shape of the kernel. A kernel is much like a mask; the pixels in the masked area are part of the neighborhood. The kernel's size and shape determines the number of pixel values used to calculate the median. You can adjust this algorithm's parameters to change the kernel's size and shape, apply selective filtering, and repetitively apply the selected filtering for any portion of the image you select.

The median filter algorithm is most useful for removing shot noise, which is noise that appears as random spots in an image. Shot noise can be caused by dust or a bad detector in image acquisition or by errors in data transfer (Lyon, Russ). Note that because there is no inverse function for the median filter algorithm, the original image cannot be reconstructed. This algorithm is also called a rank-type filter, because the list of values must be sorted before a useful value can be found.


For more information about the algorithm, refer to MIPAV Volume 2 User Guide on the MIPAV web site:{}

Image types

You can apply this algorithm to color and gray-scale 2D, 2.5D, and 3D images. However, you cannot apply this algorithm to complex images.

Special notes

The following special notes apply:

  • When this algorithm is applied to 3D datasets, you can apply the filter to either a single slice or volume kernel. If you choose to apply it to a volume kernel, MIPAV finds the median in a list of values from pixels in all directions along the x-, y-, and z-axes. Note that the kernel-size must be smaller than the number of slices in the image.
  • The resultant image is, by default, a float image.
  • An outlier detector is available for use in this algorithm. The outlier detector replaces the target pixel only if its magnitude exceeds the mean of the list by a user-inputted fraction of the standard deviation.
  • Currently the algorithm allows square and cross kernel shapes for 2D images and cube and axis kernel shapes for 3D images. Future plans include the addition of other kernel shapes.
  • Color images may be filtered across any combination of the color channels (red, green, or blue). Alpha values-those values relating to how opaque a particular pixel is-are unaffected.

Applying the Median Filter algorithm

To run this algorithm, complete the following steps:

  1. Select Algorithms > Filter > Median Filter. The Median Filter dialog box appears.
  2. Complete the fields in the dialog box. Keep the following in mind:
    • To filter a VOI region only, select the VOI and then select VOI Region(s).
    • Pixels that are too close to the edge of an image are not processed.
    • To apply a median filter to a color image, select the channels to filter. By default, MIPAV filters all three channels (red, green, and blue).
  3. Click OK when complete. The algorithm begins to run.
A pop-up window appears with the status, and the following message appears
"Filtering Image (Pass 1 of 1)." (Depending on what you entered in Number of iterations on the Median Filter dialog box, the number of passes varies.) When the algorithm finishes running, the pop-up window closes.
Depending on whether New image or Replace image was selected, results appear in a new window or replace the image to which the algorithm was applied.
Figure 1. Median Filter dialog box

Number of iterations
Indicates the number of times to filter the image with a median filter of the selected deviation, kernel size, and kernel shape.
Maximum standard deviation
The maximum allowable magnitude of the pixel value as a function of the standard deviation. The system replaces any pixel whose value is outside this function of the standard deviation from the mean of the neighborhood (as selected by the kernel-size and shape) by the median of the neighborhood. A value of 0.0 is equivalent to replacing every pixel with the median of its neighborhood. A value of 1.0 limits the filtering of the image. The system processes only target pixels whose values are greater than 1.0 standard deviation from its neighbors.
Kernel size
A k' x 'k region selects a neighborhood that extends in all directions by ('k'-1)/2, placing the target pixel in the center of the kernel.
Kernel shape
Selects which pixels in the kernel size box are included as a part of the median's neighborhood.
Kernel size adaptively changes
This checkbox indicates whether median filter should be run via adaptive filtering. Adaptive filtering has 3 main purposes:
1. To remove salt-and-pepper (impulse) noise;
2. To prove smoothing of other noise that may not be impulsive;
3. And to reduce distortion, such as excessive thinning or thickening of object borders.
Maximum Kernel Size
This is the maximum kernel size that the window size can get increased to under the algorithm.
Red channel
Filters the red channel (for use with RGB images).
Green channel
Filters the green channel (for use with RGB images).
Blue channel
Filters the blue change (for use with RGB images).
New image
Indicates where the results of the algorithm appear. If you select this option, the results appear in a new image window.
Replace image
Indicates where the results of the algorithm appear. If you select this option, the results replace the current active image.
Whole image
Applies the algorithm to the whole image.
VOI region(s)
Applies the algorithm to the volumes (regions) delineated by the VOIs.
Apply slice kernel
Filters each slice of the image independently of other slices, finding neighboring pixels from the slice.
Apply volume kernel
Gathers pixel values from the slice as well as from neighboring slices.
Applies the Median algorithm according to the specifications in this dialog box.
Disregards any changes that you made in this dialog box and closes the dialog box.
Displays online help for this dialog box.

See also: