I am trying to get an average of 3 pictures. I made a function to do that, but i have an issue with storing each of the images following some image manipulation. I am getting an error:
Warning messages:
1: In b$b_arr[i] <- m : number of items to replace is not a multiple of replacement length
2: In b$b_arr[i] <- m : number of items to replace is not a multiple of replacement length
3: In b$b_arr[i] <- m : number of items to replace is not a multiple of replacement length
This is the code that I used to do it. I know I can do this manually, but I want to make a function (and learn what is my issue with this for loop).
library(OpenImageR)
imgs <- c("img1.png", "img2.png", "img3.png")
b <- data.frame(conc = imgs,
b_arr = array(dim = c(length(imgs),831, 651, 3)))
base_fun <- functienter code hereon(imgs) {
for (i in 1:length(imgs)) {
m <- readImage(imgs[i])
m[ , , 2] = 0
m[ , , 3] = 0
m <- cropImage(m, new_width = 250:1080,
new_height = 650:1300,
type = 'user_defined')
b$b_arr[i] <<- m
}
avg_b <<- (b$b_arr[1,,,] + b$b_arr[2,,,] + b$b_arr[3,,,])/3
}
base_fun(img)