How to amplify regions with specific color in an image? I want to amplify regions with a specified color in an image. For this purpose I have defined a simple function

$B(x,y)=s_r(x,y) \cdot w_r + s_g(x,y) \cdot w_g + s_b(x,y) \cdot w_b$

which produces a gray scale image B(x,y).

The weights I have defined with

$w_r \in [-2,2],w_g \in [-2,2], w_b \in [-2,2]$

The channels of the images are the functions $s_x$ for each channel.
I use the result of this amplification for a color thresholding. For example for yellow I have manually defined
$w_r=1$, $w_g=1$ and $w_b = -2$.
My Problem now is, to get "good" values for the weights automatically. First I thought taking the maximal values of histograms would be a good way, but the results are not satisfactorily. 

How can I automatically determine the weights for the amplification? 

How would you deal with white and black?

Or is there a better way to amplify the regions with a specific color?
Let us assume you are doing a binary classification with the desired color region set as 1 after applying your algorithm.
Then you can provide a set of color images (histograms) and desired outputs. The weights can be posed as the unknown quantities for this set of linear equations. Lo you have a overdetermined system &amp; you can apply any method like Moore-penrose inversion to estimate the weights.