The cost minimisation with greedy rectangle fitting is really neat! This is a cool project and I love that you actually built it. ❤
I think the tone mapping step (going from image colours to brick colours) should maybe be done by hand. The brick colours list contains a couple of nice blues that could’ve worked for the headband, but the code here picked deep purple for some reason. It looks like the legofy function is not perceptually uniform and is picking really dark colours (because the source image is quite dark? because the dark colours are further away from each other in an RBG colourspace with a Euclidean norm?) rather than prioritising getting the hues to match. Maybe if it were working in a HSL colour space instead of RBG it’d give nicer results?