Skip to main content

Kernel

Struct Kernel 

Source
pub struct Kernel { /* private fields */ }
Expand description

A convolution kernel: odd-sized, square or rectangular, small.

Implementations§

Source§

impl Kernel

Source

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.

Source

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.

Source

pub fn square(size: u32, taps: &[f32]) -> Result<Kernel, PixelsError>

A square kernel of size taps per side.

§Errors

As Kernel::new.

Source

pub fn blur(size: u32) -> Result<Kernel, PixelsError>

A box blur of size by size.

§Errors

As Kernel::new.

Source

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.

Source

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.

Source

pub const fn width(&self) -> u32

The kernel width in taps.

Source

pub const fn height(&self) -> u32

The kernel height in taps.

Source

pub const fn radius_x(&self) -> u32

How far the kernel reaches from its centre, horizontally.

Source

pub const fn radius_y(&self) -> u32

How far the kernel reaches from its centre, vertically.

Source

pub fn taps(&self) -> &[f32]

The normalized taps, row-major.

Trait Implementations§

Source§

impl Clone for Kernel

Source§

fn clone(&self) -> Kernel

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Kernel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Kernel

Source§

fn eq(&self, other: &Kernel) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Kernel

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.