NDVI with QGIS: Calculate vegetation greenness from Satellite Images
May 19, 2025
Calculate the Normalized Difference Vegetation Index (NDVI) in QGIS using Sentinel-2 satellite imagery. Learn to do remote sensing analysis in QGIS. How to download Sentinel-2 images: https://youtu.be/98VN7sExAEE More Sentinel-2 tutorials: https://www.youtube.com/playlist?list=PLoaxBPcx2tRDNJlI8KXkVMl0PO-JCbEqM Check out my website for MORE: https://opensourceoptions.com
View Video Transcript
0:00
Welcome to OpenSource Options. In the
0:03
previous video we've done uh we've
0:06
looked at how to download Sentinel
0:08
imagery and how to visualize that
0:10
imagery in different ways. Now I want to
0:13
show you how we can actually
0:15
quantitatively analyze that imagery. So
0:18
for example here we're looking at a
0:20
color infrared image. And what this is
0:22
showing us is in red it's showing us
0:26
where we have healthy vegetation which
0:28
would appear green in a true color
0:30
image. What it's what we don't have here
0:33
though is we don't have a a objective
0:35
way to quantify how green or how healthy
0:38
that vegetation is across images um or
0:42
across time. So that's what I want to do
0:44
today is show you how we can use remote
0:46
sensing indices, specifically the
0:48
normalized difference vegetation index
0:51
to get numerical information out of
0:53
these satellite images. So let me start
0:55
off by showing you how I have this
0:57
symbolized. If you watch the sentinel uh
1:00
visualization
1:02
uh video from last time, you'll know how
1:04
to do this. But I just have this set up
1:06
as a virtual raster with all the
1:08
Sentinel bands in it. And then I have
1:10
Sentinel band 8 displayed as red, band
1:12
four displayed as green, and band three
1:15
displayed as blue. Okay, now I'm
1:18
referring to the Sentinel bands, not
1:20
included bands in the virtual image. And
1:22
let me see if I can pull those up for
1:24
you really quick here. Let's just go to
1:28
the internet. And we're going to need
1:29
this anyway. So let's look at uh
1:31
Sentinel 2
1:35
bands. And we want spectral bands. Let's
1:39
actually see if we can find
1:41
the Capernacus
1:46
website. I don't see it. We'll try
1:48
Wikipedia and see how well this does.
1:53
Um, okay. So, here we go. So, this tells
1:56
us the band one is blue. It gives us the
1:58
central wavelength uh in nanometers and
2:02
it gives us the band width in
2:04
nanometers. Okay. And it also gives us a
2:06
spatial resolution. And so these are the
2:10
bands we're working with. Um we can see
2:13
band 8 is near infrared. We can see band
2:16
8A is also near infrared. It's a
2:19
slightly different central wavelength
2:20
and it has a narrower band width. We
2:23
could use that one in place of band 8
2:25
for specific instances if we needed to.
2:28
All right. Okay. So, we're going to come
2:31
back to this because well, we might come
2:33
back to this, but this is the
2:35
information you're going to need to to
2:37
do some of these things. All right,
2:38
let's go back over to QGIS. And now,
2:41
let's calculate our normalized
2:43
difference vegetation index. Also, it's
2:46
all greenness index, which it will be
2:47
referred to sometimes. And the way we're
2:50
going to do this is we're going to
2:50
perform a calculation using the raster
2:52
bands. We're going to take two raster
2:54
bands. We're going to take the near
2:56
infrared and the red and we're going to
2:59
do some math on them to get one value
3:01
out will give us a number representing
3:03
how green a pixel location is. So, let's
3:06
go to raster and raster calculator. Um,
3:09
I'm going to close this real quick and
3:11
just show you if we search for raster
3:13
calculator in all the tools here, we
3:17
have three options. Um, we have the
3:20
Google and then we have two uh QGIS
3:24
options. I can never remember which one
3:26
I want to use. The one that I prefer is
3:28
the one here under raster raster
3:30
calculator. So, that's where I'm going
3:31
to go. Now, I'm going to write this
3:34
equation out for you down here, uh, just
3:36
so you can see what it is. What we're
3:38
going to do is we're going to take near
3:42
infrared, subtract red, and divide by
3:46
the near infrared plus the red. Okay?
3:50
And what this is doing, uh, let me
3:52
explain this. So we're taking so healthy
3:55
vegetation reflects near infrared light
3:59
and absorbs red light. So when we look
4:02
at healthy vegetation, we're going to
4:03
see a high response from near infrared
4:05
and a low response from red. So what
4:09
this what this is doing is getting at
4:10
that we're normal. So we're subtracting
4:13
we're finding out the difference between
4:14
the near infrared and the red and then
4:17
we're dividing it by the total
4:18
reflectance of those two bands. So this
4:21
this uh metric is going to range from
4:24
negative 1 to positive one with values
4:27
closer to one uh larger values
4:30
indicating more greenness.
4:33
Okay. So the way we do this is we just
4:35
replace the bands with these numbers
4:38
I've written in here or with these near
4:41
red and red designations I've written in
4:42
here. So we can do this. We'll just
4:44
double click here. We'll replace this
4:46
with band 8. We'll replace this with
4:50
band
4:52
four and again here with band
4:56
eight and again here with band
5:00
four. Okay, now we have the equation set
5:05
up. The next thing to do is to select an
5:08
output layer. If you would like, you can
5:10
create an on the-fly raster instead of
5:13
writing it to disk. I'll write it to
5:14
this just to show you how that works
5:15
because you may want to do further
5:16
analysis. But you can click this and you
5:19
can give it a layer
5:20
name. Um here I am going to save this
5:25
and I'm going to save it here to
5:27
Sentinel 2 NDVI. I created a test before
5:30
I did this just to make sure things
5:32
worked out. So yes, let's replace
5:35
it. And the next thing you may want to
5:38
adjust, we will not adjust it here is
5:40
the columns and rows. This is how you
5:42
will adjust the spatial resolution of
5:45
your output raster. As you notice, some
5:48
of these bands have different uh
5:51
resolutions. Some are 10 m, some are 20
5:54
and some are 60. Here the we've used two
5:57
bands. They're both 10 mters. My output
5:59
should be 10 m. So, we're going to leave
6:01
this as the default. And then you can
6:03
adjust your output CRS. Let's go ahead
6:06
and run this. Now, this will take just a
6:09
minute to calculate. And then it's going
6:12
to give us uh load in that that
6:25
raster. Okay, there it is. Everything is
6:28
complete. Uh we can close this message.
6:31
And now let's just go in and take a
6:32
quick look at this. One thing you may
6:35
want to do is use the value tool. This
6:37
is a QGIS plugin. You can download it
6:40
from the plugins repository and I've got
6:42
it over here as a panel. Uh this is a
6:44
very useful tool. It will show you the
6:47
value for any raster that you have
6:48
loaded in all the bands of that raster,
6:51
anything that is active. I'm going to
6:52
turn this virtual raster off just so we
6:55
can see just the sentinel to NDVI
6:57
values. Let's come into this area over
7:00
here where we have some variation. We
7:02
can see here that in this river I have a
7:05
negative NDVI value. We can see in this
7:08
field I have a value around
7:10
0.65. And we can see that in this valley
7:12
bottom and river bottom I have values um
7:15
ranging from
7:16
0.4 uh to 0.5 roughly. And then in
7:20
between in this field we have a value of
7:23
about 0.1. So we can see how numerically
7:27
this starts to pick it out and with a
7:28
single value we can describe vegetation
7:31
greenness. Now we can also go in and do
7:34
some layer styling and
7:37
um we can give this uh single band
7:40
pseudo color and we can give it like a
7:42
red green color ramp and now we can see
7:45
that uh where things are green it's
7:47
green vegetation where things are red uh
7:51
it is not green vegetation it is you
7:55
know water here specifically and so we
7:59
can um we can do do that and get a nice
8:03
visualization of where the greenness is.
8:07
And you may want to uh adjust these
8:11
colors and classification a little bit
8:13
to to show your specific places of
8:15
interest. Now the great thing about this
8:17
which we are not going into right now is
8:20
we can start to analyze images through
8:22
time. So if we have NDVI at multiple
8:24
times, then we can start to compare NDVI
8:27
at a location
8:30
um at you know in early spring across
8:33
years or from early spring to late fall
8:36
and see when that greenness peaks.
8:39
Another thing we can do as a comparison
8:41
tool if we have multiple images, we can
8:43
open up our properties here and we can
8:47
come to the histogram and we can click
8:49
compute histogram and this will show us
8:51
the distribution of pixel values uh
8:55
across our raster. So we can see there's
8:57
a spike here right around zero. I expect
9:00
that is from water and then we have
9:03
another spike of values around 0 2 and
9:05
it slowly starts to to um to taper off.
9:08
If we looked at two different images, uh
9:12
we would likely see different
9:13
histograms. So if we took an image from
9:16
December and an image from June, the
9:18
image in December would probably have a
9:20
lot more values that are closer to zero.
9:23
And then in June, we'd see that bump up
9:24
as we get the greenness as vegetation
9:27
starts to grow. Okay, so that's another
9:29
tool you can use that that you may not
9:31
have known about in QGIS. All right,
9:34
folks. I just want to let you know about
9:35
one more thing. That is that on open
9:37
source options.com, we should soon be
9:40
having some free fulllength courses that
9:44
are going to teach you GIS, remote
9:46
sensing and programming. The whole idea
9:48
is to help you become comfortable and
9:51
proficient with open-source
9:54
uh GIS and data science tools. Those
9:56
tools are free. They're powerful and I
9:59
think there should be free training
10:00
there. So, I'm trying to put together a
10:03
funding model that will support those
10:04
free courses. Uh, as always, thanks so
10:07
much for watching and hope you enjoy
10:09
your