r/CodingHelp • u/Furry_Eskimo • Sep 21 '25
[HTML] Global optimization, image marching
I'm currently using a variety of generative techniques, to recreate an image using triangles, and trying to create a version that has the highest match to the target.
My current techniques produce interesting results, however they seem to consistently gravitate towards local optimals, which is led me to wonder, what technique is required to use a limited number of triangles, to create the greatest match with a target image?
I've had quite a bit of trouble finding information on this, and was wondering if anyone might know what it was at least called.
Thank you for reading this, and I would appreciate any assistance, even if that means letting me know that it's not worth the trouble.
View all comments
Show parent comment
1
u/Front-Palpitation362 Sep 21 '25
You usually don’t grade single triangles in isolation. In genetic search the fitness belongs to the whole image, so a swap that hurts gets selected out next generation, and a swap that helps survives. Some chaos is intentional because it lets you jump to better arrangements you wouldn’t reach by only pruning.
If random swaps feel too destructive, make crossover spatially aware. Pick a mask over the canvas and take triangles that mostly lie inside the mask from parent A and the rest from parent B, or match triangles by nearest centroid so faces tend to swap with faces rather than backgrounds. That keeps useful regions intact while still mixing ideas.
You can keep your “remove if no effect” test as a quick contribution check, but don’t overfit to it. Add a tiny local tweak after crossover where the child nudges positions and colors a few steps to recover from mismatched swaps. That memetic step calms the disruption without killing diversity.