-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
61 lines (47 loc) · 4.33 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
---
title: Bayesian Smoothing of Remote Sensing Image Classification
authors: Gilberto Camara, Renato Assuncao, Rolf Simoes, Felipe Souza, Pedro Andrade, Alexandre Carvalho
output: github_document
date: "2023-05-21"
---
```{r, echo=FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-"
)
library(bayesEO)
options(warn = -1)
```
## Overview
Methods such as support vector machines, random forests, and deep learning have become the popular for remote sensing image classification. Images resulting from these classifiers frequently have outliers or misclassified pixels. For this reason, image post-processing techniques are widely used to refine the labelling in a classified image in order to enhance its classification accuracy.
The `bayesEO` package provides a new method for Bayesian post-processing of images produced by machine learning algorithms. The input to the package is an image containing the probabilities of that pixel belonging to each of the classes. The package provides efficient methods for removing outliers and improving class labelling.
## Reading a probability data cube
The input for post-classification is an image with probabilities produced by a machine learning algorithm. This file should be multi-band, where each band contains the pixel probabilities of a single class. The file name must have information on reference dates and include a version number. In the examples, we use a file produced by a random forests algorithm applied to a data cube of Sentinel-2 images for tile "20LLQ" in the period 2020-06-04 to 2021-08-26. The image has been stored as INT2S data type with integer values between [0..10000] to represent probabilities ranging from 0 ro 1.
```{r, echo = TRUE, eval = TRUE}
data_dir <- system.file("/extdata/probs/", package = "bayesEO")
file <- paste0(data_dir, list.files(data_dir))
# set the labels for the data
labels <- c("Water", "ClearCut_Burn", "ClearCut_Soil",
"ClearCut_Veg", "Forest", "Wetland")
# read the file with the terra package
probs_image <- bayes_read_probs(file, labels)
```
The training data has six classes: (a) \code{Forest} for natural tropical forest; (b) \code{Water} for lakes and rivers; (c) \code{Wetlands} for areas where water covers the soil in the wet season; (d) \code{ClearCut_Burn} for areas where fires cleared the land after tree removal. (e) \code{ClearCut_Soil} where the forest has been removed; (f) \code{ClearCut_Veg} where some vegetation remains after most trees have been removed. The class labels should also be informed by the user and associated with the SpatRaster terra object, since they are not stored in image files.
The figure below shows the plot of all layer of the probability image. The map for class \code{Forest} shows high probability values associated with compact patches and linear stretches in riparian areas. Class \code{ClearCut_Soil} is mostly composed of dense areas of high probability whose geometrical boundaries result from forest cuts. By contrast, the probability maps for classes \code{Water}, \code{ClearCut_Burn}, and \code{ClearCut_Veg} have mostly low values.
```{r pcube, width = 8, tidy="styler", fig.align = 'center', fig.cap = "Class probabilities produced by random forest algorithm."}
bayes_plot_probs(probs_image)
```
The non-smoothed labeled map shows the need for post-processing. This map is obtained by taking the class of higher probability to each pixel, without considering the spatial context. The resulting map contains a significant number of outliers and misclassified pixels.
```{r, tidy = "styler", echo=TRUE, eval=TRUE, fig.width = 10, fig.align = 'center', fig.cap = "Labelled map without smoothing."}
map_no_smooth <- bayes_label(probs_image)
bayes_plot_map(map_no_smooth)
```
## Removing Outliers for the Probability Image
To remove the outliers in the classification map, \pkg{bayesEO} provides \code{bayes_smooth()}. This function uses a Bayesian estimator. After the procedure has been applied, the resulting smoothed probability image can be converted into a map.
```{r, tidy = "styler", echo=TRUE, eval=TRUE, fig.width = 10, fig.align = 'center', fig.cap = "Labelled map with smoothing."}
smooth_image <- bayes_smooth(probs_image)
smooth_map <- bayes_label(smooth_image)
bayes_plot_map(smooth_map)
```
The outliers have been removed and the resulting labelled map has improved accuracy.