I did a color search on my photo site. To do this, I looped on all the pixels in the same image and wrote down the top 10 in my database. The problem is that since my photos have people, my seekers are really looking for the colors of the subject, not the background (sky, paving, grass, etc.). I know that it will be very difficult to completely eliminate, but I think I need to change the color a bit to give the best results.
Please see this example with one photo:

The example on the left is what I did, collecting ALL the pixels. Black and gray raised the top 3 colors in this selection, the shade of pink was 4th and the navy blue from the girl's background was 5th - I collect only the 5 best colors, and my primary color was not really rated like that well. If I could change the way the pixels scroll to select only the colors in the green box (on the right), I think this will change my collection a bit. Here I am struggling to see the math.
I did this to cut through all the pixels:
$size = @getimagesize($imageFile); for ($x = 0; $x < $size[0]; $x += $granularity) { for($y = 0; $y < $size[1]; $y += $granularity) { // do stuff here }
But I need to change this to take about 5% from the top and bottom and about 8-10% of the sides, and then scroll through the new selection.
I started this, but then stopped because I was not sure of my calculations returning odd numbers or a number I liked 1.030044858.
Here is how I guessed and hope someone can help clear it and get me out of line:
$granularity = 4; $granularity = max(1, abs((int)$granularity)); $size = @getimagesize($imageFile); $sizeX = $size[0]; $sizeY = $size[1]; $xPerCent = 8; // for me to set & adjust $yPerCent = 5; // for me to set & adjust $xSelectionWidth = ($sizeX/100) * $xPerCent; $xSelectionWidth = $sizeX - ($xSelectionWidth * 2); $xSelectionHeight = ($sizeY/100) * $yPerCent; $xSelectionHeight = $sizeY - ($ySelectionHeight * 2); $xSelectionStart = 0; $xSelectionEnd = 0; $ySelectionStart = 0; $ySelectionEnd = 0; for($x = 0; $x < $size[0]; $x += $granularity) { for($y = 0; $y < $size[1]; $y += $granularity) { // do stuff here } }
source share