-
Notifications
You must be signed in to change notification settings - Fork 0
/
QR_combo.R
77 lines (62 loc) · 2.75 KB
/
QR_combo.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
74
75
76
77
#===========================================================================
# creating data frame for image generation
#===========================================================================
# reading in image names
setwd("./stimulus/pictures/stimuli")
image_list <- list.files()
# reading in QR code names
setwd("../QR_codes")
qr_list <- list.files()
# adding image names to csv
stimuli <- data.frame(image_list, stringsAsFactors = FALSE)
names(stimuli) <- c("image")
# filling top right corner with marker 1
stimuli$rightup <- rep("marker_01.png",nrow(stimuli))
stimuli$rightdown <- rep("marker_02.png",nrow(stimuli))
stimuli$leftup <- rep("marker_03.png",nrow(stimuli))
stimuli$leftdown <- rep("marker_04.png",nrow(stimuli))
#old code
# filling top left corner half with marker 2 and half with 3
#stimuli$leftup <- rep("marker_02.png",nrow(stimuli))
#stimuli$leftup[30:56] <- "marker_03.png"
# fill ing lower right corner - further distinguishing with markers 4 & 5
#stimuli$rightdown <- rep("marker_04.png", nrow(stimuli))
#stimuli$rightdown[15:29] <- "marker_05.png"
#stimuli$rightdown[44:56] <- "marker_05.png"
# filling lower left corner by cycling through unused markers
#stimuli$leftdown <- rep("marker_06.png", nrow(stimuli))
#stimuli$leftdown[1:14] <- qr_list[7:20]
#stimuli$leftdown[15:29] <- qr_list[7:21]
#stimuli$leftdown[30:43] <- qr_list[7:20]
#stimuli$leftdown[44:56] <- qr_list[7:19]
#===========================================================================
# creating stimuli using data frame
#===========================================================================
install.packages(c("png", "jpeg", "grid", "gridExtra", "ggplot2"))
Packages <- c("png", "jpeg", "grid", "gridExtra", "ggplot2")
lapply(Packages, library, character.only = TRUE)
# reading in blank image
blank <- readPNG('../blank.png')
setwd("../stimuli")
# loop for image generation
for (i in 1:56) {
# identifying NAMES of unique QR markers
RUname <- stimuli[i, 2]
LUname <- stimuli[i, 3]
RDname <- stimuli[i, 4]
LDname <- stimuli[i, 5]
#reading in stimuli image
imagename <- stimuli[i, 1] # also will be stimuli[i,1] in the loop
image <- readJPEG(imagename)
# creating grid image, READING the QR PNG images at the same time
setwd("../QR_codes")
g <- arrangeGrob(rasterGrob(readPNG(RUname)), rasterGrob(blank), rasterGrob(readPNG(LUname)),
rasterGrob(blank), rasterGrob(image), rasterGrob(blank),
rasterGrob(readPNG(RDname)), rasterGrob(blank), rasterGrob(readPNG(LDname)),
ncol=3, widths = c(1,15,1), heights = c(.6,2,.6))
setwd("../")
mypath <- "../showpics/"
ggsave(file = paste0(mypath, i, ".png"), g) # "image_i.png" to have unique file names
#dev.off()
setwd("./stimuli/")
}