[MUSIC] Hello everyone, and welcome back. In this lecture, I'm going to show you how to calculate the normalized difference vegetation index, or NDVI. Which we can use to determine whether something is healthy vegetation, less healthy vegetation, or not at all vegetation, using remotely sensed imagery. I'll be using LandSat data that we downloaded in the last lecture for this, but it's a subset of it. I'm giving you bands one through five of LandSat, so you don't have to download it all and we'll use that to calculate NDVI. So initially, I'm going to show you how, or why it's important, or how we get it by looking at reflected spectrum, and then we're going to look at how we can calculate NDVI based upon that information from the reflected spectrum. And then we're going to do it in ArcMap two different ways, first using the image analysis window and then using raster calculator. So one of the first things we need to understand with NDVI is what a reflectance spectra looks like and what reflectance means for our data analysis. So let's draw a quick axis here and on this axis, on the y-axis, we have reflectance, so we'll measure that in percentages, so that's 100%, that's 0 down here, and 50 in the middle. And what that means, at zero, there's nothing reflecting off of anything, so we can't really sense any data, there's no light reflecting back to our sensor. 50% reflectance means 50% of the light that hit something is reflected back to some observer. And then up 100 all the way to the top, 100% of light to hit something is reflected back to some observer like in space like a satellite cameras. On the x-axis, we have wavelengths, so let's make it a little easier to write and we'll go that. And over on the left here, let's say that we have something like 400 nanometers, so that's 400 and let's say over here we have about 700 and then we're going to have not totally linear scale, we'll have something like 1,200 over here. And what that means is that we have blue light here, we have green light in the middle, and we have red light and then we have near infrared here. So excuse me for my handwriting a little bit please and we can draw curves that fit on here represent different things so lets look at vegetation really quickly. Vegetation reflects, if we think about it, vegetation reflects more green light in the visible spectrum than blue or red because it appears green. So green light reflects off of it and comes back to us and what's happening is it's photosynthesizing blue and red light and kind of on a curve in between. So what that looks like is something like this, where it's low down in the blue light, it reflects a little more in the green light, and it comes back down in the red light. Now it doesn't go all the way up to 50, it's more like 25, but for this illustration that's fine. And then we go way up near infrared and kind of level off there for a little bit. So the big thing we have here is that it reflects very little blue, very little red, a little bit of green, and a lot of near infrared. And again it's not really up at 100% reflectants but it's pretty high. Well, how do we distinguish different things if we'd have just these four bands, we have blue, green, red and the infrared. Well, what does it look like if we want something like water? Well, water kind of stays down low here, water doesn't reflect a whole lot of anything very much, so water's kind of moving around down here and it's pretty low, under vegetation. But then, what about bare soil? Well, bare soil kind of starts low, but not even as low as the green and kind of keeps going up at a pretty steady rate through this range of the electromagnetic spectrum. So what's kind of interesting, is if we want to distinguish healthy vegetation from bare soil, we can say, well the near infrared should be higher than the air soil, so the near infrared value should be higher and the red value should be lower. Whereas in bare soil they're pretty close, they're very slightly different. So, healthy vegetation is high, near infrared, low red and even relatively low green because that should be around 15, 20% in the green. Whereas in the near infrared it should be actually kind of closer to 50%. So we can modify our scale over on the left if we wanted to but again, just to verify what we're looking at, what each of these curve sets, so what each of these colors says, is how much light bounces off of them at each different wavelength. So in here, let's make, sorry let's draw kind of bands that we might get off of something like land set here. So I'm going to bracket these and kind of bands here. So let's say this is the land set band and in between those two black lines is the land set band for blue. And we can expect that bare earth in the tan there is relatively low but higher than the vegetation in green and higher still than water in the blue. And then we have a land set band for green light in here, and there's a similar ordering of them but then in red light they're pretty distinct. Water is low, vegetation is pretty low still too, but then bare earth starts getting up higher here, we can really start to see that. If it's reflecting 30% or more of, in the red area, it's probably not vegetation, it's probably something else like bare earth. And then if you really wanted to confirm, you can say, we'll if it's reflecting very highly in the near infrared band of LandSat and lower in, or pretty low in the red band, it might be healthy vegetation. But if it's reflecting moderately highly in the near infrared band and moderately highly still in the red band, it might be bare earth instead. So that is how we would read this and what we might use it for. So let's take a look at what the Normalized Difference Vegetation Index is, or NDVI, in kind of a theoretical thought experiment sense. And first we use it as a proxy for all kinds of environmental measurements because it's a great way of seeing how an ecosystem is doing through the health of its vegetation. So that's what we're really trying to get out of this is vegetation health, and part of why we use that as a proxy for all these other uses, is it's pretty cheap to gather because near-infrared light is built into lots of sensors. The camera in your phone or your pocket digital camera can detect infrared if you remove filter. By default only does blue, green, and red but that's because the red sensor on it is actually sensitive to red and near infrared, so it has a filter in front of the sensor that blocks out near infrared light so you only get the visible light. So they're really easy to convert, the sensors are readily available everywhere and that's why NDVI is great in that it only uses near infrared and red light in general and those are easily captured in cheap ways. And the algorithm to calculate NDVI is taking the near infrared band and subtracting the red band's value and then dividing that by the sum of those two bands. And this will make more sense in a moment, we're going to talk about this a little bit. So if you're still wondering what does that even mean? We'll get there. And basically think of it this way, that healthy plants absorb much more red light because they're using it for photosynthesis, right, they're using it to produce food. So they absorb the red light, they reflect the green light and they absorb blue light. And they also reflect much of light in the near infrared. So they're reflecting near infrared light in large values. We saw that in the reflectant spectra that you have high near infrared values and slightly lower than the green values for the red light. So if If the near infrared reflectance increases as it does with healthy vegetation, so does the value of the top and the bottom, which is part of the normalization of the normalized difference vegetation index. But when the red light increases, the top decreases. So if plants are reflecting more red light, that means they're not using it for photosynthesis, they're less healthy. So since we subtract the red light from the near infrared, as we get higher red values, our top value decreases. And it brings the value closer to 0 or even to -1. If it's reflecting more red light then it's reflecting near infrared, it's probably not even vegetation at all. And then when the red reflectance decreases, as it does when plants absorb it, the top value grows again. So, as red goes closer to zero, we get closer to the pure near infrared value, and the top gets closer to one, the top and bottom get closer to one if we have, say, 100% of near infrared that's reflected minus zero of the red light, say, in a theoretical situation. And then we get 100 plus 0 at the bottom. And so we'd have 100 over 100 equals 1. So in NDVI, closer to 1 is more likely to be healthy vegetation. Closer to 0 is more likely to be unhealthy vegetation. And usually somewhere below 0 is probably not vegetation at all. So the value scales from -1 to 1. And we'll see them in a moment. And there are other normalized indices that you can use to help filter out what we see from the air. There's one for determining water, and there are others that use different bands to try to get at specific interactions in the electromagnetic spectrum. Where we know in this case that near infrared is high for vegetation and red is low, so we can create this really small little algorithm to see if we can suss out vegetation using just those two bands of information. So what this ends up looking like in practice, if we have near infrared minus red, or near infrared plus red, is a RasterCalculator expression. So we would combine the bands, and this is in an image where we just have blue, green, red, and infrared, so where red is Band3 and near infrared is Band4. But with Landsat, these are one up, so red is 4 and near infrared is 5. But, imagine we just have a four-band image right now, so, we do near infrared in imageBand4- imageBand3, which is the red, and then divide it by ImageBand4 + ImageBand3. Alternatively, we can use the image analysis window. And I'll show you that as well, which can calculate this value for us without us having to remember this particular calculation. So let's go take a look at how this works in ArcMap. I have my Landsat scene here, showing just the visible light in this case. Band 4 is red, band 3 is green and band 2 is blue, and I want to view NDVI. Well first, let's just have the image analysis window do it. So I can go to Windows > Image Analysis, and it flies out. And if I select the landsat_scene here, down here, there's a little processing button that has a little leaf for NDVI. And before I click it, I'm going to set it up, because by default, it might not set it up correctly but I need to tell it in the NDVI tab, which band in my image is red and which band is infrared. So it might have it be something like this originally, say, and so I need to tell it that Band 4 is red and Band 5 is near infrared. And it's probably going to be like this as well initially and we'll have the Scientific Output button checked. And I'll click OK, and I'm going to click that leaf button now to get NDVI. And it's giving me an illustration here, so where green is more likely to be healthy vegetation and then colors that aren't green are not vegetation at all. So you can see those lakes pop out. Then we can see the heavy vegetation in the mountains here, and in the agricultural areas over here pop out with high values of NDVI. This is just the color map raster. It's assigning particular colors to things here that, and the values don't particularly mean anything. It's just giving us an illustration for our own eyes. So let's use the scientific output option and run it again. And in this case, we get more of what I was talking about. The high value of 1, and the low value of negative 1. And we can see that the lakes, not vegetation, are closer to negative 1. And that the values closest to white are the values that we saw before in the agricultural regions, and in the mountains, that were more likely to be vegetation. And what's happening here, is remember, they have high near-infrared reflectance, and low red reflectance. So if we subtract the red from the near infrared, we have some highish, positive value on top, and if we subtract, or if we add the near infrared to the red on the bottom, we get some similar value on the bottom. Because red being low value makes it inconsequential on both the top and the bottom of the equation almost. That's very little difference. So we're almost just dividing the infrared by itself, getting something close to 1. And that shows up as a bright spot in this particular image, saying it's more likely to be vegetation. Now if I don't use the Image Analysis window, if I want to do it with Raster Calculator, I'm going to need to load these bands separately into my map. So I can go to Add Data. So I'll go to Add Data button and I gave you for this demo a five band version of the Landsat data so you didn't have to download everything, and I'll go find it on my computer. And if I, again, double-click into the bands, I can add just the two bands I need here as separate bands to my map document. In your download, it's going to be in your Documents folder under ArcGIS in the Packages folder, because that's where map packages get extracted to. So you'll be able to find the package you just extracted for this with this name in that folder and then find in the ArcGIS 10.3 folder in there. Geo-database that has these data in them. So if you download the map package for this, that's where it's going to be. So now that I have both of these, I can use them in Raster Calculator. So if I go to ArcToolbox, in spacial analyst map algebra, go to Raster Calculator. And I have access to these two bands. And these two bands as rasters in Raster Calculator. And I can kind of construct a version of this equation. So first let's do it the way that I know is slightly wrong, but it's going to look right. So let's try that together. So first, let's just put it together the way we know. We know that we need to take the near infrared band and subtract the red band. And group those together so that happens separately. In the order of operations, that subtraction happens first, and then I'll divide that value by this other value. I'll do the near-infared plus the red. And then this addition will happen before the division happens. So the subtraction will happen, the addition will happen, and then the subtracted values will be divided by the added values. And I'll let it put it into my, Default geo database, and I'll name it ndvi_try1, and I'll click OK. And it's going to run Raster Calculator, And what I get here, is I get three values. Not the range of values in here on a color ramp, I get 3 values, -1, 0, and 1. And that's because it interpreted them as integer rasters. The input rasters are, not that one. An input raster is an integer raster, where all these values in here are integer values for the intensity in each band. So here we go, the 0 to 44,825. So since it's using integer rasters, it does integer math, and gives me integers as the output, not the decimals that we want. So let's take that that we just ran, and try this again, and I'll make it ndvi_try2. And what we need to do, is in the Math section, there's a Float function. So we're going to insert the Float function right there. And basically we're going to force it to turn each of these into a floating point raster before we do the math operation. And actually, we can even move that outside of here, it's before we do the division. We could subtract as integers, but then we need to divide as floating point rasters. So I'll wrap each of these parts in the Float function to turn it into basically double rasters, right? The floating point, or double data type. So we're turning them into one of those, and then we're doing the division between those new floating point rasters. This is called casting our data, it's converting between two data types. We're casting an integer as a double in this case, and then we can do floating point math on them as division. So let's try that, and I'll click OK, oops. Somewhere I probably messed up my parentheses. And it's that I don't need the extra parentheses here, And then I have an extra one at the end now here. So, I'll click OK, and run Raster Calculator down here again. And now, we get much more of what we expected before, or what we had before, based upon when ArcGIS calculated NDVI for us. And if I want to, I can use Image Analysis again. Just, I'm going to turn off these other layers here, and just have the NDVI that it calculated, and the NDVI that we calculated. And we'll just swipe and just see how it does, or if it visually looks about the same. In fact, you can't see that I am swiping, because the color ramps assigned to it are the same, and the values are the same in between them. Okay, so now we know how to calculate NDVI two different ways. If NDVI is still a little confusing for you, don't worry too much about that yet. What I want you to take away from this is when you calculate NDVI, values closer to 1 are much more likely to be vegetation. And a lot of times, 0.5 is still vegetation. But values as you get close to 0 are not vegetation, or healthy vegetation, anyway. And then as you get closer to -1, you're looking more at things that aren't vegetation at all. And so if you remember that, that's the most important part. And then calculating it is still a little more complicated. You could try looking at parts of this video again, or ask a question in the discussion forums. Try to get it sorted out, so you understand a little bit about what's going on. But mostly what you need to know for this course, is how to interpret it, and then that it exists, so that you can continue looking up how to calculate it if you need to, whenever you encounter it in your own work. Okay, so that's it for this lecture. In this lecture we discussed reflectant spectra, and then we also looked at what NDVI is, and then how to calculate it in two separate ways in ArcGIS. In the image analysis window using the NDVI tool, and using Raster Calculator. I know this was a long lecture, but I hope it was worthwhile. See you next time.