Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve mechanism that picks the closest color #2

Merged
merged 3 commits into from
Oct 11, 2018

Conversation

willemstuursma
Copy link
Contributor

The mechanism that picked the closest color was pretty naive. It took the sum of the R, G and B distances separately.

This mechanism takes into consideration that the three colors are in are 3-D space and weights R, G and B differently. I took it from Stack Overflow.

Using this source image:
source

The naive algorithm would generate this image:

lego-default

The improved algorithm generates this image:

lego-closest

Note that it is less noisy.

@ricardofiorani
Copy link
Owner

@willemstuursma Sorry I took so long to review your PRs. I tested it with some other images and I really liked the results! Thank you for this 🍻 !

@ricardofiorani ricardofiorani merged commit 7a91c1a into ricardofiorani:master Oct 11, 2018
@willemstuursma willemstuursma deleted the closest-color branch October 11, 2018 10:26
@willemstuursma
Copy link
Contributor Author

Thanks @ricardofiorani. Most of the improvements come from this line:

$image->resize($amountOfBricksX, $amountOfBricksY);

This causes each brick to have the "average" color of the underlying 16x16 pixels. Before, it would pick the pixel in the top left corner as the brick color.

@willemstuursma
Copy link
Contributor Author

I really enjoyed working on this for a few hours, thanks for creating the project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants