Large Image Catalog - Color Sorting
Posted: 2011-09-21T09:46:15-07:00
Have a large image catalog, 100,000+ images, that needs to be sorted via major colors (red, green, blue, purple, etc.).
Say about 16 major colors. How would I go about grouping the images into these groups based on pixel count. Obviously I'd need to group all the blue images together, with the images having the highest concentration of blue near the top.
I can compress the image down to its main 16 colors doing something like this:
Then, grab the histogram:
But this doesn't get me the colors sorted into the 16 main colors. The rgb values found are of course all over the board. How do I decide if an RGB value is close enough to blue for instance. The other thing this doesn't account for is the percentage of blue vs red so that I can rank the images by the amount of color.
Any help here would be appreciated and would be rewarded with Bitcoin.
Say about 16 major colors. How would I go about grouping the images into these groups based on pixel count. Obviously I'd need to group all the blue images together, with the images having the highest concentration of blue near the top.
I can compress the image down to its main 16 colors doing something like this:
Code: Select all
$img = new Imagick($image_fname);
$img->quantizeImage(16,Imagick::COLORSPACE_RGB,1,false,false);
Code: Select all
$histogram = $img->getImageHistogram();
foreach($histogram as $h){
//echo $h->getColorAsString() . "\n";
$color=$h->getColor();
$data = array("productid"=>$pid,
"red"=>$color['r'],
"green"=>$color['g'],
"blue"=>$color['b']
);
}
Any help here would be appreciated and would be rewarded with Bitcoin.