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
impl ConvertOptions
Sourcepub fn source(self, source: Option<Region>) -> Self
pub fn source(self, source: Option<Region>) -> Self
Sample only source of the input; None samples all of it.
Sourcepub fn letterbox(self, pad: [u8; 4]) -> Self
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.
Sourcepub fn placement(self, placement: LetterboxPlacement) -> Self
pub fn placement(self, placement: LetterboxPlacement) -> Self
Where a letterboxed image sits. Ignored without a letterbox fit.
Sourcepub fn pad_output(self, pad: [f32; 4]) -> Self
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.
Sourcepub fn normalization(self, normalization: impl Into<Normalization>) -> Self
pub fn normalization(self, normalization: impl Into<Normalization>) -> Self
How pixel values map to the destination.
Sourcepub fn interpolation(self, interpolation: Interpolation) -> Self
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.
Sourcepub fn get_rotation(&self) -> Rotation
pub fn get_rotation(&self) -> Rotation
The output rotation.
Sourcepub fn get_placement(&self) -> LetterboxPlacement
pub fn get_placement(&self) -> LetterboxPlacement
The letterbox placement.
Sourcepub fn get_pad_output(&self) -> Option<[f32; 4]>
pub fn get_pad_output(&self) -> Option<[f32; 4]>
The output-domain pad, when set.
Sourcepub fn get_normalization(&self) -> Normalization
pub fn get_normalization(&self) -> Normalization
The pixel value mapping.
Sourcepub fn get_interpolation(&self) -> Option<Interpolation>
pub fn get_interpolation(&self) -> Option<Interpolation>
The per-convert interpolation, or None for the processor’s.
Source§impl ConvertOptions
impl ConvertOptions
Sourcepub fn from_spec(spec: &PreprocessSpec) -> Result<Self>
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));Sourcepub fn with_spec(self, spec: &PreprocessSpec) -> Result<Self>
pub fn with_spec(self, spec: &PreprocessSpec) -> Result<Self>
Sourcepub fn content_region(
&self,
src_w: usize,
src_h: usize,
dst_w: usize,
dst_h: usize,
) -> Result<ContentRegion>
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
impl Clone for ConvertOptions
Source§impl ContentRegionSource for ConvertOptions
impl ContentRegionSource for ConvertOptions
Source§fn content_region(
&self,
src_w: usize,
src_h: usize,
dst_w: usize,
dst_h: usize,
) -> Result<ContentRegion>
fn content_region( &self, src_w: usize, src_h: usize, dst_w: usize, dst_h: usize, ) -> Result<ContentRegion>
impl Copy for ConvertOptions
Source§impl Debug for ConvertOptions
impl Debug for ConvertOptions
Source§impl Default for ConvertOptions
impl Default for ConvertOptions
Source§impl PartialEq for ConvertOptions
impl PartialEq for ConvertOptions
impl StructuralPartialEq for ConvertOptions
Auto Trait Implementations§
impl Freeze for ConvertOptions
impl RefUnwindSafe for ConvertOptions
impl Send for ConvertOptions
impl Sync for ConvertOptions
impl Unpin for ConvertOptions
impl UnsafeUnpin for ConvertOptions
impl UnwindSafe for ConvertOptions
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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