Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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?

share|improve this question
2  
Why not convert to HSB, perform the operations there, and convert back? –  J. M. Dec 13 '10 at 2:52
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$. –  Willie Wong Dec 13 '10 at 3:09
    
[real-analysis] is inappropriate. [functions] seems inappropriate too, but I have left that in. –  Aryabhata Dec 13 '10 at 3:16
3  
@Willie: In image processing, they call that gamma correction. –  Rahul Dec 13 '10 at 3:25
    
@Rahul: Thanks! Learned something new everyday. –  Willie Wong Dec 13 '10 at 3:45
show 2 more comments

1 Answer

up vote 3 down vote accepted

(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. )

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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