| Type: | Package | 
| Version: | 0.2.2 | 
| Title: | Bayesian Smoothing of Remote Sensing Image Classification | 
| Maintainer: | Gilberto Camara <gilberto.camara.inpe@gmail.com> | 
| 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. | 
| Encoding: | UTF-8 | 
| Language: | en-US | 
| Depends: | R (≥ 4.1.0) | 
| URL: | https://github.com/e-sensing/bayesEO/ | 
| BugReports: | https://github.com/e-sensing/bayesEO/issues | 
| License: | GPL-3 | 
| ByteCompile: | true | 
| Imports: | dplyr, ggplot2, grDevices, purrr, Rcpp, stars, stats, terra, tibble, tidyr, tmap, yaml | 
| Suggests: | RcppArmadillo, testthat | 
| LinkingTo: | Rcpp, RcppArmadillo | 
| RoxygenNote: | 7.3.2 | 
| Collate: | 'api_check.R' 'bayes_colors.R' 'bayes_label.R' 'bayes_plot.R' 'bayes_read.R' 'bayes_smooth.R' 'bayes_utils.R' 'bayes_variance.R' 'RcppExports.R' 'zzz.R' | 
| NeedsCompilation: | yes | 
| Packaged: | 2025-09-24 13:50:43 UTC; gilbertocamara | 
| Author: | Gilberto Camara [aut, cre], Renato Assuncao [aut], Rolf Simoes [aut], Felipe Souza [aut] | 
| Repository: | CRAN | 
| Date/Publication: | 2025-09-24 15:00:02 UTC | 
Compute the 2-D Gaussian kernel
Description
Compute the 2-D Gaussian kernel
Usage
.smooth_gauss_kernel(window_size, sigma)
Arguments
| window_size | Size of the neighbourhood. | 
| sigma | Standard deviation of the spatial Gaussian kernel | 
Value
returns a squared matrix filled with Gaussian function
Function to retrieve bayesEO color table
Description
Returns a color table
Usage
bayes_colors()
Value
A tibble with color names and values
Author(s)
Gilberto Camara, gilberto.camara@inpe.br
Function to show colors in SITS
Description
Shows the default SITS colors
Usage
bayes_colors_show()
Value
no return, called for side effects
Author(s)
Gilberto Camara, gilberto.camara@inpe.br
Label probability images to create categorical maps
Description
Takes a classified image with probabilities, and labels the image with the pixel of higher probability
Usage
bayes_label(x)
Arguments
| x | SpatRaster object with probabilities images | 
Value
A SpatRaster object
Author(s)
Gilberto Camara, gilberto.camara@inpe.br
Examples
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
Description
Plot histogram
Usage
bayes_plot_hist(x, scale = 1, quantile = NULL, sample_size = 15000)
Arguments
| 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 | 
Value
A plot object
Author(s)
Gilberto Camara, gilberto.camara@inpe.br
Examples
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
Description
Plot labelled map
Usage
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
)
Arguments
| 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) | 
Value
A plot object
Author(s)
Gilberto Camara gilberto.camara@inpe.br
Examples
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
Description
Plot probability maps
Usage
bayes_plot_probs(
  x,
  scale = 1e-04,
  labels = NULL,
  palette = "YlGnBu",
  tmap_scale = 1
)
Arguments
| 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) | 
Value
A plot object
Author(s)
Gilberto Camara, gilberto.camara@inpe.br
Examples
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 data cubes
Description
Plot RGB raster cube
Usage
bayes_plot_rgb(
  image,
  red,
  green,
  blue,
  xmin = NULL,
  xmax = NULL,
  ymin = NULL,
  ymax = NULL
)
Arguments
| 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) | 
Value
A plot object with an RGB image
Author(s)
Gilberto Camara, gilberto.camara@inpe.br
Examples
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
Description
Plot variance maps
Usage
bayes_plot_var(
  x,
  labels = NULL,
  quantile = 0.75,
  n = 15,
  style = "equal",
  palette = "YlGnBu",
  tmap_scale = 1
)
Arguments
| 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) | 
Value
A plot object
Author(s)
Gilberto Camara, gilberto.camara@inpe.br
Examples
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
Description
Read probability maps
Usage
bayes_read_image(files)
Arguments
| files | Full path to raster files | 
Value
A SpatRaster object
Author(s)
Gilberto Camara, gilberto.camara@inpe.br
Examples
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
Description
Read probability maps
Usage
bayes_read_probs(probs_file, labels)
Arguments
| probs_file | Full path to raster multi-band file containing probability matrices | 
| labels | Labels to be assigned to the bands | 
Value
A SpatRaster object
Author(s)
Gilberto Camara, gilberto.camara@inpe.br
Examples
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)
}
Informs if examples should run
Description
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")
Usage
bayes_run_examples()
Value
A logical value
Informs if tests should run
Description
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")
Usage
bayes_run_tests()
Value
TRUE/FALSE
Smooth probability images
Description
Takes a classified image with probabilities, and reduces outliers and smoothens probability according to Bayesian statistics
Usage
bayes_smooth(x, window_size = 7, neigh_fraction = 0.5, smoothness = 10)
Arguments
| 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. | 
Value
A SpatRaster object
Author(s)
Gilberto Camara, gilberto.camara@inpe.br
Examples
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)
}
Summary of categorical maps
Description
Takes a classified image with probabilities, and labels the image with the pixel of higher probability
Usage
bayes_summary(x, scale = 1, sample_size = 15000)
Arguments
| x | SpatRaster categorical object | 
| scale | Scale to apply to data | 
| sample_size | Sample size | 
Value
A tibble with information
Author(s)
Gilberto Camara, gilberto.camara@inpe.br
Examples
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)
}
Calculate the variance of a probability cube
Description
Takes a probability cube and estimate the local variance of the logit of the probability, to support the choice of parameters for Bayesian smoothing.
Usage
bayes_variance(x, window_size = 9, neigh_fraction = 0.5)
Arguments
| 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. | 
Value
A variance SpatRaster object.
Author(s)
Gilberto Camara, gilberto.camara@inpe.br
Rolf Simoes, rolf.simoes@inpe.br
Examples
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)
}
Smooth probability images with Gaussian filter
Description
Takes a classified image with probabilities, and reduces outliers and smoothens probability according to a Gaussian filter
Usage
bilateral_smooth(x, window_size = 5, sigma = 8, tau = 0.1)
Arguments
| 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 | 
Value
A SpatRaster object
Author(s)
Gilberto Camara, gilberto.camara@inpe.br
Examples
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)
}
Smooth probability images with Gaussian filter
Description
Takes a classified image with probabilities, and reduces outliers and smoothens probability according to a Gaussian filter
Usage
gaussian_smooth(x, window_size = 5, sigma = 1)
Arguments
| x | SpatRaster object with probabilities images | 
| window_size | Size of the neighborhood. | 
| sigma | Standard deviation of the spatial Gaussian kernel | 
Value
A SpatRaster object
Author(s)
Gilberto Camara, gilberto.camara@inpe.br
Examples
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)
}