edges

Crates.ioedges
lib.rsedges
version
sourcesrc
created_at2024-03-02 07:48:30.745827
updated_at2024-12-04 15:48:05.336649
descriptiona library for getting the edges of objects in images with transparency
homepagehttps://github.com/shnewto/edges
repositoryhttps://github.com/shnewto/edges
max_upload_size
id1159565
Cargo.toml error:TOML parse error at line 29, column 1 | 29 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Shea Newton (shnewto)

documentation

README

edges

Crates.io Crates.io MIT/Apache 2.0

Get the edges of objects in images with transparency.

Supported image types

  • image::DynamicImage
  • bevy::image::Image (or if you rather, bevy::prelude::Image)

Using

use edges::Edges;
use std::path::Path;

let image = image::open(Path::new("assets/car.png"));
let edges = Edges::from(image.unwrap());
println!("{:#?}", edges.single_image_edge_translated());

How it works

I was inspired by a coding train (or, coding in the cabana rather) on an implementation of "marching squares". So this crate takes a "march through all the values" approach to find edges, i.e. pixels with at least 1 empty neighboring pixel, but instead of drawing a contour in place, it just keeps track of all the actual pixel coordinates. To determine "empty" I bitwise or all the bytes for each pixel and, in images with transparency, "empty" is a zero value for the pixel.

After that, we need to put the coordinates in some kind of "drawing order" so whatever we pass all the points to, knows how we want the object constructed. For this, the crate collects all pixels, in order, that are a distance of 1 from each other. If there are pixels that have a distance greater than 1 from any pixel in an existing group, that pixel begins a new group.

License

All code in this repository is dual-licensed under either:

At your option.

Commit count: 89

cargo fmt