Struct magick_rust::KernelBuilder

source ·
pub struct KernelBuilder { /* private fields */ }
Expand description

Builder, that creates instances of KernelInfo

§Examples

Here is an example of how you can use this struct to create a kernel to convolve an image:

use magick_rust::{MagickWand, PixelWand, KernelBuilder};

fn main() -> Result<(), magick_rust::MagickError> {
    let mut wand1 = MagickWand::new();
    wand1.new_image(4, 4, &PixelWand::new())?; // Replace with `read_image` to open your image file
    let wand2 = wand1.clone();

    let kernel_info = KernelBuilder::new()
        .set_size((3, 3))
        .set_center((1, 1)) // Not really needed here - the center is in the middle of kernel
                            // by default
        .set_values(&[0.111, 0.111, 0.111,
                      0.111, 0.111, 0.111,
                      0.111, 0.111, 0.111])
        .build()?;

    wand1.convolve_image(&kernel_info)?;

    Ok(())
}

Here is an example of how you can use this struct to create builtin kernel to gaussian blur an image (not the best way to do it, just an example):

use magick_rust::{MagickWand, PixelWand, KernelBuilder, KernelInfoType, GeometryInfo};

fn main() -> Result<(), magick_rust::MagickError> {
    let mut wand1 = MagickWand::new();
    wand1.new_image(4, 4, &PixelWand::new())?; // Replace with `read_image` to open your image file
    let wand2 = wand1.clone();

    let mut geom_info = GeometryInfo::new();
    geom_info.set_sigma(15.0);
    let kernel_info = KernelBuilder::new()
        .set_info_type(KernelInfoType::Gaussian)
        .set_geom_info(geom_info)
        .build_builtin()?;

    wand1.convolve_image(&kernel_info)?;

    Ok(())
}

Implementations§

source§

impl KernelBuilder

source

pub fn new() -> KernelBuilder

source

pub fn set_size(self, size: (usize, usize)) -> KernelBuilder

Used for user defined kernels

source

pub fn set_center(self, center: (usize, usize)) -> KernelBuilder

Used for user defined kernels

source

pub fn set_values(self, values: &[f64]) -> KernelBuilder

Used for user defined kernels

source

pub fn build(&self) -> Result<KernelInfo, MagickError>

source

pub fn set_info_type(self, info_type: KernelInfoType) -> KernelBuilder

Used for builtin kernels

source

pub fn set_geom_info(self, geom_info: GeometryInfo) -> KernelBuilder

Used for builtin kernels

source

pub fn build_builtin(&self) -> Result<KernelInfo, MagickError>

Trait Implementations§

source§

impl Clone for KernelBuilder

source§

fn clone(&self) -> KernelBuilder

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for KernelBuilder

source§

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

Formats the value using the given formatter. Read more

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§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

§

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>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.