Crates.io | u_u |
lib.rs | u_u |
version | 0.1.0 |
source | src |
created_at | 2020-02-10 09:53:44.689836 |
updated_at | 2023-06-07 16:22:46.945411 |
description | Library allowing conversions of JPEG diagrams to SVGs |
homepage | https://github.com/rellfy/u_u |
repository | https://github.com/rellfy/u_u |
max_upload_size | |
id | 206964 |
size | 378,985 |
Convert diagram pictures into SVGs
This is a tool that allows converting a JPEG photo, e.g. a diagram photo, into an SVG picture, as seen in the example abvove.
As seen in examples/main.rs:
use u_u::jpeg_to_svg;
const JPEG_BYTES: &[u8] = include_bytes!("./u_u.jpg");
fn main() {
let svg_bytes = jpeg_to_svg(JPEG_BYTES).unwrap();
std::fs::write("./output_example.svg", svg_bytes).unwrap();
}
The algorithm interprets each RGB pixel as a 3D vector.
The first step is to calculate the background colour, which is calculated as the average colour of all the pixels in the image -- this means that the background of the photo (such as the white of a whiteboard, or black of a blackboard) must be more than 50% of the photo, or this fails (it could be an optional argument to pass the background colour if it is known to prevent failure on those cases).
Then, there are two passes on the image to filter out the background: