How to process multiple Jpeg images in R -
i started using rstudio, available package analyze images in r. want analyze 50 images stored in folder. how can read each image (by forming loop), perform operation on each image , save output (my output list) vector?
update:
i wrote piece of code following:
folder <- "f:/f_diff/1_d/glass/new folder/" # path folder holds multiple .jpg files file_list <- list.files(path=folder, pattern="*.jpg") # create list of .jpg files in folder (i in 1:length(file_list)){ assign(file_list[i], #read image im2 <- readimage(paste(folder, file_list[i], sep='')) #analyze each image b <- matrix(im2,nrow=808,ncol=610,byrow=false, dimnames=null) haarimtest <- tos2d(b, smooth = false, nsamples = 100) summary(haarimtest) )}
i getting following errors:
error: unexpected symbol in: " #analyze each image b" haarimtest <- tos2d(b, smooth = false, nsamples = 100) error in base::log2(x) : non-numeric argument mathematical function summary(haarimtest) error in summary(haarimtest) : object 'haarimtest' not found
)} error: unexpected ')' in " )"
update 2
after tinkering code , lot of searching, able run it. code first imports 30 .tif images of size 64x64 pixels folder , perform image analysis on each image updated code follows:
> library(tiff) library(ls2w) library(ls2wstat) > # path folder holds multiple .tif files path <- "c:/users/metaheuristics/documents/matlab/diff_64 x64/2d/" > # create list of .tif files in folder files <- list.files(path=path, pattern="*.tif") > > #import files for(file in files) { perpos <- which(strsplit(file, "")[[1]]==".") assign( > gsub(" ","",substr(file, 1, perpos-1)), > b<-readtiff(paste(path,file,sep=""))) > #perform image analysis on individual images haarimtest <- tos2d(b, smooth = false, nsamples = 100) summary(haarimtest) }
just 1 problem, not being able save result.
Comments
Post a Comment