Function to estimate the intensity image of a point pattern
.intensityImage(ppp, markSelect = NULL, bndw = NULL, dim)
.intensityImage(ppp, markSelect = NULL, bndw = NULL, dim)
ppp |
point pattern object of class |
markSelect |
character; name of mark that is to be selected for the reconstruction |
bndw |
bandwidth of kernel density estimator |
dim |
numeric; x dimension of the final reconstruction. |
list; list with the intensity image and the bandwidth and dimension parameters
Function to estimate the intensity threshold for the reconstruction of spatial structures
.intensityThreshold(densityImage, steps = 250)
.intensityThreshold(densityImage, steps = 250)
densityImage |
real-valued pixel image; output from the function |
steps |
numeric; value used to filter the density estimates, where only
densities greater than the maximum value divided by |
numeric; estimated threshold
This function assigns each spatial point in a SpatialExperiment
object (spe
) to the first intersecting structure from a given set of spatial structures.
assingCellsToStructures( spe, allStructs, imageCol, uniqueId = "structID", nCores = 1 )
assingCellsToStructures( spe, allStructs, imageCol, uniqueId = "structID", nCores = 1 )
spe |
SpatialExperiment; An object of class |
allStructs |
sf; A simple feature collection (sf object) representing spatial structures. Must contain a column which contains a unique identifier for each structure. Default = |
imageCol |
character; The column name in |
uniqueId |
character; The column name in the simple feature collection for which to compute the assignment. |
nCores |
integer; The number of cores to use for parallel processing (default is 1). |
A vector with structure assignments for each spatial point in spe
. Points that do not overlap with any structure are assigned NA
.
library("SpatialExperiment") data("sostaSPE") allStructs <- reconstructShapeDensitySPE(sostaSPE, marks = "cellType", imageCol = "imageName", markSelect = "A", bndw = 3.5, thres = 0.045 ) colData(sostaSPE)$structAssign <- assingCellsToStructures( sostaSPE, allStructs, "imageName" ) if (require("ggplot2")) { cbind( colData(sostaSPE[, sostaSPE[["imageName"]] == "image1"]), spatialCoords(sostaSPE[, sostaSPE[["imageName"]] == "image1"]) ) |> as.data.frame() |> ggplot(aes(x = x, y = y, color = structAssign)) + geom_point(size = 0.25) + coord_equal() }
library("SpatialExperiment") data("sostaSPE") allStructs <- reconstructShapeDensitySPE(sostaSPE, marks = "cellType", imageCol = "imageName", markSelect = "A", bndw = 3.5, thres = 0.045 ) colData(sostaSPE)$structAssign <- assingCellsToStructures( sostaSPE, allStructs, "imageName" ) if (require("ggplot2")) { cbind( colData(sostaSPE[, sostaSPE[["imageName"]] == "image1"]), spatialCoords(sostaSPE[, sostaSPE[["imageName"]] == "image1"]) ) |> as.data.frame() |> ggplot(aes(x = x, y = y, color = structAssign)) + geom_point(size = 0.25) + coord_equal() }
Converts a binary matrix to an sf polygon
binaryImageToSF(binaryMatrix, xmin, xmax, ymin, ymax)
binaryImageToSF(binaryMatrix, xmin, xmax, ymin, ymax)
binaryMatrix |
matrix; binary matrix |
xmin |
integer; minimum x coordinate of the coordinate system |
xmax |
integer; maximum x coordinate of the coordinate system |
ymin |
integer; minimum y coordinate of the coordinate system |
ymax |
integer; maximum y coordinate of the coordinate system |
sf object
matrixR <- matrix(c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ), nrow = 9, byrow = TRUE) polyR <- binaryImageToSF(matrixR, xmin = 0, xmax = 1, ymin = 0, ymax = 1) plot(polyR)
matrixR <- matrix(c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ), nrow = 9, byrow = TRUE) polyR <- binaryImageToSF(matrixR, xmin = 0, xmax = 1, ymin = 0, ymax = 1) plot(polyR)
Calculate the proportion of each cell type within spatial structures
cellTypeProportions(spe, structColumn, cellTypeColumn, nCores = 1)
cellTypeProportions(spe, structColumn, cellTypeColumn, nCores = 1)
spe |
SpatialExperiment object |
structColumn |
character; name of the |
cellTypeColumn |
character; name of the |
nCores |
integer; The number of cores to use for parallel processing (default is 1). |
A data frame where rows correspond to unique structures and columns correspond to cell types, containing the proportion of each cell type within each structure.
library("SpatialExperiment") data("sostaSPE") allStructs <- reconstructShapeDensitySPE(sostaSPE, marks = "cellType", imageCol = "imageName", markSelect = "A", bndw = 3.5, thres = 0.045 ) colData(sostaSPE)$structAssign <- assingCellsToStructures( sostaSPE, allStructs, "imageName" ) cellTypeProportions(sostaSPE, "structAssign", "cellType")
library("SpatialExperiment") data("sostaSPE") allStructs <- reconstructShapeDensitySPE(sostaSPE, marks = "cellType", imageCol = "imageName", markSelect = "A", bndw = 3.5, thres = 0.045 ) colData(sostaSPE)$structAssign <- assingCellsToStructures( sostaSPE, allStructs, "imageName" ) cellTypeProportions(sostaSPE, "structAssign", "cellType")
This function generates a spatial point pattern with different types of points (A
, B
, C
) distributed over the simulated tissue structure.
createPointPatternTissue(tissueImage, intA, intB, intCInA, intCInB)
createPointPatternTissue(tissueImage, intA, intB, intCInA, intCInB)
tissueImage |
Matrix; A binary matrix representing the simulated tissue. |
intA |
Numeric; Intensity of type "A" points (points per unit area) on tissue regions. |
intB |
Numeric; Intensity of type "B" points (points per unit area) on non-tissue regions. |
intCInA |
Numeric; Intensity of type "C" points placed in extended regions around tissue. |
intCInB |
Numeric; Intensity of type "C" points placed within tissue. |
A ppp
object representing the spatial point pattern.
tissueImage <- simulateTissueBlobs(128, 100, 7) createPointPatternTissue(tissueImage, 0.1, 0.1, 0.005, 0.005)
tissueImage <- simulateTissueBlobs(128, 100, 7) createPointPatternTissue(tissueImage, 0.1, 0.1, 0.005, 0.005)
Estimate reconstruction parameters from a set of images
estimateReconstructionParametersSPE( spe, marks, imageCol, markSelect = NULL, nImages = NULL, fun = "bw.diggle", dim = 500, nCores = 1, plotHist = TRUE )
estimateReconstructionParametersSPE( spe, marks, imageCol, markSelect = NULL, nImages = NULL, fun = "bw.diggle", dim = 500, nCores = 1, plotHist = TRUE )
spe |
SpatialExperiment; a object of class |
marks |
character; name of column in |
imageCol |
character; name of a column in |
markSelect |
character; name of mark that is to be selected for the reconstruction |
nImages |
integer; number of images for the estimation. Will be randomly sampled |
fun |
character; function to estimate the kernel density. Default bw.diggle. |
dim |
numeric; x dimension of the final reconstruction. A lower resolution speed up computation but lead to less exact reconstruction. Default = 500 |
nCores |
numeric; number of cores for parallel processing using |
plotHist |
logical; if histogram of estimated densities and thresholds should be plotted. Default = TRUE |
tibble; tibble with estimated intensities and thresholds
data("sostaSPE") estimateReconstructionParametersSPE(sostaSPE, marks = "cellType", imageCol = "imageName", markSelect = "A", plotHist = TRUE )
data("sostaSPE") estimateReconstructionParametersSPE(sostaSPE, marks = "cellType", imageCol = "imageName", markSelect = "A", plotHist = TRUE )
Estimate the intensity threshold for the reconstruction of spatial structures
findIntensityThreshold(ppp, markSelect = NULL, bndw = NULL, dim, steps = 250)
findIntensityThreshold(ppp, markSelect = NULL, bndw = NULL, dim, steps = 250)
ppp |
point pattern object of class |
markSelect |
character; name of mark that is to be selected for the reconstruction |
bndw |
numeric; bandwith of the sigma parameter in the density estimation,
if no value is given the bandwith is estimated using cross validation with
the |
dim |
numeric; x dimension of the final reconstruction. |
steps |
numeric; value used to filter the density estimates, where only
densities greater than the maximum value divided by |
numeric; estimated intensity threshold
data(sostaSPE) ppp <- SPE2ppp(sostaSPE, marks = "cellType", imageCol = "imageName", imageId = "image1") findIntensityThreshold(ppp, markSelect = "A", dim = 250)
data(sostaSPE) ppp <- SPE2ppp(sostaSPE, marks = "cellType", imageCol = "imageName", imageId = "image1") findIntensityThreshold(ppp, markSelect = "A", dim = 250)
Function to get the dimension based on dim of y axis
getDimXY(ppp, ydim)
getDimXY(ppp, ydim)
ppp |
point pattern object of class |
ydim |
dimension of y axis |
vector; vector with x and y dimension
data(sostaSPE) pp <- SPE2ppp(sostaSPE, marks = "cellType", imageCol = "imageName", imageId = "image1" ) getDimXY(pp, 500)
data(sostaSPE) pp <- SPE2ppp(sostaSPE, marks = "cellType", imageCol = "imageName", imageId = "image1" ) getDimXY(pp, 500)
Calculate mean shape metrics of a set of polygons
meanShapeMetrics(totalShapeMetricMatrix)
meanShapeMetrics(totalShapeMetricMatrix)
totalShapeMetricMatrix |
matrix of shape metrics |
matrix; matrix of mean shape metrics
data(sostaSPE) struct <- reconstructShapeDensityImage(sostaSPE, marks = "cellType", imageCol = "imageName", imageId = "image1", markSelect = "A", dim = 500 ) shapeMetrics <- totalShapeMetrics(struct) meanShapeMetrics(shapeMetrics)
data(sostaSPE) struct <- reconstructShapeDensityImage(sostaSPE, marks = "cellType", imageCol = "imageName", imageId = "image1", markSelect = "A", dim = 500 ) shapeMetrics <- totalShapeMetrics(struct) meanShapeMetrics(shapeMetrics)
Compute minimum boundary distances for each cell within its corresponding image structures
minBoundaryDistances(spe, imageColumn, structColumn, allStructs, nCores = 1)
minBoundaryDistances(spe, imageColumn, structColumn, allStructs, nCores = 1)
spe |
SpatialExperiment object |
imageColumn |
character; name of the |
structColumn |
character; name of the |
allStructs |
sf object; contains spatial structures with corresponding image names |
nCores |
integer; The number of cores to use for parallel processing (default is 1). |
A numeric vector containing the minimum distances between cells and structure boundaries, values within structures have negative values.
library("SpatialExperiment") data("sostaSPE") allStructs <- reconstructShapeDensitySPE(sostaSPE, marks = "cellType", imageCol = "imageName", markSelect = "A", bndw = 3.5, thres = 0.045 ) colData(sostaSPE)$structAssign <- assingCellsToStructures( sostaSPE, allStructs, "imageName" ) colData(sostaSPE)$minDist <- minBoundaryDistances( sostaSPE, "imageName", "structAssign", allStructs ) if (require("ggplot2")) { cbind(colData(sostaSPE), spatialCoords(sostaSPE)) |> as.data.frame() |> ggplot(aes(x = x, y = y, color = minDist)) + geom_point(size = 0.25) + scale_colour_gradient2() + geom_sf(data = allStructs, fill = NA, inherit.aes = FALSE) + facet_wrap(~imageName) }
library("SpatialExperiment") data("sostaSPE") allStructs <- reconstructShapeDensitySPE(sostaSPE, marks = "cellType", imageCol = "imageName", markSelect = "A", bndw = 3.5, thres = 0.045 ) colData(sostaSPE)$structAssign <- assingCellsToStructures( sostaSPE, allStructs, "imageName" ) colData(sostaSPE)$minDist <- minBoundaryDistances( sostaSPE, "imageName", "structAssign", allStructs ) if (require("ggplot2")) { cbind(colData(sostaSPE), spatialCoords(sostaSPE)) |> as.data.frame() |> ggplot(aes(x = x, y = y, color = minDist)) + geom_point(size = 0.25) + scale_colour_gradient2() + geom_sf(data = allStructs, fill = NA, inherit.aes = FALSE) + facet_wrap(~imageName) }
Function to normalize coordinates between zero and one while keep scaling
normalizeCoordinates(coords)
normalizeCoordinates(coords)
coords |
matrix; matrix with coordinates |
matrix; coordinates scaled between 0 and 1
matrixR <- matrix(c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ), nrow = 9, byrow = TRUE) coords <- xyCoordinates(matrixR) normalizeCoordinates(coords)
matrixR <- matrix(c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ), nrow = 9, byrow = TRUE) coords <- xyCoordinates(matrixR) normalizeCoordinates(coords)
This function estimates the density of a spatial point pattern (ppp
),
thresholds the density to create a binary image, and then converts it
to a valid sf
object (polygons).
reconstructShapeDensity(ppp, markSelect = NULL, bndw = NULL, thres = NULL, dim)
reconstructShapeDensity(ppp, markSelect = NULL, bndw = NULL, thres = NULL, dim)
ppp |
point pattern object of class |
markSelect |
character; name of mark that is to be selected for the reconstruction |
bndw |
bandwidth of kernel density estimator |
thres |
intensity threshold for the reconstruction |
dim |
numeric; x dimension of the final reconstruction. |
sf object of class POLYGON
data("sostaSPE") ppp <- SPE2ppp(sostaSPE, marks = "cellType", imageCol = "imageName", imageId = "image1") thres <- findIntensityThreshold(ppp, markSelect = "A", dim = 500) struct <- reconstructShapeDensity(ppp, markSelect = "A", thres = thres, dim = 500) plot(struct)
data("sostaSPE") ppp <- SPE2ppp(sostaSPE, marks = "cellType", imageCol = "imageName", imageId = "image1") thres <- findIntensityThreshold(ppp, markSelect = "A", dim = 500) struct <- reconstructShapeDensity(ppp, markSelect = "A", thres = thres, dim = 500) plot(struct)
Reconstruct structure from spe object with given image id
reconstructShapeDensityImage( spe, marks, imageCol, imageId, markSelect, dim = 500, bndw = NULL, thres = NULL )
reconstructShapeDensityImage( spe, marks, imageCol, imageId, markSelect, dim = 500, bndw = NULL, thres = NULL )
spe |
SpatialExperiment; a object of class |
marks |
character; name of column in |
imageCol |
character; name of a column in |
imageId |
character; image id, must be present in imageCol |
markSelect |
character; name of mark that is to be selected for the reconstruction |
dim |
numeric; x dimension of the final reconstruction. A lower resolution speed up computation but lead to less exact reconstruction. Default = 500 |
bndw |
numeric; smoothing bandwidth in the density estimation,
corresponds to the |
thres |
numeric; intensity threshold for the reconstruction; if NULL the threshold is set as the mean between the mode of the pixel intensity distributions |
sf object of class POLYGON
data("sostaSPE") struct <- reconstructShapeDensityImage(sostaSPE, marks = "cellType", imageCol = "imageName", imageId = "image1", markSelect = "A", dim = 500 ) plot(struct)
data("sostaSPE") struct <- reconstructShapeDensityImage(sostaSPE, marks = "cellType", imageCol = "imageName", imageId = "image1", markSelect = "A", dim = 500 ) plot(struct)
Reconstruct structure from spatial experiment object per image id
reconstructShapeDensitySPE( spe, marks, imageCol, markSelect, dim = 500, bndw = NULL, thres = NULL, nCores = 1 )
reconstructShapeDensitySPE( spe, marks, imageCol, markSelect, dim = 500, bndw = NULL, thres = NULL, nCores = 1 )
spe |
SpatialExperiment; a object of class |
marks |
character; name of column in |
imageCol |
character; name of a column in |
markSelect |
character; name of mark that is to be selected for the reconstruction |
dim |
numeric; x dimension of the final reconstruction. A lower resolution speed up computation but lead to less exact reconstruction. Default = 500 |
bndw |
numeric; bandwidth of the sigma parameter in the density estimation,
if no value is given the bandwidth is estimated using cross validation with
the |
thres |
numeric; intensity threshold for the reconstruction; if NULL the threshold is set as the mean between the mode of the pixel intensity distributions estimated for each image individual |
nCores |
numeric; number of cores for parallel processing using
|
simple feature collection
data("sostaSPE") allStructs <- reconstructShapeDensitySPE(sostaSPE, marks = "cellType", imageCol = "imageName", markSelect = "A", bndw = 3.5, thres = 0.005 ) allStructs
data("sostaSPE") allStructs <- reconstructShapeDensitySPE(sostaSPE, marks = "cellType", imageCol = "imageName", markSelect = "A", bndw = 3.5, thres = 0.005 ) allStructs
This function plots the intensity of a point pattern image and displays a histogram of the intensity values. Note that intensities less than largest intensity value divided by 250 are not displayed in the histogram.
shapeIntensityImage( spe, marks, imageCol, imageId, markSelect, bndw = NULL, dim = 500 )
shapeIntensityImage( spe, marks, imageCol, imageId, markSelect, bndw = NULL, dim = 500 )
spe |
SpatialExperiment; a object of class |
marks |
character; name of column in |
imageCol |
character; name of a column in |
imageId |
character; image id, must be present in imageCol |
markSelect |
character; name of mark that is to be selected for the reconstruction |
bndw |
numeric; smoothing bandwidth in the density estimation,
corresponds to the |
dim |
numeric; x dimension of the final reconstruction. A lower resolution speeds up computation but lead to less exact reconstruction. Default = 500 |
ggplot object with intensity image and histogram
data("sostaSPE") shapeIntensityImage(sostaSPE, marks = "cellType", imageCol = "imageName", imageId = "image1", markSelect = "A" )
data("sostaSPE") shapeIntensityImage(sostaSPE, marks = "cellType", imageCol = "imageName", imageId = "image1", markSelect = "A" )
Calculate a set of shape metrics of a polygon
shapeMetrics(sfPoly)
shapeMetrics(sfPoly)
sfPoly |
POLYGON of class sfc |
list; list of shape metrics
matrix_R <- matrix(c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ), nrow = 9, byrow = TRUE) polyR <- binaryImageToSF(matrix_R, xmin = 0, xmax = 1, ymin = 0, ymax = 1) shapeMetrics(polyR)
matrix_R <- matrix(c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ), nrow = 9, byrow = TRUE) polyR <- binaryImageToSF(matrix_R, xmin = 0, xmax = 1, ymin = 0, ymax = 1) shapeMetrics(polyR)
This function generates a simulated tissue-like structure using a Gaussian blur technique.
simulateTissueBlobs(size, seedNumber, clumpSize)
simulateTissueBlobs(size, seedNumber, clumpSize)
size |
Integer; The size (width and height) of the simulated tissue image. |
seedNumber |
Integer; The number of random seed points used to generate tissue blobs. |
clumpSize |
Numeric; The standard deviation (sigma) of the Gaussian blur applied to generate tissue clumps. |
A binary matrix representing the simulated tissue structure.
tissueImage <- simulateTissueBlobs(128, 100, 7) image(tissueImage)
tissueImage <- simulateTissueBlobs(128, 100, 7) image(tissueImage)
This dataset contains a simulated SpatialExperiment
object (sostaSPE
) representing
three tissue images, each with a corresponding spatial point pattern. The point patterns
contain different cell types (A
, B
, and C
), distributed according to simulated
tissue structures.
sostaSPE
sostaSPE
A SpatialExperiment
object with the following structure:
Numeric; x-coordinate of each point (cell location).
Numeric; y-coordinate of each point (cell location).
Factor; Cell type assigned to each point (A, B, or C).
Factor; Identifier for the tissue image (image1
, image2
, or image3
).
The dataset was generated as follows:
Three tissue images were simulated using simulateTissueBlobs()
.
Spatial point patterns were created for each tissue using createPointPatternTissue()
.
The point pattern data was converted into a SpatialExperiment
object with spatial coordinates.
Function to convert spatialCoords to an sf object
spatialCoords2SF(spe)
spatialCoords2SF(spe)
spe |
SpatialExperiment; a object of class |
sf; Simple feature collection of geometry type POINT
data(sostaSPE) speSel <- sostaSPE[, sostaSPE[["imageName"]] == "image1"] spatialCoords2SF(speSel)
data(sostaSPE) speSel <- sostaSPE[, sostaSPE[["imageName"]] == "image1"] spatialCoords2SF(speSel)
SpatialExperiment
object to a ppp
objectFunction to convert spatial coordinates of a SpatialExperiment
object to a ppp
object
SPE2ppp(spe, marks, imageCol = NULL, imageId = NULL)
SPE2ppp(spe, marks, imageCol = NULL, imageId = NULL)
spe |
SpatialExperiment; a object of class |
marks |
character; name of column in |
imageCol |
character; name of a column in |
imageId |
character; image id, must be present in imageCol |
ppp; object of type ppp
data(sostaSPE) SPE2ppp(sostaSPE, marks = "cellType", imageCol = "imageName", imageId = "image1" )
data(sostaSPE) SPE2ppp(sostaSPE, marks = "cellType", imageCol = "imageName", imageId = "image1" )
Calculate curvature of sf object
stCalculateCurvature(sfPoly, smoothness = 5)
stCalculateCurvature(sfPoly, smoothness = 5)
sfPoly |
|
smoothness |
list; curvature measures |
list; list of curvatures values
https://stackoverflow.com/questions/62250151/calculate-curvature-of-a-closed-object-in-r
matrixR <- matrix(c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ), nrow = 9, byrow = TRUE) polyR <- binaryImageToSF(matrixR, xmin = 0, xmax = 1, ymin = 0, ymax = 1) stCalculateCurvature(polyR)
matrixR <- matrix(c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ), nrow = 9, byrow = TRUE) polyR <- binaryImageToSF(matrixR, xmin = 0, xmax = 1, ymin = 0, ymax = 1) stCalculateCurvature(polyR)
Calculate curl of a polygon
stCalculateShapeCurl(sfPoly)
stCalculateShapeCurl(sfPoly)
sfPoly |
|
numeric; the curl of the polygon
matrixR <- matrix(c( 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1 ), nrow = 7, byrow = TRUE) polyR <- binaryImageToSF(matrixR, xmin = 0, xmax = 1, ymin = 0, ymax = 1) stCalculateShapeCurl(polyR)
matrixR <- matrix(c( 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1 ), nrow = 7, byrow = TRUE) polyR <- binaryImageToSF(matrixR, xmin = 0, xmax = 1, ymin = 0, ymax = 1) stCalculateShapeCurl(polyR)
Calculate the length of feature axes of an sf polygon
stFeatureAxes(sfPoly)
stFeatureAxes(sfPoly)
sfPoly |
|
list; list containing the major and minor axis lengths
matrixR <- matrix(c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ), nrow = 9, byrow = TRUE) polyR <- binaryImageToSF(matrixR, xmin = 0, xmax = 1, ymin = 0, ymax = 1) stFeatureAxes(polyR)
matrixR <- matrix(c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ), nrow = 9, byrow = TRUE) polyR <- binaryImageToSF(matrixR, xmin = 0, xmax = 1, ymin = 0, ymax = 1) stFeatureAxes(polyR)
Calculate a set of shape metrics of a set of polygons
totalShapeMetrics(sfInput)
totalShapeMetrics(sfInput)
sfInput |
|
Calculate a set of shape metrics of a set of polygons.
The function calculates all metrics that are implemented in the function
shapeMetrics()
matrix; matrix of shape metrics
data(sostaSPE) struct <- reconstructShapeDensityImage(sostaSPE, marks = "cellType", imageCol = "imageName", imageId = "image1", markSelect = "A", dim = 500 ) totalShapeMetrics(struct)
data(sostaSPE) struct <- reconstructShapeDensityImage(sostaSPE, marks = "cellType", imageCol = "imageName", imageId = "image1", markSelect = "A", dim = 500 ) totalShapeMetrics(struct)
Function to extract x y coordinates from binary image
xyCoordinates(inputMatrix)
xyCoordinates(inputMatrix)
inputMatrix |
a binary matrix |
matrix; matrix with x,y coordinates of the cell of the input matrix
matrixR <- matrix(c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ), nrow = 9, byrow = TRUE) xyCoordinates(matrixR)
matrixR <- matrix(c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ), nrow = 9, byrow = TRUE) xyCoordinates(matrixR)