Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shnewto/edges
get the edges of objects in images
https://github.com/shnewto/edges
bevy collider colliders edges image images rust sprite sprites transparency
Last synced: about 2 months ago
JSON representation
get the edges of objects in images
- Host: GitHub
- URL: https://github.com/shnewto/edges
- Owner: shnewto
- License: apache-2.0
- Created: 2024-03-02T01:46:02.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-08-13T14:25:19.000Z (4 months ago)
- Last Synced: 2024-10-23T21:55:26.085Z (2 months ago)
- Topics: bevy, collider, colliders, edges, image, images, rust, sprite, sprites, transparency
- Language: Rust
- Homepage:
- Size: 52.7 KB
- Stars: 11
- Watchers: 1
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
[![Crates.io]()]()
[![Crates.io]()]()
[![MIT/Apache 2.0]()]()# edges
get the edges of objects in images with transparency.
## supported image types
- `image::DynamicImage`
- `bevy::render::texture::Image` (or if you rather, `bevy::prelude::Image`)## using
```rust
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 eachother. 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:
- MIT License (LICENSE-MIT or )
- Apache License, Version 2.0 (LICENSE-APACHE or )at your option.