findNeighbors-methods {Cardinal} | R Documentation

## Find spatial neighbors and spatial weightst

### Description

Methods for calculating the spatial neighbors (pixels within a certain distance) or spatial weights for all pixels in a dataset.

### Usage

    #### Methods for Cardinal >= 2.x classes ####

    ## S4 method for signature 'ImagingExperiment'
    findNeighbors(x, r, groups = run(x), ...)

    ## S4 method for signature 'PositionDataFrame'
    findNeighbors(x, r, groups = run(x), dist = "chebyshev",
        offsets = FALSE, matrix = FALSE, ...)

    ## S4 method for signature 'ImagingExperiment'
    spatialWeights(x, r, method = c("gaussian", "adaptive"),
        dist = "chebyshev", matrix = FALSE, BPPARAM = getCardinalBPPARAM(), ...)

    ## S4 method for signature 'PositionDataFrame'
    spatialWeights(x, r, matrix = FALSE, ...)

    #### Methods for Cardinal 1.x classes ####

    ## S4 method for signature 'iSet'
    findNeighbors(x, r, groups = x$sample, ...)

    ## S4 method for signature 'IAnnotatedDataFrame'
    findNeighbors(x, r, groups = x$sample, dist = "chebyshev",
        offsets = FALSE, matrix = FALSE, ...)

    ## S4 method for signature 'iSet'
    spatialWeights(x, r, method = c("gaussian", "adaptive"),
        matrix = FALSE, ...)

    ## S4 method for signature 'IAnnotatedDataFrame'
    spatialWeights(x, r, matrix = FALSE, ...)

### Arguments

`x` | An imaging dataset or data frame with spatial dimensions.
`r` | The spatial radius or distance.
`groups` | A `factor` giving which pixels should be treated as spatially-independent. Pixels in the same group are assumed to have a spatial relationship.
`dist` | The type of distance metric to use. The options are ‘radial’, ‘manhattan’, ‘minkowski’, and ‘chebyshev’ (the default).
`offsets` | Should the coordinate offsets from the center of each neighborhood be returned?
`matrix` | Should the result be returned as a sparse matrix instead of a list?
`method` | The method to use to calculate the spatial weights. The 'gaussian' method refers to Gaussian-distributed distance-based weights (`alpha` weights), and 'adaptive' refers to structurally-adaptive weights for bilaterla filtering (`beta` weights).
`...` | Addtional arguments to be passed to next method.
`BPPARAM` | An optional instance of `BiocParallelParam`. See documentation for `bplapply`.

### Value

Either a list of neighbors/weights or a sparse matrix (`sparse_mat`) giving the neighbors and weights for each pixel.

For `spatialWeights`, two types of weights are calculated and returned as a list:

The `alpha` weights are distance-based, following a Gaussian distributed that produces smaller weights for larger distances. The `beta` weights are adaptive weights used for bilateral filtering, which are based on the difference in the feature-vectors between pixels.

If `method="gaussian"` only the `alpha` weights are calcualated and the `beta` weights are all set to 1. If `matrix=TRUE`, the `alpha` and `beta` weights are multiplied together to produce the weights for the matrix; otherwise, both are returned separately.

### Author(s)

Kylie A. Bemis

### See Also

`image`

### Examples

    coord <- expand.grid(x=1:9, y=1:9)
    values <- rnorm(nrow(coord))
    pdata <- PositionDataFrame(coord=coord, values=values)

    # find spatial neighbors
    findNeighbors(pdata, r=1)

    # calculate distance-based weights
    spatialWeights(pdata, r=1)

    # visualize weight matrix
    W <- spatialWeights(pdata, r=1, matrix=TRUE)
    image(as.matrix(W), col=bw.colors(100))

[Package Cardinal version 2.8.0 Index]