Takes the result of grid_metrics (a RasterLayer object) and calculates the percentage of the grid squares whose values are above or below a specified threshold.

calculate_percentage_of_grids(raster_obj, threshold, above)

Arguments

raster_obj

Raster object in the form of the output of grid_metrics.

threshold

Numeric. The threshold for defining the pattern.

above

Boolean. Indicating whether the pattern is above (TRUE) or below (FALSE) the threshold.

Value

A number is returned

Examples

grid <- grid_metrics(SPIAT::defined_image, FUN = calculate_entropy, n_split = 5,
cell_types_of_interest=c("Tumour","Immune3"), feature_colname = "Cell.Type")

calculate_percentage_of_grids(grid, threshold = 0.75, above = TRUE)
#> [1] 96