Title: The Structural Similarity Index Measure for Maps
Version: 0.1.1
Description: Extends the classical SSIM method proposed by 'Wang', 'Bovik', 'Sheikh', and 'Simoncelli'(2004) <doi:10.1109/TIP.2003.819861>. for irregular lattice-based maps and raster images. The geographical SSIM method incorporates well-developed 'geographically weighted summary statistics'('Brunsdon', 'Fotheringham' and 'Charlton' 2002) <doi:10.1016/S0198-9715(01)00009-6> with an adaptive bandwidth kernel function for irregular lattice-based maps.
Depends: R (≥ 3.5.0)
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.2.3
Imports: stats, scales, dplyr, terra, ggplot2, sf, knitr
Suggests: RColorBrewer, testthat (≥ 3.0.0), rmarkdown
URL: https://github.com/Hailyee-Ha/SSIMmap
BugReports: https://github.com/Hailyee-Ha/SSIMmap/issues
VignetteBuilder: knitr
NeedsCompilation: no
Packaged: 2023-09-26 17:50:28 UTC; hailyeeha
Author: Hui Jeong (Hailyee) Ha ORCID iD [aut, cre], Jed Long ORCID iD [aut]
Maintainer: Hui Jeong (Hailyee) Ha <hha24@uwo.ca>
Repository: CRAN
Date/Publication: 2023-09-26 18:10:02 UTC

Sample polygon data of Toronto

Description

A sf(simple feature) containing geometric boundaries of Toronto DAs(Dissemination Area) with their codes.

Usage

Toronto

Format

An object of class sf (inherits from data.frame) with 3577 rows and 5 columns.

Details

DAUID

Dissemination Area ID

CIMD_SDD

Factor score of CIMD(The Canadian Index of Multiple Deprivation) social deprivation dimension

PP_SDD

Principal score of Pampalon social deprivation dimension

P_commute

Percentage of households who commute within census subdivision (CSD) of residence

geometry

the geometry column for counties(CRS: NAD83)


Bandwidth ranges for the SSIM Index for polygon maps.

Description

This function calculates the range of the bandwidth for the SSIM index using the square root of N and optimal trade-off between bias and variance.

Usage

ssim_bandwidth(
  shape,
  map1,
  map2,
  max_bandwidth = max_bandwidth,
  standardize = TRUE,
  option = "midpoint"
)

Arguments

shape

A sf polygon containing the attributes that can create polygon-based maps.

map1

The name of the first map to compare as a column in the shape.

map2

The name of the second map to compare as a column in the shape.

max_bandwidth

Maximum size of the bandwidth, and the maximum size needs to be larger than 12.

standardize

If TRUE, standardize the variables before computing the SSIM. Default is TRUE.

option

The option for selecting the range of the bandwidth derived from the optimal trade-off between bias and variance. Default is "midpoint."

Details

This function calculates the bandwidth range for the SSIM index for polygon maps using Gaussian kernel weighting. The bandwidth is calculated by two methods: 1) the square root of N and 2) the optimal trade-off between bias and variance. Users can select the bandwidth values from the range of the optimal trade-off, which minimize the trade-off between bias and variance, generated by two maps.

Value

A plot showing the bias/variance trade-off and the range of the optimal trade-off as vertical lines including the square root of N results as well. In addition, the console shows the results.

Examples

# Load example sf class object Toronto Area with attributes for maps:
# Pampalon Index,CIMD Index,
# and percentage of household commuting within the same Census Sub-Division of residence.
data("Toronto")

# Mapping two attributes
plot(Toronto$CIMD_SDD)
plot(Toronto$PP_SDD)

# Execution of bandwidth with maps above

ssim_bandwidth(Toronto,"CIMD_SDD","PP_SDD",max_bandwidth=100)



Constants for the SSIM Index for polygon maps.

Description

This function calculates rescaled constants (k1 and k2) for the SSIM index based on the global maximum value of the maps.

Usage

ssim_constant(shape, map1, map2, standardize = TRUE)

Arguments

shape

a sf polygon containing the attributes that can create polygon-based maps.

map1

The name of the first map to compare as a column in the shape.

