Skip to main content

ConvertOptions

Struct ConvertOptions 

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

Options for convert. The default converts the whole source, stretched, with no rotation or flip, resamples with the processor’s interpolation, and maps pixels as Normalization::unsigned for float destinations.

let opts = ConvertOptions::new()
    .letterbox([0, 0, 0, 255])
    .placement(LetterboxPlacement::TopLeft)
    .pad_output([0.0; 4])
    .normalization(Normalization::imagenet())
    .rotation(Rotation::None);

Implementations§

Source§

impl ConvertOptions

Source

pub fn new() -> Self

The default options.

Source

pub fn rotation(self, rotation: Rotation) -> Self

Rotate the output, in 90° steps.

Source

pub fn flip(self, flip: Flip) -> Self

Flip the output.

Source

pub fn crop(self, crop: Crop) -> Self

Set the source region and fit together.

Source

pub fn source(self, source: Option<Region>) -> Self

Sample only source of the input; None samples all of it.

Source

pub fn letterbox(self, pad: [u8; 4]) -> Self

Letterbox: keep the source aspect ratio and pad the rest with the RGBA pixel pad, which is mapped like the image.

Source

pub fn placement(self, placement: LetterboxPlacement) -> Self

Where a letterboxed image sits. Ignored without a letterbox fit.

Source

pub fn pad_output(self, pad: [f32; 4]) -> Self

Pad with these values as written to the destination (after normalization; quantized for integer destinations), instead of mapping the pixel pad. Ignored without a letterbox fit.

Source

pub fn normalization(self, normalization: impl Into<Normalization>) -> Self

How pixel values map to the destination.

Source

pub fn interpolation(self, interpolation: Interpolation) -> Self

Resample with interpolation when this convert resizes, instead of the processor’s setting (see ImageProcessor::set_interpolation). Interpolation::Bicubic and Interpolation::Area run as Interpolation::supported, with a warning logged once per mode. EDGEFIRST_INTERPOLATION, when set, takes precedence.

Source

pub fn get_rotation(&self) -> Rotation

The output rotation.

Source

pub fn get_flip(&self) -> Flip

The output flip.

Source

pub fn get_crop(&self) -> Crop

The source region and fit.

Source

pub fn get_placement(&self) -> LetterboxPlacement

The letterbox placement.

Source

pub fn get_pad_output(&self) -> Option<[f32; 4]>

The output-domain pad, when set.

Source

pub fn get_normalization(&self) -> Normalization

The pixel value mapping.

Source

pub fn get_interpolation(&self) -> Option<Interpolation>

The per-convert interpolation, or None for the processor’s.

Source§

impl ConvertOptions

Source

pub fn from_spec(spec: &PreprocessSpec) -> Result<Self>

Options that apply a model’s preprocessing: its normalization, fit, letterbox placement, pad and interpolation.

§Errors

Error::InvalidOptions for a pixel-space pad outside 0–255 or a non-finite pad.

use edgefirst_image::{ConvertOptions, LetterboxPlacement, PadSpace, PreprocessSpec};

let mut spec = PreprocessSpec::new();
spec.placement = LetterboxPlacement::TopLeft;
spec.pad = [0.0; 3];
spec.pad_space = PadSpace::Normalized;
let opts = ConvertOptions::from_spec(&spec)?;
assert_eq!(opts.get_placement(), LetterboxPlacement::TopLeft);
assert_eq!(opts.get_pad_output(), Some([0.0, 0.0, 0.0, 1.0]));
assert_eq!(opts.get_interpolation(), Some(spec.interpolation));
Source

pub fn with_spec(self, spec: &PreprocessSpec) -> Result<Self>

These options with a model’s preprocessing applied; rotation, flip and the source crop are kept. See from_spec.

§Errors

As from_spec.

Source

pub fn content_region( &self, src_w: usize, src_h: usize, dst_w: usize, dst_h: usize, ) -> Result<ContentRegion>

Where convert puts the image content when converting an src_w×src_h source into a dst_w×dst_h destination with these options: the letterbox rectangle, or the whole destination for a stretch. It is computed by the same code the convert paints with, so mapping results back through it is exact.

§Errors

Error::CropInvalid when the source crop falls outside the source.

use edgefirst_image::{ConvertOptions, Region};

let opts = ConvertOptions::new().letterbox([114, 114, 114, 255]);
let r = opts.content_region(1280, 720, 640, 640)?;
assert_eq!(r.pixels, Region::new(0, 140, 640, 360));
assert_eq!(r.normalized, [0.0, 0.21875, 1.0, 0.78125]);

Trait Implementations§

Source§

impl Clone for ConvertOptions

Source§

fn clone(&self) -> Self

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 ContentRegionSource for ConvertOptions

Source§

fn content_region( &self, src_w: usize, src_h: usize, dst_w: usize, dst_h: usize, ) -> Result<ContentRegion>

The content region for an src_w×src_h source converted into a dst_w×dst_h destination. Read more
Source§

impl Copy for ConvertOptions

Source§

impl Debug for ConvertOptions

Source§

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

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

impl Default for ConvertOptions

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for ConvertOptions

Source§

fn eq(&self, other: &Self) -> 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 ConvertOptions

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more