 If you've taken photos before, you might realize that there are some areas that are too bright and you can't really see what's going on in there. And so photographers will tell you that there's a solution for this. You just take more photos and then you combine them together on the computer using a high dynamic range algorithm. And as any business person will tell you, the right platform to implement your solutions is always Microsoft Excel. So I thought long and hard about this and the conclusion I came to was that we need to do HDR in Microsoft Excel. So I'll just skip straight to the background. So let's try to think about what we might need for an HDR algorithm. So let's say we have these two pictures here and one's brighter than the other. So we'll just take these areas that are kind of blown out and copy and paste them from the darker picture where they're a little more detailed to the brighter picture. And we also need to brighten them up a little bit because the picture on the right is brighter and we want everything to match up. Now the problem here is that we don't know how much we should brighten up this image. So let's learn about cameras for 30 seconds. This is a shutter and it opens and closes to let in light. Now the longer this shutter is open, the more light is going to come in. And this principle is called reciprocity. So if we open the shutter for twice as long, we're going to let in twice the amount of light into our camera. Okay, so I'm just going to go through, take all these numbers in my image and multiply them by two times. And we're good, right? But it's not that simple because there's this thing called nonlinearity. So I have this chart here and what it shows is basically how the camera responds to different amounts of light coming in. So you can see here that if we increase the amount of light on the bottom axis by the same step each time, we're going to get a different number in our JPEG file when we take a picture. So two times more light doesn't mean you're going to get a twice as big number inside your file. So if only we had some way of knowing what this function in our camera is, we would be able to fix our images so that this statement down here is actually true. And fortunately, we don't have to figure this out for ourselves because I'm smart kids in the 90s at Berkeley already did. But the way they solve this was with a lot of math and a lot of equations. And this is making our business people kind of bored. But it's OK because I told them at the beginning that I'm going to explain this using emoji and pictures. And now there's a lot of synergy right now. So let's get started. Back to these three pictures, but I'm not going to look at the whole thing. I'm only going to care about these pixels in the roof. So I'm looking at the same location in three different images. And I'll tell you that this first pixel has a brightness value of 31. And because we took these pictures, we know that to get from the first picture to the second picture, we let in twice the amount of light as before. But we're also not tricked by this because we know we're not going to get 62. We're going to get something slightly different. And the same thing happens when we go from the second picture to the third picture. We get twice the amount of light, but we're not going to get a number that's twice as big. So now I'll take these data points and I'll rearrange them on a graph. And this is the same thing we saw earlier. So this tells me that when I open my file and I see 31 here, and then when I open a different file and I see 78 there, I know that the difference between these two pixels is twice the amount of light that was coming into the camera at that time. And so this is just the information we get from looking at a single location in the image. What if we could look at every pixel in the image and collect a bunch of data that's just like this? And as it turns out, when we do that, we fill in all these gaps in the middle and we recover the g function, the function that we were looking for earlier. OK. So now let's write all this down using math. So of course we know there's some function that we don't know. And it takes in the amount of light and gives us a number that we can store in our digital files. And we also know that the amount of light is just the brightness multiplied by how long we let the shutter stay open. So now I'll just give these some letters. And this function f doesn't actually do what we want. It takes in light and gives us a digital number. But in this case, we already have our digital files with our digital numbers. So we actually want to go the other way. So I'll invert this function f. Then I'll just rename it. So I'll make another function g that is just f inverse. And this function g is the one that we want to recover. Now, this equation down here, I've written it as one equation. But it's actually a template that can be used to create many equations. So for each pixel value in our images, for each z value, we're just going to write this equation out another time. And we're going to end up with one equation for every pixel in every image. And so this system of equations, when you solve it, it gives you the g function that we've been looking for. So OK, now let's solve it. And the way you do this is you use linear algebra. So you put everything into a very big matrix. And then when you solve this equation, you get your answers out. Now, I didn't really understand how to set up this problem. So I googled around. And basically, this is what I found. This is how you slice and dice your pictures to form those matrices. And so I was like, all right, sounds good. So that's how we set it up. And now we have to solve it. And to do that, we need to invert this matrix A here. That's the key part of solving the system of equations. And there's two types of inverse. There's a real inverse, and then there's a fake inverse. And this plus sign means the fake inverse. But as it turns out, Excel only has real inverses. And so I googled around some more. And I found this website that told me how to rewrite this fake inverse in terms of only things that we have available in Excel. And you know that this equation is legit, because it comes from a website called MathAss. So that's what we're going to go with. Now it's Microsoft Excel time. So I put all my data into this spreadsheet. I made the images black and white. But you can't really tell what's going on here. It's just a bunch of numbers. But don't worry, because the business people have us covered. They have this thing called conditional formatting, where you give it one color for the bottom range, another color for the top range, and it fills in everything in between. So now all we have to do is make our cells square. And then once we set the zoom level here, so that's the first step to turning Excel into an image editor. So I did this seven more times for all of my images. And after that, Excel started using 13 gigs of RAM. So like any obedient Microsoft customer, I rebooted my computer in order to continue working. And so the next thing I did was I just started entering more things. This is all of the shutter times for all my eight pictures. And we don't want to use the entire image in our calculations, because it's pretty big. So I'm just going to pick a few coordinates to take out and use those values in my calculations. And it's starting to get very complicated, and you can't really tell what's going on. So we need to leave comments in the program that we're writing in Excel. And the way to do that is you use WordArt. But if you zoom in here, there's a little bit of a problem. These are all really boring styles. I want the rainbow one and the 3D one. But fortunately, fifth grade me had the foresight to save one of each type of WordArt into this file. So now all I have to do is copy and paste. And so now you know exactly what this sheet is trying to calculate. And so this is the first step on the road to success for this project. Now this is another sheet that uses the sheet I made before. So before we were picking which coordinates we're interested in in the image. And this is actually pulling out the values at those locations. And so I have one column for each image. And this is just reformatting it for my next sheet, which is also zoomed out at 10%. And it's so small that we don't actually look at the numbers. We just look at whether there is a number there or whether it's zero. So if there is a number, I basically make it red. So you can kind of see the shape of this A matrix. Then I solve it. And this is the g function that we've been looking for this whole time. And this equation up here, this formula up here, looks kind of long and confusing. But it's just the way that you write this thing that we saw before in Excel. So I've pulled out this g function here. And as we remember, this is going to take our digital number and give us a brightness value. But we're not quite there yet. We still need to output our final image so that we can get into National Geographic, because this isn't going to make it. And this got so long that I had to edit this formula in Sublime, but it's actually pretty simple. This basically just calls into this g function to get the light intensity. And then the rest of it is just doing some fancy averaging. So I pasted this into my spreadsheet. And it actually took about 30 seconds to calculate, but I cut that part out. And so this is our final result. So you can see here that the windows on the right, you can actually see the stained glass artwork where you can't on the left. So you can tell there's a picture of Jesus on the cross and some other stuff in the other windows. And so this means we're successful and our business people are so happy now because they can uninstall Photoshop and only use Microsoft Excel. So that's all I have. If you like this, please go to my website, click on LinkedIn, and don't forget to endorse me from Microsoft Office.