| imagedist | R Documentation |
Given two grayscale images represented as numeric matrices, compute their
Wasserstein distance using an exact balanced optimal transport solver.
Each image is interpreted as a discrete probability distribution on a common (m\times n) grid.
The ground cost is defined using the Euclidean distance between grid locations.
imagedist(x, y, p = 2)
x |
a grayscale image matrix of size |
y |
a grayscale image matrix of size |
p |
an exponent for the order of the distance (default: 2). |
a list containing
the Wasserstein distance W_p(x,y).
the optimal transport plan matrix of size (mn\times mn).
#----------------------------------------------------------------------
# Small MNIST-like Example
#----------------------------------------------------------------------
# DATA
data(digit3)
x <- digit3[[1]]
y <- digit3[[2]]
# COMPUTE
W1 <- imagedist(x, y, p=1)
W2 <- imagedist(x, y, p=2)
# SHOW RESULTS
print(paste0("Wasserstein-1 distance: ", round(W1$distance,4)))
print(paste0("Wasserstein-2 distance: ", round(W2$distance,4)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.