Joachim Schork
Joachim Schork

Reputation: 2147

Reverse black and white colors of image

I'm searching for a way to reverse the colors of a black and white image that I have loaded into R. Consider the following example:

With the magick package, I can load a JPEG image into R as follows:

library("magick")
picture <- image_read("path/picture.jpg")

I can also set the colors of this image to black and white:

picture <- image_quantize(picture, colorspace = "gray")

However, I didn't find a way how to reverse the colors of this image (i.e. black gets white and white gets black). How could I do that in R?

Upvotes: 2

Views: 1755

Answers (1)

Art
Art

Reputation: 1225

Try the `image_negate()' function.

https://cran.r-project.org/web/packages/magick/vignettes/intro.html#filters_and_effects

Upvotes: 3

Related Questions