NOT_CRAN <- identical(tolower(Sys.getenv("NOT_CRAN")), "true")
NOT_TRAVIS <- !identical(Sys.getenv("TRAVIS"), "true")
NOT_APPVEYOR <- !identical(Sys.getenv("APPVEYOR"), "True")

Pastec is an open-source image matching engine that does Google-images-esque fuzzy searching of a database of images that you compile. It is very good at finding close-but-not-exact matches, such as different versions of a photograph, or rotated, cropped, or resized versions of images.

PastecR provides a wrapper around the Pastec API, which can be particularly useful when parsing the results returned by an image search request.

Self-hosted or Saas?

You can compile and run Pastec yourself, however there is also a hosted version available with both a free and a paid option at PastecR supports both options:


# open_pastec_server defaults to the same port defaults as Pastec
ops <- open_pastec_server(url = "localhost", port = 4212)

# You can find the index_id and auth_key for your account at
# <>
hps <- hosted_pastec_server(index_id = "XXXXXXXXXXXXXXXXXXXX", auth_key = "XXXXXXXXXXXXXXXXXXXX")

Load images and search

We'll be using a number of artowrks for this example, including three different versions of a print.

Portret van Desiderius Erasmus, Philips Galle, Hans Holbein (II), Benedictus Arias Montanus, 1572 Portret van Desiderius Erasmus, Philips Galle, Hans Holbein (II), Janus Vitalis, 1604 - 1608 Portret van Desiderius Erasmus, Philips Galle, Hans Holbein (II), Benedictus Arias Montanus, 1572 Militia Company of District II under the Command of Captain Frans Banninck Cocq, Known as the 'Night Watch', Rembrandt Harmensz. van Rijn, 1642

Once you have established either your own instance of Pastec, or an account at, you may add images with the add_image() command. You must set an integer image_id when adding.

# Get image paths
erasmus1 <- system.file("img", "RP-P-1906-1485.jpg", package = "PastecR")
erasmus2 <- system.file("img", "RP-P-1906-1486.jpg", package = "PastecR")
erasmus3 <- system.file("img", "RP-P-1906-1487.jpg", package = "PastecR")
nightwatch <- system.file("img", "SK-C-5.jpg", package = "PastecR")

add_image(erasmus1, 1, ops)
add_image(erasmus2, 2, ops)
add_image(erasmus3, 3, ops)
add_image(nightwatch, 4, ops)

# Images can also be removed by index
remove_image(4, ops)

Once your index is loaded, you can search for similar images, and parse the results with a number of helper commands.

search_result <- search_image(erasmus1, ops)

See ?pastec_response for other parsing functions.

Index operations

To clear the index, use clear_index(server). On the open, self-hosted version of Pastec, you can also save and load index files to disk by using save_index() and load_index(). At the moment, these commands are not available for the SaaS version of pasted, and will throw an error.

mdlincoln/PastecR documentation built on May 22, 2017, 2:13 a.m.