My Problem My customers are uploading images to put on a t-shirt. I need to know how many main colors are within the design. I have tried PHP scripts and Imagemagick , I can't seem to get the results I am looking for.
This image has 5 main color variations. When I use imagemagick's -unique-colors, I get a huge range of different colors. Is there a line of code or script that I can use to get an outcome of 5.
Here is the code I am using to try and get unique color count with imagemagick but I get way to many colors.
exec(convert $origimage -unique-colors -scale 1000% $newimage);
Reading this discussion should help you : http://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=12818
Basically, you should use imagemagic to generate an histogram of the color used, and sort the result by occurences (or percentage if you prefer) Then you can decide to take top 2 lines and it should give you a not so bad answer.
A more robust algorithm could be to choose a threshold of the percentage values, and keep the colors being above this threshold...
I hope this gives you some clues.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With