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?

  • $\begingroup$ Why don't try working in HSB ... seems much easier $\endgroup$ Commented Jan 17, 2012 at 4:29
  • $\begingroup$ Do you want to amplify regions matching exactly a color or do you want to make a more or less smooth amplification include colors close to your chosen one? $\endgroup$
    – halirutan
    Commented Jan 17, 2012 at 14:30
  • $\begingroup$ The second, I want to amplify a color range. $\endgroup$
    – martin
    Commented Jan 20, 2012 at 13:36
  • $\begingroup$ @martin, I would like to attenuate regions matching exactly a "True" RGB color where I know the bounding box x and y coordinates. How might I do that? $\endgroup$
    – Frank
    Commented Feb 14, 2016 at 8:32

1 Answer 1


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 & you can apply any method like Moore-penrose inversion to estimate the weights.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.