imageproc::map

Function map_pixels

Source
pub fn map_pixels<I, P, Q, F>(image: &I, f: F) -> Image<Q>
where I: GenericImage<Pixel = P>, P: Pixel, Q: Pixel, F: Fn(u32, u32, P) -> Q,
Expand description

Applies f to each pixel in the input image.

ยงExamples

use image::Rgb;
use imageproc::map::map_pixels;

let image = gray_image!(
    1, 2;
    3, 4);

let rgb = rgb_image!(
    [1, 0, 0], [2, 1, 0];
    [3, 0, 1], [4, 1, 1]);

assert_pixels_eq!(
    map_pixels(&image, |x, y, p| {
        Rgb([p[0], x as u8, y as u8])
    }),
    rgb);