1
$\begingroup$

I want to create a function $f : [0,255]^3 \rightarrow [0,255]^3$ over the integers such that if you pass in three RGB color values, a triple with a darker or lighter color will be returned, and I want the values to increase in some sort of proportion to how dark or light they are already; lightness and darkness being determined by, say, taking the average of the values.

Is there a relatively simple function that will do this? If not, is there a way to emulate it?

  • 2
    Why not convert to HSB, perform the operations there, and convert back?2010-12-13
  • 2
    There is a bijection used by my dad when he taught elementary school to scale grades, which can be modified to be $h(x) = 16 * \sqrt{x}$ for $x\in [0,256]$. You can perform this entry-wise on RGB. To change the dependence on the starting value, you can change $\sqrt{x}$ to $|x|^p$ for $p < 1$.2010-12-13
  • 0
    [real-analysis] is inappropriate. [functions] seems inappropriate too, but I have left that in.2010-12-13
  • 3
    @Willie: In image processing, they call that [gamma correction](http://en.wikipedia.org/wiki/Gamma_correction).2010-12-13
  • 0
    @Rahul: Thanks! Learned something new everyday.2010-12-13
  • 0
    @[Rahul , Willie Wong]: Thank you both, I learned something too.2010-12-13
  • 0
    @Willie (I apologize for the late response) if you make that an answer I would be happy to accept it as such!2011-03-31

1 Answers 1

3

(This was a comment. Posting as CW answer so the question can be marked as solved.)

There is a bijection used by my dad when he taught elementary school to scale grades, which can be modified to be $h(x)=16 \sqrt{x}$ for $x\in [0,256]$. You can perform this entry-wise on RGB. To change the dependence on the starting value, you can change $\sqrt{x}$ to $|x|^p$ for $p<1$.

(And as Rahul pointed out in the comments, the above is nothing but gamma correction. )