Calculating vegetation indices & plant/soil separation with QGIS (Drones in agriculture series, 3/7)

In this video we’ll discuss how to identify plants and separate them from soil using red, green blue imagery, so the first thing that we’re going to need is we’re going to need some outputs on the reflectance in the red, green and blue parts of the spectrum. We’ve already gone over how to extract those. It’s really important that, if you’re using something like pix4d mapper that you’re developing those in the index section and not just in the orthomosaic section, so it’s important that these individual pixel values in your maps that you’re starting with, are actually telling you something about the real reflectance and it they might not necessarily look good if you open them up on their own. So, for example, let’s just take a look at these input files that are discussed elsewhere. So, if i just try to open this, then i mean you can see in the preview. It’s not necessarily going to look very good if opened in a normal photo viewer kind of program, because each one of those has a piece of data about the reflectance that might not translate well into how a photo viewer normally! I would expect the the formatting to be so again uh, it’s actually probably a good sign if your images are not starting out in a way that is very clear what they look like, so we’re going to open up qgis! This is where we’re going to be doing a lot of our work and we’re going to start off! Let’s go back to this we’re going to start off by opening this new project? You can click there or we can go to project new, and now we have this new blank project and we can select the images that we want to use! These are our raster files and i just moved them over!

All i have to do is highlight them and bring them in? You can see they’ve now loaded there, and now we have them here as red, blue and green! That’s not the order that the spectrum is laid out, so we, i think of them as being red? Green blue! I’m gonna move this down great um? So what we see here is the blue is on top and that box is checked, and that means that what we’re looking at here is blue and we can zoom in on this and take a closer look and whatever is on top, is what will be loaded. So this is the blue map, and this is a good sign that looks the way. I would expect i’ll go through that in a second um, so we can uncheck these boxes and see what’s below so here uh the plants look very dark in our red orthomosaic and that’s that’s great. That’s exactly what we would expect, because chlorophyll should be absorbing really strongly in the red in a healthy plant. I mean it should not be reflecting that out and it chlorophyll should also be absorbing really strongly in the blue in a healthy plant and less in the green. So what we should see is that the plants look really dark in the red, really dark in the blue and maybe intermediate in the green and that little bit of reflectance in the green is why they look green to us, so yeah sure enough. Those plants definitely are reflecting more light here, and this is the green compared to the red there. So that’s what i would expect and then we can check this blue sure enough, they’re a little bit darker in the blue, so they’re reflecting less, and this is all exactly what i would want? So that’s a good sign. So the next thing that we can do we go into the raster tab here and then the raster calculator.

This is going to be super important for us to calculate vegetation indices, and a vegetation index is a simple thing, but it can be kind of it can seem complex, sometimes when you’re starting out, but all it is, is just an equation where you can take the reflectance in different parts of the spectrum and calculate the the ratios of them using some equation and get a sense of how the plants are performing, for example, or or any any surface is so there’s one thing this example called ndvi that maybe you’ve heard of and we’ll go through, that in a separate video, but but basically you can imagine, since we already talked about how the plants are reflecting a lot of green compared to red or blue, then they should be emitting most of the light that they’re emitting in that green section we can say well what percent is green and maybe a plant? that’s not healthy. It’s really yellow and really kind of bright color. Well, maybe it’s going to have more reflectance across the spectrum in the red and the blue too, and therefore the percent of reflection of reflectance! That’s in the green is going to be lower, so we’re going to use a quick equation using the raster calculator to determine essentially how much of the light that’s being reflected from these is green, and this equation is called excess green. So, let’s get into this.

So the first thing that we want to do in this raster calculator is to specify where our output map is going to be saved to and i’ll save it here. That looks good and we can call this again: excess, green and then again this is an equation that somebody determined was related to the health of plants, and so we can look up what that equation is, and then it’s super important that we keep the right order of operations as we go through this. So here’s the equation for excess, green and then it’s very, very important that we go through and we plug in the right bands for each of these, and we make sure we have all the parentheses in the right spots and everything. So we can start this off by just going back to qgis here!

So i’m going to go through this and i’m going to put in here the equation so two times and then it’s going to be green, green reflectance, divided by all light total reflectance, and so i can go do that two times and then i can use these or i can just type it in either way is fine and then i’m going to choose my green band, divided by parentheses, red plus, green plus, for example that looks good and then i’m going to check my parentheses?

We have two parentheses there!

That’s very important so close that and then what we’re gonna do is. This is two times green, divided by total minus red, minus blue by total. So then i know that i’m going to be just using this expression quite a bit, and i can just copy that so now i’ve entered that whole expression in and i’m going to double check it, because it’s really important that we have all of those parentheses the right way, two times two times parentheses. So now.

I’ve double checked that and that looks good to me and i’ll click!

Ok, here great.

So that’s now finished processing i’m going to take a look at our output! If you ever want these to load a little bit more quickly, you can actually uncheck the ones below because we’re not seeing those they’re all covered up, but they will load every time we zoom in or zoom out, so it can be kind of better to have them not load. Every time we want to zoom in and zoom out and so sure enough!

You can see that these plants that we’re showing up as being very dark in our images, have a higher excess green value and that’s exactly what we would expect. So i can check. What’s underneath and those dark plants are showing up as having a very high excess green value? Comparatively we can use this select tool. We can actually get a sense of what our higher values are versus: lower values. Okay, so some of our higher values are in the range of 0.

37, some of our oh, it’s important here that we are selecting the right layer, so we i did have that selected, but sometimes you can be looking at this layer and you think you’re selecting that, but actually, if you go and click that you’re still looking at the same layer but now you’re getting totally different values! So again, it’s just important that was selected yeah, so sure enough! Our low values are in here. This soil, for example, really does not have any excess of green? It is not green, it’s you know very close to zero in those values, whereas our plants definitely do have an excess of green by comparison. So then we can actually do a few kind of neat things here! If we want to, we can, for example, we can change the color scaling, for example. So that’s the way that that currently looks we can change that by going to properties. So we can change this color using this, so we can go to single band pseudo color and then use this equal interval and change.

The number of classes up to about 10 and that should look good afterwards! Let’s see how this looks cool, so this is just one way that we could change what this looks like so now we can go back to our raster calculator? Now. If we want to separate out the the plants from the soil, then we can do that pretty easily! By again, we have to determine where we want to save this and i’ll save it, as so, usually in my own, like notation, i put the decimal as a second position there.

So i’ll know that that’s 0. 1 was the threshold and then what we can do is we can take this excess green value, and if our number is over about 0. 1, then it should classify as soil and if it’s below that then it’ll classify it as or sorry if it’s a bloat it’ll classify it as soil, if it’s above it it’ll classify it as a plant, great cool! So now we have a map that should pretty well distinguish between plants and soil, and it can be a good idea to go back and check this against our original images. Okay, so now our original ortho mosaic is loaded, and i can compare this against my threshold map.

I think that’s pretty good. I mean we could maybe bring that threshold down a little bit, so you could maybe bring that down. You know 0! 8 or something 0. 08, sorry, but i think overall, this looks pretty good, and so this is a good starting point where we can really start determining what’s plant what soil now and we can start splitting it up.

So this is where we want to really get for now in the process? So i hope you’ve learned something in this video and we’ll check in next time on how to separate all of these out into individual plots and determine how much of that is actually canopy area versus how much the soil. ?