[][src]Struct signed_distance_field::distance_field::SignedDistanceField

pub struct SignedDistanceField<D: DistanceStorage> {
    pub width: u16,
    pub height: u16,
    pub distances: D,
    pub distance_targets: Vec<(u16, u16)>,
}

Contains the distance field and the vector field produced by SignedDistanceField::compute. Can be normalized in order to convert to an image with limited range. The type parameter D can be used to customize the memory layout of the distance field. The library provides default Storages for Vec<f16> and Vec<f23> alias F16DistanceStorage and F32DistanceStorage.

If any distance in this field is INFINITY, no shapes were found in the binary image.

Fields

width: u16height: u16distances: D

A row-major image vector with for each pixel of the original image containing the distance from that pixel to the nearest edge

distance_targets: Vec<(u16, u16)>

A row-major image vector with for each pixel of the original image containing the absolute position of the nearest edge from that pixel

Methods

impl<D> SignedDistanceField<D> where
    D: DistanceStorage
[src]

pub fn compute(
    binary_image: &impl BinaryImage
) -> Self
[src]

Approximates the signed distance field of the specified image. The algorithm used is based on the paper "The dead reckoning signed distance transform" by George J. Grevara, 2004.

pub fn get_distance(&self, x: u16, y: u16) -> f32[src]

Returns the distance of the specified pixel to the nearest edge in the original image.

pub fn get_distance_target(&self, x: u16, y: u16) -> (u16, u16)[src]

Returns the absolute index of the nearest edge to the specified pixel in the original image.

pub fn flatten_index(&self, x: u16, y: u16) -> usize[src]

Convert x and y pixel coordinates to the corresponding one-dimensional index in a row-major image vector.

pub fn normalize_distances(self) -> Option<NormalizedDistanceField<D>>[src]

Scales all distances such that the smallest distance is zero and the largest is one. Also computes the former minimum and maximum distance, as well as the new edge-value. Returns None if the binary image did not contain any shapes.

pub fn normalize_clamped_distances(
    self,
    min: f32,
    max: f32
) -> Option<NormalizedDistanceField<D>>
[src]

Scales all distances such that the min distances are zero and max distances are one. All distances smaller than min and larger than max will be clamped. Edges (formerly zero-distances) will be at the center, put to 0.5. Also collects the former minimum and maximum distance. Returns None if the binary image did not contain any shapes.

Trait Implementations

impl<D: Clone + DistanceStorage> Clone for SignedDistanceField<D>[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl<D: PartialEq + DistanceStorage> PartialEq<SignedDistanceField<D>> for SignedDistanceField<D>[src]

impl<D: Debug + DistanceStorage> Debug for SignedDistanceField<D>[src]

Auto Trait Implementations

impl<D> Send for SignedDistanceField<D> where
    D: Send

impl<D> Sync for SignedDistanceField<D> where
    D: Sync

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]