首页
22 条评论
bobbyi_settv将近 5 年前
Using the distance of the colors in a Euclidian space makes sense, but RGB isn't the best space to use.<p>You probably want something like CIELAB which is (quoting from Wikipedia) "designed so that the same amount of numerical change... corresponds to roughly the same amount of visually perceived change."<p><a href="https://en.m.wikipedia.org/wiki/CIELAB_color_space" rel="nofollow">https://en.m.wikipedia.org/wiki/CIELAB_color_space</a>
评论 #23497694 未加载
评论 #23496903 未加载
评论 #23499049 未加载
评论 #23497213 未加载
rozab将近 5 年前
This seems like a really fun problem and I think you found the solution with the best cost/effort ratio. The first thing that sprung to mind on seeing the problem for me was to use the fact that products often come in several colour variations but use very similar images for each. If you mask out the parts of the image that are similar you can get the single 'actual' colour as it might be labeled by a human. This would also allow you to search for neutral tones like grey and black.<p>And seeing as you've gone to all the trouble of figuring out how to grab dominant colours from images, why not allow users to upload an image of their logo and grab the dominant colour from that? This could help avoid the problem of having noticably different shades, without making the user do anything technical like searching with an RGB value and a threshold.
julian37将近 5 年前
You'll get better results using a perceptually uniform color space [1]<p>CIE76 is not ideal but would let you continue to use CUBE.<p>You could consider doing a first pass with CIE76 and then sort by something more accurate in a second pass.<p>[1] <a href="https://en.wikipedia.org/wiki/Color_difference" rel="nofollow">https://en.wikipedia.org/wiki/Color_difference</a>
aasasd将近 5 年前
> <i>I just took the euclidean distance between the given color and (0,255,0)</i><p>If you used HSL, you possibly could match on the hue while being more lax on the brightness and saturation—so a pastel-pink color could still match to a red image. Not sure if the database can use different weights for positions in a vector (though with pre-processing S and L could be collapsed to narrower ranges, so they match more freely afterwards). Just need to make sure that white and black aren't matched to random hue values.<p>Though, I guess if you use only the distance to fixed chosen high-saturation values then it's about the same thing.<p>Except it seems that with just RGB distance, a semi-saturated cyan or yellow color might be counted as closer to ‘pure green’ than dark-green. Something like (0,255,180) vs (0,70,0).<p>Also:<p>> <i>values('(${ color })'</i><p>2020 and still no placeholders.
评论 #23496374 未加载
Angostura将近 5 年前
I'm only marginally technical, but I would like to congratulate the author for a great example of how to explain the issues, the sequence of problem solving and the solutions so clearly and entertainly. Very good writing.
评论 #23499031 未加载
kinkrtyavimoodh将近 5 年前
This might be a dumb question, but what does coffee have to do with this task?
评论 #23497122 未加载
LoSboccacc将近 5 年前
the palette approach is a little reductive. we've built a solution in this space, a more robust approach would be to get the dominant colour, and from that colour brightness and tone extract the accent colour and the contrast colour by considering both distance from the dominant and extent on the image, that solves the problem of having a weighted palette ignoring, say, a red stitching because it's too small
评论 #23495766 未加载
评论 #23495936 未加载
njudah将近 5 年前
I wrote a tutorial a while back on how to do this in Postgres using the Google Cloud Vision API in case its useful for anyone..<p><a href="https://medium.com/@adamgross_6978/getting-started-with-json-and-postgres-782cba93c706" rel="nofollow">https://medium.com/@adamgross_6978/getting-started-with-json...</a>
crawdog将近 5 年前
I like the color pallet option you provided showing the primary colors. Adding the colors as facet options would be interesting since you can align each of the colors with the items, then maybe a numeric metric you can use to sort the results by the percent coverage of that color.<p>Another item to consider is also taking into account how the user might search - "red shoes", then classify the query as "color: red" & "shoes".<p>The next fun challenge is determining which image to display if you have a variant product (color/size combination for clothing for example). Figuring out which product image to show in the result set requires identifying the primary color in the search.
jbmsf将近 5 年前
Always happy to learn about more good ways to use PostgreSQL!
maurits将近 5 年前
Mike Bostock (the d3 creator) has a nice little demo illustrating the use of linear RGB to assign an average color to an image. [1]<p>[1] <a href="https://observablehq.com/@mbostock/image-average" rel="nofollow">https://observablehq.com/@mbostock/image-average</a>
thdrdt将近 5 年前
Vibrant.js [1] also does this.<p>It is nice to look into the source code to see how it is done.<p>But in my experience it works around 80% of the time because there are so many exceptions.<p>[1] <a href="https://jariz.github.io/vibrant.js/" rel="nofollow">https://jariz.github.io/vibrant.js/</a>
snemvalts将近 5 年前
There's a classic injection attack when interpolating in the SQL query<p>Also as others have mentioned RGB space and human perceptible color space is different enough that distance in RGB doesn't equate to difference/similarity between colors
评论 #23498952 未加载
评论 #23498325 未加载
tomcam将近 5 年前
Impressive. I wasn't expecting that approach! The whole thing implemented as a stored procedure in PosgresSQL a data type (cube) I didn't even know existed. That was a wild ride for me.
kelvin0将近 5 年前
Great article. However in my experience, using the Euclidean distance in RGB space can bring about some really weird visual 'matches'. The best color space I've found so far for this type of task is the L<i>A</i>B color space.<p>And there are also other tricks of the trade. But for starters this simple solution might be enough.<p>This solution also assumes the colors in the images are 'calibrated' and are consistent. This is almost never the case, but may be overlooked in for the given use case.
alphachloride将近 5 年前
I don't believe coffee (good or bad) contributed to this article.
评论 #23495621 未加载
yoava将近 5 年前
Good article, and I like the implementation.<p>I am sure it has some drawbacks, like distance on the rgb space may not be the best option, or that it does not ignore background color of it is not transparent, still, I like the way of thinking
raldi将近 5 年前
What does the title refer to?
lmilcin将近 5 年前
I really like this title: "Can we implement something easier than a Convolutional Neural Network?"<p>Nice to see people still remember problems can be solved with anything else than, ehm, "AI".
ponker将近 5 年前
I thought this was going to be about how coffee is a consistent color so you can white balance your customers uploads by asking them to photograph coffee in their ambient lighting.
评论 #23495759 未加载
评论 #23495858 未加载
评论 #23501723 未加载
shalmanese将近 5 年前
xkcd did a perceptual color survey a few years ago: <a href="https://blog.xkcd.com/2010/05/03/color-survey-results/" rel="nofollow">https://blog.xkcd.com/2010/05/03/color-survey-results/</a><p>It's population specific to the type of people who read xkcd but it's an interesting starting point if you want higher resolution info on, eg: exactly where people draw the line between "green" and "blue".<p>Raw data is here: <a href="http://xkcd.com/color/colorsurvey.tar.gz" rel="nofollow">http://xkcd.com/color/colorsurvey.tar.gz</a>
ComodoHacker将近 5 年前
Nice write-up, thank you.<p>Nitpick. What's the point of writing a good guide with rich text and images, but showing end result only in video? I have embedded YouTube videos disabled by default, so it's a little embarrassing.
评论 #23495982 未加载