pub struct Kernel { /* private fields */ }Expand description
A convolution kernel: odd-sized, square or rectangular, small.
Implementations§
Source§impl Kernel
impl Kernel
Sourcepub const MAX_SIZE: u32 = 63
pub const MAX_SIZE: u32 = 63
The largest kernel accepted, per axis.
“Arbitrary small kernels” (SPEC §Core ops) needs a number attached to it. Beyond this a separable or frequency-domain implementation is the right answer, and silently accepting a 999-tap kernel would be an invitation to a very slow surprise.
Sourcepub fn new(width: u32, height: u32, taps: &[f32]) -> Result<Kernel, PixelsError>
pub fn new(width: u32, height: u32, taps: &[f32]) -> Result<Kernel, PixelsError>
Build a kernel from width * height taps in row-major order.
Taps are normalized by their sum, so [1; 9] and [1.0/9.0; 9] are the
same blur. A kernel summing to zero — an edge detector — is left
unnormalized rather than divided by zero.
§Errors
Returns PixelsError::InvalidArgument if the dimensions are even or
zero, exceed Kernel::MAX_SIZE, disagree with the tap count, or if
any tap is not finite.
Sourcepub fn gaussian(sigma: f32) -> Result<Kernel, PixelsError>
pub fn gaussian(sigma: f32) -> Result<Kernel, PixelsError>
A Gaussian blur approximated at sigma, sized to 3 sigma each way.
§Errors
Returns PixelsError::InvalidArgument if sigma is not finite and
positive, or if the implied kernel exceeds Kernel::MAX_SIZE.
Sourcepub fn sharpen(amount: f32) -> Result<Kernel, PixelsError>
pub fn sharpen(amount: f32) -> Result<Kernel, PixelsError>
A 3x3 sharpen: the identity plus a Laplacian scaled by amount.
§Errors
Returns PixelsError::InvalidArgument if amount is not finite.