-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImageClassifier.R
49 lines (31 loc) · 1.11 KB
/
ImageClassifier.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
library(biOps)
folder = 'data/samples/'
files = dir(folder, pattern = "^[a-lr]", full.names = TRUE, ignore.case = TRUE)
buildClassificationMatrix <- function ( filename=file, classtype=class.type ) {
# main image
image.rgb = readJpeg(filename)
# convert to gray
#image.gray= imgRGB2Grey(image.rgb)
# generate KMeans image
image.KMeans = imgKDKMeans(imgdata=image.rgb,k=12,maxit=20)
# generate EKMeans image - unsupervised classification through the k-means
image.EKMeans = imgKDKMeans(imgdata=image.rgb,k=12,maxit=20)
# generate histogram
image.hist = imgHistogram(image.EKMeans,col='red')
x = as.data.frame(t(image.hist$density),stringsAsFactors=FALSE)
result = data.frame(c(type=classtype,x))
result
}
for (i in 1:length(files)) {
file = files[i]
# establish cat or dog from filename
class.type = substr(file,start=14,stop=16)
result = buildClassificationMatrix(filename=file, classtype=class.type)
if (i == 1 ) {
#finalresult = result
print(ncol(result))
} else {
#finalresult = rbind(finalresult, result)
print(ncol(result))
}
}