# NOT RUN {
library(curveDepth)
# Pixel-grid filling function for an image
plotGridImage <- function(dims){
redDims1 <- dims[1] - 1
redDims2 <- dims[2] - 1
for (i in 1:(dims[1] - 1)){
lines(c(i / redDims1 - 0.5 / redDims1,
i / redDims1 - 0.5 / redDims1),
c(0 - 0.5 / redDims2, 1 + 0.5 / redDims2),
lwd = 1, lty = 3, col = "lightgray")
lines(c(0 - 0.5 / redDims1, 1 + 0.5 / redDims1),
c(i / redDims2 - 0.5 / redDims2,
i / redDims2 - 0.5 / redDims2),
lwd = 1, lty = 3, col = "lightgray")
}
rect(0 - 0.5 / redDims1, 0 - 0.5 / redDims2,
1 + 0.5 / redDims1, 1 + 0.5 / redDims2)
}
# Load two Sevens and one One, and plot them
data("mnistShort017")
# First Seven
firstSevenDigit <- mnistShort017$`7`[, , 5]
image(as.matrix(rev(as.data.frame(firstSevenDigit))),
col = gray((255:0) / 256), asp = 1,
xlim = c(0 - 1 / 27, 1 + 1 / 27),
ylim = c(0 - 1 / 27, 1 + 1 / 27))
plotGridImage(dim(firstSevenDigit)[1:2])
# Second Seven
secondSevenDigit <- mnistShort017$`7`[, , 6]
image(as.matrix(rev(as.data.frame(secondSevenDigit))),
col = gray((255:0) / 256), asp = 1,
xlim = c(0 - 1 / 27, 1 + 1 / 27),
ylim = c(0 - 1 / 27, 1 + 1 / 27))
plotGridImage(dim(secondSevenDigit)[1:2])
# A One
aOneDigit <- mnistShort017$`1`[, , 1]
image(as.matrix(rev(as.data.frame(aOneDigit))),
col = gray((255:0) / 256), asp = 1,
xlim = c(0 - 1 / 27, 1 + 1 / 27),
ylim = c(0 - 1 / 27, 1 + 1 / 27))
plotGridImage(dim(aOneDigit)[1:2])
# Caculate distances between all the images
threeDigits <- array(NA, dim = c(nrow(firstSevenDigit),
ncol(firstSevenDigit), 3))
threeDigits[, , 1] <- firstSevenDigit
threeDigits[, , 2] <- secondSevenDigit
threeDigits[, , 3] <- aOneDigit
distMatrix <- dist.images(threeDigits)
# Print distance matrix
print(distMatrix)
# }
Run the code above in your browser using DataLab