rrmagick

How can I create a condition to delete the files?


I am trying to get the pixel-variance of each image from my data folder and delete them when it's lower than 800. I have worked with deleting rows or columns in dataframes but this doesn't work for lists. Can someone here help me with what exactly I am doing wrong here?

library(magick)
library(tidyverse)
Folder <- "......."
images <- list.files(path = Folder, pattern = "*.JPG", full.names = TRUE)
images <- map(images, image_read)
images[$image_variance <= 800.0000,]


Solution

  • You can use purrr::keep

    result <- purrr::keep(images, ~image_variance(.x) > 800)
    

    Or base R Filter to keep only those images when their variance is greater than 800.

    result <- Filter(function(x) image_variance(x) > 800, images)