

library(imager)

# Input data files are available in the "../input/" directory.
# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory

system("ls ../input")

S_R <- vector()
S_B <- vector()
S_G <- vector()
image_num <- c(201,376,470, 553, 709, 1027, 1131, 1389, 1473, 254,
                110, 190, 231, 209, 94, 178, 204, 112, 404, 610,
                202, 325, 350, 1479, 1177, 1256, 1128, 1120, 1113, 1347)
cervix_type <- c(rep(1,10),rep(2,10),rep(3,10))
for (i in 1:length(image_num)){
    print(i)
    path <- paste(c("../input/train/Type_",cervix_type[i],"/",image_num[i],".jpg"),collapse="")
    img1 <- load.image(path)
    h_R <- R(img1)
    h_B <- B(img1)
    h_G <- G(img1)
    S_R[i] <- mean(h_R)
    S_B[i] <- mean(h_B)
    S_G[i] <- mean(h_G)
    print(paste("S_R , S_B, S_G equals : ",S_R, S_B, S_G, collapse = ' >> ')) 
}
    
l <- lm( cervix_type ~ S_R + S_B + S_G)
print(l)
summary(l)    
plot(S_R)
plot(S_B)
plot(S_G)

# Any results you write to the current directory are saved as output.