map2

The name of the second map to compare as a column in the shape.

standardize

If TRUE, standardize the variables before computing the SSIM. Default is TRUE.

Details

This function calculates the rescaled constants (k1 and k2) for the SSIM index. k1 and k2 in the original SSIM method, which are for the 8-bit grey scale images, are 0.01 and 0.03 respectively. The SSIM for maps can use the rescaled k1 and k2 based on the global maximum value of two maps.

Value

The rescaled constants (k1 and k2).

Examples

# Load example sf class Toronto Area with attributes for maps:
# Toronto Areas with attributes for maps:Pampalon Index,CIMD Index,
# and percentage of household commuting within the same Census Sub-Division of residence.
data("Toronto")
ssim_constant(Toronto,"PP_SDD","CIMD_SDD")


The SSIM index for polygon maps.

Description

This function computes the SSIM, a measure of similarity between two polygon maps.

Usage

ssim_polygon(
  shape,
  map1,
  map2,
  standardize = TRUE,
  bandwidth = NULL,
  k1 = NULL,
  k2 = NULL,
  global = TRUE
)

Arguments

shape

A sf polygon containing the attributes that can create polygon-based maps.

map1

The name of the first map to compare as a column in the shape.

map2

The name of the second map to compare as a column in the shape.

standardize

If TRUE, standardize the variables before computing the SSIM. Default is TRUE.

bandwidth

The size of bandwidth for the Gaussian kernel weighting used in the SSIM calculation. Default is the square root of N.

k1

The constant used in the SSIM calculation. Default is NULL, in which case it is computed from the maximum value of the variables.

k2

The constant used in the SSIM calculation. Default is NULL, in which case it is computed from the maximum value of the variables.

global

If global is TRUE, returning the global average of SSIM, SIM, SIV, and SIP. If the option is FALSE, a sf polygon containing the SSIM, SIM, SIV, and SIP for each polygon is returned. Default is TRUE.

Details

This function computes the SSIM index for two polygon maps.

Value

If global is TRUE, returning the global average SSIM, SIM, SIV, and SIP on the console window. If global is FALSE, a sf object containing the SSIM, SIM, SIV, and SIP for each polygon.

Examples

# Load example sf object Toronto Area with three attributes for maps:
# Pampalon Index, CIMD Index,
# and percentage of household commuting within the same Census Sub-Division of residence.
data("Toronto")

# Mapping two attributes
plot(Toronto$CIMD_SDD)
plot(Toronto$PP_SDD)
# Finding global ssim

ssim_polygon(Toronto,"CIMD_SDD","PP_SDD")
df<-ssim_polygon(Toronto,"CIMD_SDD","PP_SDD",global=FALSE)


The SSIM index for raster images.

Description

This function calculates the SSIM, a measure of similarity between two raster images

Usage

ssim_raster(img1, img2, global = TRUE, w = 3, k1 = NULL, k2 = NULL)

Arguments

img1

A terra raster object representing the first image.

img2

A terra raster object representing the second image.

global

If global is TRUE, returning the global average of SSIM, SIM, SIV, and SIP. If the option is FALSE, a terra raster brick containing the SSIM, SIM, SIV, and SIP for each cell is returned.Default is TRUE.

w

Integer specifying the window size for the local neighborhood. Default is 3.

k1

The constant used in the SSIM calculation. Default is NULL, in which case it is computed from the maximum value of the images.

k2

The constant used in the SSIM calculation. Default is NULL, in which case it is computed from the maximum value of the images.

Details

This function computes the SSIM index for two raster images.

Value

If global is TRUE, returning the global average of SSIM, SIM, SIV, and SIP. If the option is FALSE, a terra raster brick containing the SSIM, SIM, SIV, and SIP for each cell is returned.

Examples

single<-system.file("/ex/single2nm.tif", package="SSIMmap")
group<-system.file("/ex/groups2nm.tif", package="SSIMmap")
whale_single<-terra::rast(single)
whale_groups<-terra::rast(group)
ssim_raster(whale_single,whale_groups)
result_raster<-ssim_raster(whale_single,whale_groups,global=FALSE)