-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQR_combo_2.R
150 lines (118 loc) · 5.16 KB
/
QR_combo_2.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#===========================================================================
# creating data frame for image generation
#===========================================================================
# reading in image names
setwd("./SA_Stimulus/pictures_2/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
#===========================================================================
# load required packages
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:28) {
# 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_2/"
ggsave(file = paste0(mypath, i, ".png"), g) # "image_i.png" to have unique file names
#dev.off()
setwd("./stimuli/")
}
#### generating fixation image ####
# read in image
fixate <- readPNG('../fix_cross.png')
setwd("../QR_codes/")
# generate stim with QRs
g <- arrangeGrob(rasterGrob(readPNG('marker_05.png')), rasterGrob(blank), rasterGrob(readPNG('marker_06.png')),
rasterGrob(blank), rasterGrob(fixate), rasterGrob(blank),
rasterGrob(readPNG('marker_07.png')), rasterGrob(blank), rasterGrob(readPNG('marker_08.png')),
ncol=3, widths = c(1,15,1), heights = c(.6,2,.6))
setwd("../")
mypath <- "../showpics_2/"
ggsave(file = paste0(mypath, "fix.png"), g)
#### generating iaps images ####
setwd("../IAPS/high_valence")
image_list_pos <- list.files()
setwd("../low_valence")
image_list_neg <- list.files()
# adding image names to csv
iaps <- data.frame(image_list_pos, image_list_neg, stringsAsFactors = FALSE)
names(iaps) <- c("pos_image", "neg_image")
setwd("../high_valence")
# loop for high valence image generation
for (i in 1:21) {
#reading in stimuli image
imagename <- iaps[i, 1]
image <- readJPEG(imagename)
# creating grid image, reading the QR images at the same time
setwd("../../pictures_2/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 <- "./show_iaps/high_valence/"
ggsave(file = paste0(mypath, i, ".png"), g) # "image_i.png" to have unique file names
#dev.off()
setwd("./IAPS/high_valence/")
}
setwd("../low_valence")
# loop for low valence image generation
for (i in 1:21) {
#reading in stimuli image
imagename <- iaps[i, 2]
image <- readJPEG(imagename)
# creating grid image, reading the QR images at the same time
setwd("../../pictures_2/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 <- "./show_iaps/low_valence/"
ggsave(file = paste0(mypath, i, ".png"), g) # "image_i.png" to have unique file names
#dev.off()
setwd("./IAPS/low_valence/")
}