A
A
alezzz2019-07-31 18:09:03
PHP
alezzz, 2019-07-31 18:09:03

How to find similar products by COLOR in the image?

How to implement a search for similar products (product images) on the site?
Like how it's done here or at least here
How I imagine the algorithm:
1. Indexing images on the site. Highlighting dominant colors for each product image. Recording in the database, for example, 5 primary colors and their percentages (ideally). Or a hash of the received values. In this case, the color values ​​should be "rounded", that is, there should not be thousands of grayscale values, but several tens at most.
2. The user uploads an image on the site.
3. Selects an area in the picture.
4. The area is analyzed by the algorithm from point 1. 5 colors of the selected area of ​​the image are calculated with "rounding".
5. There is a search in the database of goods according to the calculated parameters.
How to implement this on a site running on PHP? The main thing is how to implement point 1, especially "rounding".
UPD1: Thanks everyone for the replies. But, I realized that I did not formulate the question quite accurately. You need to look for images similar in COLOR . The shape and type of goods do not matter in this case. That is, when searching by the image of a red-green sofa, you can show red-green curtains. At the same time, if the sofa has purple legs, which occupy, for example, 5% of the image area, you do not need to take into account the purple color when searching.
And it is important that there are any red-greencurtains and not just those with HEX color values ​​that match the colors of the sofa. And it is necessary that the degree of similarity of colors can be set.
It seems to me that here you can do without machine vision, working with images and low-level languages.
Basically it's working with numbers. I found a similar question
here .
But it is not clear how to "average" the colors and cut off the colors that occupy, for example, less than 10% of the image.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
X
xmoonlight, 2019-08-01
@alezzz

https://github.com/jenssegers/imagehash
https://github.com/xwiz/phash
Look for the minimum Hamming distance and after - already on them look for pixel color ratios (RED25%/TOTAL, RED50%/TOTAL, ... , GREEN25%/TOTAL, GREEN50%/TOTAL,....): each color segment of one channel to the total number of pixels.
A color segment is a percentage over a color channel.
The closest fractions of the color you need - this will be what you need: similar with a specific color.

And it is necessary that the degree of similarity of colors can be set.
The width of the channel ranges and the unit distance between specific color ratios (fractions). Those. collect the prevailing colors in a cluster and compare not one color within the range, but several at once (from the cluster).
Reduce number of colors: here and see 1st comment!
PS: for now - you can do everything without the National Assembly.

D
dom1n1k, 2019-08-01
@dom1n1k

The advisers are a little stubborn. What other machine vision, what deep learning? Let's get the blockchain going.
The algorithm is something like this:
1. Pictures are transferred to the CIE Lab space. You can first reduce them to speed up (although with a decrease there are some nuances).
2. All colors in the picture are clustered and 2-3 dominant clusters are highlighted. There are a lot of clustering algorithms, read Wikipedia.
3. The similarity of the dominant colors of two pictures is determined by the DeltaE formula, it is also on Wikipedia. You don't have to bother with the advanced version of DE2000, most likely the usual DE1976 will suffice.

S
stkevich, 2019-07-31
@stkevich

This is the task of machine vision. No need to try to use php for this. Take python and NumPy for example.

T
ThunderCat, 2019-07-31
@ThunderCat

I didn’t find anything related to the search for similar ones, if this is the Compare Similar Items section, then stupidly averaged parameters are selected there, there is no magician with pictures there.
UPD: I found what it is about, but upon request, a fairly random game is issued. How is it related to the product - xs, perhaps with tags - the grid defines the object as a word (or possible objects-words in the picture) and then this set of words is searched in the description.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question