Calculate RGB color values given amounts of two types of melanin

181 Views Asked by At

I've been trying to create a function that can take values representing amounts of eumelanin and pheomelanin and return reasonably accurate numbers for red, green, and blue that I can use to tint a picture of white hair to a new hair color.

Eumelanin is often misrepresented as brown, but it's actually gray with a slight blue cast, as seen in gray hair. Browns come from combination with pheomelanin and perhaps heme. Pheomelanin is yellow or orange, varying in hue with concentration similarly to Seymour’s rule of ink hue shift. I don't know the exact spectrum of either one. When both are absent, you get white, but "black" hair with high concentrations of both seems to have a slight green cast (though that might be from lighting).

Trying to simulate all of this with factors and exponents has given me days' worth of problems, most often numbers going into negatives, certain natural colors not appearing, and unnatural colors appearing where they shouldn't. At this point, I think I just don't understand the math well enough to select the right operations.