https://github.com/patryk27/linez
Approximate images usings lines
https://github.com/patryk27/linez
art image image-processing rust
Last synced: about 1 year ago
JSON representation
Approximate images usings lines
- Host: GitHub
- URL: https://github.com/patryk27/linez
- Owner: Patryk27
- Created: 2025-01-09T17:47:45.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-11T19:03:47.000Z (over 1 year ago)
- Last Synced: 2025-04-10T06:44:58.887Z (about 1 year ago)
- Topics: art, image, image-processing, rust
- Language: Rust
- Homepage:
- Size: 9.86 MB
- Stars: 66
- Watchers: 1
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# linez
Quick & fun tool that approximates images using lines:
## Usage
``` shell
$ git clone https://github.com/Patryk27/linez
$ cd linez
$ cargo run --release -- images/starry-night.jpg
# (press escape to close the app)
```
## Algorithm
1. Load image provided by user (aka the target image).
2. Create a black image (aka the approximated image).
3. Sample a line: randomize starting point, ending point, and color.
4. Check if drawing this line on the approximated image would reduce _the distance_ between the approximated image and the target image.
5. If so, draw the line; otherwise don't draw it.
6. Go to 3.
... where "distance between images" is e.g. mean squared error:
```
fn image_distance(img_a, img_b):
assert img_a.size() == img_b.size()
dist = 0.0
for all pixels in img_a and img_b:
dist += pixel_distance(pixel_a, pixel_b)
return dist
fn pixel_distance(pixel_a, pixel_b):
dist_r = (pixel_a.red - pixel_b.red) ^ 2
dist_g = (pixel_a.green - pixel_b.green) ^ 2
dist_b = (pixel_a.blue - pixel_b.blue) ^ 2
return dist_r + dist_g + dist_b
```
## License
MIT License
Copyright (c) 2024 Patryk Wychowaniec