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
impl KernelBuilder
pub fn new() -> KernelBuilder
sourcepub fn set_size(self, size: (usize, usize)) -> KernelBuilder
pub fn set_size(self, size: (usize, usize)) -> KernelBuilder
Used for user defined kernels
sourcepub fn set_center(self, center: (usize, usize)) -> KernelBuilder
pub fn set_center(self, center: (usize, usize)) -> KernelBuilder
Used for user defined kernels
sourcepub fn set_values(self, values: &[f64]) -> KernelBuilder
pub fn set_values(self, values: &[f64]) -> KernelBuilder
Used for user defined kernels
pub fn build(&self) -> Result<KernelInfo, MagickError>
sourcepub fn set_info_type(self, info_type: KernelInfoType) -> KernelBuilder
pub fn set_info_type(self, info_type: KernelInfoType) -> KernelBuilder
Used for builtin kernels
sourcepub fn set_geom_info(self, geom_info: GeometryInfo) -> KernelBuilder
pub fn set_geom_info(self, geom_info: GeometryInfo) -> KernelBuilder
Used for builtin kernels
pub fn build_builtin(&self) -> Result<KernelInfo, MagickError>
Trait Implementations§
source§impl Clone for KernelBuilder
impl Clone for KernelBuilder
source§fn clone(&self) -> KernelBuilder
fn clone(&self) -> KernelBuilder
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for KernelBuilder
impl RefUnwindSafe for KernelBuilder
impl Send for KernelBuilder
impl Sync for KernelBuilder
impl Unpin for KernelBuilder
impl UnwindSafe for KernelBuilder
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more