knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(RcppParallelGMM)
library(doSNOW)
library(foreach)
options(digits=10)

path = "../data/seg_train"
fileNames = dir(path)
filePath = vector(mode = "character", length = length(fileNames))
for ( i in 1: length(fileNames)){
  filePath[i] = sapply(fileNames[i], function(x){paste(path, x, sep = "/")})
}

for (j in 1:length(filePath)){
  imageNames = dir(filePath[j])
  assign(paste0("imagePath_", j ) ,sapply(imageNames, function(x){paste(filePath[j],x,sep = "/")}))
  as.vector(paste0("imagePath_", j ))
}

train = c(
  imagePath_1[201:500],
  imagePath_2[201:500],
  imagePath_3[201:500],
  imagePath_4[201:500],
  imagePath_5[201:500],
  imagePath_6[201:500]
)
## Randomly shuffle
#set.seed(257)
rows <- sample(length(train))
shuffle_train = train[rows]

Y = Readjpeg(shuffle_train)
## Initialization
N = nrow(Y)
p = ncol(Y)
## Components
K = 6
#prob = rep(1/K, K)
prob = runif(K, min=0.1, max = 0.9)
prob = prob/sum(prob)

mean = matrix(rnorm(K*p), K, p)
sigma = array(rep(diag(p), K), dim = c(p, p, K))

ans = EM(prob, mean, sigma, Y)
table(ans$class)


image(K, ans, shuffle_train)

Sometimes the result does not seem very significant. It might be that the color difference between the selected pictures are not very large. We can choose pictures with significant difference in RGB color for experiment.



yehanxuan/tamu-689-final documentation built on Dec. 8, 2019, 5:25 p.m.