sgmix: Spatial Gaussian Mixture Model

View source: R/sgmix.R

sgmixR Documentation

Spatial Gaussian Mixture Model

Description

Spatially segment a single-channel image using a Dirichlet Gaussian mixture model (DGMM).

Usage

# Spatial Gaussian mixture model
sgmix(x, y, vals, r = 1, k = 2, group = NULL,
	weights = c("gaussian", "bilateral", "adaptive"),
	metric = "maximum", p = 2, neighbors = NULL,
	annealing = TRUE, niter = 10L, tol = 1e-3,
	compress = FALSE, verbose = NA, ...)

# Multiple spatial Gaussian mixture models
sgmixn(x, y, vals, r = 1, k = 2, byrow = FALSE,
	verbose = NA, nchunks = NA, BPPARAM = bpparam(), ...)

## S3 method for class 'sgmix'
fitted(object, type = c("mu", "sigma", "class"), ...)

## S3 method for class 'sgmix'
logLik(object, ...)

Arguments

x, y, vals

Pixel coordinates and their intensity values. Alternatively, x can be a matrix, in which case the matrix elements are used for vals and x and y are generated from the matrix's dimensions. For sgmixn, vals should be a list of images or a matrix where the rows or columns should be interpreted as flattened images.

r

The spatial smoothing radius.

k

The number of segments (per group, if applicable).

group

A vector of pixel groups. Pixels belonging to each group will be segmented independently, and will be assigned to different segments.

weights

The type of spatial weights to use.

metric

Distance metric to use when finding neighboring pixels. Supported metrics include "euclidean", "maximum", "manhattan", and "minkowski".

p

The power for the Minkowski distance.

neighbors

An optional list giving the neighboring pixel indices for each pixel.

annealing

Should simulated annealing be attempted every iteration? (If FALSE, simulated annealing will still be attempted if the log-likelihood decreases instead of increases during an iteration.)

niter

The maximum number of iterations.

tol

The tolerance for convergence, as measured by the change in log-likelihood in successive iterations.

compress

Should the results be compressed? The resulting sgmix object will be larger than the original image, so compression can be useful. If TRUE, then the class component is compressed using drle, and the probability component is not returned.

byrow

If vals is a matrix, should its rows or columns be plotted?

verbose

Should progress be printed for each iteration?

nchunks

The number of chunks to use.

BPPARAM

An optional instance of BiocParallelParam. See documentation for bplapply.

...

Additional options passed to kmeans or sgmix (for sgmixn).

object

An object inheriting from sgmix.

type

The type of fitted values to extract.

Details

Spatial segmentation is performed using a Gaussian mixture model from Guo et al. (2019) that uses Dirichlet priors to incorporate spatial dependence. The strength of the spatial smoothing depends on the smoothing radius (r) and the type of spatial weights. The "bilateral" and "adaptive" weights can preserve edges better than the standard "gaussian" weights at the expense of a (potentially) noisier segmentation.

The segmentation is initialized using k-means clustering. An expectation-maximization (E-M) algorithm with gradient descent is then used to estimate the model parameters based on log-likelihood. Optionally, simulated annealing can be used to prevent the model from getting stuck in local maxima.

To spatially segment multiple images in parallel, use sgmixn.

Value

An object of class sgmix, with the following components:

  • class: The predicted classes.

  • probability: (Optional) A matrix of posterior class probabilities.

  • mu: The fitted class means.

  • sigma: The fitted class standard deviations.

  • alpha: The fitted Dirichlet priors.

  • beta: The estimated strength of the spatial dependence.

  • group: (Optional) The pixel groups.

Author(s)

Kylie A. Bemis

References

D. Guo, K. Bemis, C. Rawlins, J. Agar, and O. Vitek. “Unsupervised segmentation of mass spectrometric ion images characterizes morphology of tissues” Bioinformatics, vol. 35, issue 14, pp. i208-i217, 2019.

See Also

kmeans

Examples

require(datasets)

set.seed(1)
seg <- sgmix(volcano, k=3)

image(fitted(seg, "class"))

kuwisdelu/matter documentation built on May 11, 2024, 9:15 a.m.