title: Group photos by color
body: <p>I have a pretty big number of photos and a RGB color map (let's say of about 100 colors). How can I group the pictures by color and obtain something like the following: <a href="http://labs.ideeinc.com/multicolr" rel="nofollow noreferrer">http://labs.ideeinc.com/multicolr</a> ?</p>
  
  <p>My current idea is this: Using ImageMagick, do this for each photo:</p>
  
  <ol>
  <li>Resize it to a smaller size so that it can be processed faster.</li>
  <li><a href="http://www.imagemagick.org/Usage/quantize/#map" rel="nofollow noreferrer">Quantize</a> it without dithering using my chosen color map.</li>
  <li>Get the photo's <a href="http://www.imagemagick.org/Usage/files/#histogram" rel="nofollow noreferrer">histogram</a> to obtain how many times each color appears.</li>
  <li>Store the colors in a database, but I haven't figured out what is the best way to do this for fast retrievals.</li>
  </ol>
  
  <p>Do you know any better and more efficient way to do this? My language of choice is PHP since all the heavy processing will be done by ImageMagick, and the database is PostgreSQL.
  Thank you in advance!</p>