# get image path and read in image
img_path <- system.file("extdata/chongi.png", package = "recolorize")
img <- png::readPNG(img_path)
recolorize::plotImageArray(img)
# generate a white background condition
bg_condition <- backgroundCondition(lower = rep(0.9, 3),
upper = rep(1, 3))
# index background pixels
bg_indexed <- backgroundIndex(img, bg_condition)
# we can reconstruct the original image from the flattened array
img2 <- bg_indexed$flattened_img
dim(img2) <- bg_indexed$img_dims
# notice the original background color (light gray) now shows
recolorize::plotImageArray(img2)
Run the code above in your browser using DataLab