logoalt Hacker News

andai10/12/20242 repliesview on HN

Inspired by this, I stayed up all night building this!

https://jsbin.com/josuxarufu/1/edit?js,console,output

It tries to "evolve" the target image (right) by making random changes to the origin (left) -- output after 1 step is in center.

It's eventually supposed to be a genetic algorithm, but for now it just goes through it pixel by pixel, and if the pixel doesn't match the target, it inverts one of its neighbors. If that's beneficial (checking loss in a 5x5 rect centered on the test pixel), we keep the change. I get loss down to about 25% then it plateaus.

Feel free to fiddle, fork, etc! (I stayed up pretty late so the code is bad! Suggestions welcome!)


Replies

andai10/12/2024

Another strat I thought about is to precompute all possible outputs for all possible inputs. This is feasible for small tiles (e.g. 5x5 grid has ~35 million permutations), maybe a sliding window could be used. I'm stuck on how to deal with tile overlap, and the fact that many outputs have more than one input -- you'd want to check all possible input tiles against all possible neighboring input tiles?

RedNifre10/12/2024

Wouldn't it be better to have the target image as grayscale or black/white instead of dithered?

show 1 reply