require(MASS)
# Create example data
d <- 6 # Number of bands
n.class <- 5 # Number of classes
n <- rep(1000, 5)
mu <- round(matrix(rnorm(d*n.class, 128, 1),
ncol=n.class, byrow=TRUE), 0)
x <- matrix(double(), ncol=d, nrow=0)
classes <- integer()
for (i in 1:n.class) {
f <- svd(matrix(rnorm(d^2), ncol=d))
sigma <- t(f$v) %*% diag(rep(10, d)) %*% f$v
x <- rbind(x, mvrnorm(n[i], mu[, i], sigma))
classes <- c(classes, rep(i, n[i]))
}
colnames(x) <- paste0("band", 1:6)
classes <- factor(classes, labels=c("water", "forest",
"shrub", "urban", "ag"))
# Separability for multi-band (multivariate) spectra
spectral.separability(x, classes)
# Separability for single-band (univariate) spectra
spectral.separability(x[,1], classes)
Run the code above in your browser using DataLab