-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathprocess_cropped_test_images.R
executable file
·73 lines (61 loc) · 1.6 KB
/
process_cropped_test_images.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Clean environment and load required packages
rm(list=ls())
cat("\014")
require(EBImage)
library(data.table)
#Read training file
setwd("~/darknet-master/build/darknet/x64/results/")
file_name = "keeper_20_last_chanceconfidence_v4.csv"
data <- read.csv(file_name,header=TRUE,na.strings="",row.names=NULL)
# Main loop. Loop over each image
setwd("~/drivendata/fish/cropped_test_images/")
# Set width
w <- 32
# Set height
h <- 32
# Set up df
df <- data.frame()
my.list <- vector(mode="list")
colnames(data) <- c("filenames","score","x1","y1","x2","y2")
for(i in 1:dim(data)[1])
{
filename = paste(data$filename[i],".jpg",sep="")
#print(filename)
# Read image
img <- readImage(filename)
#img <- normalize(img)
img <- channel(img,"gray")
img <- resize(img,w,h)
# Get the image as a matrix
img_matrix <- matrix(img@.Data)
# Coerce to a vector
img_vector <- as.vector(t(img_matrix))
#vec <- c(img_vector)
# Bind rows
my.list[[i]]<-img_vector
#df <- rbind(df,img_vector)
# Print status info
if (i == 34369)
{
print ("25% complete")
}
if (i == 68738)
{
print ("50% complete")
}
if (i == 103122)
{
print ("75% complete")
}
#print(paste("Done ", i, sep = ""))
}
# Set image size.
print("Complete dataframe creation")
df <- rbind(df, do.call(rbind, my.list))
img_size <- w*h
# Set names
names(df) <- paste("pixel", c(1:img_size))
# Out file
out_file <- paste("~/drivendata/fish/","crop_test_20_last_chance","_",w,"x",h,".csv",sep="")
# Write out dataset
write.csv(df, out_file, row.names = FALSE)