[][src]Function imageproc::filter::median_filter

pub fn median_filter<P>(image: &Image<P>, radius: u32) -> Image<P> where
    P: Pixel<Subpixel = u8> + 'static, 

Applies a median filter of given radius to an image. Each output pixel is the median of the pixels in a 2 * radius + 1 square of pixels in the input image.

Pads by continuity. Performs O(radius) operations per pixel.

Examples

use imageproc::filter::median_filter;

let image = gray_image!(
    1,   2,   3;
  200,   6,   7;
    9, 100,  11
);

// Padding by continuity means that the values we use
// for computing medians of boundary pixels are:
//
//   1     1     2     3     3
//      -----------------
//   1 |   1     2     3 |   3
//
// 200 | 200     6     7 |   7
//
//   9 |   9   100    11 |  11
//      -----------------
//   9     9   100    11    11

let filtered = gray_image!(
    2,  3,  3;
    9,  7,  7;
    9, 11, 11
);

assert_pixels_eq!(median_filter(&image, 1), filtered);
use imageproc::filter::median_filter;

// Image channels are handled independently.
// This example sets the red channel to have the same
// contents as the image from the grayscale example,
// the green channel to a vertically inverted copy of that
// image and the blue channel to be constant.
//
// See the grayscale image example for an explanation of how
// boundary conditions are handled.

let image = rgb_image!(
    [  1,   9, 10], [  2, 100,  10], [  3,  11,  10];
    [200, 200, 10], [  6,   6,  10], [  7,   7,  10];
    [  9,   1, 10], [100,   2,  10], [ 11,   3,  10]
);

let filtered = rgb_image!(
    [ 2,  9, 10], [ 3, 11, 10], [ 3, 11, 10];
    [ 9,  9, 10], [ 7,  7, 10], [ 7,  7, 10];
    [ 9,  2, 10], [11,  3, 10], [11,  3, 10]
);

assert_pixels_eq!(median_filter(&image, 1), filtered);