sgmix | R Documentation |
Spatially segment a single-channel image using a Dirichlet Gaussian mixture model (DGMM).
# 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, BPPARAM = bpparam(), ...)
## S3 method for class 'sgmix'
fitted(object, type = c("mu", "sigma", "class"), ...)
## S3 method for class 'sgmix'
logLik(object, ...)
x , y , vals |
Pixel coordinates and their intensity values. Alternatively, |
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 |
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 |
byrow |
If |
verbose |
Should progress be printed for each iteration? |
BPPARAM |
An optional instance of |
... |
Additional options passed to |
object |
An object inheriting from |
type |
The type of fitted values to extract. |
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
.
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.
Kylie A. Bemis
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.
kmeans
require(datasets)
set.seed(1)
seg <- sgmix(volcano, k=3)
image(fitted(seg, "class"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.