Hello everybody,
I have to develop a script in R that saves the vectors resulting from the transformation of several images in a data frame that will have as many rows as images (1000) and as many columns as variables (4096). The data frame will be exported to a csv file.
I have tried a loop so that it reads the images and transforms them one by one and then join them in a matrix or data frame. I'm new to this... I am lost... I share you what I have tried. Any idea or improvement?
set.seed(1234)
mypath = "C:/dataset/dataset/effusion/" #file where the images are
files <- list.files(path=mypath, pattern=".png$")
length(files)
for (i in files){
im <- readImage(mypath[i], header = FALSE)
grises <- rgb_2gray(im[i])
# Resize the image to a size of 64 x64 pixels:
resiz = resizeImage(grises[i], width = 64, height = 64, method = 'nearest')
# Convert to vector:
im.convert <- as.vector(resiz[i])
out <- as.data.frame(do.call(rbind, im.convert)) # create a data frame
}
return(out)
Thank you very much!