Mixing two RGB color vectors to get resultant

前端 未结 4 1676
粉色の甜心
粉色の甜心 2020-12-06 05:28

I am trying to mix two source RGB vectors to create a third \"resultant vector\" that is an intuitive mix of the first two.

Ideally, I would be able to emulate \"re

相关标签:
4条回答
  • 2020-12-06 05:44

    I think you should really define what is "+" in your color scheme.

    Based on your requirements, I've translated them into estimated hex color codes, (rgb represention can be deduced easily).

    RED     + BLACK   = DARK RED  
    #ff0000 + #000000 = #800000
    RED     + WHITE   = LIGHT RED
    #ff0000 + #ffffff = #ff8080
    
    optimally, also with real paint characteristics:
    RED     + BLUE    = PURPLE
    #ff0000 + #0000ff = #800080
    RED     + YELLOW  = ORANGE
    #ff0000 + #ffff00 = #ff8000
    

    I do not see a definite pattern which you can work out some formulas to achieve that.

    John's and Nils' methods probably will come close to the colors but probably not to the exact values. I suggest you give theirs a try.

    EDIT:
    Updated the wrong color codes. Well it does made a lot more sense now.

    0 讨论(0)
  • 2020-12-06 05:47

    Is what you suggested the same as a weighted average?

    Average R = w1*R1 + w2*R2 + w3*R3 + ... + wn*Rn
    
    Average G = w1*G1 + w2*G2 + w3*G3 + ... + wn*Gn
    
    Average B = w1*B1 + w2*B2 + w3*B3 + ... + wn*Bn
    

    The w's are the weighting fractions and the sum of them is 1.

    R1 is the red component of the first color to mix, for example.

    So if you wanted to mix two colors evenly, it would be:

    Average R = 0.5*R1 + 0.5*R2
    
    Average G = 0.5*G1 + 0.5*G2
    
    Average B = 0.5*B1 + 0.5*B2
    

    As for mapping the resultant color to a named color ("dark red") maybe just do a lookup table and pick the closest one?

    0 讨论(0)
  • 2020-12-06 05:57

    The problem is that you're trying to relate two different color theories. RGB is additive color theory (colored light is emitted from the source). In this case the more of the spectrum you add to the mix, the closer you get to white.

    For "paint mixing" you need to emulate subtractive color theory which governs the way reflected colors are mixed. (i.e. reflected light such as paints, different surfaces etc.) Here's an overview.

    The JavaScript on this page is a clue as to how you might proceed in converting RGB to CMYK.

    0 讨论(0)
  • 2020-12-06 05:59

    Mixing RGB colors to simulate subtractive color mixture (i.e., paint-like mixture) can be done by transforming the RGB values to spectral reflectance curves, then doing the mixture there. This question is very similar to another, stackoverflow.com/questions/10254022/, where the solution is discussed in more detail.

    0 讨论(0)
提交回复
热议问题