How to average two (or more) hexadecimal color codes into one color code? #211145
Discussion TypeProduct Feedback Discussion ContentI am trying to find a nice, sky blue color code from an image I have. I have taken several samples across the image and have come up with a small list: #77A3E0, #7BA6DD, #7FAAE1, #6E9AD7, #6F9BD8 XXXXXX = RRGGBB = RR GG BB #77A3E0, #7BA6DD #77A3E0 + #7BA6DD = 77A3E0, 7BA6DD = 77 A3 E0, 7B A6 DD ((77 + 7B) / 2) = (F2 / 2) = 79 79 A4 DE = 79A4DE = #79A4DE https://meyerweb.com/eric/tools/color-blend/ https://www.utilitytoolslab.com/color-tools/color-mixer https://rapidtoolset.com/en/tool/average-color-calculator The UtilityToolsLab gave a range of results, but all gave the same answer for the 0% "midpoint", which is: #77A3E0, which is close to what I have, but not the same. I checked against UtilityToolsLab's multiple "midpoints" and none of those is what I came up with either. So, what am I missing for averaging tow or more hexadecimal colors into a sample average? |
Replies: 2 comments
|
Your approach is basicly correct. The part you're missing is the rounding. For your two colors the channel averages are: R: (0x77 + 0x7B) / 2 = 0x79 #79A5DF For all five colors in the question, that gives approximately: R = 118 => #76A2DC One small caveat: RGB hex values are normally sRGB, which is gamma encoded. For a physically correct color average you'd convert sRGB to linear RGB first, average there, then convert back. For colors this close together though, the difference will be very small. |
|
💬 Your Product Feedback Has Been Submitted 🎉 Thank you for taking the time to share your insights with us! Your feedback is invaluable as we build a better GitHub experience for all our users. Here's what you can expect moving forward ⏩
Where to look to see what's shipping 👀
What you can do in the meantime 💻
As a member of the GitHub community, your participation is essential. While we can't promise that every suggestion will be implemented, we want to emphasize that your feedback is instrumental in guiding our decisions and priorities. Thank you once again for your contribution to making GitHub even better! We're grateful for your ongoing support and collaboration in shaping the future of our platform. ⭐ |
Your approach is basicly correct. The part you're missing is the rounding.
For your two colors the channel averages are:
R: (0x77 + 0x7B) / 2 = 0x79
G: (0xA3 + 0xA6) / 2 = 164.5 decimal = 0xA4.8
B: (0xE0 + 0xDD) / 2 = 222.5 decimal = 0xDE.8
So #79A4DE is what you get if you truncate the fractional parts. If you round to the nearest integer instead, you get:
#79A5DF
For more colors, do exactly the same thing: sum each R, G and B component seperately, divide each sum by the number of colors, round, then convert back to hex.
For all five colors in the question, that gives approximately:
R = 118
G = 161.6
B = 220.2
=> #76A2DC
Also, a mixer showing #77A3E0 at "0%" isn't saying that's the avera…