| imageinterp | R Documentation |
Given two grayscale images represented as numeric matrices of identical size,
compute interpolated images along a 2-Wasserstein geodesic connecting them.
The function interprets each image as a discrete probability distribution on
a common (m\times n) grid, computes an exact optimal transport plan,
and constructs intermediate measures by pushing the
plan through the linear interpolation map z=(1-t)x+t y (displacement
interpolation / McCann's interpolation).
imageinterp(image1, image2, t = 0.5, ...)
image1 |
a grayscale image matrix of size |
image2 |
another grayscale image matrix of size |
t |
a scalar or numeric vector in |
... |
extra parameters including
|
Because the interpolated support locations generally do not coincide with
the original grid points, the resulting distribution is projected back onto
the grid by depositing transported mass to the nearest grid location.
This is a simple and robust "re-binning" step, analogous in spirit to how
histinterp re-bins interpolated quantile samples.
If length(t)==1, a single (m\times n) matrix representing the interpolated image.
If length(t)>1, a length-length(t) list of (m\times n) matrices.
#----------------------------------------------------------------------
# Digit Interpolation between 1 and 8
#----------------------------------------------------------------------
# LOAD DATA
set.seed(11)
data(digits)
x1 <- digits$image[[sample(which(digits$label==1),1)]]
x2 <- digits$image[[sample(which(digits$label==8),1)]]
# COMPUTE
tvec <- seq(0, 1, length.out=10)
path <- imageinterp(x1, x2, t = tvec)
# VISUALIZE
opar <- par(no.readonly=TRUE)
par(mfrow=c(2,5), pty="s")
for (k in 1:10){
image(path[[k]], axes=FALSE, main=sprintf("t=%.2f", tvec[k]))
}
par(opar)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.