Title: | Bayesian Smoothing of Remote Sensing Image Classification |
---|---|
Description: | A Bayesian smoothing method for post-processing of remote sensing image classification which refines the labelling in a classified image in order to enhance its classification accuracy. Combines pixel-based classification methods with a spatial post-processing method to remove outliers and misclassified pixels. |
Authors: | Gilberto Camara [aut, cre], Renato Assuncao [aut], Rolf Simoes [aut], Felipe Souza [aut] |
Maintainer: | Gilberto Camara <[email protected]> |
License: | GPL-3 |
Version: | 0.2.1 |
Built: | 2024-11-02 06:37:58 UTC |
Source: | CRAN |
Returns a color table
bayes_colors()
bayes_colors()
A tibble with color names and values
Gilberto Camara, [email protected]
Shows the default SITS colors
bayes_colors_show()
bayes_colors_show()
no return, called for side effects
Gilberto Camara, [email protected]
Takes a classified image with probabilities, and labels the image with the pixel of higher probability
bayes_label(x)
bayes_label(x)
x |
SpatRaster object with probabilities images |
A SpatRaster object
Gilberto Camara, [email protected]
if (bayes_run_examples()) { # select a file with probability values data_dir <- system.file("/extdata/probs/", package = "bayesEO") file <- list.files(data_dir) # create a SpatRaster object from the file probs_file <- paste0(data_dir, "/", file) # provide the labels labels <- c("Water", "ClearCut_Burn", "ClearCut_Soil", "ClearCut_Veg", "Forest", "Wetland") # read the probs file probs <- bayes_read_probs(probs_file, labels) # produce a labelled map map <- bayes_label(probs) # plot the labelled map bayes_plot_map(map) }
if (bayes_run_examples()) { # select a file with probability values data_dir <- system.file("/extdata/probs/", package = "bayesEO") file <- list.files(data_dir) # create a SpatRaster object from the file probs_file <- paste0(data_dir, "/", file) # provide the labels labels <- c("Water", "ClearCut_Burn", "ClearCut_Soil", "ClearCut_Veg", "Forest", "Wetland") # read the probs file probs <- bayes_read_probs(probs_file, labels) # produce a labelled map map <- bayes_label(probs) # plot the labelled map bayes_plot_map(map) }
Plot histogram
bayes_plot_hist(x, scale = 1, quantile = NULL, sample_size = 15000)
bayes_plot_hist(x, scale = 1, quantile = NULL, sample_size = 15000)
x |
SpatRaster to be plotted. |
scale |
Scale factor for SpatRaster |
quantile |
Threshold of values that will be plotted |
sample_size |
Number of samples to extract values |
A plot object
Gilberto Camara, [email protected]
if (bayes_run_examples()) { # get the probability file data_dir <- system.file("/extdata/probs/", package = "bayesEO") file <- list.files(data_dir) # read the probability file into a SpatRaster x <- terra::rast(paste0(data_dir, "/", file)) # include the labels labels <- c("Water", "ClearCut_Burn", "ClearCut_Soil", "ClearCut_Veg", "Forest", "Wetland") # associate the labels to the names of the SpatRaster names(x) <- labels # calculate the variance v <- bayes_variance(x) # Plot the variance histogram bayes_hist(v, quantile = 0.75) }
if (bayes_run_examples()) { # get the probability file data_dir <- system.file("/extdata/probs/", package = "bayesEO") file <- list.files(data_dir) # read the probability file into a SpatRaster x <- terra::rast(paste0(data_dir, "/", file)) # include the labels labels <- c("Water", "ClearCut_Burn", "ClearCut_Soil", "ClearCut_Veg", "Forest", "Wetland") # associate the labels to the names of the SpatRaster names(x) <- labels # calculate the variance v <- bayes_variance(x) # Plot the variance histogram bayes_hist(v, quantile = 0.75) }
Plot labelled map
bayes_plot_map( x, legend = NULL, palette = "Spectral", xmin = NULL, xmax = NULL, ymin = NULL, ymax = NULL, tmap_graticules_labels_size = 0.6, tmap_legend_title_size = 0.7, tmap_legend_text_size = 0.7, tmap_legend_bg_color = "white", tmap_legend_bg_alpha = 0.5, tmap_max_cells = 1e+06 )
bayes_plot_map( x, legend = NULL, palette = "Spectral", xmin = NULL, xmax = NULL, ymin = NULL, ymax = NULL, tmap_graticules_labels_size = 0.6, tmap_legend_title_size = 0.7, tmap_legend_text_size = 0.7, tmap_legend_bg_color = "white", tmap_legend_bg_alpha = 0.5, tmap_max_cells = 1e+06 )
x |
SpatRaster to be plotted. |
legend |
Named vector that associates labels to colors. |
palette |
A sequential RColorBrewer palette |
xmin |
Subset to be shown (xmin) |
xmax |
Subset to be shown (xmax) |
ymin |
Subset to be shown (ymin) |
ymax |
Subset to be shown (ymax) |
tmap_graticules_labels_size |
Size of graticules labels (default: 0.7) |
tmap_legend_title_size |
Size of legend title (default: 1.5) |
tmap_legend_text_size |
Size of legend text (default: 1.2) |
tmap_legend_bg_color |
Color of legend backgound (default: "white") |
tmap_legend_bg_alpha |
Transparency of legend background (default: 0.5) |
tmap_max_cells |
Maximum number of cells for tmap (default = 1e+06) |
A plot object
Gilberto Camara [email protected]
if (bayes_run_examples()) { # Define location of a probability file data_dir <- system.file("/extdata/probs", package = "bayesEO") # list the file file <- list.files(data_dir) # build the full path probs_file <- paste0(data_dir, "/", file) # define labels labels <- c("Water", "ClearCut_Burn", "ClearCut_Soil", "ClearCut_Veg", "Forest", "Wetland") probs_image <- bayes_read_probs(probs_file, labels) # Label the probs image y <- bayes_label(x) # produce a map of the labelled image bayes_plot_map(y) }
if (bayes_run_examples()) { # Define location of a probability file data_dir <- system.file("/extdata/probs", package = "bayesEO") # list the file file <- list.files(data_dir) # build the full path probs_file <- paste0(data_dir, "/", file) # define labels labels <- c("Water", "ClearCut_Burn", "ClearCut_Soil", "ClearCut_Veg", "Forest", "Wetland") probs_image <- bayes_read_probs(probs_file, labels) # Label the probs image y <- bayes_label(x) # produce a map of the labelled image bayes_plot_map(y) }
Plot probability maps
bayes_plot_probs( x, scale = 1e-04, labels = NULL, palette = "YlGnBu", tmap_scale = 1 )
bayes_plot_probs( x, scale = 1e-04, labels = NULL, palette = "YlGnBu", tmap_scale = 1 )
x |
SpatRaster to be plotted. |
scale |
Scaling factor to apply to the data |
labels |
Labels to be plotted |
palette |
An RColorBrewer palette |
tmap_scale |
Global scale parameter for map (default: 1.0) |
A plot object
Gilberto Camara, [email protected]
if (bayes_run_examples()) { # get the probability file data_dir <- system.file("/extdata/probs/", package = "bayesEO") file <- list.files(data_dir) # build the full path probs_file <- paste0(data_dir, "/", file) # include the labels labels <- c("Water", "ClearCut_Burn", "ClearCut_Soil", "ClearCut_Veg", "Forest", "Wetland") # associate the labels to the names of the SpatRaster probs <- bayes_read_probs(probs_file, labels) # Plot the probability image bayes_plot_probs(probs, scale = 0.0001, tmap_scale = 1.0) }
if (bayes_run_examples()) { # get the probability file data_dir <- system.file("/extdata/probs/", package = "bayesEO") file <- list.files(data_dir) # build the full path probs_file <- paste0(data_dir, "/", file) # include the labels labels <- c("Water", "ClearCut_Burn", "ClearCut_Soil", "ClearCut_Veg", "Forest", "Wetland") # associate the labels to the names of the SpatRaster probs <- bayes_read_probs(probs_file, labels) # Plot the probability image bayes_plot_probs(probs, scale = 0.0001, tmap_scale = 1.0) }
Plot RGB raster cube
bayes_plot_rgb( image, red, green, blue, xmin = NULL, xmax = NULL, ymin = NULL, ymax = NULL )
bayes_plot_rgb( image, red, green, blue, xmin = NULL, xmax = NULL, ymin = NULL, ymax = NULL )
image |
Object of class SpatRaster. |
red |
Band for red color. |
green |
Band for green color. |
blue |
Band for blue color. |
xmin |
Subset to be shown (xmin) |
xmax |
Subset to be shown (xmax) |
ymin |
Subset to be shown (ymin) |
ymax |
Subset to be shown (ymax) |
A plot object with an RGB image
Gilberto Camara, [email protected]
if (bayes_run_examples()) { # Define location of a RGB files rgb_dir <- system.file("/extdata/rgb", package = "bayesEO") # list the file files <- list.files(rgb_dir) # build the full path image_files <- paste0(rgb_dir, "/", files) rgb_image <- bayes_read_image(image_files) bayes_plot_rgb(rgb_image, red = "B11", green = "B8A", blue = "B03") }
if (bayes_run_examples()) { # Define location of a RGB files rgb_dir <- system.file("/extdata/rgb", package = "bayesEO") # list the file files <- list.files(rgb_dir) # build the full path image_files <- paste0(rgb_dir, "/", files) rgb_image <- bayes_read_image(image_files) bayes_plot_rgb(rgb_image, red = "B11", green = "B8A", blue = "B03") }
Plot variance maps
bayes_plot_var( x, labels = NULL, quantile = 0.75, n = 15, style = "equal", palette = "YlGnBu", tmap_scale = 1 )
bayes_plot_var( x, labels = NULL, quantile = 0.75, n = 15, style = "equal", palette = "YlGnBu", tmap_scale = 1 )
x |
SpatRaster to be plotted. |
labels |
Labels to be plotted |
quantile |
Thereshold of values to be plotted |
n |
Preferred number of classes |
style |
Method to process the color scale |
palette |
An RColorBrewer palette |
tmap_scale |
Global scale parameter for map (default: 1.5) |
A plot object
Gilberto Camara, [email protected]
if (bayes_run_examples()) { # get the probability file data_dir <- system.file("/extdata/probs/", package = "bayesEO") file <- list.files(data_dir) # build the full path probs_file <- paste0(data_dir, "/", file) # include the labels labels <- c("Water", "ClearCut_Burn", "ClearCut_Soil", "ClearCut_Veg", "Forest", "Wetland") # associate the labels to the names of the SpatRaster probs <- bayes_read_probs(probs_file, labels) # calculate the variance var <- bayes_variance(probs) # Plot the variance image bayes_plot_var(var, n = 15, style = "order", quantile = 0.75, palette = "YlGn", labels = c("Forest", "ClearCut_Veg")) }
if (bayes_run_examples()) { # get the probability file data_dir <- system.file("/extdata/probs/", package = "bayesEO") file <- list.files(data_dir) # build the full path probs_file <- paste0(data_dir, "/", file) # include the labels labels <- c("Water", "ClearCut_Burn", "ClearCut_Soil", "ClearCut_Veg", "Forest", "Wetland") # associate the labels to the names of the SpatRaster probs <- bayes_read_probs(probs_file, labels) # calculate the variance var <- bayes_variance(probs) # Plot the variance image bayes_plot_var(var, n = 15, style = "order", quantile = 0.75, palette = "YlGn", labels = c("Forest", "ClearCut_Veg")) }
Read probability maps
bayes_read_image(files)
bayes_read_image(files)
files |
Full path to raster files |
A SpatRaster object
Gilberto Camara, [email protected]
if (bayes_run_examples()) { # Define location of a probability file data_dir <- system.file("/extdata/rgb", package = "bayesEO") # list the file files <- list.files(data_dir) # build the full path image_files <- paste0(data_dir, "/", files) rgb_image <- bayes_read_image(image_files) }
if (bayes_run_examples()) { # Define location of a probability file data_dir <- system.file("/extdata/rgb", package = "bayesEO") # list the file files <- list.files(data_dir) # build the full path image_files <- paste0(data_dir, "/", files) rgb_image <- bayes_read_image(image_files) }
Read probability maps
bayes_read_probs(probs_file, labels)
bayes_read_probs(probs_file, labels)
probs_file |
Full path to raster multi-band file containing probability matrices |
labels |
Labels to be assigned to the bands |
A SpatRaster object
Gilberto Camara, [email protected]
if (bayes_run_examples()) { # Define location of a probability file data_dir <- system.file("/extdata/probs", package = "bayesEO") # list the file file <- list.files(data_dir) # build the full path probs_file <- paste0(data_dir, "/", file) # define labels labels <- c("Water", "ClearCut_Burn", "ClearCut_Soil", "ClearCut_Veg", "Forest", "Wetland") probs_image <- bayes_read_probs(probs_file, labels) }
if (bayes_run_examples()) { # Define location of a probability file data_dir <- system.file("/extdata/probs", package = "bayesEO") # list the file file <- list.files(data_dir) # build the full path probs_file <- paste0(data_dir, "/", file) # define labels labels <- c("Water", "ClearCut_Burn", "ClearCut_Soil", "ClearCut_Veg", "Forest", "Wetland") probs_image <- bayes_read_probs(probs_file, labels) }
This function informs if examples should run. To run the examples, set "BAYES_RUN_EXAMPLES" environment variable to "YES" using Sys.setenv("BAYES_RUN_EXAMPLES" = "YES") To come back to the default behaviour, please unset the enviroment variable Sys.unsetenv("BAYES_RUN_EXAMPLES")
bayes_run_examples()
bayes_run_examples()
A logical value
This function informs if tests should run. To run the examples, set "BAYES_RUN_TESTS" environment variable to "YES" using Sys.setenv("BAYES_RUN_TESTS" = "YES") To come back to the default behaviour, please unset the enviroment variable Sys.unsetenv("BAYES_RUN_TESTS")
bayes_run_tests()
bayes_run_tests()
TRUE/FALSE
Takes a classified image with probabilities, and reduces outliers and smoothens probability according to Bayesian statistics
bayes_smooth(x, window_size = 7, neigh_fraction = 0.5, smoothness = 10)
bayes_smooth(x, window_size = 7, neigh_fraction = 0.5, smoothness = 10)
x |
SpatRaster object with probabilities images |
window_size |
Size of the neighborhood. |
neigh_fraction |
Fraction of neighbors with high probabilities to be used in Bayesian inference. |
smoothness |
Estimated variance of logit of class probabilities (Bayesian smoothing parameter). It can be either a vector or a scalar. |
A SpatRaster object
Gilberto Camara, [email protected]
if (bayes_run_examples()) { # select a file with probability values data_dir <- system.file("/extdata/probs/", package = "bayesEO") file <- list.files(data_dir) # create a full path for the file probs_file <- paste0(data_dir, "/", file) # provide the labels labels <- c("Water", "ClearCut_Burn", "ClearCut_Soil", "ClearCut_Veg", "Forest", "Wetland") # read the probs file probs <- bayes_read_probs(probs_file, labels) # smooth the probability image probs_smooth <- bayes_smooth(probs, window_size = 7, smoothness = 20 ) # plot the probability image bayes_plot_probs(probs_smooth) }
if (bayes_run_examples()) { # select a file with probability values data_dir <- system.file("/extdata/probs/", package = "bayesEO") file <- list.files(data_dir) # create a full path for the file probs_file <- paste0(data_dir, "/", file) # provide the labels labels <- c("Water", "ClearCut_Burn", "ClearCut_Soil", "ClearCut_Veg", "Forest", "Wetland") # read the probs file probs <- bayes_read_probs(probs_file, labels) # smooth the probability image probs_smooth <- bayes_smooth(probs, window_size = 7, smoothness = 20 ) # plot the probability image bayes_plot_probs(probs_smooth) }
Takes a classified image with probabilities, and labels the image with the pixel of higher probability
bayes_summary(x, scale = 1, sample_size = 15000)
bayes_summary(x, scale = 1, sample_size = 15000)
x |
SpatRaster categorical object |
scale |
Scale to apply to data |
sample_size |
Sample size |
A tibble with information
Gilberto Camara, [email protected]
if (bayes_run_examples()) { # select a file with probability values data_dir <- system.file("/extdata/probs/", package = "bayesEO") file <- list.files(data_dir) # create a SpatRaster object from the file probs_file <- paste0(data_dir, "/", file) # provide the labels labels <- c("Water", "ClearCut_Burn", "ClearCut_Soil", "ClearCut_Veg", "Forest", "Wetland") # read the probs file probs <- bayes_read_probs(probs_file, labels) # produce a labelled map map <- bayes_label(probs) # plot the labelled map bayes_summary(map) }
if (bayes_run_examples()) { # select a file with probability values data_dir <- system.file("/extdata/probs/", package = "bayesEO") file <- list.files(data_dir) # create a SpatRaster object from the file probs_file <- paste0(data_dir, "/", file) # provide the labels labels <- c("Water", "ClearCut_Burn", "ClearCut_Soil", "ClearCut_Veg", "Forest", "Wetland") # read the probs file probs <- bayes_read_probs(probs_file, labels) # produce a labelled map map <- bayes_label(probs) # plot the labelled map bayes_summary(map) }
Takes a probability cube and estimate the local variance of the logit of the probability, to support the choice of parameters for Bayesian smoothing.
bayes_variance(x, window_size = 9, neigh_fraction = 0.5)
bayes_variance(x, window_size = 9, neigh_fraction = 0.5)
x |
SpatRaster object containing probabilities. |
window_size |
Size of the neighborhood. |
neigh_fraction |
Fraction of neighbors with highest probability to be used in Bayesian inference. |
A variance SpatRaster object.
Gilberto Camara, [email protected]
Rolf Simoes, [email protected]
if (bayes_run_examples()) { # select a file with probability values data_dir <- system.file("/extdata/probs/", package = "bayesEO") file <- list.files(data_dir) # create a SpatRaster object from the file x <- terra::rast(paste0(data_dir, "/", file)) # provide the labels labels <- c("Water", "ClearCut_Burn", "ClearCut_Soil", "ClearCut_Veg", "Forest", "Wetland") # name the layers in the SpatRaster with the labels names(x) <- labels # calculate the variance v <- bayes_variance(x) # plot the variance bayes_plot_var(v, quantile = 0.75) }
if (bayes_run_examples()) { # select a file with probability values data_dir <- system.file("/extdata/probs/", package = "bayesEO") file <- list.files(data_dir) # create a SpatRaster object from the file x <- terra::rast(paste0(data_dir, "/", file)) # provide the labels labels <- c("Water", "ClearCut_Burn", "ClearCut_Soil", "ClearCut_Veg", "Forest", "Wetland") # name the layers in the SpatRaster with the labels names(x) <- labels # calculate the variance v <- bayes_variance(x) # plot the variance bayes_plot_var(v, quantile = 0.75) }
Takes a classified image with probabilities, and reduces outliers and smoothens probability according to a Gaussian filter
bilateral_smooth(x, window_size = 5, sigma = 8, tau = 0.1)
bilateral_smooth(x, window_size = 5, sigma = 8, tau = 0.1)
x |
SpatRaster object with probabilities images |
window_size |
Size of the neighborhood. |
sigma |
Standard deviation of the spatial Gaussian kernel |
tau |
Standard deviation of the class probs value |
A SpatRaster object
Gilberto Camara, [email protected]
if (bayes_run_examples()) { # select a file with probability values data_dir <- system.file("/extdata/probs/", package = "bayesEO") file <- list.files(data_dir) # create a full path for the file probs_file <- paste0(data_dir, "/", file) # provide the labels labels <- c("Water", "ClearCut_Burn", "ClearCut_Soil", "ClearCut_Veg", "Forest", "Wetland") # read the probs file probs <- bayes_read(probs_file, labels) # smooth the probability image bilat <- bilateral_smooth(probs, window_size = 5, sigma = 8, tau = 0.1 ) # plot the probability image bayes_plot(bilat, scale = 0.0001) }
if (bayes_run_examples()) { # select a file with probability values data_dir <- system.file("/extdata/probs/", package = "bayesEO") file <- list.files(data_dir) # create a full path for the file probs_file <- paste0(data_dir, "/", file) # provide the labels labels <- c("Water", "ClearCut_Burn", "ClearCut_Soil", "ClearCut_Veg", "Forest", "Wetland") # read the probs file probs <- bayes_read(probs_file, labels) # smooth the probability image bilat <- bilateral_smooth(probs, window_size = 5, sigma = 8, tau = 0.1 ) # plot the probability image bayes_plot(bilat, scale = 0.0001) }
Takes a classified image with probabilities, and reduces outliers and smoothens probability according to a Gaussian filter
gaussian_smooth(x, window_size = 5, sigma = 1)
gaussian_smooth(x, window_size = 5, sigma = 1)
x |
SpatRaster object with probabilities images |
window_size |
Size of the neighborhood. |
sigma |
Standard deviation of the spatial Gaussian kernel |
A SpatRaster object
Gilberto Camara, [email protected]
if (bayes_run_examples()) { # select a file with probability values data_dir <- system.file("/extdata/probs/", package = "bayesEO") file <- list.files(data_dir) # create a full path for the file probs_file <- paste0(data_dir, "/", file) # provide the labels labels <- c("Water", "ClearCut_Burn", "ClearCut_Soil", "ClearCut_Veg", "Forest", "Wetland") # read the probs file probs <- bayes_read(probs_file, labels) # smooth the probability image gauss <- gaussian_smooth(probs, window_size = 5, sigma = 1 ) # plot the probability image bayes_plot_probs(gauss) }
if (bayes_run_examples()) { # select a file with probability values data_dir <- system.file("/extdata/probs/", package = "bayesEO") file <- list.files(data_dir) # create a full path for the file probs_file <- paste0(data_dir, "/", file) # provide the labels labels <- c("Water", "ClearCut_Burn", "ClearCut_Soil", "ClearCut_Veg", "Forest", "Wetland") # read the probs file probs <- bayes_read(probs_file, labels) # smooth the probability image gauss <- gaussian_smooth(probs, window_size = 5, sigma = 1 ) # plot the probability image bayes_plot_probs(gauss) }