# 2.6.6.5 imgMedian

Median

## Brief Information

Apply median filter to image

## Command Line Usage

 

1. imgMedian d:=10; 

2. imgMedian d:=5 img:=mat(1) oimg:=mat(2); 

## Variables

Display
Name
Variable
Name
I/O
and
Type
Default
Value
Description
Dimension d

Input

int

2

Specifies the dimensions of the neighborhood on which median filtering is applied. This value should not be less than 2.

Input Matrix img

Input

Image

<active>

Specifies the source image to be manipulated. The default input is the active image.

Output Image oimg

Output

Image

<input>

Specifies the output image. By default, the output image is the same as the input image.

See the syntax here.

## Description

This function applies median filtering to an image. Each pixel of the input image is replaced by the median of the pixels in its neighborhood.

Median filter is usually used for noise removal. It is especially suitable for removing salt and pepper noise and pulse noise.

It is more advantageous over average filter in that it tends to preserve more features, for example, true edges, in the input image.

## Examples

In this example, we use the imgMedian function to remove noise from the input image:

1. When the input image is active, select Image: Spatial Filters: Median to open the dialog of the X-Function.
2. In the dialog, change the settings as the screenshot below and click OK to close the dialog.

A new image is created. We can see some noise is removed.

The original image

The output image

## Algorithm

The computation uses L_MedianFilterBitmap() function from LEADTOOLS Main API. Please refer to the LEADTOOLS Main API Help file, Version 14 and read L_MedianFilterBitmap topic.

## References

LEADTOOLS Main API Help file, Version 14