I'd like to give you an explanation here about what map algebra is, and to use the calculation of the Normalized Difference Vegetation Index, or NDVI, as an example of using map algebra. So, map algebra is typically as far as I would think of it a local function. So, a local function just means that you're applying a calculation to one cell at a time, and that can be one cell and one dataset, or it can be that same cell across multiple datasets. So, for example, if we had two different datasets that represents snowfall amounts in centimeters for two different months of the year for the same location, if we just added those two together, that would be a form of map algebra. So, here we would take the same cell in both datasets. So, we have a five in the January file, and a 10 in the February file. Of course, we're just adding them together here and that gives us a 15. The operation then moves over to the next one and repeats, and does that to fill in all of the values for the entire operation. So, the term map algebra was coined by a GIS pioneer named Dana Tomlin and it's a really powerful idea. Simple as it may seem right here, the main idea is that you are treating each map layer as a variable in an equation. So, here literally, we could just be able to express this as in, for example, a plus b equals c. So, yes that's a very simple equation, but what is happening in terms of how this is implemented or how the software is actually doing it, is that a is the value here, and here, and here, and then it's the next one here, and then here, and then here. So, it's taking that equation and applying it to those same data cell values across those datasets to perform the calculation. As you can probably imagine, the map algebra equations can get as sophisticated as you want. Literally, you can do any kind of math you want. So, this is used for things like the universal soil loss equation, for heat modelling, albedo, urban heat islands, anything you want. Any kind of mathematical model can be applied to an entire area, geographic region, using this map algebra approach. So, it is in some ways very simple, but it's also a really powerful concept, and way of being able to think about your analysis. So, let's see how map algebra can be used to calculate the Normalized Difference Vegetation Index, and what that is, and why it's useful and how we do the calculation. So, like I said, this is just a way of kind of building a couple of different ideas here, one is map algebra, one is NDVI. Okay, so here we have a natural color image from the Landsat 8 Operational Land Imager, OLI, that's the name of the sensor on the Landsat satellite which the Landsat 8 is the name of the vehicle that is literally on. So, here we have an image that's natural color, and if we key in on things like the ravines, you'll see here that they show up as green because there's a fair amount of vegetation in them, they haven't been built on, so there's a lot of trees and shrubs in there. You can see high park over here, one of my favorite places to go. This is another ravine over here. Okay, and then we have the downtown area which isn't very vegetated at all, and of course Lake Ontario here. So, I'm just talking about this in terms of land cover and vegetation amounts as we go through this so you see how the NDVI works. If we look at the same locations, but now we're using a false color infrared version of the data, then we're able to highlight different things. So, one of the great things about this false color infrared combination is that anything that reflects high amounts of near infrared, which is being assigned to red in terms of the display here, will show up as bright red. So, we know the vegetation as we'll see, vegetation reflects a lot of near infrared. If we assign your fread to read on the image, that means anywhere that I see lots of red, there's probably lots of vegetation. So, you really even much more than you can see with the natural color version, you can really see these vegetated areas jump out clearly. Probably shouldn't be using a red pen color on top of a false color red image, sorry about that, but I think you can hopefully make that out. So, here we've just isolated the near-infrared band by itself instead of making it part of a band composite. Again, the idea here in terms of learning about interpreting remote sensing imagery and what is it that we're looking at, if we have a high amount of near-infrared, like a high value, then it's going to be closer to white in the grayscale, low values going to be closer to black in the grayscale. So, once again same thing. Here's our ravine. Because we have lots of vegetation, it is reflecting a lot in the near infrared. We have high values in the near-infrared band. Now, what's interesting is if we take the same image from the same day, but now we're looking at the red band, we see basically kind of the opposite, is that that ravine looks very dark in the red bands. That's because we get low values for vegetation in the red band because the plants absorb a lot of red light. So, same thing over here with the park, and the the Hunter Valley as well. So, I'm just trying to set up this contrast or comparison where the vegetation reflects a lot of near infrared and it absorbs a lot of the red. So, there's a big difference between those two bands based on how much vegetation there is. I wonder if we could use that somehow. So, what I did was I took some cell values for different land cover types from that image and I've plotted them across here. So, each of these across the bottom is one of the Landsat 7 bands, we have blue, green, red, near-infrared, and infrared far-infrared. Up the side here, we have the cell values for those. So, these are real values that I've taken examples of, so you can see what they look like, and how different they are. So, here we have water, and you'll notice that water reflects a lot of blue light as you can probably imagine. Less green, less red, and it goes down as you go through here, because water absorbs a lot of infrared light, and so that would be the spectral profile for water, for these bands with this sensor. If we look at buildings, we get a different spectral profile. So, they're reflecting more than water across all of the different bands, and a slightly different combination. Then we have what I'm referring to as a treat neighborhood. Lets neighborhood with a fair amount of trees in it, and you'll notice that we have a profile here where there's a fair amount of blue, less green, less red, and then it jumps up a bit in the near-infrared. So, in that band, we have a kind of a peak here, and then it goes down again for the rest of them. With a ravine, there's even more vegetation than you would have in this treat neighborhood, so we have very similar values for all of the bands, except there's a bigger difference here with our near infrared band. There's still a difference here in near infrared, and slight difference in the far-infrared. If we look at a golf course, which really even though it's not trees, it's just short grass, it's very dense. So, there's almost no space in between the blades of grass, if you think of it that way. So, there's actually a lot of vegetation, a lot of leaves, if you want, even though they are short and close to the ground, that are packed together in a small space. So, what do we have here? Again, very similar values across the visible part, blue, green, and red, but an even higher peak in the near-infrared. So, I think you may be able to see where I'm going with this. So, why is this happening? Its that chlorophyll and leaves absorbs red light. So, the more chlorophyll you have, the lower the cell values are going to be in the red band. Conversely, the leaf cell structure actually reflects a lot of near infrared light. So the more vegetation you have, the higher the cell values will be in the near infrared band. So, now that we've established that there's this inverse relationship going on here, where the more vegetation there is the less red and the more near-infrared, then there's this difference that's being set up that we can take advantage of and we can use that with our map algebra to subtract one from the other to see what that difference is and use that to map the amount of vegetation that we're seeing across a given area. So, just to boil this down, more leaves means bigger difference. We have a difference here with our treed neighborhood between red, and near-infrared. We have a bigger difference with the ravine and an even bigger difference with the golf course. All right. So, let's turn that into some kind of equation that we can use to map things. So really, I mean I'm literally just talking about a difference. So, you can subtract one from the other. If you just said infrared minus red. The reason you would do that is, infrared values are higher, the red are lower. So, this way we have positive values instead of the other way around when you'd have negative values. So, let's just try to be simple mathematical common sense, we're going to subtract red from infrared. So, you could just do that and be done with it and say, okay now we know what the difference is we can measure those. However, in order to be able to standardize these, in order to be able to compare these values from one scene to another. From one location to another. From one time period to another. It's helpful to standardize those values in order to make them more similar so that it's easier to make a direct comparison. How do we standardize that? We divide by the sum of the two. So, we calculate the difference for the numerator and we calculate the sum for the denominator. That gives us what's known as our Normalized Difference Vegetation Index. So, it's normalized because we're dividing by the total. That's what normalizing means and that's what turns it into an index. So, it's a difference. So, it's literally this is the normalizing part. This is the difference part and that by dividing one by the other and that's what gives us the index and that's where that term comes from of NDVI. It's a very common index that's used all over the place because it's actually quite simple to do, and it's quite reliable overall. Okay. So, find NDVI is a difference divided by the total. What I like to do is to run through some examples. I do this myself but I'm just learning about something to get a sense of, okay what are the possible values that I should expect to see when I do this? So, the most extreme version of this would be, okay if there was the maximum difference possible if we have an 8-bit image, which means that the highest possible values 255 and the lowest is zero. If that's the maximum difference that we could have, then if we subtract those two and divide by the total, then that gives us a value of one. So, that's really useful to know, is that the maximum possible NDVI value is one. You can't get any higher than that. So, we have lots of leaves. We have a big difference, that means we have an NDVI equal to one. What if there is not much difference at all? In fact, what if we have equal values for our near infrared and red? So, here we've got 50 and 50. If we use that, and we divide them then we're going to end up with a zero. So that means if there's few leaves, there's a very small difference. Of course, there's no difference here but it could be near-zero. But so, this is another extreme or marker if you want. So, that means that we have an NDVI of zero when there's basically almost no leaves at all. Now, we can actually have the opposite difference depending on what the land cover is. So, for example, with buildings, you'll see that the reflection in the red is actually higher than the reflectance in the near infrared. The same thing is true for water. So, we have higher values in red than we do for near-infrared. So in other words, it's possible to reverse this so that we have, again this is just an absolute extreme, is we could have a value of zero for the near infrared and a value of 255 for the red, and that would give us a minimum possible value of negative one. So, we can actually have a negative influence. So what that means is that, we have a range of possible in NDVI values from negative one to positive one. It's unusual that you'll actually see those values in any given image when you do it NDVI. You may approach those but don't expect to see those every time. Okay. So, here we have our two images. You can tell because the one on the left has areas that are darker, that's our red. Once they are vegetated on the right are lighter that's our near infrared. So, if we wanted to actually calculate this we can use a raster tool called the raster calculator. This is directly related to this idea of map algebra is that, they've built in this thing that's supposed to literally resemble a calculator. Where we have a number pad. We have typical operations that you would use. So, multiply, divide, and so on. Then, there's actually a whole bunch of more mathematical operators that you can use. There's a list of them there I'll go through all of them. But if you want to take the log of something or the exponent, or whatever those are in there too. So, I've just made this a little bit easier for you to read. But the what I'm doing here is applying this map algebra idea. So, here's our variables. These are our inputs, and those they call them variables and layers. Two are our map algebra equation and here's the equation here then I'm going to use. Now, remember all this is, is 4 minus 3 divided by 4 plus 3. Now, it doesn't look exactly like that here. So, let me just make sure this is all clear to you. So, why does this look a little more complicated? Well, because it's essentially turning this into a computer little equation program if you want. So, let me just break it down a little bit. So, the first thing that you may notice is that there's these float things here. Now what is that for? Because the inputs to this are integers but the output we want to have decimal values. So, in other words, if we have a range of possible NDVI values from negative one to positive one, if we want to have credations of values between those, we have to have decimals. Otherwise, we're only going to have three possible values if they're integer, negative one, zero, and positive one and which isn't that informative or useful. If we allow it to have decimal values by telling it to the output should be float, which is a way of saying decimals, then we can have a whole range of values between negative one and positive one. So, that's why those floats are there. In other words you have to tell it that you want to have decimals in the output. A very common mistake is to forget to put those in. You'll do your NDVI, you'll get the output and you'll see almost nothing on there and you say what happened, and it's because all of your values your either negative one, zero, or one. So, the next part that we'll notice is that we have the name of the band here. So, this is band five. The actual full name that I have in the original data is L8_band_5. I simplified it a little bit up here but it's the same data. It's using double quotes here, just to tell the software that that's the name of the file. Or the name of the roster grid, okay? Then, we want to put these in parentheses because the float operations parentheses. Then, we have parentheses for this whole part here. So that, this is all part of the subtraction. This is the division and then we have parentheses here because this is all part of the addition. So, we're taking this. We're dividing by this and that's going to do our NDVI. So, it's really important I think for you to get used to the idea of looking at something like this. If you're not familiar with using computer notation, syntax, things like that. Just don't let it get you all freaked out early on and what that looks like. It's really not that hard, you just have to break it down. So, what is this that's happening here? It's important to really pay attention to the syntax. That's the little details like whether it's a single quote, or a double quote. You can actually get the software to build this for you. So, you can click on here and that will actually add that in for you. You can click on the float and that will add that in for you. You can click on the operator here and that will add that in for you. If you do this in the right order, it should build that equation for you with all of the correct syntax. It's a great way to get started, but I would always recommend that you know what the syntax is just to make sure that it's doing it correctly. Or if you want to edit it in some way that you're able to do so. So, here's the results of our NDVI. We have values in our dataset between negative 0.25 and positive 0.65. So again, you're not going to always get exactly right to the extremes. I've done this as a grayscale on purpose just so you can see it. But conventionally, this is the color scheme that's often used. So, green is for high NDVI values and the reddish orange is for lower values. So, this all makes sense is that, for example, if we zoom in a little bit here, you can see the downtown area. We have fairly dark reddish values those are low NDVI values, whereas the vegetated areas are in green and those are higher NDVI values. So, it worked. In other words we performed our NDVI correctly. By the way you don't have to use the raster calculator to do this. Its actually a really handy tool built into the image analysis window. But I wanted to show you how this works in terms of learning how to perform your own raster operations.