Skip to contents

Minimizes the weighted sum of W2 distances over probability masses on the common image grid, using exact OT values and objective-checked mass updates. The mass-space median objective is nonconvex. A local stopping criterion is not a global-optimality certificate; a dominating input can be certified separately by the triangle inequality for the default Euclidean geometry.

Usage

imagemed(images, weights = NULL, C = NULL, ...)

Arguments

images

A nonempty list of nonnegative finite image matrices of the same size.

weights

Nonnegative outer weights, normalized to sum to one.

C

Optional finite nonnegative squared-cost matrix on the pixel grid. An arbitrary supplied matrix defines a sum of rooted OT costs, with no metric or median robustness guarantee asserted.

...

Named controls: maxiter (30), abstol (1e-6), rtol (1e-8), init.image (uniform positive mass), step0 (1), max_backtrack (30), inner_maxiter (10000), inner_tol (1e-10), print.progress (FALSE), and return_result (FALSE). Unsupported controls are rejected.

Value

An image probability-mass matrix with a diagnostics attribute, or a full fit when return_result = TRUE.

Details

Since version 0.2.0, the old denominator-floor IRLS and its nested bary.*/delta controls have been replaced by the shared fixed-support median solver. Input zero masses are retained exactly. An uncertified stationary point, ambiguous zero-distance collisions, and inner solver failures are reported; no failed input is discarded or downweighted. Pixel columns span [0,1] and rows run from y=1 to y=0, as in imagedist.

Examples

if (FALSE) { # \dontrun{
#----------------------------------------------------------------------
#                             MNIST Example
#
# Use 6 images from digit '8' and 4 images from digit '1'.
# The median should look closer to the shape of '8'.
#----------------------------------------------------------------------
# DATA PREP
set.seed(11)
data(digits)
dat_8 = digits$image[sample(which(digits$label==8), 6)]
dat_1 = digits$image[sample(which(digits$label==1), 4)]
dat_all = c(dat_8, dat_1)

# COMPUTE BARYCENTER AND MEDIAN
img_bary = imagebary(dat_all, maxiter=50)
img_med  = imagemed(dat_all, maxiter=50)

# VISUALIZE
opar <- par(no.readonly=TRUE)
par(mfrow=c(1,2), pty="s")
image(img_bary, axes=FALSE, main="Barycenter")
image(img_med,  axes=FALSE, main="Median")
par(opar)
} # }