2-D median filtering

`J = medfilt2(I)`

```
J = medfilt2(I,[m
n])
```

`J = medfilt2(___,padopt)`

Median filtering is a nonlinear operation often used in image processing to reduce "salt and pepper" noise. A median filter is more effective than convolution when the goal is to simultaneously reduce noise and preserve edges. For information about performance considerations, see

`ordfilt2`

.If the input image

`I`

is of an integer class, then all the output values are returned as integers. If the number of pixels in the neighborhood (i.e.,`m*n`

) is even, then some of the median values might not be integers. In these cases, the fractional parts are discarded. Logical input is treated similarly. For example, the true median for the following 2-by-2 neighborhood in a`uint8`

array is 4.5, but`medfilt2`

discards the fractional part and returns 4.1 5 4 8

If you specify

`padopt`

as`'zeros'`

or`'indexed'`

, then the padding can skew the median near the image boundary. Pixels within one-half the width of the neighborhood (

) of the edges can appear distorted.`[m n]`

/2

On the CPU, `medfilt2`

uses `ordfilt2`

to perform the filtering.

[1] Lim, Jae S., *Two-Dimensional
Signal and Image Processing*, Englewood Cliffs, NJ, Prentice
Hall, 1990, pp. 469-476.