Spectral indices and image classification
UAT 452 Remote Sensing and Geographic Information Systems for UAS
Lesson
By the end of this module you will be able to
- Compute and interpret NDVI, NDRE and NDWI from reflectance
- Explain supervised and unsupervised image classification
- Build an error matrix from field checkpoints and compute overall, producer's and user's accuracy and kappa
- Plan field checkpoints so the assessment is trustworthy
- Adjust the area of each class with the error matrix and report it with a confidence interval
- Compute tree height and canopy cover from a DSM and a DTM and judge a plot against the FAO forest definition
Why this matters
Agriculture staff have no time to look at five bands pixel by pixel. They need maps that say “which fields have poor rice” and “where is water, soil or buildings”. Spectral indices compress several bands into one meaningful number, and classification turns numbers into land types, but both kinds of map are only useful for decisions when their accuracy is known.
Spectral indices
Most indices take the form of a normalised difference , ranging from −1 to +1 and reducing the effect of overall brightness, such as shade versus sunlight.
- NDVI (Rouse et al. 1974) uses near infrared and red. High values mean dense, healthy vegetation, but in very dense vegetation the index saturates near 0.8–0.9
- NDRE uses near infrared and red edge, sensitive to chlorophyll where NDVI has already saturated, suiting mid- to late-season rice
- NDWI as defined by McFeeters (1996) uses green and near infrared; positive values indicate open water, separating canals and flooded fields from vegetation and soil
Example 1 Three indices for four surfaces
pixels = { # reflectance: (green, red, red edge, near infrared)
"healthy rice": (0.08, 0.05, 0.20, 0.45),
"stressed rice": (0.09, 0.09, 0.18, 0.30),
"canal water": (0.07, 0.05, 0.04, 0.03),
"bare soil": (0.12, 0.16, 0.20, 0.24),
}
nd = lambda a, b: (a - b) / (a + b) # normalised difference
for name, (g, r, re, nir) in pixels.items():
print(f"{name:<14} NDVI {nd(nir, r):+.2f} NDRE {nd(nir, re):+.2f} NDWI {nd(g, nir):+.2f}")
healthy rice NDVI +0.80 NDRE +0.38 NDWI -0.70
stressed rice NDVI +0.54 NDRE +0.25 NDWI -0.54
canal water NDVI -0.25 NDRE -0.14 NDWI +0.40
bare soil NDVI +0.20 NDRE +0.09 NDWI -0.33
Healthy rice has an NDVI of 0.80, stressed rice 0.54, canal water is negative and is the only surface with a positive NDWI. Bare soil has a slightly positive NDVI. Using only NDVI with a low threshold may confuse moist soil with sparse weeds and newly transplanted rice, so several indices should be read together along with the rice growth stage.
Image classification
Image classification assigns a class to each pixel or object.
- Supervised: the user selects training areas for each class and an algorithm learns their characteristics, for example minimum distance to means, maximum likelihood or random forest
- Unsupervised: the algorithm groups similar pixels itself, for example with k-means, and the user names the groups afterwards
- Object-based: the image is first segmented into contiguous groups of pixels, which are classified as a whole. This suits very detailed drone images, where one paddy field consists of millions of slightly different pixels
Inputs need not be raw bands; they can include indices, heights from a DSM and texture, which help separate buildings whose colour resembles soil.
Assessing accuracy with an error matrix
Congalton (1991) established that the accuracy of a classified map must be assessed with an error matrix comparing mapped classes with true classes at independent checkpoints.
- Overall accuracy : correct counts on the diagonal divided by the total
- Producer’s accuracy: of the real examples of a class, what percentage were mapped correctly, showing errors of omission
- User’s accuracy: of what the map calls a class, what percentage really is that class, showing errors of commission, the figure map users care about
- Kappa compares accuracy with that expected by chance,
Example 2 Assessing a four-class map with 200 checkpoints
classes = ["rice", "water", "soil", "built"]
cm = [ # rows = true class from field checkpoints, columns = classified class
[62, 1, 5, 2],
[2, 38, 0, 0],
[6, 0, 44, 5],
[1, 0, 4, 30],
]
n = sum(map(sum, cm))
diag = sum(cm[i][i] for i in range(4))
po = diag / n
pe = sum(sum(cm[i]) * sum(row[i] for row in cm) for i in range(4)) / n ** 2
for i, c in enumerate(classes):
producer = cm[i][i] / sum(cm[i])
user = cm[i][i] / sum(row[i] for row in cm)
print(f"{c:<6} producer's {producer:.1%} user's {user:.1%}")
print(f"n = {n}, overall accuracy {po:.1%}, kappa {(po - pe) / (1 - pe):.3f}")
rice producer's 88.6% user's 87.3%
water producer's 95.0% user's 97.4%
soil producer's 80.0% user's 83.0%
built producer's 85.7% user's 81.1%
n = 200, overall accuracy 87.0%, kappa 0.822
An overall accuracy of 87% and kappa of 0.82 look good, but the soil class has a producer’s accuracy of only 80%, because real soil was mapped as rice at 6 points and as built-up at 5. Built-up has a user’s accuracy of only about 81%, so if staff used this map to count buildings encroaching on the canal bank, they would overcount. Adding DSM heights would help separate roofs from soil.
Checkpoints must be sampled separately from the training areas, spread across the area, with enough points in every class, including rare ones. Stratified random sampling by class ensures small classes get enough checkpoints.
From a classified map to true area
The area counted from the pixels of a classified map is usually not the true area, because misclassified pixels move area from one class to another. Olofsson et al. (2013, 2014) propose correcting it with the error matrix from checkpoints drawn by random sampling stratified by the map classes. Weight each row by the area proportion of map class , then add up by true class to get , where is the number of checkpoints that the map calls class but that truly are class . The 95% confidence interval is times the standard error (SE), as written in the code of the mapaccuracy package.
Example 3 True rice area against the area counted from the map
Use the matrix of Example 2 with the rows turned into the map classes. The study area is 1 square kilometre (100 ha), and the map area of each class is assumed.
import math
classes = ["rice", "water", "soil", "built"]
# rows = map class, columns = true class from the checkpoints (Example 2 with rows and columns swapped)
n = [[62, 2, 6, 1], [1, 38, 0, 0], [5, 0, 44, 4], [2, 0, 5, 30]]
mapped_ha = [62.0, 8.0, 18.0, 12.0] # area of each class in the map (ha, assumed)
total = sum(mapped_ha)
w = [a / total for a in mapped_ha] # area proportion W of each class in the map
n_i = [sum(row) for row in n]
for j, name in enumerate(classes):
p = sum(w[i] * n[i][j] / n_i[i] for i in range(4)) # area proportion of true class j
var = sum(w[i] ** 2 * (n[i][j] / n_i[i]) * (1 - n[i][j] / n_i[i]) / (n_i[i] - 1) for i in range(4))
print(f"{name:<6} map {mapped_ha[j]:5.1f} ha, estimated {p * total:5.1f} +/- {1.96 * math.sqrt(var) * total:4.1f} ha")
rice map 62.0 ha, estimated 56.7 +/- 5.1 ha
water map 8.0 ha, estimated 9.5 +/- 2.4 ha
soil map 18.0 ha, estimated 21.8 +/- 4.6 ha
built map 12.0 ha, estimated 12.0 +/- 2.6 ha
The map shows 62.0 ha of rice, but the adjusted value is 56.7 +/- 5.1 ha, because some soil and built-up pixels were classified as rice (user’s accuracy 87%), while the true water and soil areas are larger than counted. The recipient should therefore get the adjusted area with its confidence interval, not the figure from counting pixels.
Forestry: tree height and canopy cover
A forest survey asks not only which pixels are trees but how tall the trees are and what share of the ground the crowns cover. Drone photogrammetry gives two models: the digital surface model (DSM), the height of the top of everything the camera sees, and the digital terrain model (DTM), the height of the bare ground. Subtracting them cell by cell gives the canopy height model (CHM), , the height of whatever stands above the ground. Canopy cover is the share of cells whose CHM exceeds a threshold.
A common threshold comes from the FAO forest definition in the Global Forest Resources Assessment FRA 2025: land of more than 0.5 ha with trees taller than 5 m and canopy cover above 10%, excluding land mainly under agricultural or urban use. Cover of 5-10% is other wooded land.
The limit is that a camera cannot see the ground under a dense canopy, so a DTM from images has few ground points and usually sits above the true ground, making trees look shorter. Wallace et al. (2016) found in a eucalypt plot that individual tree height from images (SfM) had an RMSE of 1.30 m against 0.92 m from lidar, and canopy cover of 50% against 63%. In dense forest, use a DTM from lidar or ground survey and fly the drone again only for a new DSM (Iglhaut et al., 2019).
Example 4 Is this plot a forest under the FAO definition?
A community forest plot (assumed) has a 0.5 m CHM; the cells inside the plot boundary are counted by height class.
counts = {(0, 2): 19800, (2, 5): 4600, (5, 10): 5100, (10, 15): 2200, (15, 30): 300} # CHM height class (m): cell count
CELL = 0.5 * 0.5 # cell area (m2) of a 0.5 m CHM
n = sum(counts.values())
plot_ha = n * CELL / 10000
cover = sum(c for (lo, hi), c in counts.items() if lo >= 5) / n
print(f"plot {plot_ha:.2f} ha, canopy cover above 5 m: {cover:.1%}")
print(f"FAO forest (> 0.5 ha, trees > 5 m, cover > 10%): {plot_ha > 0.5 and cover > 0.10}")
dsm_top, dtm = 47.9, 31.6 # treetop on the DSM and ground on the DTM (m)
print(f"tree height = {dsm_top - dtm:.1f} m")
plot 0.80 ha, canopy cover above 5 m: 23.8%
FAO forest (> 0.5 ha, trees > 5 m, cover > 10%): True
tree height = 16.3 m
The 0.80 ha plot has 23.8% cover above 5 m and passes all three thresholds, so it counts as forest. Cells of 2-5 m (shrubs and saplings) are not canopy. The tallest tree is about 16.3 m, but if the DTM under it comes from images of dense forest the value may be off by a metre or more, so report it with its uncertainty.
Module lab
Lab: indices and a classified map
- From the reflectance images of module 2, compute NDVI, NDRE and NDWI with the QGIS Raster Calculator, checking sample values against the code in Example 1
- Select training areas for four classes and run a supervised classification with the plugin your lecturer specifies
- Draw a stratified random sample of at least 30 checkpoints per class and determine their true class from detailed imagery or a field visit
- Build the error matrix and compute the four accuracy measures with the code in Example 2
- Add a DSM height layer, classify again, and compare the accuracy of the built-up class
Common mistakes
Watch out
- Reading high NDVI as “good yield” every time, when it may be weeds or rice not yet heading
- Comparing NDVI across camera models with different band widths without checking consistency
- Using the same areas for training and testing, inflating accuracy
- Reporting only overall accuracy, hiding badly classified classes
- Simple random sampling where one class dominates, leaving small classes with almost no checkpoints
Summary
- Normalised-difference indices reduce brightness effects; NDVI shows overall vegetation, NDRE stays sensitive where NDVI saturates, NDWI separates open water
- Classification can be supervised, unsupervised or object-based, and can use extra inputs such as height
- An error matrix gives overall, producer’s and user’s accuracy and kappa, which must be reported per class
- Checkpoints must be separate from training data and stratified so every class has enough points
Check your understanding
- With NIR reflectance 0.40 and red 0.10, what is the NDVI?
- What does a positive McFeeters NDWI indicate?
- How does user’s accuracy differ from producer’s accuracy?
- If and , what is kappa?
- Why must checkpoints be separate from the training areas?
Answers
- Open water
- User’s accuracy is how often what the map calls a class really is that class; producer’s accuracy is how often real examples of the class were mapped correctly
- If the same set is used, the algorithm has already seen the answers and accuracy will be inflated
Key formulas
| NDVI | |
| NDRE | |
| NDWI (McFeeters) | |
| Kappa | |
| Adjusted area of a true class | |
| Canopy height model |
Key references
- Rouse, J. W., Haas, R. H., Schell, J. A., & Deering, D. W. (1974). Monitoring vegetation systems in the Great Plains with ERTS. Third ERTS-1 Symposium, NASA. link
- Tucker, C. J. (1979). Red and photographic infrared linear combinations for monitoring vegetation. Remote Sensing of Environment, 8(2), 127–150. link
- McFeeters, S. K. (1996). The use of the Normalized Difference Water Index (NDWI) in the delineation of open water features. International Journal of Remote Sensing, 17(7), 1425-1432. https://doi.org/10.1080/01431169608948714 link
- Congalton, R. G. (1991). A review of assessing the accuracy of classifications of remotely sensed data. Remote Sensing of Environment, 37(1), 35-46. https://doi.org/10.1016/0034-4257(91)90048-B link
- Lillesand, T., Kiefer, R. W., & Chipman, J. (2015). Remote sensing and image interpretation (7th ed.). Wiley. link
- U.S. Geological Survey. Landsat normalized difference vegetation index. link
- Olofsson, P., Foody, G. M., Stehman, S. V., & Woodcock, C. E. (2013). Making better use of accuracy data in land change studies: Estimating accuracy and area and quantifying uncertainty using stratified estimation. Remote Sensing of Environment, 129, 122-131. https://doi.org/10.1016/j.rse.2012.10.031 link
- Olofsson, P., Foody, G. M., Herold, M., Stehman, S. V., Woodcock, C. E., & Wulder, M. A. (2014). Good practices for estimating area and assessing accuracy of land change. Remote Sensing of Environment, 148, 42–57. link
- Costa, H. (2024). mapaccuracy: Unbiased thematic map accuracy and area (R package version 0.1.2). Comprehensive R Archive Network. link
- OpenDroneMap Authors. Outputs. OpenDroneMap documentation (Version 3.6.0). link
- Food and Agriculture Organization of the United Nations. (n.d.). Global Forest Resources Assessment 2025: Terms and definitions. FRA Platform. link
- Wallace, L., Lucieer, A., Malenovský, Z., Turner, D., & Vopěnka, P. (2016). Assessment of forest structure using two UAV techniques: A comparison of airborne laser scanning and structure from motion (SfM) point clouds. Forests, 7(3), 62. link
- Iglhaut, J., Cabo, C., Puliti, S., Piermattei, L., O'Connor, J., & Rosette, J. (2019). Structure from motion photogrammetry in forestry: A review. Current Forestry Reports, 5(3), 155-168. link
Further reading
Study the assigned knowledge units in advance, review media and take the module quiz
In class / field
Lab or field practice from worksheets with a safety checklist
Learning evidence: Checked worksheets and quiz results