How to average color

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
nice here if you're averaging color in Photoshop you can get different results for the same image this is also true if you just resizing or rotating pixel art is especially susceptible to this because you can have a high amount of contrast between neighboring pixels but the same thing happens in your phone whenever you straighten a photo let's look at this normal Minecraft painting and we'll use glass to represent pixels if we wanted to reduce the resolution by half the pixels are staying the same size so we need to recalculate what color each pixel is going to be same thing if we want to rotate it the pixel's resulting color will be the weighted average of the colors sampled there are many different ways to resample the colors and that's a topic for another video but no matter what there was always averaging and the differences I open with are because the math was being done in two different color spaces I was working on a video talking about texture noise and how to quantify it part of it deals with averaging colors and that led me down this little rabbit hole and I thought it was worth making a video about so let's talk about color averaging and why something that seems like it should be incredibly simple is actually complex due to old limitations in our dumb organic bodies if you're just dealing with the regular numerical average you add up your numbers and then you divide that by the total count of numbers if you're working with colors in srgb there are values for red green and blue and you can just average each Channel this is how Photoshop Blends colors in srgb by default but this average color is actually darker than either of the two starting colors you can see this in Photoshop when you use a brush with a feathered Edge it Blends the background and the brush color along the edges and you end up with this darker color and this is because srgb has something called a gamma correction applied to its values I talked a bit about this in the OK lab episode but our eyes don't have a linear response to light and I saw a good demonstration of this on a minute physics video which I'll duplicate here if you think about this in real life the difference between one candle and two candles is noticeable to our eyes but if you add one candle to 99 candles it is nearly an indistinguishable difference even though the amount of change from 1 to two candles and 99 to 100 candles is the same as then we are adding one candle more of photons the more light there is the less sensitive our eyes are however to a camera that change is the same amount so a gamma correction is applied to make it look right for our eyes this is just rooting the original value to some amount and for right now we're just going to say that the values are the square root of the real values and so when we are averaging these RGB colors we are actually averaging the square root and the problem is that the average of a sum of square roots is not the same as the square root of an average this makes a lot more sense to me visually so let's take a look at the colors in srgb the original RGB colors are on the ends and the averag is in the middle if we remove the gamma correction all the colors shift lower in the space and you can see that the average is no longer directly in the middle it's no longer the average the real average would be here if we reapply the gamma the better average moves up and is in more of an arc between the two colors we can look at the actual math for this normally when working with color we work in the range of 0 to one so first we divide everything by 255 and then we remove the gamma by square rooting our values and then we calculate the average for each Channel and then we just reverse all of that and this produces the color we saw over in the space I have seen people using just square and square roots for gamma usually like stack Overflow or some other programming sites when people are talking about color but while that's the simplest thing you can do to get better results it's still very easy to do better than that the best value for gamma is actually dependent on your viewing environment an image viewed on a screen outside will look different than in a dark room most movie theaters actually use gamma values of 2.6 now but lucky for us the srgb standard actually includes the expected light level for the room and uses a value of 2.4 for most of the range so if you're working with an srgb image and staying in that space this is probably the best you can do without taking the view environment into consideration which means me back to our block here I used the Photoshop average filter to get the values I used in the color world most of the Minecraft textures are in srgb and so the averages were calculated with the gamma still applied when I realized this I was curious how much of a difference it would actually make compared to other methods we can display all the colors present in the block and scale them based on their abundance as well as place the Block in its average location calculated in srgb if we remove the gamma you can see the color shift and how much that average color moves out of alignment with the other colors if we calculated the average color now without the gamma it would be back here we could reapply gamma to that new average and then use that as our value but that still isn't the best answer and for that we need to discuss the second problem srgp is not perceptually uniform I've done a video talking about perceptually uniform color spaces before but in short it's a space where the dist distribution of color is based on how our eyes actually perceive color and the colors are evenly distributed in the space some people commented that the colors look washed out in the examples that I used and yeah you're right our eyes like contrast the real power of a space like this comes from calculating color in it the space is nearly linear in all dimensions and so we can convert each pixel into okay lab and then do all of our averaging there removing the gamma is part of the conversion process to okay lab by the way and then we can convert all those different averages back into srg and see if it really makes a difference I've labeled the averages with the space they were done in and the difference is actually quite large about 15 blocks in total I did purposely pick glazed orange terra cotta because I think it has the highest contrast of any block and the higher the contrast the greater this difference is going to be I wanted to do this for all the blocks so I wrote a script that calculates the average color in two different ways we're going to start with the image that's in srgb and then calculate the average color just normally and then we can convert that average into okay lab we can also take that srgb image and convert it into okay lab and then calculate the average there and then convert that average into srgb and so in the end we'll have two averages in each color space in RGB we'll have the srgb average and the okay lab average and then in okay lab we'll have the okay lab average and the srgb average it's more confusing than it seems I'm going to load the blocks in and I will label them on the screen and we'll animate through both of these okay so we can summon in our our srgb average in srgb and then we can see the difference if the colors were averaged in okay lab and then converted back into srgb you'll notice that blocks that have higher contrast move more we'll go back to srgb and you can see that the glazed terracota blocks are going to be the ones that move a lot back to the OK lab average now let's look at the srgb average in OK lab and compare that to the okay lab average displayed in okay lab and the movement is a lot less this is because the space is more compact but there's still a pretty big difference between some of these blocks and okay lab is technically the most correct the best type of correct in my opinion there isn't a lot of good information out there that explains this Gamma or averaging very well or I should say that there is so much bad or incomplete information that it's not easy for a novice to figure out why certain things are done the way they are so hopefully this helps somebody going forward I'll be doing all of my averaging for the color world in the okay lab space and I do have a couple more things before I go here's a couple tips for better averaging in Photoshop if you need to do averaging you can change your mode to lab color and if you're doing any blending with brushes you can go to your color settings and blend RGB colors using gamma and this will fix the issues with the blending on the edges of the brush I took this out of an earlier part of this episode but I still thought it was interesting and so I'm just putting it here this is white concrete with every level of Sky M Block light level in Minecraft or any game really if you adjust the brightness slider you aren't just changing the bright brightness literally you are adjusting the gamma in Minecraft default is almost linear Moody dips down a bit and bright ramps up faster before leveling out all right that's it now I can get back to working on other episodes see you guys later bye-bye
Info
Channel: Gneiss Name
Views: 144,090
Rating: undefined out of 5
Keywords:
Id: e0HM_vfSuDw
Channel Id: undefined
Length: 7min 45sec (465 seconds)
Published: Fri May 10 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.