Created
February 4, 2016 13:24
-
-
Save guidocor/fa0ace8cf39172abd080 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ------------------------------------------------------- | |
# READ IMAGES: Script that reads the images (png) of a folder and | |
# create a csv with number, size y bytes, x and y length | |
# ------------------------------------------------------- | |
setwd("~/Dropbox/p1/") | |
source("./utils/install.R") #source("https://raw.githubusercontent.com/guidocor/R_utils/master/install.R") | |
install_and_detach("png",clean = F,load = T) | |
# my own script (install.R), but you can use | |
# install.packages("png"); library(png) | |
# -------------------------------------------------------- | |
# CONFIG | |
# -------------------------------------------------------- | |
target_folder = "./estimulos/" | |
csv_name = "stim_info.csv" | |
# ------------------------------------------------------- | |
# Main script. | |
# ------------------------------------------------------- | |
# create a list of images on the folder that we need to inspect | |
list_image <- list.files(path = target_folder, pattern = "*.PNG") | |
# initialize variables | |
store <- data.frame(); size <- c(); stim <- c(); x <- c(); y <- c() | |
# loop that reads image and create vectors of each | |
for( image in 1:length(list_image)){ | |
size <- c(size, file.info(paste0(target_folder, list_image[image]))$size) | |
stim <- c(stim, list_image[image]) | |
x <- c(x, dim(readPNG(paste0(target_folder, list_image[image])))[1]) | |
y <- c(y, dim(readPNG(paste0(target_folder, list_image[image])))[2]) | |
} | |
store <- data.frame(stim, size, x, y) | |
head(store) | |
write.csv(store, file = csv_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment