This approach works a little faster
img = array(255, dim = c(1800,1800, 3)) img[img[,,1] == 255 & img[,,2] == 255 & img[,,3] == 255] <- 0 grid::grid.raster(img / 255)