 Yeah, so this is a kind of a huge work with Stefan here. And I'm going to tell you a little bit about how we designed a new default color map from that problem. And how you can too, hopefully sort of, just like showing you color maps is boring. I hope you actually learned something about how this all works. So color maps, right? Color maps are pretty important in science because you have this problem like you gather a bunch of data. There's, I think, 440 numbers there. And you just look at that and it's like, what do you do? You can't make any sense of this, right? But if you have some nice, like, ordering of colors and then you map different values to those colors, and then you go through and you do that to reach your data point, suddenly you can see what's going on, right? So the color map is really important because it's the interface between your data and your brain, basically, right? The exact same data that over here makes a lot more sense, right? But not all color maps are created equal. So for example, this one in the upper left here is called JET. It is the current map.lib default. It used to be the MATLAB default for many, many, many years also. It's mostly famous for how much it distorts data. There's like a big literature on this, like literally dozens of papers about why you should never use JET. Just to pick one, I think it's particularly something. So Birken et al did this like a user study. They had a bunch of doctors who used this tool to look at these imaging results on arteries to try and figure out if these people have heart disease. Like, do we need to intervene? Like, what's going on here? And of course, the tool they actually use every day is one that uses this rainbow JET kind of color map up here. Because, yeah, that's just the default color map everyone uses. And they tried comparing it to some sort of more rationally designed color maps over here. What they found is if you ask the doctors, which of these color maps works best for you? What do you like? They said, oh yeah, the JET one. They practiced with it. It's nice and colorful. They like it. But if you actually look at their performance, then when they're using JET as compared to these, they're about twice as slow and they make more diagnostic errors. Right? Like, JET, like, people's matter, right? I mean, that's a joke, but like, it's true. Like, you know, it may have killed people. I don't know. So, right, so can we do any better? Okay, so if we want to do something better, we have to decide, like, what do we want to do instead? Here's one sort of possible candidate that might come to mind. It's called Perula, sort of a funny name. It's named after this bird, Perula Americana. This is MATLAB's new default I finally switched to last year after inflicting JET on the rest of us for decades. It's not grayed, maybe? I don't know. The projector's kind of not showing it to its best light here actually. But it's a lot better than JET. You might think, okay, let's, we could just use that, keep it easy. Except, if you ask, let me say, no, no, we put a lot of work into this so you can't have it. So, I mean, I'm not going to say, like, the math work, like, wants you to die, but I might kind of humorously imply it. Like, okay, fine. We're not going to use Perula. I'm sure it's not that great anyway. We'll just make a better one, right? Finest open source strategy. How hard could it be? This slide also, like, for instance, explains why it took me seven years to finish my PhD. But, yeah, Rick or you? We'll get into sort of the, well, actually, so, you know, right, what makes a color map good or bad? Right, so we have to decide this. So, well, one thing that people, a default color map should probably be colorful because people like that, if you want them to actually use this, and pretty for the same reason. It should probably be sequential. So, it's opposed to, like, diverging or circular or these other kinds of color maps that assume some structure in your data. Because if it's a default color map, like, you don't know, like, for, like, a diverging color map, you know what is the center of the data, and then look at deviations from that. Or if you just, suddenly just plot something and it doesn't tell you anything about the data, you can't make that a new assumption. You just want a color map to just sort of assume that numbers get bigger as they get bigger. That we can be pretty confident. We wanted to accurately represent the data in this meaning, sort of, we call this, like, perceptually uniform. So, like, if it looks like there's a big jump in colors, that should mean that there actually is a big jump in the data. And vice versa, right? It would be nice, especially for a default that people sort of use all the time without really kind of thinking about it. If it works well, even if it's printed in black and white, because that does happen a lot. And because we are, you know, decent human beings, we wanted to be accessible to as wide an audience as possible. So we wanted to be usable even for people who are colorblind. So, okay, these, you know, top ones are kind of subjective or easy. These ones, you got to actually sort of think, okay, what is, that sounds nice. Of course, you wanted to be perceptually uniform. What is that actually, how do you do that? You have to know something about how color works and brains work and all that. So, let me quickly teach you all of color theory, so I can do that. Okay, it's not actually, yeah, it's a 15-minute version. But I think people have a lot of misconceptions and, like, there's a lot of sorts of weird folklore and such about color. It's not that complicated, actually, if you sort of know how it fits together. So I'm going to try and sort of give you that sort of a big picture how it fits together. And so then you will be able to go read Wikipedia and not just drown in a sea of acronyms. So, for scientists, right, to start from the basics, how does, how does this work? What's going on? So if you have some data and you show it using a color map, the first thing that happens is each of those data points gets mapped to some RGB value, which is just like some triple of numbers, which gets sent as a signal down to your monitor. The monitor fits out some photons. This is what photons look like according to Wikipedia. Those photons hit your eye, go into the lens, and hit the sensor at the back, the retina, which transmutes them into some sort of chemical, electrochemical signal, which gets shot out the back, down a nerve fiber to your brain. And then your brain does something with it, turns it into your subjective perception, the process that apparently involves lightning. So if you understand how, you know, what's going on with a color map, we need to understand these steps, like what's happening. The place to start actually is to look at how light and the retina interact, because that turns out to be, there's a massive simplification here that makes everything else a lot easier. So how does this work? Well, so people often talk about colors and lighter in terms of wavelengths, but that's actually kind of confusing, because when light is not, like, you can't talk about the wavelengths of light, because any given light source has lots and lots of different wavelengths in it. A single photon has a wavelength, but like an actual light has many, many photons, many, many different wavelengths. So, I mean, you could have a light that is just lots and lots of photons on the same wavelength. So, for example, this laser pointer is such a light, but most light sources have a mixture of lots of different wavelengths. All kinds of fatty stuff can happen. Now, when that hits your eye, your eye has three different sensor cells in it that are relevant for us right now. Call them one, two, three. And basically, each of them is sensitive to different mixture of wavelengths. And so what happens is this is just like a matrix product, right? We understand linear algebra. It makes things easy. What's going on here is we've got some high-dimensional vectors over here which are the actual, how the world really works. And then we hit these three different cell types, and that's this massive dimensionality reduction, right? There's many, many different vectors over here that get squished down into the same vector over here. And that three-dimensional signal of look actually goes to the brain. And so we can make our lives a lot easier in dealing with color if we, instead of trying to keep track of all these different spectra, which usually lots of them, distinctions there don't even matter because the eye throws it away, instead we'll keep track of all the different possible signals that come here. So each possible three-dimensional signal corresponds to this infinite high-dimensional hyperplane of different spectra that all are indistinguishable from our point of view. We don't need to worry about it. Okay, so let's, so what people did back in the 30s to say, okay, can we make a map of all the different possible, of that three-dimensional space? Give it a coordinate. Basically, you know, find a basis, right? Now, you might think the natural basis would be just to use these three basis vectors, but it was 1930, they didn't have any way to measure those. All they could do was measure what people find indistinguishable or not. And so you can find, you can identify the subspace but not the uniquely identified basis. So they just picked an arbitrary basis. So this is the one they picked. It has these three-coordinated axes called X, Y, and Z. So we're looking at a three-dimensional plot here, so imagine we're looking straight down the X, where they're all equal, right? It's coming straight out of the screen. So we're looking down at this three-dimensional coordinate axis, right? And you can imagine that whatever colors, the set of possible colors is not actually the whole space because you can't have negative photons, right? So in the high-dimensional space, it's just like the positive quadrant is the only, is the space of possible spectra. They have to get projected down. You have, you're going to end up with some sort of like kind of conical kind of thing coming out of the origin, right? And then sort of get a sense of what the cone looks like. We're going to take a slice through that three-dimensional space and look at a cross-section of it, right? So this is the slice of X plus Y plus E equals 1, right? So sort of the standard simplex. And when you take that slice, what you get is this classic kind of color shark fin diagram that you may have seen before. So, right. So, like, what's... So, right, this is, in fact, what you have then is this thing just sort of like an infinite cone like that coming out and we're just, this is a slice through. And that's what it looks like. Okay. So try and sort of get oriented. We can try and look at, take some wavelengths that we under, or sort of light spectra that we understand to figure out where they go here. So, for example, my laser pointer right here has that spectra and it lands right here. I have a red laser pointer, has a different spectra, right? And that spectra lands, like, right here. And you can see, one thing you can immediately see is that this diagram is totally a lie, right? Like the actual color I'm showing here because if this were actually showing all these different colors correctly, you would not be able to see my green laser pointer there because that would be what the projector was already showing you. Obviously that is not the case because, yeah, projectors are terrible. So, imagine, like, you know, all the stuff around the edges here really should be like extra super glowy intense, like the laser pointer. You can also... Yeah, what's that? What? So, it's going to be some kind of shape. And it turns out that it kind of has some curvature to it is just what happens if you take that high-dimensional thing projected down through those particular sensor cell basis vectors you have in your eye. Actually, let me come back to this in, like, one minute, right? Yeah. I mean, so this is only identified up to a linear transformation. So they sort of arbitrarily picked it, so the linear transformation is such that this would kind of not really fit inside the triangle. But, yeah, why it kind of has a curve to it? It's just kind of how it ends up working. But we'll say a little bit more about that, right? So one thing we can also do with this representation is useful is you might think, like, you might want to be able to predict what other kinds of wavelengths would look like, or a different spectra, right? So, for example, what if I have a light that consists of a mixture of these two kinds of photons? What will that look like? So that in the high-dimensional space, this is just like a mixture of these two lights, right? If you took two lasers and pointed them in the same direction, what you'll get was a light that had this spectrum. This spectrum is a linear combination of these two spectra. Linear combinations are preserved under linear projections, which means that in this space, the point corresponding to this spectrum should be the linear combination of this point and this point. So it should end up somewhere around here, is what we would think. In fact, if you do the experiment, you do. You get a nice talent. And so that also sort of explains something about this shape here. So what's going on here is this line on the edge is the set of all sort of laser-like, pure spectral colors. And the reason for that is that if you think in the high-dimensional space, these kind of laser-like spectra are a basis. They're the natural basis, right? The kind of light you can make by mixing together a bunch of single wavelengths, which means that the space of all possible spectra is the convex hole of these kinds of vectors. And that means you protect it down, that's still true. So here's where all the single-wavelength things happen to land. If you do linear algebra and then the space of all possible colors is just all the things you can make as a convex combination. So it makes a lot of sense, actually, sort of think back to freshman, sophomore, linear algebra. You can all kind of fit together. Okay. So that's what's going on with sort of light in the retina. And now this has this great simplifying thing. Now we can think about this three-dimensional space of colors. We try and identify these equivalence classes of spectra. And so now I'm going to think about the exact spectra. And now let's think about what's going on with the monitors. And the people who make monitors know about everything I just told you, and they take advantage of it. Instead of trying to make it so all monitors fit out to fit you, you give them a particular signal, they spit out a fixed spectra for that signal. Instead of their designs so that for any particular signal you can predict what XYZ coordinates you'll get. It may or may not be the same spectra. In fact, it will be different for different monitors, but it'll be different spectra that look the same. Okay, so in a way to monitor works, basically there's three little lights in each pixel. You can turn each light on more or less strongly. And like I said, we don't need to know exactly what photons come out. As long as we know where each of these lights are in XYZ space, how strongly each one's turned on, then hey, this is just like what we were saying about like mixing the lasers together, right? You're mixing together, if these are the three lights, which they ought to be for a good monitor, then these are the colors you can get, are the linear combinations of those, right? You can also see why the diagram is totally lie. It can only possibly tell the truth in that triangle, everything outside of stuff the monitor can't do, right? And so, yeah, and then there's just, you can go look it up. There's like a standard for like how a monitor is supposed to work for a standard, you know, computer monitor you have on your desktop called FRGB. Those are the three lights you use. This is the curve that maps. If you send like, you know, 10 or 100 or 50 or whatever as your number for how strongly should be turned on, it doesn't actually turn on, send out 10 or 50 or 100 times more photons. There's this nonlinear mapping. That's because this is how old cathode ray tubes work, and now we emulate them in software. So that's how it, you just, so yeah, you need to know what that curve is. Again, you just, you look it up, there's an equation of the standard that everyone's, all the monitors was originally written down as like an attempt to describe how monitors and actual use worked. Now all the monitor manufacturers look at this curve and try and match it. So if you know these two things, then for any given set of RGB values, say, okay, we'll use the SRGB standard, tell me how to interpret those, tell me which XYZ values I'm going to get. So we're doing pretty good, right? Now we know we can get some data all the way around to XYZ to figure out how, when we're trying to understand how our color maps work. All we got to do is do this little bit right now, just figure out how to go, just written that to perception. No piece of cake, right? So yeah, just as laughing because psychologist knows this is the diagram that everyone likes to scare like a neuroscience student, but this is a simplified wiring diagram of the early visual system. Each of these little boxes is basically a supercomputer. We're not, we don't try to like simulate this. It's not what we do. Instead, we just, we do some, but yeah, we kind of do some sort of curve fitting, trying to get built in simplified models and kind of capture the important parts. Probably the most important thing that's different between how you perceive light and how light, you know, the signal from your retina or whatever, is that, well, there's a lot that's different. First of all, I should make it very clear. Like just knowing like what's coming out of your retina does not tell you at all what something's going to look like, as, I mean, this famously shows, right, people, you know, wildly disagree on what it looks like even though they're getting the exact same light, right? All right, okay. Who sees blue here and gold there? Okay, how about the other one? What is the other one? Okay, yeah. I totally, okay. Who sees blue and black? Who sees white and gold? It's really compelling. So the reason for this is that your eye doesn't necessarily care like about the photons per se. Your eye's trying to figure out how does the world work. The lighting changes. Like if the light's redder or blue or yellow or whatever, that kind of changes the photons that you're getting from everything, but it doesn't change what the objects actually look like, right? Or it shouldn't. The objects stay the same. If you want to like trying your point of visions to understand how the world works, so you want to correct for the lighting. And so your eye's always trying to figure out, okay, what is the light source? And then I'm going to kind of sort of normalize everything against that. So if you think that you're kind of in a dark lighting and you get these kind of pixel values, it looks like white and gold. If you think you're in sort of a bright yellow lighting and you get these pixel values, which, by the way, are exactly the same in these two pictures. Because I, oh, I took out, no, they are. I promise that they are. Then it looks totally different, right? So it's not just about the pixels, it's about all this sort of complicated downstream processing. And in particular, because you have this kind of white point normalization, you might call it, the space of all... the space of all light is this giant, infinite cone, right? But in any given scene, there's like the brightest thing sort of sets, that's what white is. And then you divide everything by that. So in practice, you get the space of colors is sort of this finite blob, right? That's what does that. So this is kind of like a picture of the space of perceptual colors, what things actually look like. You usually do it. So there's one axis here, the vertical axis is from dark to light. And then there's two axes here. One is green to red and one is blue to yellow. And that's sort of all the different possible hues at a given brightness, right? Hues and degrees of saturation, right? So if you get towards the middle, it's sort of more gray. If you move out towards the edge, it's more like really, really blue or red or whatever. So this is a useful space to have in mind. This is the space of colors you get to play with and design a color map. There's lots of different models about how exactly to do that perceptual thing, the trying to sort of simplify how the brain actually works into something you actually use. The 1976 state-of-the-art model is sort of what you might expect from what I said. You take your XYZ value, you normalize it by whatever the assumed white point is. There's this non-linearity that's in brightness perception for whatever reason. There's non-linearity and everything about perceptions. So you approximate it with this cube root thing. And then you do a change of basis and you rescale to kind of move to a more useful coordinate space. Where one axis really is sort of brightness is kind of the idea. You can see this is a very simple model designed in the era when you would be doing it like with a calculator. There's a more recent model, 2002. The map looks like this. Three pages of equations. So to sort of compare and contrast, this is sort of what many people have heard of that's very popular or common to use. It's primarily designed as a model color distance. This other one I'm talking about, CKMO2, is state-of-the-art estimating things like brightness and hue. It's like, what does it actually look like? How blue is it? That kind of question. Which is much better at that than lab is. So for lab you can have colors that are allegedly the same hue, but they aren't. It's pretty common actually. Because they only really were trying to measure how far apart colors were. CKMO2 is really good at capturing hue and saturation and all those things. But it doesn't even try to be a model color distance. So we're actually going to use a third model called KMO2 UCS which is built off of CKMO2 so it sort of inherits all its good stuff. And then it sort of rescales things in such a way to make it also be a really excellent model color distance. So that diagram is showing you this is this KMO2 UCS space. The idea is that if you follow a line straight up or down it stays the same color and same saturation. It just gets brighter or darker. Everything at the same level like this is really is the same brightness. That kind of thing. Because of all those three pages of math trying to do it. But it's also the case in this space that the gradient distance between two points is a pretty good estimate of how similar a human would judge those two colors. So this is really nice. Now once we're actually working in this space then it's really you can sort of forget about all this. It's very easy to draw curves that have particular properties, whatever you like. So great. So now we know how to do everything. If you have some math to do you can convert it to X, Y, Z. We can do a bunch of math. Give an X, Y, Z guys. Do that for us. So it's pretty easy to do. And so with all these things that's enough to complete the circle. Now given some data we can see how does it actually look to people? How does your brain process it? At least that's for most people. But what about colorblind people? Remember? Not everyone actually you know has the same eye. So what's going on with that? So remember I said there's these three different kinds of sensors in the eye that are sensitive to different mixers of wavelength. There's four kinds of common color blindness and they all have very similar effects. So you see how these two sensors here look really, really similar. They're not quite identical. This one's like a little bit lower and a little bit more peak. But they're very similar. And what happens in color blindness is either one of those sensors is kind of messed up so that it becomes even more similar to the other one. It's not helpful. Or one of them is missing entirely. Right? And those are all relatively common. The ones where they can be more as actually like a client you can have more or less severe versions of this. So, okay. Okay, the facts about this. This is the one disadvantage in life that hits white men the worst. The reason is, well I don't it's just I don't know why it is that it happens to be the most common among European descent but it is by some amount. It's much more common among men than women because the genes that code for these two the proteins there, the one that gets messed up is on the X chromosome. Most men only have one X chromosome so if the gene's messed up, that's it. Most women have two X chromosomes so even if one's mixed up, well maybe you saw the backup. So if you look at the rate, and so the rate of among women is about the rate among men squared. That thing has to happen twice, yeah. And the effect of this is so those are very similar sensors but they do give you some sensitivity to some like particular bits of the wavelength of the spectra rather, particular wavelengths sort of right on the edges. The way your eye exploits that or your eye brain, everything put together you compute the difference between the output of those two sensors and that gives you kind of a nice signal for some particular narrow bits of the spectrum and that signal is mostly the red versus green signal. So we have these four different types so they all kind of have the same effect of making these two sensors output even more similar than they normally are and that has the effect of it kind of takes that red-green axis and kind of squishes it down partially or all the way if you're missing it entirely. So that's why you can there's these models you can read about, download, implement, whatever to try and estimate. So if this is what it looks like someone with regular color vision this is what it might look like to people with different variants of green color blindness. So how do these models work? They cheat a lot. So you first of all if you think about it right especially if you're in this, you know three quarters of people with color blind actually have three dimensions of vision just they have different sensors which means they actually are seeing a different slice of that infinite high-dimensional, super complicated reality, right? So you can actually have two colors that look identical to someone with normal vision that look different to somebody who is color blind, right? But like it's something like a photo like this the camera does not actually capture the spectra of the real scene, right? The camera's job is like hey it knows how regular people's eyes works it tries to first thing it does is throw away that high-dimensional space, reduce it to something that will let it reproduce what it looks like to someone with regular color vision it has no idea what it would look like to someone with color blind especially the anomalous trichromacy kind. So the way you deal with this in these kinds of like simulations of color blindness is you don't even try what you actually try to simulate is well okay, not what would the scene look like if someone with color blind was looking at it but what would this picture look like if someone with color blind was looking at it on a monitor? That's what the model is actually trying to simulate. And furthermore because you need to know the actual spectra being emitted it's not enough to know the XYZ coordinates and like we said different monitors vary on that so the model isn't even assuming trying to model what it looks like if they're looking at it on this monitor it's trying, if they were looking at this on a different monitor in fact I think for the model that we're using here just the one, because it's the one that's sort of easily available in literature they're trying to simulate what if someone with color blind were looking at this image as shown on a particular CRT monitor so you know, you do your best it's a useful tool it kind of gives you some approximation don't count on it for the details but it's useful I think kind of a sense of like how this actually works, it's not magic it's just sort of working through the math you might also look at this and think this is a really weird way to design a visual system right? like why is it that you have these two sensors that are almost identical and why is it that those two sensors get messed up in all these different ways but all kind of have these similar effects but not, you very very rarely see other kinds of mess up, like it's possible but it's like a thousand times rarer right? like what's going on here right? so as Kevin mentioned I spent three years in Edinburgh and one thing you learn if you move from California to Scotland is how much you know how important guacamole is and how much you miss it right? because it's amazing, it's wonderful it's delicious it does have one annoying feature though which is if you don't eat it immediately I don't know why you would not eat it immediately but if you don't, you let it sit for a while it gets kind of brown and icky after a while right? does anyone know what do you do to stop that happening? lemon lemon, yeah right? which is great because you think okay I put in the lemon it makes it stop looking terrible but lemon is also delicious but also makes it taste wonderful right? isn't that a nice coincidence right? so the lemon solves both these problems for us why does lemon help? it's kind of random the answer is because the problem here is that oxygen the air is very reactive it's attacking the various molecules on the guacamole and breaking them down oxidizing them lemon juice has ascorbic acid vitamin C in it which is a potent antioxidant it stops oxygen from attacking things like that which is also one of the reasons why your body really likes vitamin C because your body doesn't like being attacked proteins being attacked by oxidants either so you have to make sure you have vitamin C or you'll get scurvy and that is really not a fun time it turns out though vitamin C is so important it's such a useful molecule it's not very complicated or anything it's so important almost every creature in this world can make their own vitamin C it's totally immune to scurvy we're actually really weird that we can get scurvy so among all of mammals bats can get scurvy guinea pigs can get scurvy and primates at least heplerin primates can get scurvy like every other mammal it's kind of weird and what's going on here is that these are three different clouds that happen to have diets that are very rich in vitamin C just sort of by accident starting about that point in the evolutionary tree primates are basically living on like fresh fruit and like fresh newly spreaded leaves which have tons and tons of vitamin C in it and so what happened is you had some you know entropy who had a mutation in their gene they needed to synthesize vitamin C that messed it up so it didn't work anymore but no one noticed because they were getting so much vitamin C from the diet this was totally it didn't affect their life at all they still had kids and all of that and so over time just entropy happened and this gene just got lost and no one noticed until you know many many many millennia later like you have like the age of sale and for the first time you have people living on these like basically beef jerky for months at a time and the preservation process turns out it destroys vitamin C and terrible things happen so right that's what's going on with vitamin C and guinea pigs and bats also have diets different diets but also once it happened to be very high in vitamin C similar things happen another interesting thing about evolution is that most of the creatures on this picture in fact almost all mammals are dichromats they're like people on this one they only have two sensors on the right the reason for that is that we'll actually way way way back in vertebrate evolution almost all vertebrates actually have four sensors that's the ancestral form but the common ancestor of all mammals was probably like a nocturnal burrowing critter that that's a useful way to live if you want to survive the KT event to kill off the dinosaur but it means you don't make a lot of use of your color vision if you spend all your time underground or only come out at night and so the same kind of thing happened is with the vitamin C right you don't use it, entropy happens you lose it and so mammals in general are color blind in the sense that they have two sensors that have the three that we take for granted there's one exception to that among the central mammals are primates so starting around here you have polymorphic trichromats so this is sort of like trichromacy light the budget version so what happens in these critters is that you have the different genes of cells those ones I showed you the number one and number two but they're located at the same place on the chromosome so if you have one X chromosome, you get one of them sorry, that gives you two sensors total if you have two X chromosomes you might get the same one twice, in which case again you've got two total or if you have two X chromosomes that have different settings for that gene no, you can use both so something like a third of these critters, mostly basically all females are trichromats, the rest are trichromats and then in a few lediages they figured out another trick is why don't we take those two genes and make a copy of it so it's possible to have both at once even if you only have one X chromosome so this is why that last third dimension is kind of fragile this very recent thing in evolutionary time, the way we got it is that we took that existing gene and just made some little tweaks to it poke at it until the protein looked a little different was sensitive to a little bit different light that's why they have such similar receptive patterns and it's also why it's sort of fragile because those genes are very similar it's very easy for when things are getting copied around for them to get mixed up or to end up with sort of half of one and half of the other protein that's kind of as sensitivity kind of in between all that kind of stuff right? it also sort of tells an interesting story about the alchemy because for those of us with full three-dimensional vision this looks disgusting but if you're most mammals they don't look very different actually so the moral of the story is that it's not actually a coincidence it makes it tasty or end makes it look better in fact our ability to tell that it looks better is evolution's way of tricking us into eating delicious lemon okay, back to color maps I just couldn't resist enough time so hopefully you learned something anyway not about color maps so color maps so now we know how to take model regular color vision and also color blind color vision we can tell you okay how is this actually going to function how is it going to work is it actually going to be a good interface between your data and your brain do that we wrote some code to actually implement those transformations so you can try this yourself with the little color spacious library it's very easy to use you just say okay I have some coordinates in our sRGB space scaled to be from 0 to 1 and I want them in camo to UCS here you go is it's got this just like I showed you knows how to make all these little transformations from one space to another which we implemented using numpy and all that and this is where it's like yes, Python so you want that numerical stuff to figure out like how do you convert from you know sRGB, linearize to x, y, z whatever but then it's really hassle trying to like we actually try this trial, it was really annoying trying to like say okay first I convert sRGB to here and then to here and then to here so what we did is we said okay we'll just put this graph into the program this picture I'm showing you is actually dunked from the source code like the program knows this graph and when I say I got sRGB 1, I want camo to UCS okay, I'll just do a little graph search find a path and apply those in order done, so you don't have to worry about it yeah, nice having data structures right try doing that in that language, it's such a pain okay, anyway not that there's anything wrong with Matlab some of my best friends use Matlab okay, so we have this capability now another interesting anecdote while developing that of course it's hard to like know did you get those three pages of math right for example or did you have a Python somewhere unfortunately Mark Fairchild who wrote the book on the subject has a nice little spreadsheet on his website you can download that implements those calculations and it's great because normally spreadsheets are annoying in this case it's really nice because you can see all the intermediate results right there so when something goes wrong at the end point you can just track back and see where did your calculation diverge from here so I wrote a bunch of tests like plugging numbers into there and making sure mine matched except there was I kept fixing those bugs but I couldn't figure out what the bug was, I was getting a different answer what was going on here I eventually figured it worked out so I sent Aaron the spreadsheet so I emailed him just to let him know and he said, huh, that's funny I mean a lot of people have reviewed the spreadsheet no one's found any errors the last 13 years so like a moral of the story like test your code I don't know like I don't think like science is actually like being you know like a Cold War spy novel or something like that it kinda is just like sense of paranoia trust nobody your advisor probably isn't like a Soviet agent trying to backstab you but do you know that maybe you should write some tests okay let's actually okay we've got tools, let's use them now we built a little tool now to let us take a color map and see what's going on with it how does the color map work how good is that kind of thing so here's Jet you can try it yourself at home pretty easy so what you see up here is just that's the color map itself and then down here what we've done is we've calculated perceptually how far apart our adjacent points on this color map it's like a derivative if it's perceptually uniform so move smoothly this should just be a nice flat light so what's going on so like for example this big peak here is when it suddenly jumps from blue to green pretty quickly that really flat bit is there's just like it doesn't change at all for a bit there Jet is terrible don't let your kids use Jet over here we have the same thing just we convert to black and white first it's like if you look right there's a black and white printer and then the same thing for the black and white version again terrible here's the four different common types of color blindness not looking so great and then down here this is more useful in the interactive version if you actually run it this just takes the points on the color map and draws them in that three dimensional space we can sort of see what it's actually doing in fact let me just pull that up there's many options we'll talk later about some of the reasons why you might want one or another so here's the interactive version you can actually get a sense of how it's laid out and so you can see it has a sort of funny not very well thought out kind of you can also see these little dots are equally spaced in data space so if there's a big jump that means that it's not very uniform if they really squish together it means it's not very uniform and you can also see kind of what's going on with Jet so if I click this button it shows me this is the base of all colors you can actually show on a monitor and basically they're just like we want color! so we're going to go right to the edge of that space stay there that's kind of the design principle that underlies that and then over on the right here we just have some sample images we made up to to if you can sort of see how it works just now so I can compare it to so this is a version for Prula you can sort of see for example like on this is a topographic view of Mount St. Helens you can see Jet adds all these like sharp lines looks like a fried egg they're not really there or down here what you actually have are sort of these smooth how sort of moving through this area where they get higher it totally flips it it looks terrible it really distorts your data don't use Jet we can also then here's Prula Matlabs you can see it's not flat perfectly but doing a lot better than Jet notice the scale here that goes to 200 that goes to 700 it's a lot better though it does it is a little weird so it's got this big peak over here and if you the projector is kind of mangling everything but if you look at it on a good computer screen you it actually is kind of a weird bump there where it has this nice smooth thing and then it's just like blue weird little thing once you notice it it's kind of hard to stop seeing it they didn't even try to make it smooth in black and white space and you can see this they sort of how they designed it they have this kind of clever trick they dodged over into orange to get a little more length before finishing up with yellow yeah to make it a little give a little more variation yeah so what's going on with this why is it kind of distorted and all that well it turns out the way this color map was designed is they picked a curve and then they made it the point equally spaced in lab space right and here I'm using cameras in UCS and they're different so they get different results and which is better or why is Poole actually we thought okay, like chemo cheese is actually telling you something because we looked at it and yeah there is this weird blue hump can you actually look at it what's going on here well so it turns out if you look back to the literature there's lots and lots of literature on how do you design models of how similar colors are very like important in industrial and all things like that then colors that are far away C-lab and camo to UCS both do pretty well lots of different models all do pretty well about the same for colors that are very similar so to find distinctions lab is terrible right these numbers are, sorry are like error like you ask a bunch of people how similar are these colors how about these ones, these ones so yeah, lab is really bad at estimating similar between new by color so that's exactly what for a color map where you want it to be uniform that's what you need, you're like calculating like a derivative it's all about being smooth locally and camo to UCS is basically state of the art on both kinds of things notice also like these are mostly different all the other ones on here are mostly not even the same people design a model either for nearby colors or for far away colors camo to UCS is kind of unique it's not quite the very best for some of these, but it does really well at everything so that's why it's a nice choice for us so okay, so now we've seen why jet is really terrible and fluo is okay, but it could be better now can we go the other way given a description of like here's how we want it to work give me a color map like that we can, so we can say here's how the data, here's what I want each possible thing to look like and then you can take this mathematical stuff and invert it you can invert back to a color map so here's just a demo to show you how easy this can be say you want to have a circular color map you're trying to do a plot of angles so you don't want it to be that 359 degrees and 1 degree look totally different because I mean they will like 1 and 359, those are really different those color maps will quite rightfully make those look very different but if they're angles, they should look the same right, so how are we going to do this? Well I think, okay so I want an arc in that color space it should be a circle because that's what I want so I'm going to do is draw a circle with constant lightness and I'm going to take a bunch of points equally spaced along that and that will be my color map so we just say all right say 100 points, I'm going to set my brightness, it's called j prime that's the notation to be 75 I'm going to have a radius of 30 and I'm just going to do a little trigonometry to make a circle in 3D space with those corners jam them together and then just say all right, that's a circle in camera 2 UCS give me an SRGB right, and this one line of code here has 100 years of color theory baked into it you don't have to worry about it you just work directly in that nice space and you get as a nice circular color map so these are wind direction there's also, we've overlaid it with some darkness for wind strength and so you can see nice things like there's this shear here where the wind's going in opposite direction sort of smoother transitions as you move along and basically my goal in doing this is not that ah here is the great circular color map it's like I can do that that's exactly what I hope you're thinking right color maps don't have to be some weird mysterious thing right, you have the tools you have a little bit of understanding you can just build a color map doing whatever you want okay, now let's get back to our real goal here it's come up with a good default color map now we had our list of criteria so we can say all right colorful, pretty sequential accurately make it perceptually uniform that means we can draw whatever arc we like in camera to UCS space as long as we make our points equally we sort of move along in equal five steps, it'll be perceptually uniform make it uniform in black and white it needs to that tells us what we should do along the brightness axis it should be equal to five steps there as well so we can sort of work through it okay, so we know to be color blind friendly first of all, we want to avoid having red with green so our main axis of variation should be blue versus yellow and then like I was saying to be gray-scary or friendly we want to go from dark to light in a nice uniform way okay, so do you go from dark blue to light yellow or from dark yellow to light blue well, sort of intuitively there's an obvious answer to this question because there actually is no such thing as dark yellow or light blue and to say there is no blue that as bright as the bright yellow and there is no yellow that as dark as dark blue it's just a funny fact about how color space is shaped so you definitely want to go from dark blue to light yellow it gives you a lot more room to work with and so then there's basically only one choice left right, we know we're going from this corner to this corner now looking down on the space from above we could either go like this through green or like this through and we thought, okay well, so we could go through green but one, there's less space to work with that way you can see it just sort of bulges out more in the red direction it gives you more room to work with and anyway, Prula goes through green so if we want to sort of be the stinkers and show off our awesome color map maybe we should go through that kind of branding thing, why not so that's what we want to do we know how to design a color now we just have to solve the problem how do we actually pick a particular curve we wrote a little interactive tool, again you can just download this yourself and try it it looks like this so the trick here we know that on that vertical axis we're going to make just evenly spaced steps we need to know where to start and where to end but other than that, that axis is like totally determined by the grayscale friendliness thing so it's kind of hard to draw curves in three dimensions, we're going to collapse out that axis so we have these two little sliders down here let us change where do we start and where do we end in brightness so we can make it darker at the end brighter at the end but that's all we need to do and then this up here is like this shows us a horizontal slice through the space looking down from above and we can pick how we want to move in two dimensions by dragging around these little control points it's nice and easy interactive over here you see a preview you also see the biggest problem challenge in doing this is you want to make sure you only use colors that actually can be displayed on a monitor so it's staying in gamut so what this is showing is down here our curve is going out as possible colors, what's going on with that so if I slide down here we see the problem is I click down here, this chooses which brightness which slice through the space I want to show and we can see yep that little yellow point there is the point that corresponds to the line and it's in fact outside of the what the heck yeah no there's this is being displayed like transpose the thing in the background oh well do not install everything much better okay so let me pull it so we have a problem over here now here you can see right that's because if you slide this you can see the yellow kind of moves into the space it becomes okay so it's just a little video game keep a little yellow dot inside the colors and then when you do that it takes like two minutes to design a color map Kevin what's your favorite color green okay let's start with green it's kind of up here because these are dark if I slide it up you can see it better we'll start with like a dark green and Allie what's your favorite color blue okay let's end up with blue and what should we go through anyone maybe sort of through the magenta you kind of thing alright there we go oh I got it okay so this the bottom is supposed to be up in green and the top is supposed to be down in blue sorry okay it's not working as well this is why we need a separate person to drive so first let me make sure I'm actually okay so that's the top the top is supposed to be down here in blue here's the bottom but you want that to be okay now at least I'm unconfused now let's move this into green sorry into a green that's actually possible and let's move this into a light blue that's actually possible you can see it's not very good because there aren't a lot of blues we could try cutting make it so the brightest thing is not so bright so we get a little more and then we can say well let's make the middle sort of move out more towards sort of pinky red as far as we can go yeah great and it's a color map right that's all it takes it's really easy to do this is terrible this is a huge problem so now we've solved all these problems we can design a new wonderful color map in two minutes we're trying to get a group like this anarchist collective open source project to agree on one color map so this is sort of a classic failure mode of this kind of group it's called bike shedding this is based on an old story about some old management who watched a meeting of a like a planning board the first thing on the agenda was they had to build plans for a nuclear power plant they have this stack of documents like this high and they sort of flip through and they took beta for 10 minutes and they passed it no problem the next slide on the agenda is about the bike shed to be built next to the nuclear power plant this turns into a two hour debate about like what color should it be because it's a nuclear power plant that's kind of hard to have an opinion bike shed everyone's got an opinion on that so that's easy everyone wants to have their opinion heard respected and listened to and get involved in this case this is a classic bike tipping we're actually literally trying to decide what color to make the bike shed so to try and kind of keep this from blowing up and getting totally out of hand let's try to do this we designed three color maps 123, 123, ADC we said alright everyone here are three color maps tell us which ones you like this way people have a chance to see how they feel like they participated we can actually maybe hope to convert but it won't try to do a try so we did that send it out to the mailing list and sort of did the kind of straw hole then we got some really useful data back what we learned is that democracy is useless and we also had a bit of that problem I was mentioning because the tool is so easy we just posted it up and someone said hey so I just downloaded and I tried making a green color map how about this maybe we should add it to the list so fine have a green option we tweaked it a little bit and put it up option D and then we learned something else really interesting we thought we done a pretty good job of thinking through all the different complexities that are really digging in and making really like getting it right but you know you put something up for peer review people come up with things you didn't think of and it turned out there was a criterion that we didn't take into account a very important criterion started getting an email like this one plus one for option D because it has green in it that's the whole email there's no bodies it turns out people like green things and it's not just that one person that was yeah so okay so we said fine I don't care it's not yet that's the important thing so let me introduce here it is this is what it looks like this is an example the name is Latin word for green but this is Python in fact is named after a snake if you don't like snakes you could also pretend this name after a really pretty fish or if you have some application where like MATLAB compatibility is very important it could also be named after a bird so that's where it is we gave this talk at sci-fi like saying alright so this is what we're all going to use and people believed us so it was true so this is what MATLAB is in fact going to use when they get around to making a release with it as compared to Perula we have more variation in light versus dark less variation in terms of color they're both reasonable but I think Veritas is better I mean I would but it does avoid that weird little hump down there and it has one key feature which is you can actually use it for whatever you want and people are actually so immediately after we put this up Veritas for R download it if you want someone made a whole look at the school bar there explaining to our bloggers why you should use this giving examples and all that picking it up, hey what's the best color for a colorblind audience because people are complaining at these logical deciding minutes oh Veritas that's Veritas neither of those are me I promise people seem to be picking up on it you know back over flow someone asked a question about color maps in pgf plots this law tech plotting library well I love this thing so much let me do some publicity pair of you Veritas let's add Veritas to airing a show or rw2i or vizpi or vcf even available for MATLAB so so yay seems to be working so yeah we said MATLAB 2.0 big major release changing everything they're keeping everything the same except changing the default style you can read about it there and they are switching to Veritas it will be the new default no more jet, hooray we like it, maybe you do too maybe you want to use it, feel free if you don't like it, all of these are available they all have names now or you can make your own hopefully I've shown you it's not too hard and yeah