| Title: | Information Theory, Geometry and Statistics for Synthetic Aperture Radar Data |
|---|---|
| Description: | Statistical models, information-theoretic measures and image analysis tools for Synthetic Aperture Radar (SAR) and polarimetric SAR (PolSAR) data. It implements intensity models (Gamma, generalized Gamma and G0I) and matrix models (scaled complex Wishart, G0 polarimetric and the compound truncated Poisson and compound geometric complex Wishart laws), maximum likelihood and expectation-maximization estimation, closed-form Shannon entropies with their asymptotic variances, entropy-based hypothesis tests and change detection, entropy-based image segmentation by (stochastic) expectation-maximization, stochastic distances and a family of divergence-based classifiers (Kullback-Leibler, Jeffreys, Bhattacharyya and Renyi) for Gaussian vector features and complex Wishart matrix features. The main tools are 'R6' classes and the classifiers are available as a 'parsnip' model, so they can be used inside 'tidymodels' workflows. Methods are described in Ferreira, Coelho and Nascimento (2021) <doi:10.1080/01431161.2020.1826060>, Ferreira and Nascimento (2020) <doi:10.1109/JSTARS.2020.2997666>, Ferreira, Nascimento and Frery (2022) <doi:10.3390/rs14205083> and Nascimento, Ferreira and Frery (2023) <doi:10.1007/s11222-023-10298-0>. |
| Authors: | Jodavid Ferreira [aut, cre] (ORCID: <https://orcid.org/0000-0002-2131-6464>), Abraao Nascimento [aut] (ORCID: <https://orcid.org/0000-0003-2673-219X>) |
| Maintainer: | Jodavid Ferreira <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.0.0 |
| Built: | 2026-11-06 21:12:56 UTC |
| Source: | https://github.com/cran/SITSAR |
Computes the usual accuracy measures of binary change maps: detection rate (DR, percentage of true changes that were detected), false alarm rate (FA, percentage of unchanged pixels flagged as changed), and the percentages of false positives (FP) and false negatives (FN) with respect to all pixels.
change_detection_metrics(truth, estimate)change_detection_metrics(truth, estimate)
truth |
Logical (or 0/1) vector/matrix of true changes. |
estimate |
Logical (or 0/1) vector/matrix of detected changes. |
A tibble with DR, FA, FP, FN (in percent) and the
overall accuracy OA (in percent).
truth <- c(TRUE, TRUE, FALSE, FALSE, FALSE) est <- c(TRUE, FALSE, TRUE, FALSE, FALSE) change_detection_metrics(truth, est)truth <- c(TRUE, TRUE, FALSE, FALSE, FALSE) est <- c(TRUE, FALSE, TRUE, FALSE, FALSE) change_detection_metrics(truth, est)
Applies the entropy test of entropy_test() pixel by pixel, using the
observations of a moving window in two co-registered images, and returns
the map of p-values and the binary change map.
change_map( image1, image2, model = c("gamma", "g0i", "ggamma", "wishart", "g0p"), window = 5, L = NULL, channel = 1, level = 0.01 )change_map( image1, image2, model = c("gamma", "g0i", "ggamma", "wishart", "g0p"), window = 5, L = NULL, channel = 1, level = 0.01 )
image1, image2
|
Co-registered images (SARImage objects or arrays) of the same size. |
model |
One of |
window |
Odd side of the moving window. |
L |
Known number of looks. If |
channel |
Channel used by intensity models. |
level |
Significance level used to declare a change. |
A list of class sitsar_change with the matrices statistic,
p_value and change (logical), and the level.
set.seed(1) a <- matrix(rgammasar(40 * 40, mu = 1, L = 4), 40) b <- a b[11:30, 11:30] <- rgammasar(400, mu = 4, L = 4) cd <- change_map(a, b, model = "gamma", window = 5, L = 4) cd plot_map(cd$change, main = "Detected changes")set.seed(1) a <- matrix(rgammasar(40 * 40, mu = 1, L = 4), 40) b <- a b[11:30, 11:30] <- rgammasar(400, mu = 4, L = 4) cd <- change_map(a, b, model = "gamma", window = 5, L = 4) cd plot_map(cd$change, main = "Detected changes")
Density and random generation for the compound truncated Poisson complex
Wishart (CTPCW) and compound geometric complex Wishart (CGCW) laws
(Ferreira, Nascimento and Frery, 2022). They describe the PolSAR return
as a random sum of independent (unscaled)
complex Wishart matrices with
, where the number of scatterers follows a
zero-truncated Poisson law with mean parameter (CTPCW) or a
geometric law on with success probability
(CGCW). Their densities are
which are able to describe multimodal intensities. The series is evaluated in log-scale and truncated when the terms become negligible.
dctpcw(x, lambda, Sigma, L, log = FALSE, kmax = 500L) rctpcw(n, lambda, Sigma, L, output = c("array", "vec")) dcgcw(x, p, Sigma, L, log = FALSE, kmax = 500L) rcgcw(n, p, Sigma, L, output = c("array", "vec"))dctpcw(x, lambda, Sigma, L, log = FALSE, kmax = 500L) rctpcw(n, lambda, Sigma, L, output = c("array", "vec")) dcgcw(x, p, Sigma, L, log = FALSE, kmax = 500L) rcgcw(n, p, Sigma, L, output = c("array", "vec"))
x |
PolSAR observations: a complex array |
lambda |
Mean parameter of the zero-truncated Poisson law
( |
Sigma |
Hermitian positive definite |
L |
Number of looks of each Wishart component ( |
log |
Logical; if |
kmax |
Maximum number of terms of the series. |
n |
Number of observations. |
output |
Format of the generated sample: |
p |
Success probability of the geometric law ( |
dctpcw()/dcgcw() return (log-)densities; rctpcw()/rcgcw()
return the simulated sample, with the simulated numbers of components in
the attribute "N".
Ferreira, J. A., Nascimento, A. D. C. and Frery, A. C. (2022). PolSAR models with multimodal intensities. Remote Sensing, 14(20), 5083. doi:10.3390/rs14205083
CompoundWishart for the R6 interface and EM estimation.
Sigma <- polsar_example_sigma("forest") set.seed(1) S <- rctpcw(3, lambda = 2, Sigma = Sigma, L = 4) attr(S, "N") dctpcw(S, lambda = 2, Sigma = Sigma, L = 4, log = TRUE) S2 <- rcgcw(3, p = 0.6, Sigma = Sigma, L = 4) dcgcw(S2, p = 0.6, Sigma = Sigma, L = 4, log = TRUE)Sigma <- polsar_example_sigma("forest") set.seed(1) S <- rctpcw(3, lambda = 2, Sigma = Sigma, L = 4) attr(S, "N") dctpcw(S, lambda = 2, Sigma = Sigma, L = 4, log = TRUE) S2 <- rcgcw(3, p = 0.6, Sigma = Sigma, L = 4) dcgcw(S2, p = 0.6, Sigma = Sigma, L = 4, log = TRUE)
R6 class for the compound truncated Poisson (CTPCW) and compound
geometric (CGCW) complex Wishart laws of Ferreira, Nascimento and Frery
(2022); see dctpcw(). Parameters are estimated by the
expectation-maximisation (EM) algorithm, treating the number of
scatterers as missing data:
E-step: ;
M-step: and
(CTPCW) or
(CGCW).
The Shannon entropy has no closed form and is approximated by Monte Carlo.
An R6::R6Class generator. CompoundWishart$new() returns a new CompoundWishart
object; its methods are described in the Methods section below.
SARModel -> CompoundWishart
countingCounting law: "poisson" (zero-truncated) or "geometric".
iterationsNumber of EM iterations of the last fit.
CompoundWishart$new()Create a compound Wishart model.
CompoundWishart$new(
counting = c("poisson", "geometric"),
Sigma = diag(3) + (0+0i),
L = 4,
lambda = 1,
p = 0.5
)
counting"poisson" (CTPCW) or "geometric" (CGCW).
SigmaHermitian positive definite matrix.
LNumber of looks of each component.
lambda, pParameter of the counting law.
CompoundWishart$density()(Log-)density.
CompoundWishart$density(x, log = FALSE)
xPolSAR observations.
logReturn log-densities?
CompoundWishart$random()Simulate PolSAR observations.
CompoundWishart$random(n, output = "array")
nNumber of observations.
output"array" or "vec".
CompoundWishart$fit()Fit by the EM algorithm.
CompoundWishart$fit(x, L, tol = 1e-06, max_iter = 500L)
xPolSAR observations.
LKnown number of looks of each component.
tolConvergence tolerance (relative change of the parameters).
max_iterMaximum number of iterations.
CompoundWishart$entropy()Monte Carlo approximation of the Shannon entropy.
CompoundWishart$entropy(nsim = 2000L)
nsimNumber of simulated observations.
CompoundWishart$entropy_variance()Not available for compound models.
CompoundWishart$entropy_variance(n = self$n)
nIgnored.
CompoundWishart$clone()The objects of this class are cloneable with this method.
CompoundWishart$clone(deep = FALSE)
deepWhether to make a deep clone.
Ferreira, J. A., Nascimento, A. D. C. and Frery, A. C. (2022). PolSAR models with multimodal intensities. Remote Sensing, 14(20), 5083. doi:10.3390/rs14205083
set.seed(1) S <- rctpcw(200, lambda = 1.5, Sigma = polsar_example_sigma("forest"), L = 4) m <- CompoundWishart$new(counting = "poisson")$fit(S, L = 4) m$params$lambda m$iterationsset.seed(1) S <- rctpcw(200, lambda = 1.5, Sigma = polsar_example_sigma("forest"), L = 4) m <- CompoundWishart$new(counting = "poisson")$fit(S, L = 4) m$params$lambda m$iterations
Density, distribution function, quantile function and random generation
for the distribution, the
multiplicative model for multilook SAR intensities with reciprocal gamma
backscatter and gamma speckle (Frery et al., 1997).
dg0i(x, alpha, gamma, L, log = FALSE) pg0i(q, alpha, gamma, L, lower.tail = TRUE, log.p = FALSE) qg0i(p, alpha, gamma, L, lower.tail = TRUE, log.p = FALSE) rg0i(n, alpha, gamma, L)dg0i(x, alpha, gamma, L, log = FALSE) pg0i(q, alpha, gamma, L, lower.tail = TRUE, log.p = FALSE) qg0i(p, alpha, gamma, L, lower.tail = TRUE, log.p = FALSE) rg0i(n, alpha, gamma, L)
x, q
|
Vector of quantiles. |
alpha |
Roughness parameter ( |
gamma |
Scale parameter ( |
L |
Number of looks ( |
log, log.p
|
Logical; if |
lower.tail |
Logical; if |
p |
Vector of probabilities. |
n |
Number of observations. |
The density is
with roughness , scale and number of
looks . If then
follows a Snedecor F distribution with
and degrees of freedom, which is used to compute
the distribution and quantile functions exactly.
dg0i() gives the density, pg0i() the distribution function,
qg0i() the quantile function and rg0i() generates random deviates.
Frery, A. C., Muller, H.-J., Yanasse, C. C. F. and Sant'Anna, S. J. S. (1997). A model for extremely heterogeneous clutter. IEEE Transactions on Geoscience and Remote Sensing, 35(3), 648–659.
Nascimento, A. D. C., Cintra, R. J. and Frery, A. C. (2010). Hypothesis testing in speckled data with stochastic distances. IEEE Transactions on Geoscience and Remote Sensing, 48(1), 373–385.
G0I for the R6 interface (estimation and entropy).
set.seed(1) z <- rg0i(5, alpha = -1.5, gamma = 2, L = 8) dg0i(z, alpha = -1.5, gamma = 2, L = 8) pg0i(c(0.5, 1, 2), alpha = -1.5, gamma = 2, L = 8) qg0i(c(0.1, 0.5, 0.9), alpha = -1.5, gamma = 2, L = 8)set.seed(1) z <- rg0i(5, alpha = -1.5, gamma = 2, L = 8) dg0i(z, alpha = -1.5, gamma = 2, L = 8) pg0i(c(0.5, 1, 2), alpha = -1.5, gamma = 2, L = 8) qg0i(c(0.1, 0.5, 0.9), alpha = -1.5, gamma = 2, L = 8)
Density and random generation for the polarimetric
law (also known as
), obtained from the multiplicative model
with and reciprocal
gamma texture with unit
mean (Freitas et al., 2005):
with . When it converges to
the scaled complex Wishart law.
dg0p(x, alpha, Sigma, L, log = FALSE) rg0p(n, alpha, Sigma, L, output = c("array", "vec"))dg0p(x, alpha, Sigma, L, log = FALSE) rg0p(n, alpha, Sigma, L, output = c("array", "vec"))
x |
PolSAR observations: a complex array |
alpha |
Roughness parameter ( |
Sigma |
Hermitian positive definite |
L |
Number of looks ( |
log |
Logical; if |
n |
Number of observations. |
output |
Format of the generated sample: |
dg0p() returns (log-)densities and rg0p() the simulated
sample.
Freitas, C. C., Frery, A. C. and Correia, A. H. (2005). The polarimetric G distribution for SAR data analysis. Environmetrics, 16(1), 13–31.
Nascimento, A. D. C., Ferreira, J. A. and Frery, A. C. (2023). Unsupervised segmentation of PolSAR data with complex Wishart and G0m distributions and Shannon entropy. Statistics and Computing, 33, 129. doi:10.1007/s11222-023-10298-0
G0Polarimetric for the R6 interface.
Sigma <- polsar_example_sigma("urban") set.seed(1) Z <- rg0p(3, alpha = -3, Sigma = Sigma, L = 4) dg0p(Z, alpha = -3, Sigma = Sigma, L = 4, log = TRUE)Sigma <- polsar_example_sigma("urban") set.seed(1) Z <- rg0p(3, alpha = -3, Sigma = Sigma, L = 4) dg0p(Z, alpha = -3, Sigma = Sigma, L = 4, log = TRUE)
Density, distribution function, quantile function and random generation
for the multilook intensity Gamma law parametrised by its mean
and number of looks :
This is the model for homogeneous areas (fully developed speckle).
dgammasar(x, mu, L, log = FALSE) pgammasar(q, mu, L, lower.tail = TRUE, log.p = FALSE) qgammasar(p, mu, L, lower.tail = TRUE, log.p = FALSE) rgammasar(n, mu, L)dgammasar(x, mu, L, log = FALSE) pgammasar(q, mu, L, lower.tail = TRUE, log.p = FALSE) qgammasar(p, mu, L, lower.tail = TRUE, log.p = FALSE) rgammasar(n, mu, L)
x, q
|
Vector of quantiles. |
mu |
Mean ( |
L |
Number of looks ( |
log, log.p
|
Logical; if |
lower.tail |
Logical; if |
p |
Vector of probabilities. |
n |
Number of observations. |
Density, distribution function, quantile function or random deviates.
GammaSAR for the R6 interface.
dgammasar(c(0.5, 1, 2), mu = 1, L = 4) rgammasar(3, mu = 1, L = 4)dgammasar(c(0.5, 1, 2), mu = 1, L = 4) rgammasar(3, mu = 1, L = 4)
Density, distribution function, quantile function and random generation
for the generalized Gamma (Stacy) law with power , shape
and inverse-scale :
For it reduces to the Gamma law with shape
and rate ; in SAR applications plays the role of the
number of looks.
dggamma(x, alpha, phi, mu, log = FALSE) pggamma(q, alpha, phi, mu, lower.tail = TRUE, log.p = FALSE) qggamma(p, alpha, phi, mu, lower.tail = TRUE, log.p = FALSE) rggamma(n, alpha, phi, mu)dggamma(x, alpha, phi, mu, log = FALSE) pggamma(q, alpha, phi, mu, lower.tail = TRUE, log.p = FALSE) qggamma(p, alpha, phi, mu, lower.tail = TRUE, log.p = FALSE) rggamma(n, alpha, phi, mu)
x, q
|
Vector of quantiles. |
alpha |
Power parameter ( |
phi |
Shape parameter ( |
mu |
Inverse-scale parameter ( |
log, log.p
|
Logical; if |
lower.tail |
Logical; if |
p |
Vector of probabilities. |
n |
Number of observations. |
Density, distribution function, quantile function or random deviates.
Li, H.-C., Hong, W., Wu, Y.-R. and Fan, P.-Z. (2011). On the empirical- statistical modeling of SAR images with generalized gamma distribution. IEEE Journal of Selected Topics in Signal Processing, 5(3), 386–397.
GGammaSAR for the R6 interface.
dggamma(c(0.5, 1, 2), alpha = 1.5, phi = 2, mu = 1) rggamma(3, alpha = 1.5, phi = 2, mu = 1)dggamma(c(0.5, 1, 2), alpha = 1.5, phi = 2, mu = 1) rggamma(3, alpha = 1.5, phi = 2, mu = 1)
Computes stochastic distances between two laws by
numerical integration (Nascimento, Cintra and Frery, 2010).
distancesg0i( par_1, par_2, p = 1/2, type = c("KL", "Renyi", "Bhattacharyya", "Hellinger", "Arithmetic-Geometric", "Triangular", "Harmonic-Mean") )distancesg0i( par_1, par_2, p = 1/2, type = c("KL", "Renyi", "Bhattacharyya", "Hellinger", "Arithmetic-Geometric", "Triangular", "Harmonic-Mean") )
par_1, par_2
|
Parameter vectors |
p |
Order of the Rényi distance, in (0, 1). |
type |
One of |
An object of class distancesg0i with the parameters, the type
and the distance_value.
Nascimento, A. D. C., Cintra, R. J. and Frery, A. C. (2010). Hypothesis testing in speckled data with stochastic distances. IEEE Transactions on Geoscience and Remote Sensing, 48(1), 373–385.
distancesg0i(c(-1.5, 2, 4), c(-1.5, 2, 4)) res <- distancesg0i(c(-1.5, 2, 8), c(-3, 2, 4), type = "Hellinger") resdistancesg0i(c(-1.5, 2, 4), c(-1.5, 2, 4)) res <- distancesg0i(c(-1.5, 2, 8), c(-3, 2, 4), type = "Hellinger") res
Fits the law to each intensity channel of two
rectangular regions of an image and computes all the stochastic
distances of distancesg0i() between them.
distancesg0itable(image, marks1, marks2, p = 1/2, L = NULL)distancesg0itable(image, marks1, marks2, p = 1/2, L = NULL)
image |
A SARImage or an array ( |
marks1, marks2
|
Region limits as |
p |
Order of the Rényi distance. |
L |
Known number of looks; estimated when |
An object of class distancesg0itable with the marks and the
table of distances (distancestable, channels in rows).
res <- distancesg0itable(SanFrancisco150, c(10, 30, 10, 30), c(10, 30, 120, 140), L = 4) resres <- distancesg0itable(SanFrancisco150, c(10, 30, 10, 30), c(10, 30, 120, 140), L = 4) res
divergence_classifier() defines the divergence-based classifier of
Ferreira, Coelho and Nascimento (2021) as a 'parsnip' model
specification, so it can be used with 'workflows', 'recipes', 'rsample',
'tune' and 'yardstick'. The engine selects the family of features:
"gaussian" (multivariate normal intensity features, the default) or
"wishart" (complex Wishart PolSAR matrix features). The predictors must
be in the format of sar_features(); extra columns such as row/col
are ignored by the engine (it is good practice to give them an "id"
role in a recipe).
divergence_classifier( mode = "classification", divergence = NULL, order = NULL, kind = NULL, engine = "gaussian" ) ## S3 method for class 'divergence_classifier' update( object, parameters = NULL, divergence = NULL, order = NULL, kind = NULL, fresh = FALSE, ... )divergence_classifier( mode = "classification", divergence = NULL, order = NULL, kind = NULL, engine = "gaussian" ) ## S3 method for class 'divergence_classifier' update( object, parameters = NULL, divergence = NULL, order = NULL, kind = NULL, fresh = FALSE, ... )
mode |
A single character string for the type of model. The only
possible value is |
divergence |
Divergence: |
order |
Order of the Rényi divergence, in (0, 1). Tunable with
|
kind |
Form of the Rényi divergence (1 to 4); see divergences. |
engine |
|
object |
A |
parameters |
A 1-row tibble or named list with the main parameters. |
fresh |
Replace the arguments instead of updating them? |
... |
Not used. |
A model specification object with classes
divergence_classifier and model_spec.
DivergenceClassifier, sar_features()
spec <- divergence_classifier(divergence = "renyi", order = 0.5) |> parsnip::set_engine("wishart") spec feats <- sar_features(SARImage$new(SanFrancisco150)$crop(1:60, 1:60), window = 5) feats$class <- factor(as.vector(SanFrancisco150_gt[1:60, 1:60])) fit <- parsnip::fit(spec, class ~ ., data = feats) head(predict(fit, feats)) head(predict(fit, feats, type = "prob"))spec <- divergence_classifier(divergence = "renyi", order = 0.5) |> parsnip::set_engine("wishart") spec feats <- sar_features(SARImage$new(SanFrancisco150)$crop(1:60, 1:60), window = 5) feats$class <- factor(as.vector(SanFrancisco150_gt[1:60, 1:60])) fit <- parsnip::fit(spec, class ~ ., data = feats) head(predict(fit, feats)) head(predict(fit, feats, type = "prob"))
Implements the family of divergence-based classifiers of Ferreira, Coelho
and Nascimento (2021). Each pixel is represented by the model fitted to
the observations of a moving window (see sar_features()) and each class
by the model fitted to its training pixels. A pixel is assigned to the
class that minimises the chosen divergence between the two fitted models:
Two families of features are available:
"gaussian"multivariate normal laws for the intensity vector,
using the columns mean_* and cov_* of sar_features(). The class
covariance combines the average local covariance and the covariance
of the local means (law of total variance).
"wishart"scaled complex Wishart laws for the full PolSAR
covariance matrix, using the columns c11, c12_re, c12_im, ...
of sar_features(). Since all laws share the number of looks, it
only rescales the divergences and does not affect the classification.
The classifier is also available as the 'parsnip' model
divergence_classifier(), for use in 'tidymodels' workflows.
An R6::R6Class generator. DivergenceClassifier$new() returns a new DivergenceClassifier
object; its methods are described in the Methods section below.
family"gaussian" or "wishart".
divergenceDivergence used (see divergence_gaussian()).
orderOrder of the Rényi divergence.
kindForm (1-4) of the Rényi divergence.
classesClass labels.
prototypesList with the fitted model of each class.
channelsChannels (Gaussian) or matrix order (Wishart) used.
DivergenceClassifier$new()Create a classifier.
DivergenceClassifier$new(
family = c("gaussian", "wishart"),
divergence = c("renyi", "kl", "jeffreys", "bhattacharyya"),
order = 0.5,
kind = 1
)
family"gaussian" or "wishart".
divergence"kl", "jeffreys", "bhattacharyya" or "renyi".
orderOrder of the Rényi divergence, in (0, 1).
kindForm of the Rényi divergence (1 to 4).
DivergenceClassifier$fit()Fit the class prototypes.
DivergenceClassifier$fit(x, y)
xData frame of features (see sar_features()); other columns
are ignored.
yFactor (or vector) of class labels.
DivergenceClassifier$distances()Divergence between every row of x and every class.
DivergenceClassifier$distances(x)
xData frame of features.
DivergenceClassifier$predict()Predict classes, pseudo-probabilities or distances.
DivergenceClassifier$predict(x, type = c("class", "prob", "distance"))
xData frame of features.
type"class", "prob" (softmax of minus the divergences) or
"distance".
DivergenceClassifier$print()Print the classifier.
DivergenceClassifier$print(...)
...Ignored.
DivergenceClassifier$clone()The objects of this class are cloneable with this method.
DivergenceClassifier$clone(deep = FALSE)
deepWhether to make a deep clone.
Ferreira, J. A., Coelho, H. and Nascimento, A. D. C. (2021). A family of divergence-based classifiers for polarimetric synthetic aperture radar (PolSAR) imagery vector and matrix features. International Journal of Remote Sensing, 42(4), 1201–1229. doi:10.1080/01431161.2020.1826060
img <- SARImage$new(SanFrancisco150)$crop(1:80, 1:80) feats <- sar_features(img, window = 5) feats$class <- factor(as.vector(SanFrancisco150_gt[1:80, 1:80]), labels = c("ocean", "forest", "urban")) set.seed(1) train <- feats[sample(nrow(feats), 300), ] clf <- DivergenceClassifier$new(family = "wishart", divergence = "renyi", order = 0.5, kind = 3) clf$fit(train, train$class) pred <- clf$predict(feats) mean(pred == feats$class) head(clf$predict(feats, type = "distance"))img <- SARImage$new(SanFrancisco150)$crop(1:80, 1:80) feats <- sar_features(img, window = 5) feats$class <- factor(as.vector(SanFrancisco150_gt[1:80, 1:80]), labels = c("ocean", "forest", "urban")) set.seed(1) train <- feats[sample(nrow(feats), 300), ] clf <- DivergenceClassifier$new(family = "wishart", divergence = "renyi", order = 0.5, kind = 3) clf$fit(train, train$class) pred <- clf$predict(feats) mean(pred == feats$class) head(clf$predict(feats, type = "distance"))
Closed-form divergences between two multivariate normal laws
and , and between two
scaled complex Wishart laws and
with a common number of looks. They are
the building blocks of the divergence-based classifiers of Ferreira,
Coelho and Nascimento (2021).
divergence_gaussian( mu1, Sigma1, mu2, Sigma2, type = c("kl", "jeffreys", "bhattacharyya", "renyi"), order = 0.5, kind = 1 ) divergence_wishart( Sigma1, Sigma2, L, type = c("kl", "jeffreys", "bhattacharyya", "renyi"), order = 0.5, kind = 1 )divergence_gaussian( mu1, Sigma1, mu2, Sigma2, type = c("kl", "jeffreys", "bhattacharyya", "renyi"), order = 0.5, kind = 1 ) divergence_wishart( Sigma1, Sigma2, L, type = c("kl", "jeffreys", "bhattacharyya", "renyi"), order = 0.5, kind = 1 )
mu1, mu2
|
Mean vectors. |
Sigma1, Sigma2
|
Covariance matrices (real symmetric for Gaussian laws, Hermitian for Wishart laws). |
type |
Divergence: |
order |
Order |
kind |
Form of the Rényi divergence (1 to 4). |
L |
Number of looks (common to both Wishart laws). |
Available measures (type):
"kl"Kullback-Leibler divergence .
"jeffreys"Jeffreys divergence
.
"bhattacharyya"Bhattacharyya distance
.
"renyi"Rényi divergence of order (order),
in one of four forms (kind): 1, ;
2, ; 3, the symmetrised mean
;
and 4, ,
where .
For Gaussian laws the Rényi divergence uses the normalisation of Pardo
(2006), , which gives
with and . For Wishart laws the normalisation of Frery,
Nascimento and Cintra (2014), , is used:
Both converge to the Kullback-Leibler divergence when
.
A single non-negative number.
Ferreira, J. A., Coelho, H. and Nascimento, A. D. C. (2021). A family of divergence-based classifiers for polarimetric synthetic aperture radar (PolSAR) imagery vector and matrix features. International Journal of Remote Sensing, 42(4), 1201–1229. doi:10.1080/01431161.2020.1826060
Frery, A. C., Nascimento, A. D. C. and Cintra, R. J. (2014). Analytic expressions for stochastic distances between relaxed complex Wishart distributions. IEEE Transactions on Geoscience and Remote Sensing, 52(2), 1213–1226.
Pardo, L. (2006). Statistical Inference Based on Divergence Measures. Chapman & Hall/CRC.
S1 <- diag(3); S2 <- diag(c(2, 1, 0.5)) divergence_gaussian(c(0, 0, 0), S1, c(1, 0, 0), S2, type = "kl") divergence_gaussian(c(0, 0, 0), S1, c(1, 0, 0), S2, type = "renyi", order = 0.5, kind = 3) W1 <- polsar_example_sigma("forest"); W2 <- polsar_example_sigma("urban") divergence_wishart(W1, W2, L = 4, type = "jeffreys") divergence_wishart(W1, W2, L = 4, type = "renyi", order = 0.9)S1 <- diag(3); S2 <- diag(c(2, 1, 0.5)) divergence_gaussian(c(0, 0, 0), S1, c(1, 0, 0), S2, type = "kl") divergence_gaussian(c(0, 0, 0), S1, c(1, 0, 0), S2, type = "renyi", order = 0.5, kind = 3) W1 <- polsar_example_sigma("forest"); W2 <- polsar_example_sigma("urban") divergence_wishart(W1, W2, L = 4, type = "jeffreys") divergence_wishart(W1, W2, L = 4, type = "renyi", order = 0.9)
Density and random generation for the scaled complex Wishart law
, the reference model for multilook
PolSAR covariance (coherency) matrices in homogeneous areas:
where and
.
dwishart_sar(x, Sigma, L, log = FALSE) rwishart_sar(n, Sigma, L, output = c("array", "vec"))dwishart_sar(x, Sigma, L, log = FALSE) rwishart_sar(n, Sigma, L, output = c("array", "vec"))
x |
PolSAR observations: a complex array |
Sigma |
Hermitian positive definite |
L |
Number of looks ( |
log |
Logical; if |
n |
Number of observations. |
output |
Format of the generated sample: |
Random matrices are generated with the complex Bartlett decomposition,
so non-integer numbers of looks are allowed.
dwishart_sar() returns a vector of (log-)densities;
rwishart_sar() returns the simulated sample.
Goodman, N. R. (1963). Statistical analysis based on a certain multivariate complex Gaussian distribution. The Annals of Mathematical Statistics, 34(1), 152–177.
Lee, J.-S., Grunes, M. R. and Kwok, R. (1994). Classification of multi-look polarimetric SAR imagery based on complex Wishart distribution. International Journal of Remote Sensing, 15(11), 2299–2311.
WishartSAR for the R6 interface.
Sigma <- polsar_example_sigma("forest") set.seed(1) Z <- rwishart_sar(3, Sigma, L = 4) dim(Z) dwishart_sar(Z, Sigma, L = 4, log = TRUE)Sigma <- polsar_example_sigma("forest") set.seed(1) Z <- rwishart_sar(3, Sigma, L = 4) dim(Z) dwishart_sar(Z, Sigma, L = 4, log = TRUE)
Closed-form Shannon entropies for the models
used in SAR (intensity) and PolSAR (matrix) image analysis. All functions
are vectorised in the scalar parameters.
entropy_gamma(mu, L) entropy_g0i(alpha, gamma, L) entropy_ggamma(alpha, phi, mu) entropy_wishart(Sigma, L) entropy_g0p(alpha, Sigma, L)entropy_gamma(mu, L) entropy_g0i(alpha, gamma, L) entropy_ggamma(alpha, phi, mu) entropy_wishart(Sigma, L) entropy_g0p(alpha, Sigma, L)
mu |
Mean of the Gamma law, or inverse scale of the generalized Gamma law. |
L |
Number of looks. |
alpha |
Roughness (G0I, G0 polarimetric) or power (generalized Gamma) parameter. |
gamma |
Scale parameter of the G0I law. |
phi |
Shape parameter of the generalized Gamma law. |
Sigma |
Hermitian positive definite covariance matrix. |
.
(Ferreira and Nascimento, 2020)
.
.
(Nascimento, Ferreira and Frery, 2023)
, with
.
(Nascimento, Ferreira and Frery, 2023) obtained
from and
.
Numeric vector of entropies.
Ferreira, J. A. and Nascimento, A. D. C. (2020). Shannon entropy for the G0I model: a new segmentation approach. IEEE Journal of Selected Topics in Applied Earth Observations and Remote Sensing, 13, 2547–2553. doi:10.1109/JSTARS.2020.2997666
Nascimento, A. D. C., Ferreira, J. A. and Frery, A. C. (2023). Unsupervised segmentation of PolSAR data with complex Wishart and G0m distributions and Shannon entropy. Statistics and Computing, 33, 129. doi:10.1007/s11222-023-10298-0
entropy_gamma(mu = 1, L = 4) entropy_g0i(alpha = -3, gamma = 2, L = 4) entropy_ggamma(alpha = 1, phi = 4, mu = 4) # equals the Gamma entropy S <- polsar_example_sigma("forest") entropy_wishart(S, L = 4) entropy_g0p(alpha = -5, Sigma = S, L = 4)entropy_gamma(mu = 1, L = 4) entropy_g0i(alpha = -3, gamma = 2, L = 4) entropy_ggamma(alpha = 1, phi = 4, mu = 4) # equals the Gamma entropy S <- polsar_example_sigma("forest") entropy_wishart(S, L = 4) entropy_g0p(alpha = -5, Sigma = S, L = 4)
Estimates, at every pixel, the parameters of a SAR/PolSAR model with the observations inside a square moving window and returns the map of Shannon entropies (Ferreira and Nascimento, 2020; Nascimento, Ferreira and Frery, 2023). Optionally, the map of asymptotic variances of the entropy estimators is returned as well.
entropy_map( image, model = c("gamma", "g0i", "ggamma", "wishart", "g0p"), window = 7, L = NULL, channels = NULL, variance = FALSE )entropy_map( image, model = c("gamma", "g0i", "ggamma", "wishart", "g0p"), window = 7, L = NULL, channels = NULL, variance = FALSE )
image |
A SARImage or an array accepted by |
model |
One of |
window |
Odd side of the moving window. |
L |
Known number of looks. If |
channels |
Channels used by intensity models (default: all). |
variance |
Also return the variance map? |
For the Gamma and Wishart models the computations are fully vectorised (local sufficient statistics are obtained from integral images), so the maps are computed in a fraction of a second. The G0I, generalized Gamma and G0 polarimetric models require a numerical maximisation per pixel and are therefore slower (use small images or crops to explore them).
A matrix (one channel or matrix model) or an array
nrow x ncol x channels of entropies. If variance = TRUE, a list with
elements entropy, variance and n (window sizes).
Ferreira, J. A. and Nascimento, A. D. C. (2020). Shannon entropy for the G0I model: a new segmentation approach. IEEE Journal of Selected Topics in Applied Earth Observations and Remote Sensing, 13, 2547–2553. doi:10.1109/JSTARS.2020.2997666
Nascimento, A. D. C., Ferreira, J. A. and Frery, A. C. (2023). Unsupervised segmentation of PolSAR data with complex Wishart and G0m distributions and Shannon entropy. Statistics and Computing, 33, 129. doi:10.1007/s11222-023-10298-0
img <- SARImage$new(SanFrancisco150) H <- entropy_map(img, model = "wishart", window = 7, L = 4) dim(H) plot_map(H, main = "Wishart entropy") Hg <- entropy_map(img, model = "gamma", window = 7, channels = "HV") small <- img$crop(1:15, 1:15) Hi <- entropy_map(small, model = "g0i", window = 5, L = 4, channels = 1)img <- SARImage$new(SanFrancisco150) H <- entropy_map(img, model = "wishart", window = 7, L = 4) dim(H) plot_map(H, main = "Wishart entropy") Hg <- entropy_map(img, model = "gamma", window = 7, channels = "HV") small <- img$crop(1:15, 1:15) Hi <- entropy_map(small, model = "g0i", window = 5, L = 4, channels = 1)
Tests whether two samples come from the same distribution by comparing their estimated Shannon entropies. Under the null hypothesis of equal entropies, and by the asymptotic normality of the maximum likelihood estimator of the entropy,
follows asymptotically a distribution. This statistic is
the basis of the entropy-based change detectors of the thesis of
J. A. Ferreira (2021).
entropy_test( x, y, model = c("gamma", "g0i", "ggamma", "wishart", "g0p"), L = NULL )entropy_test( x, y, model = c("gamma", "g0i", "ggamma", "wishart", "g0p"), L = NULL )
x, y
|
Samples: numeric vectors of intensities (intensity models) or PolSAR observations (matrix models). |
model |
One of |
L |
Known number of looks; estimated when |
An object of class htest.
Ferreira, J. A. (2021). Entropias e somas compostas para matrizes estocásticas aplicadas a sistemas PolSAR. PhD thesis, Universidade Federal de Pernambuco.
set.seed(1) x <- rg0i(200, alpha = -3, gamma = 2, L = 4) y <- rg0i(200, alpha = -3, gamma = 2, L = 4) z <- rg0i(200, alpha = -1.5, gamma = 1, L = 4) entropy_test(x, y, model = "g0i", L = 4) entropy_test(x, z, model = "g0i", L = 4)$p.valueset.seed(1) x <- rg0i(200, alpha = -3, gamma = 2, L = 4) y <- rg0i(200, alpha = -3, gamma = 2, L = 4) z <- rg0i(200, alpha = -1.5, gamma = 1, L = 4) entropy_test(x, y, model = "g0i", L = 4) entropy_test(x, z, model = "g0i", L = 4)$p.value
Unsupervised segmentation of SAR/PolSAR images from maps of estimated
Shannon entropies (Ferreira and Nascimento, 2020; Nascimento, Ferreira and
Frery, 2023). By the asymptotic normality of the entropy estimators, the
entropy vector of a pixel of the -th region is approximately
Gaussian, so the image is modelled as a finite mixture of Gaussian laws
(with diagonal covariance matrices) fitted by the expectation-maximisation
algorithm (method = "em") or by its stochastic version (method = "sem"), in which the E-step is followed by a random allocation of every
pixel to a class drawn from its posterior probabilities. Pixels are then
labelled by the maximum a posteriori rule.
An R6::R6Class generator. EntropySegmenter$new() returns a new EntropySegmenter
object; its methods are described in the Methods section below.
kNumber of classes.
method"em" or "sem".
weightsMixture weights.
meansMatrix (k x features) of class means.
variancesMatrix (k x features) of class variances.
posteriorMatrix of posterior probabilities.
labelsInteger vector of labels (classes ordered by the mean of the first feature).
loglikTrace of the log-likelihood.
iterationsNumber of iterations.
convergedLogical convergence flag.
dimSpatial dimensions when fitted to a map (NULL otherwise).
EntropySegmenter$new()Create a segmenter.
EntropySegmenter$new(
k = 2,
method = c("em", "sem"),
max_iter = 200L,
tol = 1e-08
)
kNumber of classes.
method"em" or "sem".
max_iterMaximum number of iterations.
tolTolerance for the relative change of the log-likelihood.
EntropySegmenter$fit()Fit the mixture.
EntropySegmenter$fit(x, init = NULL, is_map = TRUE)
xEntropy features: a matrix (one map, or pixels in rows and
features in columns when is_map = FALSE), an array
nrow x ncol x features (several maps), or a numeric vector.
initInitial labels (integer vector) or NULL for k-means.
is_mapTreat a matrix x as a single map? Default TRUE.
EntropySegmenter$predict()Labels of new observations (maximum a posteriori).
EntropySegmenter$predict(x, is_map = TRUE)
xEntropy features in the same format used in $fit().
is_mapTreat a matrix x as a single map?
EntropySegmenter$label_map()Labels as a matrix with the spatial dimensions of the fitted map.
EntropySegmenter$label_map()
EntropySegmenter$print()Print a summary.
EntropySegmenter$print(...)
...Ignored.
EntropySegmenter$clone()The objects of this class are cloneable with this method.
EntropySegmenter$clone(deep = FALSE)
deepWhether to make a deep clone.
Ferreira, J. A. and Nascimento, A. D. C. (2020). Shannon entropy for the G0I model: a new segmentation approach. IEEE Journal of Selected Topics in Applied Earth Observations and Remote Sensing, 13, 2547–2553. doi:10.1109/JSTARS.2020.2997666
Nascimento, A. D. C., Ferreira, J. A. and Frery, A. C. (2023). Unsupervised segmentation of PolSAR data with complex Wishart and G0m distributions and Shannon entropy. Statistics and Computing, 33, 129. doi:10.1007/s11222-023-10298-0
H <- entropy_map(SanFrancisco150, model = "wishart", window = 7, L = 4) set.seed(1) seg <- EntropySegmenter$new(k = 3)$fit(H) seg plot_map(seg$label_map(), main = "Entropy-based segmentation") kappa_statistics(SanFrancisco150_gt, seg$label_map())H <- entropy_map(SanFrancisco150, model = "wishart", window = 7, L = 4) set.seed(1) seg <- EntropySegmenter$new(k = 3)$fit(H) seg plot_map(seg$label_map(), main = "Entropy-based segmentation") kappa_statistics(SanFrancisco150_gt, seg$label_map())
R6 class for the law (see
dg0i()) with maximum likelihood estimation (analytic score, quasi-Newton
optimisation on a transformed scale with several starting points),
closed-form Shannon entropy (Ferreira and Nascimento, 2020) and the
asymptotic variance of its estimator.
An R6::R6Class generator. G0I$new() returns a new G0I
object; its methods are described in the Methods section below.
SARModel -> G0I
G0I$new()Create a G0I model.
G0I$new(alpha = -2, gamma = 1, L = 1)
alphaRoughness (< 0).
gammaScale (> 0).
LNumber of looks (> 0).
G0I$density()(Log-)density.
G0I$density(x, log = FALSE)
xNumeric vector of intensities.
logReturn log-densities?
G0I$random()Simulate intensities.
G0I$random(n)
nNumber of observations.
G0I$fit()Fit by maximum likelihood.
G0I$fit(x, L = NULL, start = NULL)
xNumeric vector of positive intensities.
LKnown number of looks. If NULL (default) it is estimated.
startOptional named vector of starting values
(alpha, gamma and, if estimated, L).
G0I$entropy()Shannon entropy.
G0I$entropy()
G0I$clone()The objects of this class are cloneable with this method.
G0I$clone(deep = FALSE)
deepWhether to make a deep clone.
Ferreira, J. A. and Nascimento, A. D. C. (2020). Shannon entropy for the G0I model: a new segmentation approach. IEEE Journal of Selected Topics in Applied Earth Observations and Remote Sensing, 13, 2547–2553. doi:10.1109/JSTARS.2020.2997666
set.seed(1) z <- rg0i(1000, alpha = -3, gamma = 2, L = 4) m <- G0I$new()$fit(z, L = 4) m m$entropy_variance() G0I$new()$fit(z)$params # L estimatedset.seed(1) z <- rg0i(1000, alpha = -3, gamma = 2, L = 4) m <- G0I$new()$fit(z, L = 4) m m$entropy_variance() G0I$new()$fit(z)$params # L estimated
Maximum likelihood estimation of the parameters.
This is a convenience wrapper around G0I$fit(), kept for
compatibility with previous versions of the package.
g0iestimation(Theta, x, L_fixed = FALSE)g0iestimation(Theta, x, L_fixed = FALSE)
Theta |
Initial values |
x |
Vector of observations. |
L_fixed |
Logical; if |
Named vector c(alpha, gamma, L) of estimates.
set.seed(1) y <- rg0i(1000, alpha = -1.5, gamma = 2, L = 8) g0iestimation(c(-1, 1, 1), y) g0iestimation(c(-1, 1, 8), y, L_fixed = TRUE)set.seed(1) y <- rg0i(1000, alpha = -1.5, gamma = 2, L = 8) g0iestimation(c(-1, 1, 1), y) g0iestimation(c(-1, 1, 8), y, L_fixed = TRUE)
R6 class for the law (see
dg0p()). Following Nascimento, Ferreira and Frery (2023),
is estimated by the sample mean (since )
and by maximising the likelihood (analytic score).
The variance of the entropy estimator combines the inverse observed
information of with a moment estimate of the variance
of .
An R6::R6Class generator. G0Polarimetric$new() returns a new G0Polarimetric
object; its methods are described in the Methods section below.
SARModel -> G0Polarimetric
G0Polarimetric$new()Create a G0 polarimetric model.
G0Polarimetric$new(alpha = -3, Sigma = diag(3) + (0+0i), L = 4)
alphaRoughness (< -1).
SigmaHermitian positive definite matrix.
LNumber of looks.
G0Polarimetric$density()(Log-)density.
G0Polarimetric$density(x, log = FALSE)
xPolSAR observations.
logReturn log-densities?
G0Polarimetric$random()Simulate PolSAR observations.
G0Polarimetric$random(n, output = "array")
nNumber of observations.
output"array" or "vec".
G0Polarimetric$fit()Fit by maximum likelihood.
G0Polarimetric$fit(x, L = NULL)
xPolSAR observations.
LKnown number of looks. If NULL (default) it is estimated.
G0Polarimetric$entropy()Shannon entropy.
G0Polarimetric$entropy()
G0Polarimetric$clone()The objects of this class are cloneable with this method.
G0Polarimetric$clone(deep = FALSE)
deepWhether to make a deep clone.
set.seed(1) Z <- rg0p(400, alpha = -4, Sigma = polsar_example_sigma("urban"), L = 4) m <- G0Polarimetric$new()$fit(Z, L = 4) m m$entropy_variance()set.seed(1) Z <- rg0p(400, alpha = -4, Sigma = polsar_example_sigma("urban"), L = 4) m <- G0Polarimetric$new()$fit(Z, L = 4) m m$entropy_variance()
R6 class for the multilook Gamma law ; see
dgammasar(). The maximum likelihood estimator of is the
sample mean and solves .
An R6::R6Class generator. GammaSAR$new() returns a new GammaSAR
object; its methods are described in the Methods section below.
SARModel -> GammaSAR
GammaSAR$new()Create a Gamma model.
GammaSAR$new(mu = 1, L = 1)
muMean.
LNumber of looks.
GammaSAR$density()(Log-)density.
GammaSAR$density(x, log = FALSE)
xNumeric vector of intensities.
logReturn log-densities?
GammaSAR$random()Simulate intensities.
GammaSAR$random(n)
nNumber of observations.
GammaSAR$fit()Fit by maximum likelihood.
GammaSAR$fit(x, L = NULL)
xNumeric vector of positive intensities.
LKnown number of looks. If NULL (default) it is estimated.
GammaSAR$entropy()Shannon entropy.
GammaSAR$entropy()
GammaSAR$entropy_variance()Asymptotic variance of the entropy estimator (closed form).
GammaSAR$entropy_variance(n = self$n)
nSample size.
GammaSAR$clone()The objects of this class are cloneable with this method.
GammaSAR$clone(deep = FALSE)
deepWhether to make a deep clone.
set.seed(1) z <- rgammasar(500, mu = 2, L = 4) m <- GammaSAR$new()$fit(z) m m$entropy() m$entropy_variance() generics::tidy(m)set.seed(1) z <- rgammasar(500, mu = 2, L = 4) m <- GammaSAR$new()$fit(z) m m$entropy() m$entropy_variance() generics::tidy(m)
R6 class for the generalized Gamma law (see dggamma()). Estimation is
carried out by profiling: for a given power , the maximum
likelihood estimates of and are available in closed
form (up to a one-dimensional root), so the profile likelihood is
maximised over only.
An R6::R6Class generator. GGammaSAR$new() returns a new GGammaSAR
object; its methods are described in the Methods section below.
SARModel -> GGammaSAR
GGammaSAR$new()Create a generalized Gamma model.
GGammaSAR$new(alpha = 1, phi = 1, mu = 1)
alphaPower (> 0).
phiShape (> 0).
muInverse scale (> 0).
GGammaSAR$density()(Log-)density.
GGammaSAR$density(x, log = FALSE)
xNumeric vector of intensities.
logReturn log-densities?
GGammaSAR$random()Simulate intensities.
GGammaSAR$random(n)
nNumber of observations.
GGammaSAR$fit()Fit by (profile) maximum likelihood.
GGammaSAR$fit(x, phi = NULL)
xNumeric vector of positive intensities.
phiKnown shape (number of looks). If NULL it is estimated.
GGammaSAR$entropy()Shannon entropy.
GGammaSAR$entropy()
GGammaSAR$clone()The objects of this class are cloneable with this method.
GGammaSAR$clone(deep = FALSE)
deepWhether to make a deep clone.
set.seed(1) z <- rggamma(1000, alpha = 1.5, phi = 3, mu = 2) m <- GGammaSAR$new()$fit(z) mset.seed(1) z <- rggamma(1000, alpha = 1.5, phi = 3, mu = 2) m <- GGammaSAR$new()$fit(z) m
Computes Cohen's kappa coefficient of agreement, its asymptotic variance
(Congalton and Green, 2009) and the overall accuracy from a confusion
matrix or from two vectors (or matrices) of labels. Unlike
yardstick::kap(), the variance of the estimator is also returned, which
allows comparing classifiers with Z tests.
kappa_statistics(truth, estimate = NULL, match = FALSE)kappa_statistics(truth, estimate = NULL, match = FALSE)
truth |
Either a square confusion matrix (estimates in rows, truth in columns) or a vector/matrix of reference labels. |
estimate |
Vector/matrix of estimated labels (when |
match |
Relabel the estimated classes to maximise agreement? |
Labels of unsupervised methods are arbitrary: use match = TRUE to
relabel the estimated classes so that they best agree with the truth
(an exhaustive search over permutations for up to 8 classes).
A tibble with kappa, variance, std_error,
overall_accuracy and the number of observations n.
Congalton, R. G. and Green, K. (2009). Assessing the Accuracy of Remotely Sensed Data: Principles and Practices. CRC Press.
truth <- c(1, 1, 2, 2, 3, 3, 3) est <- c(1, 2, 2, 2, 3, 3, 1) kappa_statistics(truth, est) kappa_statistics(table(est, truth))truth <- c(1, 1, 2, 2, 3, 3, 3) est <- c(1, 2, 2, 2, 3, 3, 1) kappa_statistics(truth, est) kappa_statistics(table(est, truth))
Displays a matrix as an image with the first row on top: continuous maps (e.g. entropy maps) use a sequential palette and integer/factor maps (e.g. segmentation or classification results) use a qualitative one.
plot_map(x, palette = NULL, main = NULL, legend = FALSE)plot_map(x, palette = NULL, main = NULL, legend = FALSE)
x |
A numeric, integer, logical or factor matrix. |
palette |
Optional vector of colours. |
main |
Title. |
legend |
Add a legend for discrete maps? |
Invisibly, x.
plot_map(SanFrancisco150_gt, main = "Ground truth", legend = TRUE) plot_map(matrix(rnorm(100), 10), main = "Noise")plot_map(SanFrancisco150_gt, main = "Ground truth", legend = TRUE) plot_map(matrix(rnorm(100), 10), main = "Noise")
Typical covariance matrices (scaled to unit magnitude)
for urban, forest and pasture areas, taken from the simulation studies of
the authors' dissertation and thesis. They are handy to simulate PolSAR
data.
polsar_example_sigma(type = c("urban", "forest", "pasture"))polsar_example_sigma(type = c("urban", "forest", "pasture"))
type |
One of |
A complex Hermitian positive definite matrix.
polsar_example_sigma("forest")polsar_example_sigma("forest")
PolSAR observations are Hermitian positive definite matrices. SITSAR
accepts them either as a complex array of dimension m x m x n or as an
n x p complex matrix in which each row stores the
distinct entries in the order (the
intensities) followed by the upper triangle . For this is the usual layer order
HH, HV, VV, HH.HV*, HH.VV*, HV.VV* of the SanFrancisco150 image.
as_polsar_array(x) as_polsar_vec(x)as_polsar_array(x) as_polsar_vec(x)
x |
A complex array ( |
as_polsar_array() returns a complex array m x m x n;
as_polsar_vec() returns an n x p complex matrix.
S <- diag(3) + 0i S[1, 2] <- 0.2 + 0.1i S[2, 1] <- Conj(S[1, 2]) v <- as_polsar_vec(S) v as_polsar_array(v)[, , 1]S <- diag(3) + 0i S[1, 2] <- 0.2 + 0.1i S[2, 1] <- Conj(S[1, 2]) v <- as_polsar_vec(S) v as_polsar_array(v)[, , 1]
'dials' parameter objects for divergence_classifier():
renyi_order() for the order of the Rényi divergence and
divergence_type() for the divergence measure. Both require the 'dials'
package.
renyi_order(range = c(0.05, 0.95), trans = NULL) divergence_type(values = c("renyi", "kl", "jeffreys", "bhattacharyya")) renyi_kind(range = c(1L, 4L))renyi_order(range = c(0.05, 0.95), trans = NULL) divergence_type(values = c("renyi", "kl", "jeffreys", "bhattacharyya")) renyi_kind(range = c(1L, 4L))
range |
Range of the Rényi order. |
trans |
A transformation object (or |
values |
Candidate divergences. |
A 'dials' parameter object.
if (requireNamespace("dials", quietly = TRUE)) { renyi_order() divergence_type() }if (requireNamespace("dials", quietly = TRUE)) { renyi_order() divergence_type() }
A crop of the fully polarimetric L-band AIRSAR image
of the San Francisco Bay area (nominal 4 looks), used in the
dissertation and thesis of J. A. Ferreira. The scene contains ocean,
vegetation (forest/park) and urban areas; see SanFrancisco150_gt.
SanFrancisco150SanFrancisco150
A complex array of dimension 150 x 150 x 6. For each pixel the
six layers are the distinct entries of the Hermitian
covariance matrix: , ,
(real intensities), , and
(complex products).
NASA/JPL AIRSAR mission.
dim(SanFrancisco150) img <- SARImage$new(SanFrancisco150, looks = 4) img$plot()dim(SanFrancisco150) img <- SARImage$new(SanFrancisco150, looks = 4) img$plot()
Reference map of the SanFrancisco150 image with three classes.
SanFrancisco150_gtSanFrancisco150_gt
An integer matrix 150 x 150 with values 1 (ocean), 2
(vegetation) and 3 (urban area).
table(SanFrancisco150_gt) plot_map(SanFrancisco150_gt)table(SanFrancisco150_gt) plot_map(SanFrancisco150_gt)
Computes moving-window statistics around every pixel, in the format used
by DivergenceClassifier and the divergence_classifier() 'parsnip'
model. Window statistics are computed with integral images, so the cost
does not depend on the window size. Windows are truncated at the image
borders.
sar_features(image, window = 3, type = c("all", "gaussian", "wishart"))sar_features(image, window = 3, type = c("all", "gaussian", "wishart"))
image |
A SARImage or an array accepted by |
window |
Odd window side. |
type |
Which features: |
Two groups of columns are produced:
mean_<ch>: local mean of each intensity
channel; cov_<ch1>_<ch2>: local (unbiased) covariance between the
intensities. Together they define the multivariate normal fitted to
the intensity vector in the window.
c<i><i> and
c<i><j>_re/c<i><j>_im: entries of the local mean covariance
matrix, i.e. the maximum likelihood estimate of for the
scaled complex Wishart law in the window.
A tibble with the columns row, col and the features.
img <- SARImage$new(SanFrancisco150)$crop(1:20, 1:20) f <- sar_features(img, window = 3) names(f)img <- SARImage$new(SanFrancisco150)$crop(1:20, 1:20) f <- sar_features(img, window = 3) names(f)
SARImage stores a SAR image as an array of dimension
nrow x ncol x layers. Two types are supported:
"polsar"a complex array whose p = m(m+1)/2 layers are the
distinct entries of the covariance matrix of each
pixel, in the order (for : HH, HV, VV, HH.HV*, HH.VV*, HV.VV*), as
in SanFrancisco150;
"intensity"a real (or real-valued complex) array whose layers are intensity channels.
The class offers cropping, Pauli colour composition, plotting, local (moving-window) features for classification, entropy maps and conversion to tibbles.
An R6::R6Class generator. SARImage$new() returns a new SARImage
object; its methods are described in the Methods section below.
dataThe image array.
type"polsar" or "intensity".
channelsNames of the intensity channels.
looksNominal number of looks (optional, NULL if unknown).
nrowNumber of rows (read-only).
ncolNumber of columns (read-only).
mNumber of channels; matrix order for PolSAR images (read-only).
SARImage$new()Create a SAR image.
SARImage$new(data, type = NULL, looks = NULL, channels = NULL)
dataArray nrow x ncol x layers (a matrix is treated as a
single intensity channel).
type"polsar" or "intensity". Guessed when NULL: complex
arrays with m(m+1)/2 layers (m >= 2) and non-zero imaginary
parts are PolSAR images.
looksNominal number of looks.
channelsNames of the intensity channels.
SARImage$intensity()Intensity of one channel.
SARImage$intensity(channel = 1)
channelChannel index or name.
SARImage$intensities()All intensity channels as a real array.
SARImage$intensities()
SARImage$crop()Crop the image.
SARImage$crop(rows, cols)
rows, colsRow and column indices to keep.
SARImage$pixel()Observation at a pixel: the Hermitian covariance matrix (PolSAR) or the vector of intensities.
SARImage$pixel(row, col)
row, colPixel position.
SARImage$window()Observations inside a square window centred at a pixel
(truncated at the borders). Returns an n x layers matrix.
SARImage$window(row, col, window = 3)
row, colPixel position.
windowOdd window side.
SARImage$pauli()Pauli RGB composition scaled to [0, 1] (PolSAR images with three channels); for other images the first three intensities are used.
SARImage$pauli(stretch = 0.98, gamma = 0.5)
stretchUpper quantile used for linear stretching.
gammaGamma correction exponent.
SARImage$plot()Plot the image (Pauli composition or one channel in dB).
SARImage$plot(type = c("pauli", "intensity"), channel = 1, main = NULL, ...)
type"pauli" or "intensity".
channelChannel for type = "intensity".
mainTitle.
...Passed to graphics::rasterImage().
SARImage$features()Local features for classification; see sar_features().
SARImage$features(window = 3, type = c("all", "gaussian", "wishart"))
windowOdd window side.
typeWhich features: "all", "gaussian" or "wishart".
SARImage$entropy_map()Entropy map; see entropy_map().
SARImage$entropy_map(...)
...Passed to entropy_map().
SARImage$as_tibble()Convert to a tibble with one row per pixel.
SARImage$as_tibble()
SARImage$print()Print a summary.
SARImage$print(...)
...Ignored.
SARImage$clone()The objects of this class are cloneable with this method.
SARImage$clone(deep = FALSE)
deepWhether to make a deep clone.
img <- SARImage$new(SanFrancisco150, looks = 4) img small <- img$crop(1:40, 1:40) dim(small$intensities()) small$pixel(1, 1) head(small$features(window = 3)) img$plot()img <- SARImage$new(SanFrancisco150, looks = 4) img small <- img$crop(1:40, 1:40) dim(small$intensities()) small$pixel(1, 1) head(small$features(window = 3)) img$plot()
SARModel is the abstract parent of all model classes of SITSAR
(GammaSAR, G0I, GGammaSAR, WishartSAR, G0Polarimetric and
CompoundWishart). Every model can evaluate densities, simulate data,
be fitted by maximum likelihood ($fit()) and report its Shannon entropy
and the asymptotic variance of the entropy estimator.
Fitted models work with the generics verbs tidy(),
glance(), as well as with stats::logLik() and
stats::AIC().
An R6::R6Class generator. SARModel$new() returns a new SARModel
object; its methods are described in the Methods section below.
nameModel name.
paramsNamed list of parameters.
fixedNames of parameters held fixed during estimation.
nSample size used in the last fit (NULL if not fitted).
loglikMaximised log-likelihood (NULL if not fitted).
convergedLogical convergence flag of the last fit.
SARModel$new()Abstract constructor.
SARModel$new(...)
...Ignored.
SARModel$density()(Log-)density of observations.
SARModel$density(x, log = FALSE)
xObservations.
logReturn log-densities?
SARModel$random()Generate random observations.
SARModel$random(n)
nNumber of observations.
SARModel$fit()Fit the model by maximum likelihood.
SARModel$fit(x, ...)
xObservations.
...Model specific arguments.
SARModel$log_likelihood()Log-likelihood of a sample.
SARModel$log_likelihood(x)
xObservations.
SARModel$entropy()Shannon entropy at the current parameters.
SARModel$entropy()
SARModel$entropy_variance()Asymptotic variance of the entropy estimator (delta method with the inverse observed Fisher information).
SARModel$entropy_variance(n = self$n)
nSample size. Defaults to the size of the fitted sample.
SARModel$n_parameters()Number of free parameters.
SARModel$n_parameters()
SARModel$tidy()Parameters as a tibble.
SARModel$tidy()
SARModel$glance()One-row summary of the fit.
SARModel$glance()
SARModel$print()Print the model.
SARModel$print(...)
...Ignored.
SARModel$clone()The objects of this class are cloneable with this method.
SARModel$clone(deep = FALSE)
deepWhether to make a deep clone.
Tidy and glance methods for SITSAR models
## S3 method for class 'SARModel' tidy(x, ...) ## S3 method for class 'SARModel' glance(x, ...) ## S3 method for class 'SARModel' logLik(object, ...)## S3 method for class 'SARModel' tidy(x, ...) ## S3 method for class 'SARModel' glance(x, ...) ## S3 method for class 'SARModel' logLik(object, ...)
x |
A fitted SARModel object. |
... |
Not used. |
object |
A fitted SARModel object. |
tidy() returns a tibble with one row per scalar parameter;
glance() a one-row tibble; logLik() an object of class logLik.
set.seed(1) m <- G0I$new()$fit(rg0i(300, -2, 1, 4), L = 4) generics::tidy(m) generics::glance(m) logLik(m)set.seed(1) m <- G0I$new()$fit(rg0i(300, -2, 1, 4), L = 4) generics::tidy(m) generics::glance(m) logLik(m)
Convenience wrapper that computes the entropy map(s) with
entropy_map() and segments them with EntropySegmenter.
segment_sar( image, k = 2, model = c("wishart", "g0p", "gamma", "g0i", "ggamma"), window = 7, L = NULL, channels = NULL, method = c("em", "sem"), ... )segment_sar( image, k = 2, model = c("wishart", "g0p", "gamma", "g0i", "ggamma"), window = 7, L = NULL, channels = NULL, method = c("em", "sem"), ... )
image |
A SARImage or an array accepted by |
k |
Number of classes. |
model |
One of |
window |
Odd side of the moving window. |
L |
Known number of looks. If |
channels |
Channels used by intensity models (default: all). |
method |
|
... |
Passed to |
A fitted EntropySegmenter; the labels are available with
$label_map().
set.seed(1) seg <- segment_sar(SanFrancisco150, k = 3, model = "gamma", window = 7, L = 4) table(seg$label_map(), SanFrancisco150_gt)set.seed(1) seg <- segment_sar(SanFrancisco150, k = 3, model = "gamma", window = 7, L = 4) table(seg$label_map(), SanFrancisco150_gt)
R6 class for the scaled complex Wishart law
(see dwishart_sar()). The maximum likelihood estimator of
is the sample mean and solves
(Anfinsen et al., 2009). The entropy variance is available in closed
form (Nascimento, Ferreira and Frery, 2023).
An R6::R6Class generator. WishartSAR$new() returns a new WishartSAR
object; its methods are described in the Methods section below.
SARModel -> WishartSAR
WishartSAR$new()Create a Wishart model.
WishartSAR$new(Sigma = diag(3) + (0+0i), L = 4)
SigmaHermitian positive definite matrix (default identity 3x3).
LNumber of looks.
WishartSAR$density()(Log-)density.
WishartSAR$density(x, log = FALSE)
xPolSAR observations (array m x m x n or vec matrix).
logReturn log-densities?
WishartSAR$random()Simulate PolSAR observations.
WishartSAR$random(n, output = "array")
nNumber of observations.
output"array" or "vec".
WishartSAR$fit()Fit by maximum likelihood.
WishartSAR$fit(x, L = NULL)
xPolSAR observations (array m x m x n or vec matrix).
LKnown number of looks. If NULL (default) it is estimated.
WishartSAR$entropy()Shannon entropy.
WishartSAR$entropy()
WishartSAR$entropy_variance()Asymptotic variance of the entropy estimator (closed form).
WishartSAR$entropy_variance(n = self$n)
nSample size.
WishartSAR$clone()The objects of this class are cloneable with this method.
WishartSAR$clone(deep = FALSE)
deepWhether to make a deep clone.
Anfinsen, S. N., Doulgeris, A. P. and Eltoft, T. (2009). Estimation of the equivalent number of looks in polarimetric synthetic aperture radar imagery. IEEE Transactions on Geoscience and Remote Sensing, 47(11), 3795–3809.
set.seed(1) Z <- rwishart_sar(300, polsar_example_sigma("forest"), L = 4) m <- WishartSAR$new()$fit(Z) m m$entropy_variance()set.seed(1) Z <- rwishart_sar(300, polsar_example_sigma("forest"), L = 4) m <- WishartSAR$new()$fit(Z) m m$entropy_variance()