pub struct ForegroundHandle { /* private fields */ }Expand description
Composed RGBA foreground image with transparent background.
Final output produced by composing the original RGB image with a mask as the alpha channel.
The mask’s grayscale values map to alpha, producing smooth or hard edges depending on processing.
Obtain by calling foreground on a crate::MatteHandle
or crate::MaskHandle.
§Example
use outline::Outline;
let outline = Outline::new("model.onnx");
let session = outline.for_image("input.jpg")?;
// Soft edges from raw matte
let soft = session.matte().foreground()?;
soft.save("soft-cutout.png")?;
// Hard edges from processed mask
let hard = session.matte()
.blur()
.threshold()
.processed()?
.foreground()?;
hard.save("hard-cutout.png")?;Implementations§
Source§impl ForegroundHandle
impl ForegroundHandle
Sourcepub fn dimensions(&self) -> (u32, u32)
pub fn dimensions(&self) -> (u32, u32)
Return the foreground image dimensions.
Sourcepub fn into_image(self) -> RgbaImage
pub fn into_image(self) -> RgbaImage
Consume the handle and return the RGBA foreground image.
Sourcepub fn save(&self, path: impl AsRef<Path>) -> OutlineResult<()>
pub fn save(&self, path: impl AsRef<Path>) -> OutlineResult<()>
Save the RGBA foreground image to the specified path.
Sourcepub fn bounding_box(&self) -> Option<BoundingBox>
pub fn bounding_box(&self) -> Option<BoundingBox>
Compute the bounding box of non-transparent content using a non-zero alpha threshold.
Sourcepub fn bounding_box_with(&self, threshold: u8) -> Option<BoundingBox>
pub fn bounding_box_with(&self, threshold: u8) -> Option<BoundingBox>
Compute the bounding box of content whose alpha is at or above threshold.
Sourcepub fn pad(self, padding: impl Into<Padding>) -> Self
pub fn pad(self, padding: impl Into<Padding>) -> Self
Expand the canvas by the given padding, filling new pixels with transparency.
Sourcepub fn crop(self, bounds: BoundingBox) -> Option<Self>
pub fn crop(self, bounds: BoundingBox) -> Option<Self>
Crop the image to bounds.
Returns None when bounds is empty or outside the current image canvas.
Sourcepub fn crop_to_content(self) -> Option<Self>
pub fn crop_to_content(self) -> Option<Self>
Crop the image to its non-transparent content.
Returns None when the image has no non-transparent pixels.
Sourcepub fn crop_to_content_with(self, threshold: u8) -> Option<Self>
pub fn crop_to_content_with(self, threshold: u8) -> Option<Self>
Crop the image to content whose alpha is at or above threshold.
Returns None when the image is fully transparent at the given threshold.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ForegroundHandle
impl RefUnwindSafe for ForegroundHandle
impl Send for ForegroundHandle
impl Sync for ForegroundHandle
impl Unpin for ForegroundHandle
impl UnsafeUnpin for ForegroundHandle
impl UnwindSafe for ForegroundHandle
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> 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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.