Is there a way to find images of a certain color from certain sites?

First off, I don't mean Google Image Search!

I would like to give users the opportunity to select the hexadecimal color value, and then program the search (from the specified sites / directories on the Internet) for the image where the dominant color is the color that they indicated (or close to).

Is there any technology that can do this? I would prefer PHP / MySQL, but I would be willing to use other languages ​​if it were easier.


EDIT

With a few suggestions, I managed to find this: http://www.coolphptools.com/color_extract , which does a decent job of extracting the most common colors from an image.

The next step is to calculate the distance from the selected colors to the color you are looking for. I have no problem implementing it, but I don’t know how to best calculate the distance between colors ?

I looked at this site and google for a specific answer, but came up with a dry one. The tool above extracts the colors in hexadecimal color codes. I am currently converting this to RGB and using these.

Should I try to convert RGB to Y'UV? I am trying using:

sqrt(((r - r1) * .299)^2 + ((g - g1) * .587)^2 + ((b - b1) * .114)^2)

(based on the answer here: RGB to the nearest predefined color )

This is not very accurate. What should I change the color distance formula so that it calculates the exact color distance (to the human eye)?

+4
source share
2 answers

Interesting. First problem: "What is the dominant color of the image?" Most pixels probably have. What do you do with similar shades of the same color? Will you group around similar colors?

I would do it like this: Take all the images inside the search paths. Clusters are dominated by the colors used in each of them, and the largest cluster. You will have to play a little with the cluster sizes and the number of clusters. If this color is in a certain range of shades, saturation and brightness of your desired color, it matches.

+1
source

First, I wonder how you can crawl sites / directories to find a specific color of an image if you don't have a large list of websites. If this is not related to your question, then just ignore it.

Returning to your question, I personally think that this is an interesting question. Since this requires a lot of research, I just want to point out some ideas for you.

What you need to do is get the user-defined hexadecimal colors and convert them to RGB colors, because most of the image functions in PHP, which, as I know, work only with RGB. Now, if you have a list of directories that you can search for, just scan them and use some basic functions to get the contents of the desired web page (for example, file_get_contents or cURL ). If you have the content of a specific page, you will need to use the DOM functions to get the URLs of the images from that page (you can solve it yourself using: getElementsByTagName () and getAttribute () ), Now, assuming you keep the list The URLs of the images, now you need to get their colors and try to match them with the colors you specify (don't forget to convert everything to RGB).

In PHP, we have a very handy GD library that works with images. If your server supports GD2, you can look at imagecolorclosest () . This function "Returns the color index in the palette of the image" closest "to the specified RGB value." Note that the function returns only the closest match (it doesn’t exactly match), so you need to make some comparisons to select the correct images (I find this easy because now you have RGB colors with very convenient values ​​for work, say using some method of subtraction and adjustment).

In addition, not only images, when you have certain content on the page, you can try to find the color scheme of this page (getting its value "background-color"), there are quite a few details that you can get and play with :) Of course, the image color is somehow related to the colors of the page styling scheme, to think logically wider.

If I say something incomprehensible, feel free to comment on my answer :)

Happy coding.

0
source

All Articles