R package to perform fuzzy comparison of images. The threshold argument allows the level of fuzziness to be compared.
Until visualTest
gets on CRAN, you can install it directly from
GitHub with
source("https://install-github.me/mangothecat/visualTest")
Call getFingerprint
to calculate a fingerprint of an image file.
You can then use compareWithFingerprint
to compare it to the
fingerprint of another file. Visually similar files will result
similar fingerprints.
library(visualTest)
getFingerprint("mango.png")
#> [1] "FAB5894A8C963369"
getFingerprint("mango2.png")
#> [1] "FAB5894A8C963369"
getFingerprint("cat.jpg")
#> [1] "FA85C13A9865BCCA"
To use visualTest
in your test cases, you can store the fingerprint
of the desired image, and then compare that to the one generated in
the test case.
Because various platforms generate slightly different images, you might need to allow some bits to change when you compare the image to the fingerprint. The default fingerprint is 64 bits long, and here we allow a mismatch of 8 bits:
tmp <- tempfile(fileext = ".png")
pairs(iris[1:4], main = "Anderson's Iris Data -- 3 species",
pch = 21, bg = c("red", "green3", "blue")[unclass(iris$Species)])
dev.copy(png, tmp)
dev.off()
isSimilar(tmp, "BA68E7B3948C8936", threshold = 8)
#> [1] TRUE
GPL 2 © Mango Solutions.