[−][src]Function imageproc::gradients::sobel_gradient_map
pub fn sobel_gradient_map<P, F, Q>(image: &Image<P>, f: F) -> Image<Q> where
P: Pixel<Subpixel = u8> + WithChannel<u16> + WithChannel<i16> + 'static,
Q: Pixel + 'static,
ChannelMap<P, u16>: HasBlack,
F: Fn(ChannelMap<P, u16>) -> Q,
Computes per-channel gradients using Sobel filters and calls f
to compute each output pixel.
Examples
use imageproc::gradients::{sobel_gradient_map}; use image::Luma; use std::cmp; // A shallow horizontal gradient in the red // channel, a steeper vertical gradient in the // blue channel, constant in the green channel. let input = rgb_image!( [0, 5, 0], [1, 5, 0], [2, 5, 0]; [0, 5, 2], [1, 5, 2], [2, 5, 2]; [0, 5, 4], [1, 5, 4], [2, 5, 4] ); // Computing independent per-channel gradients. let channel_gradient = rgb_image!(type: u16, [ 4, 0, 8], [ 8, 0, 8], [ 4, 0, 8]; [ 4, 0, 16], [ 8, 0, 16], [ 4, 0, 16]; [ 4, 0, 8], [ 8, 0, 8], [ 4, 0, 8] ); assert_pixels_eq!( sobel_gradient_map(&input, |p| p), channel_gradient ); // Defining the gradient of an RGB image to be the // mean of its per-channel gradients. let mean_gradient = gray_image!(type: u16, 4, 5, 4; 6, 8, 6; 4, 5, 4 ); assert_pixels_eq!( sobel_gradient_map(&input, |p| { let mean = (p[0] + p[1] + p[2]) / 3; Luma([mean]) }), mean_gradient ); // Defining the gradient of an RGB image to be the pixelwise // maximum of its per-channel gradients. let max_gradient = gray_image!(type: u16, 8, 8, 8; 16, 16, 16; 8, 8, 8 ); assert_pixels_eq!( sobel_gradient_map(&input, |p| { let max = cmp::max(cmp::max(p[0], p[1]), p[2]); Luma([max]) }), max_gradient );