Title: | Tools for Assessment the Association Between Two Spatial Processes |
---|---|
Description: | Tools to assess the association between two spatial processes. Currently, several methodologies are implemented: A modified t-test to perform hypothesis testing about the independence between the processes, a suitable nonparametric correlation coefficient, the codispersion coefficient, and an F test for assessing the multiple correlation between one spatial process and several others. Functions for image processing and computing the spatial association between images are also provided. Functions contained in the package are intended to accompany Vallejos, R., Osorio, F., Bevilacqua, M. (2020). Spatial Relationships Between Two Georeferenced Variables: With Applications in R. Springer, Cham <doi:10.1007/978-3-030-56681-4>. |
Authors: | Felipe Osorio [aut, cre] , Ronny Vallejos [aut] , Francisco Cuevas [ctb], Diego Mancilla [ctb] |
Maintainer: | Felipe Osorio <[email protected]> |
License: | GPL-3 |
Version: | 0.4-1 |
Built: | 2024-10-30 06:54:59 UTC |
Source: | CRAN |
This function returns the image which restricts pixel value from the specified range.
clipping(img, low = 0, high = 1)
clipping(img, low = 0, high = 1)
img |
input grayscale image matrix. |
low |
lowest value. |
high |
highest value. |
grayscale image matrix with the same size as img
.
data(texmos2) plot(as.raster(texmos2)) # the appearance of next one doesn't change because of normalization x <- normalize(2 * texmos2) plot(as.raster(x)) title(main = "Doubled pixel value with normalization", font.main = 1) # the next one is saturated as expected x <- clipping(2 * texmos2) plot(as.raster(x)) title(main = "Doubled pixel value with clipping", font.main = 1)
data(texmos2) plot(as.raster(texmos2)) # the appearance of next one doesn't change because of normalization x <- normalize(2 * texmos2) plot(as.raster(x)) title(main = "Doubled pixel value with normalization", font.main = 1) # the next one is saturated as expected x <- clipping(2 * texmos2) plot(as.raster(x)) title(main = "Doubled pixel value with clipping", font.main = 1)
Computes the codispersion coefficient between two spatial variables for a given number of classes for the lag distance.
codisp(x, y, coords, nclass = 13)
codisp(x, y, coords, nclass = 13)
x |
an |
y |
an |
coords |
an |
nclass |
a single number giving the number of cells for the codispersion
coefficient. The default is 13. If this argument is |
The procedure computes the codispersion coefficient for two spatial sequences defined on general (non-rectangular) grids. First, a given number of bins are constructed for the lag distance. Then the codispersion is computed for each bin.
A list with class "codisp"
containing the following components:
coef |
a vector of size |
upper.bounds |
upper bounds of the intervals constructed to compute the codispersion coefficient. |
card |
number of elements in each interval generated to compute the codispersion coefficient. |
The function plot
can be used to obtain a graph of the codispersion coefficient
versus the lag distance.
Cuevas, F., Porcu, E., Vallejos, R. (2013). Study of spatial relationships between two sets of variables: A nonparametric approach. Journal of Nonparametric Statistics 25, 695-714.
Matheron, G. (1965), Les Variables Regionalisees et leur Estimation. Masson, Paris.
Rukhin, A., Vallejos, R. (2008), Codispersion coefficient for spatial and temporal series. Statistics and Probability Letters 78, 1290-1300.
Vallejos, R. (2008). Assessing the association between two spatial or temporal sequences. Journal of Applied Statistics 35, 1323-1343.
# Murray Smelter site dataset data(murray) # defining the arsenic (As) and lead (Pb) variables from the murray dataset x <- murray$As y <- murray$Pb # extracting the coordinates from Murray dataset coords <- murray[c("xpos","ypos")] # computing the codispersion coefficient z <- codisp(x, y, coords) z ## plotting the codispersion coefficient vs. the lag distance plot(z) # Comovement between two time series representing the monthly deaths # from bronchitis, emphysema and asthma in the UK for 1974-1979 x <- mdeaths y <- fdeaths coords <- cbind(1:72, rep(1,72)) z <- codisp(x, y, coords) # plotting codispersion and cross-correlation functions par(mfrow = c(1,2)) ccf(x, y, ylab = "cross-correlation", max.lag = 20) plot(z)
# Murray Smelter site dataset data(murray) # defining the arsenic (As) and lead (Pb) variables from the murray dataset x <- murray$As y <- murray$Pb # extracting the coordinates from Murray dataset coords <- murray[c("xpos","ypos")] # computing the codispersion coefficient z <- codisp(x, y, coords) z ## plotting the codispersion coefficient vs. the lag distance plot(z) # Comovement between two time series representing the monthly deaths # from bronchitis, emphysema and asthma in the UK for 1974-1979 x <- mdeaths y <- fdeaths coords <- cbind(1:72, rep(1,72)) z <- codisp(x, y, coords) # plotting codispersion and cross-correlation functions par(mfrow = c(1,2)) ccf(x, y, ylab = "cross-correlation", max.lag = 20) plot(z)
Computes a nonparametric version of the codispersion coefficient between two spatial variables using a Nadaraya-Watson estimator.
codisp.ks(x, y, coords, lags, kernel = "epanech", bandwidths)
codisp.ks(x, y, coords, lags, kernel = "epanech", bandwidths)
x |
an |
y |
an |
coords |
an |
lags |
a 2D vector of spatial lags. |
kernel |
character string which determines the smoothing kernel. |
bandwidths |
a 3D vector with the kernel bandwidth smoothing parameters. |
The procedure computes the codispersion coefficient for two spatial variables which is based on a Nadaraya-Watson version of the codispersion coefficient through a suitable kernel.
A vector with the semivariogram for each variable, the crossed semivariogram and the codispersion coefficient.
Cuevas, F., Porcu, E., Vallejos, R. (2013). Study of spatial relationships between two sets of variables: A nonparametric approach. Journal of Nonparametric Statistics 25, 695-714.
Vallejos, R., Osorio, F., Bevilacqua, M. (2020). Spatial Relationships Between Two Georeferenced Variables: With Applications in R. Springer, Cham.
# Pinus Radiata dataset data(radiata) # defining basal-area and height variables from the Pinus Radiata dataset x <- radiata$basal y <- radiata$height # extracting the coordinates from Pinus Radiata dataset coords <- radiata[,1:2] # computing the codispersion coefficient bwds <- c(174, 247, 187) cf <- codisp.ks(x, y, coords, lags = c(200,200), kernel = "epanech", bandwidths = bwds) cf
# Pinus Radiata dataset data(radiata) # defining basal-area and height variables from the Pinus Radiata dataset x <- radiata$basal y <- radiata$height # extracting the coordinates from Pinus Radiata dataset coords <- radiata[,1:2] # computing the codispersion coefficient bwds <- c(174, 247, 187) cf <- codisp.ks(x, y, coords, lags = c(200,200), kernel = "epanech", bandwidths = bwds) cf
Computes Tjostheim's coefficient for two spatial sequences observed over the same locations on the plane.
cor.spatial(x, y, coords)
cor.spatial(x, y, coords)
x |
an |
y |
an |
coords |
an |
The implemented technique is a nonparametric coefficient that summarizes the
association between two spatial variables. This coefficient was first introduced
by Tjostheim (1978) and later generalized by Hubert and Golledge (1992). The
computation of the coefficient is based on the construction of ranks associated
to suitable modifications of the coordinates. Tjostheim's coefficient is a variant
of the correlation coefficient (cor
) to be used in a spatial statistics
context.
Tjostheim's coefficient. The variance is returned as the attribute "variance"
.
Tjostheim, D., (1978), A measure of association for spatial variables. Biometrika 65, 109-114.
Hubert, L., Golledge, R.G., (1982), Measuring association between spatially defined variables: Tjostheim's coefficient index and some extensions. Geographical Analysis 14, 273-278.
# Murray Smelter site dataset data(murray) # defining the arsenic (As) and lead (Pb) variables from the murray dataset x <- murray$As y <- murray$Pb # extracting the coordinates from Murray dataset coords <- murray[c("xpos","ypos")] # computing Tjostheim's coefficient z <- cor.spatial(x, y, coords) z
# Murray Smelter site dataset data(murray) # defining the arsenic (As) and lead (Pb) variables from the murray dataset x <- murray$As y <- murray$Pb # extracting the coordinates from Murray dataset coords <- murray[c("xpos","ypos")] # computing Tjostheim's coefficient z <- cor.spatial(x, y, coords) z
This function computes a similarity index (CQ) based on the codispersion coefficient.
CQ(x, y, h = c(0,1), eps = c(0.01, 0.03), L = 255)
CQ(x, y, h = c(0,1), eps = c(0.01, 0.03), L = 255)
x |
reference image matrix (grayscale) |
y |
distorted image matrix (grayscale) |
h |
2-dimensional vector of the spatial lag. Default value is |
eps |
rescaling constants, by default |
L |
dynamic range of the images, by default |
A list containing the following components:
CQ |
codispersion based similarity index between images |
direction |
vector of spatial lag. |
comps |
components of |
stats |
sample statistics (means, variances and covariance) for each image. |
speed |
Running time taken by the procedure. |
Ojeda, S.M., Lamberti, P.W., Vallejos, R. (2012). Measure of similarity between images based on the codispersion coefficient. Journal of Electronic Imaging 21, 023019.
Vallejos, R., Mancilla, D., Acosta, J. (2016). Image similarity assessment based on coefficients of spatial association. Journal of Mathematical Imaging and Vision 56, 77-98.
data(texmos2) y <- imnoise(texmos2, type = "gaussian") plot(as.raster(y)) o <- CQ(texmos2, y, h = c(0,1)) o y <- imnoise(texmos2, type = "speckle") plot(as.raster(y)) o <- CQ(texmos2, y, h = c(0,1)) o
data(texmos2) y <- imnoise(texmos2, type = "gaussian") plot(as.raster(y)) o <- CQ(texmos2, y, h = c(0,1)) o y <- imnoise(texmos2, type = "speckle") plot(as.raster(y)) o <- CQ(texmos2, y, h = c(0,1)) o
This function removes noise from an input image.
denoise(img, type = "Lee", looks = 1, damping = 1)
denoise(img, type = "Lee", looks = 1, damping = 1)
img |
input grayscale image matrix. |
type |
character string, specifying the type of filter: |
looks |
specifies the equivalent (or effective) number of looks used to estimate
noise variance, and it effectively controls the amount of smoothing applied to the
image by the filter. A smaller value leads to more smoothing; a larger value preserves
more distinct image features. The default value is |
damping |
specifies the extent of exponential damping effect on filtering,
by default |
The median filter, in which each pixel is replaced by the median of nearby values is suitable to remove additive noise from an image.
The Lee filter reduces the speckle noise by applying a spatial filter to each pixel in an image, which filters the data based on local statistics calculated within a square window. The value of the center pixel is replaced by a value calculated using the neighboring pixels. Use the Lee filter to smooth speckled data that has a multiplicative component.
The Enhanced Lee filter is a refined version of the Lee filter, reducing the speckle noise effectively by preserving image sharpness and detail. Use the Enhanced Lee filter to reduce speckle while preserving texture information.
The Kuan filter follows a similar filtering process to the Lee filter in reducing speckle noise. This filter also applies a spatial filter to each pixel in an image, filtering the data based on local statistics of the centered pixel value that is calculated using the neighboring pixels.
Nathan filter is a particular case of the Kuan filter, obtained by puting looks
= 1
, and is thus applicable to 1-look SAR images only.
The size of the pixel window used to each filter is 3-by-3.
Filtered image, returned as a numeric matrix. It allows a better image interpretation.
The denoise
function clips output pixel values to the range after
removing the noise.
Lee, J.S. (1980). Digital image enhancement and noise filtering by use of local statistics. IEEE Transactions on Pattern Analysis and Machine Intelligence PAMI-2, 165-168.
data(texmos2) x <- imnoise(texmos2, type = "saltnpepper", epsilon = 0.10) plot(as.raster(x)) y <- denoise(x, type = "median") plot(as.raster(y)) x <- imnoise(texmos2, type = "speckle") plot(as.raster(x)) y <- denoise(x, type = "Lee") plot(as.raster(y))
data(texmos2) x <- imnoise(texmos2, type = "saltnpepper", epsilon = 0.10) plot(as.raster(x)) y <- denoise(x, type = "median") plot(as.raster(y)) x <- imnoise(texmos2, type = "speckle") plot(as.raster(x)) y <- denoise(x, type = "Lee") plot(as.raster(y))
This function adds noise to an input image.
imnoise(img, type = "gaussian", mean = 0, sd = 0.01, epsilon = 0.05, var = 0.04, looks = 1)
imnoise(img, type = "gaussian", mean = 0, sd = 0.01, epsilon = 0.05, var = 0.04, looks = 1)
img |
input grayscale image matrix. |
type |
character string, specifying the type of contamination: |
mean |
mean for the Gaussian noise, default value is |
sd |
standard deviation for the Gaussian noise, default value is |
epsilon |
contamination percentage for the salt and pepper noise with default noise
density |
var |
variance of uniform multiplicative noise using the equation |
looks |
parameter of gamma multiplicative noise. The default value is |
Noisy image, returned as a numeric matrix. The imnoise
function clips output
pixel values to the range after adding noise.
data(texmos2) x <- imnoise(texmos2, type = "saltnpepper", epsilon = 0.10) plot(as.raster(x)) y <- imnoise(texmos2, type = "speckle") plot(as.raster(y)) z <- imnoise(texmos2, type = "gamma", looks = 4) plot(as.raster(z))
data(texmos2) x <- imnoise(texmos2, type = "saltnpepper", epsilon = 0.10) plot(as.raster(x)) y <- imnoise(texmos2, type = "speckle") plot(as.raster(y)) z <- imnoise(texmos2, type = "gamma", looks = 4) plot(as.raster(z))
Performs a modified version of the F test to assess the multiple correlation between one spatial processes and several others.
modified.Ftest(x, y, coords, nclass = 13)
modified.Ftest(x, y, coords, nclass = 13)
x |
an |
y |
an |
coords |
an |
nclass |
a single number giving the number of cells for Moran's index.
The default is 13. If this argument is |
The methodology implemented is a modified F test for assessing the multiple correlation between one spatial process and several others. The test is based on corrections of the multiple correlation coefficient between the two spatially correlated sequences and required the estimation of an effective sample size. This factor takes into account the spatial association of both processes.
A list with class "mod.Ftest"
containing the following components:
corr |
the sample correlation coefficient. |
ESS |
the estimated effective sample size. |
Fstat |
the value of the (unscaled) F-statistic. |
df1 , df2
|
degrees of freedom for the F-statistic. |
p.value |
the p-value for the test. |
upper.bounds |
upper bounds of the intervals constructed to compute Moran's I. |
card |
number of elements in each interval generated to compute Moran's I. |
imoran |
a matrix containing Moran's index for each interval associated with the response and predicted variables. |
The generic functions print
and summary
are used to obtain
and print additional details about the modified F test.
Dutilleul, P., Pelletier, B., Alpargu, G. (2008). Modified F tests for assessing the multiple correlation between one spatial process and several others. Journal of Statistical Planning and Inference 138, 1402-1415.
# The Pinus Radiata data set data(radiata) # defining the response and predictor variables from the radiata data set y <- radiata$height x <- radiata[c("basal","altitude","slope")] # extracting the coordinates from the radiata data set coords <- radiata[c("xpos","ypos")] # computing the modified F-test of spatial association z <- modified.Ftest(x, y, coords) z # display the upper bounds, cardinality and the computed Moran's index summary(z)
# The Pinus Radiata data set data(radiata) # defining the response and predictor variables from the radiata data set y <- radiata$height x <- radiata[c("basal","altitude","slope")] # extracting the coordinates from the radiata data set coords <- radiata[c("xpos","ypos")] # computing the modified F-test of spatial association z <- modified.Ftest(x, y, coords) z # display the upper bounds, cardinality and the computed Moran's index summary(z)
Performs a modified version of the t test to assess the correlation between two spatial processes.
modified.ttest(x, y, coords, nclass = 13)
modified.ttest(x, y, coords, nclass = 13)
x |
an |
y |
an |
coords |
an |
nclass |
a single number giving the number of cells for Moran's index.
The default is 13. If this argument is |
The methodology implemented is a modified t test of spatial association based on the work of Clifford and Richardson (1989). The test is based on corrections of the sample correlation coefficient between the two spatially correlated sequences and required the estimation of an effective sample size. This factor takes into account the spatial association of both processes.
A list with class "mod.ttest"
containing the following components:
corr |
the sample correlation coefficient. |
ESS |
the estimated effective sample size. |
Fstat |
the value of the (unscaled) F-statistic. |
dof |
the estimated degrees of freedom for the F-statistic. |
p.value |
the p-value for the test. |
upper.bounds |
upper bounds of the intervals constructed to compute Moran's I. |
card |
number of elements in each interval generated to compute Moran's I. |
imoran |
a matrix containing Moran's index for each interval associated with both variables. |
The generic functions print
and summary
are used to obtain
and print additional details about the modified t test.
Clifford, P., Richardson, S., Hemon, D. (1989). Assessing the significance of the correlation between two spatial processes. Biometrics 45, 123-134.
Dutilleul, P. (1993). Modifying the t test for assessing the correlation between two spatial processes. Biometrics 49, 305-314.
# Murray Smelter site dataset data(murray) # defining the arsenic (As) and lead (Pb) variables from the murray dataset x <- murray$As y <- murray$Pb # extracting the coordinates from Murray dataset coords <- murray[c("xpos","ypos")] # computing the modified t-test of spatial association z <- modified.ttest(x, y, coords) z # display the upper bounds, cardinality and the computed Moran's index summary(z)
# Murray Smelter site dataset data(murray) # defining the arsenic (As) and lead (Pb) variables from the murray dataset x <- murray$As y <- murray$Pb # extracting the coordinates from Murray dataset coords <- murray[c("xpos","ypos")] # computing the modified t-test of spatial association z <- modified.ttest(x, y, coords) z # display the upper bounds, cardinality and the computed Moran's index summary(z)
The dataset consists of soil samples collected in and around the vacant, industrially contaminated, Murray smelter site (Utah, USA). This area was polluted by airborne emissions and the disposal of waste slag from the smelting process. A total of 253 locations were included in the study, and soil samples were taken from each location. Each georeferenced sample point is a pool composite of four closely adjacent soil samples in which the concentration of the heavy metals arsenic (As) and lead (Pb) was determined.
data(murray)
data(murray)
A data frame with 253 observations on the following 5 variables.
arsenic concentrations measurements.
lead concentrations measurements.
x
-coordinates.
y
-coordinates.
a factor where numbers indicate different sub-regions within the area.
Griffith, D., Paelinck, J.H.P. (2011). Non-Standard Spatial Statistics. Springer, New York.
This function normalizes an image matrix so that the minimum value is 0 and the maximum value is 1.
normalize(img)
normalize(img)
img |
target image |
Image matrix in which minimum value is 0 and maximum value is 1.
data(twelve) x <- RGB2gray(twelve, method = "RMY") x <- normalize(x) plot(as.raster(x))
data(twelve) x <- RGB2gray(twelve, method = "RMY") x <- normalize(x) plot(as.raster(x))
Pinus radiata is one of the mostly widely planted species in Chile and is planted in a wide array of soil types and regional climates. The plots were located in the Escuadron sector, south of Concepcion, in the southern portion of Chile and has an area of 1244.43 hectares.
data(radiata)
data(radiata)
A data frame with 468 observations on the following 6 variables.
x
-coordinates.
y
-coordinates.
basal area measurements.
dominant tree height.
altitude in meters.
slope of the terrain plot.
Cuevas, F., Porcu, E., Vallejos, R. (2013). Study of spatial relationships between two sets of variables: A nonparametric approach. Journal of Nonparametric Statistics 25, 695-714.
Vallejos, R., Osorio, F., Bevilacqua, M. (2020). Spatial Relationships Between Two Georeferenced Variables: With Applications in R. Springer, Cham.
This function converts color image to gray image.
RGB2gray(img, method = "average", weights = NULL)
RGB2gray(img, method = "average", weights = NULL)
img |
target image, specified as an |
method |
character, procedure for converting color to grayscale. Available methods
are |
weights |
weights for red (R), green (G), and blue (B) channels. Required if
|
Grayscale image, returned as an nrow
-by-ncol
numeric matrix with values
in the range .
RGB2gray
converts RGB values to grayscale values by forming a weighted sum
of the R, G, and B channels.
data(twelve) par(pty = "s", mfrow = c(1,3)) plot(as.raster(twelve)) # in RGB title(main = "original", font.main = 1) x <- RGB2gray(twelve, method = "RMY") plot(as.raster(x)) # in grayscale title(main = "RMY", font.main = 1) x <- RGB2gray(twelve, method = "ITU") plot(as.raster(x)) # OMG! 12 is gone... title(main = "ITU", font.main = 1)
data(twelve) par(pty = "s", mfrow = c(1,3)) plot(as.raster(twelve)) # in RGB title(main = "original", font.main = 1) x <- RGB2gray(twelve, method = "RMY") plot(as.raster(x)) # in grayscale title(main = "RMY", font.main = 1) x <- RGB2gray(twelve, method = "ITU") plot(as.raster(x)) # OMG! 12 is gone... title(main = "ITU", font.main = 1)
This function computes the structural similarity index (SSIM) proposed by Wang et al. (2004).
SSIM(x, y, alpha = 1, beta = 1, gamma = 1, eps = c(0.01, 0.03), L = 255)
SSIM(x, y, alpha = 1, beta = 1, gamma = 1, eps = c(0.01, 0.03), L = 255)
x |
reference image matrix (grayscale) |
y |
distorted image matrix (grayscale) |
alpha |
weight associated with luminance, default value is |
beta |
weight associated with contrast, default value is |
gamma |
weight associated with structure, default value is |
eps |
rescaling constants, by default |
L |
dynamic range of the images, by default |
A list containing the following components:
SSIM |
structural similarity index between images |
coefficients |
weights ( |
comps |
components of |
stats |
sample statistics (means, variances and covariance) for each image. |
speed |
Running time taken by the procedure. |
Wang, Z., Bovik, A.C. (2002). A universal image quality index. IEEE Signal Processing Letters 9, 81-84.
Wang, Z., Bovik, A.C., Sheikh, H.R., Simoncelli, E.P. (2004). Image quality assessment: From error visibility to structural similarity. IEEE Transactions on Image Processing 13, 600-612.
data(texmos2) y <- imnoise(texmos2, type = "gaussian") plot(as.raster(y)) o <- SSIM(texmos2, y) o y <- imnoise(texmos2, type = "speckle") plot(as.raster(y)) o <- SSIM(texmos2, y) o
data(texmos2) y <- imnoise(texmos2, type = "gaussian") plot(as.raster(y)) o <- SSIM(texmos2, y) o y <- imnoise(texmos2, type = "speckle") plot(as.raster(y)) o <- SSIM(texmos2, y) o
Gray-level texture map with information about mosaic composed of eight different texture samples taken from the Brodatz texture book, available from USC-SIPI image database.
data(texmos2)
data(texmos2)
A grayscale matrix of size 512-by-512.
Brodatz, P. (1966). Textures: A Photographic Album for Artist and Designers. Dover Publications, New York.
Ishihara plate number 1, with the numeral '12'
designed to be visible by all
persons.
data(twelve)
data(twelve)
An array of 380-by-380-by-3 representing a RGB image.
Gray-level texture image depicting wheat taken from the Brodatz texture book, available from USC-SIPI image database.
data(wheat)
data(wheat)
A grayscale matrix of size 512-by-512.
Brodatz, P. (1966). Textures: A Photographic Album for Artist and Designers. Dover Publications, New York.