M
M
misha912012-08-28 18:41:42
JavaScript
misha91, 2012-08-28 18:41:42

How can I determine if a color is a shade of white using RGB?

The algorithm itself is important, but if anything, the Javascript programming language.

Answer the question

In order to leave comments, you need to log in

7 answer(s)
M
Mezomish, 2012-08-28
@Mezomish

What is meant by "shade of white"? Something like "yellowish white", "bluish white" and so on?
The easiest way is to convert RGB to HSL and then look at the last component (lightness). How close it will be to one is your metric.
If you meant a shade of gray , then look at the saturation component.
Converting RGB to HSL is easy .

V
VBart, 2012-08-28
@VBart

R==B==G?

C
ComodoHacker, 2012-08-28
@ComodoHacker

A shade of grey, I guess.
Strictly speaking, it's just R = G = B. But in colors from the real world (in photographs, for example), this does not occur. Yes, and in the design of sites very light color shades are often used.
If this is taken into account, then the formula needs to be complicated. Offhand, let's calculate the distance in color space between the points (r, g, b) and (m, m, m), where m = (r+g+b)/3. if it does not exceed a certain threshold, we will consider the shade "gray".

K
Keyten, 2012-08-29
@Keyten

Shade of white???
Those. As I understand it, identify all the light colors. close to white. Light gray (#eee), reddish white (#fee), etc.
Well, then something like this:
function isWhited(r, g, b){ return r > 240 && g > 240 && b > 240 }
If you need to determine whether the color is gray, then like this:
function isGray(r, g, b){ return r == g == b }

@
@ngreduce, 2012-08-28
_

probably meant brightness.

N
niko83, 2012-08-28
@niko83

Determining whether a color is neutral or there is some kind of shade and which one, and how strong is the easiest way in Lab.
There is an excellent book dedicated to this color space alone (Margulis D.Photoshop LAB Color The Mystery of the Canyon and other adventures in the most powerful color space)
If you work in Photoshop and are not familiar with Lab, fill this gap urgently.

B
Bodigrim, 2012-09-09
@Bodigrim

According to the mind, as you have already been pointed out, you need to translate RGB into Lab and then calculate using the CIEDE2000 formulas .
If everything is not so serious, then you can simply calculate the distance in three-dimensional space from a point with coordinates (R, G, B) to (255, 255, 255):
dist = sqrt( (255-R)^2 + (255-G )^2 + (255-B)^2 )
- and compare the distance obtained with the experimentally selected boundary.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question