Quick & fun tool that approximates images using lines:
$ git clone https://github.com/Patryk27/linez
$ cd linez
$ cargo run --release -- images/starry-night.jpg
# (press escape to close the app)
- Load image provided by user (aka the target image).
- Create a black image (aka the approximated image).
- Sample a line: randomize starting point, ending point, and color.
- Check if drawing this line on the approximated image would reduce the distance between the approximated image and the target image.
- If so, draw the line; otherwise don't draw it.
- 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
MIT License
Copyright (c) 2024 Patryk Wychowaniec