Loop through a given area of โ€‹โ€‹pixels

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:

enter image description here

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 } } 
+4
source share
1 answer

If you want to ignore something in the picture, I suggest you convert it to B&W and take the largest white area (you will need to set the conversion details to be sure that you will not get all non-white colors like black).

I mean red, and the skin color should be set to white and purple as black. In this case, the background and any dark surface will be black. Read http://www.switchonthecode.com/tutorials/csharp-tutorial-convert-a-color-image-to-grayscale its wonderful introduction, but I'm talking about real black and white, so you can customize / adapt this one.

This will help you focus on the right side of the image.

The more accurate the B & W shape recognition is, the better you can determine the topic with which you will look. Please read http://en.wikipedia.org/wiki/Pattern_recognition for details on pattern recognition.

Get the set of coordinates that you want to see in the original image.

Sory I'm not a PHP person, I cannot be more specific, but hopefully this helps you ...

0
source

All Articles