-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathimage.rb
More file actions
314 lines (280 loc) · 9.15 KB
/
image.rb
File metadata and controls
314 lines (280 loc) · 9.15 KB
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
#
# image data
# http://gnuplot.sourceforge.net/demo_4.6/image.html
require_relative "gpl"
# # demo for plotting images using pixels and binary 2d data
# load binary data
blutux = Numo::UInt8.from_string(open("blutux.rgb").read,[128,128,3]).reverse(0)
blutux_ave = Numo::Int16.cast(blutux).sum(2)/3
# set title "Larry Ewing's GIMP penguin on vacation basking in\nthe balmy waters off the coast of Murmansk"
# set xrange [-10:137]
# set yrange [-10:157]
# set label "\"I flew here... by plane. Why? For the halibut.\"" at 64,135 center
# plot 'blutux.rgb' binary array=(128,128) flipy format='%uchar' with rgbimage
gpl do
set title:"Larry Ewing's GIMP penguin on vacation basking in\nthe balmy waters off the coast of Murmansk"
set xrange:-10..137
set yrange:-10..157
set label:"\"I flew here... by plane. Why? For the halibut.\"", at:[64,135], center:true
plot blutux, with:"rgbimage"
end
# reset
# set title "Translations of position variables via 'using'"
# set xrange [-10:275]
# set yrange [-10:300]
# unset key
# set label "\"Time for a dip...\"" at 132,285 center
# plot 'blutux.rgb' binary array=(128,128) flipy center=( 64,201 ) format='%uchar' with rgbimage, \
# 'blutux.rgb' binary array=(128,128) flipy rotation=-90d center=(201,201) format='%uchar' with rgbimage, \
# 'blutux.rgb' binary array=(128,128) flip=y rotate=3.1415 center=(201,64) format='%uchar' with rgbimage, \
# 'blutux.rgb' binary array=(128,128) flip=y rot=0.5pi center=(64,64) format='%uchar' using 1:2:3 with rgbimage
gpl do
reset
set title:"Translations of position variables via 'using'"
set xrange:-10..275
set yrange:-10..300
unset :key
set label:"\"Time for a dip...\"", at:[132,285], center:true
plot [blutux, 'center=( 64,201 )', with:"rgbimage"],
[blutux, 'rotation=-90d center=(201,201)', with:"rgbimage"],
[blutux, 'rotate=3.1415 center=(201,64)', with:"rgbimage"],
[blutux, 'rot=0.5pi center=(64,64)', with:"rgbimage"]
end
# reset
# unset key
# set xrange [-10:137]
# set yrange [-10:157]
# set label 1 "\"I am the penguin, GOO GOO GOO JOOB.\"" at 63,140 center
# set title "Palette mode 'image' used to produce psychedelic bird"
# unset colorbox
# plot 'blutux.rgb' binary array=(128,128) flipy format='%uchar%uchar%uchar' using ($1+$2+$3) with image
gpl do
reset
unset :key
set xrange:-10..137
set yrange:-10..157
set :label, 1, "\"I am the penguin, GOO GOO GOO JOOB.\"", at:[63,140], center:true
set title:"Palette mode 'image' used to produce psychedelic bird"
unset :colorbox
plot Numo::Int16.cast(blutux).sum(2), with:"image"
end
# reset
# unset key
# set xrange [-10:137]
# set yrange [-10:157]
# set tics out
# set label 1 "\"This picture was taken by my friend Ansel Adams.\"" at 63,140 center
# set title "The palette can be changed from color to gray scale"
# set palette gray
# unset colorbox
# plot 'blutux.rgb' binary array=(128,128) flipy format='%uchar%uchar%uchar' using ($1+$2+$3)/3 with image
gpl do
reset
unset :key
set xrange:-10..137
set yrange:-10..157
set :tics, :out
set :label, 1, "\"This picture was taken by my friend Ansel Adams.\"", at:[63,140], center:true
set title:"The palette can be changed from color to gray scale"
set :palette, "gray"
unset :colorbox
plot blutux_ave, with:"image"
end
# unset label 1
# unset key
# set pm3d map
# set xrange [10:117]
# set yrange [10:117]
# set tics out
# set colorbox
# set cbrange [0:255]
# set title "As with 3d color surfaces, a color box may be added to the plot"
# splot 'blutux.rgb' binary array=(128,128) flipy format='%uchar%uchar%uchar' using ($1+$2+$3)/3 with image
gpl do
unset label:1
unset :key
set :pm3d, :map
set xrange:10..117
set yrange:10..117
set :tics, :out
set :colorbox
set cbrange:0..255
set title:"As with 3d color surfaces, a color box may be added to the plot"
splot blutux_ave, with:"image"
end
# set key
# set xrange [-10:138]
# set yrange [-10:138]
# set tics out
# set title "Polygons used to draw pixels for rotated images\nNotice the slower refresh rate than for the next plot"
# unset colorbox
# plot 'blutux.rgb' binary array=(128,128) dx=0.70711 dy=0.70711 flipy rotation=45d center=(63.5,63.5) format='%uchar' using ($1+$2+$3)/3 with image
gpl do
set :key
set xrange:-10..138
set yrange:-10..138
set :tics, :out
set title:"Polygons used to draw pixels for rotated images\nNotice the slower refresh rate than for the next plot"
unset :colorbox
plot [blutux_ave, 'dx=0.70711 dy=0.70711 rotation=45d center=(63.5,63.5)', with:"image"]
end
# reset
# unset key
# set xrange [-138:10]
# set yrange [-10:138]
# set tics out
# set title "Terminal image routine used to draw plot rotated about origin\nNotice the faster refresh rate than for the previous plot"
# unset colorbox
# plot 'blutux.rgb' binary array=(128,128) dx=1 flip=y rotation=0.5pi origin=(0,0) format='%uchar' using ($1+$2+$3)/3 with image
gpl do
reset
unset :key
set xrange:-138..10
set yrange:-10..138
set :tics, :out
set title:"Terminal image routine used to draw plot rotated about origin\nNotice the faster refresh rate than for the previous plot"
unset :colorbox
plot [blutux_ave, 'dx=1 rotation=0.5pi origin=(0,0)', with:"image"]
end
# reset
# set size 1.0, 1.0
# set origin 0.0, 0.0
# set multiplot
# set size 0.5,0.48
# set origin 0.0,0.47
# unset key
# set xrange [-0.5:127.5]
# set yrange [-0.5:127.5]
# set tics out
# set label 1 "Selection of the input channels via \`using\`" at 140,160 center
# set title '"I do impersonations..."' offset 0,-0.5
# plot 'blutux.rgb' binary array=(128,128) flip=y format='%uchar' using 1:2:3 with rgbimage
# unset label 1
# set size 0.5,0.48
# set origin 0.5,0.47
# set title '"A cardinal."'
# plot 'blutux.rgb' binary array=(128,128) flip=y format='%uchar%*uchar%*uchar' using 1:(0):(0) with rgbimage
# set size 0.5,0.48
# set origin 0.0,0.0
# set title '"A parrot."'
# plot 'blutux.rgb' binary array=(128,128) flipy format='%*uchar%uchar%*uchar' using (0):1:(0) with rgbimage
# set size 0.5,0.48
# set origin 0.5,0.0
# set title '"A bluebird."'
# plot 'blutux.rgb' binary array=(128,128) flipy format='%*uchar%*uchar%uchar' using (0):(0):1 with rgbimage
# unset multiplot
gpl do
reset
set size:[1.0,1.0]
set origin:[0.0,0.0]
set :multiplot
set size:[0.5,0.48]
set origin:[0.0,0.47]
unset :key
set xrange:-0.5..127.5
set yrange:-0.5..127.5
set :tics, :out
set :label, 1, "Selection of the input channels via 'using'", at:[140,160], center:true
set title:'"I do impersonations..."', offset:[0,-0.5]
plot blutux, with:"rgbimage"
unset label:1
set size:[0.5,0.48]
set origin:[0.5,0.47]
set title:'"A cardinal."'
a = blutux.copy
a[true,true,1..2] = 0
plot a, with:"rgbimage"
set size:[0.5,0.48]
set origin:[0.0,0.0]
set title:'"A parrot."'
a = blutux.copy
a[true,true,[0,2]] = 0
plot a, with:"rgbimage"
set size:[0.5,0.48]
set origin:[0.5,0.0]
set title:'"A bluebird."'
a = blutux.copy
a[true,true,0..1] = 0
plot a, with:"rgbimage"
unset :multiplot
end
# reset
# set size 1.0, 1.0
# set origin 0.0, 0.0
# set multiplot
# set size 0.5,0.48
# set origin 0.0,0.47
# unset key
# set xrange [-0.5:127.5]
# set yrange [-0.5:127.5]
# set tics out
# set label 1 "Luminance adjustment via \`cbrange\`" at 140,160 center
# set title 'Lake Mendota, "or Wonk-sheck-ho-mik-la!"' offset 0,-0.5
# set cbrange [*:*]
# plot 'blutux.rgb' binary array=(128,128) flipy format='%uchar' using 1:2:3 with rgbimage
# unset label 1
# set size 0.5,0.48
# set origin 0.5,0.47
# set title '"Lucky I brought sunscreen."'
# set cbrange [0:200]
# plot 'blutux.rgb' binary array=(128,128) flip=y format='%uchar' using 1:2:3 with rgbimage
# set size 0.5,0.48
# set origin 0.0,0.0
# set title 'Sunset on the Terrace'
# set cbrange [0:400]
# plot 'blutux.rgb' binary array=(128,128) flip=y format='%uchar' using (1.5*$1):2:3 with rgbimage
# set size 0.5,0.48
# set origin 0.5,0.0
# set title 'Sultry evening'
# set cbrange [0:400]
# plot 'blutux.rgb' binary array=(128,128) flipy format='%uchar' using 1:2:3 with rgbimage, '-' w points pt 7 ps 6 lt -2, '-' w points pt 7 ps 0.65 lt -2
# 110 100
# e
# 10 95
# 38 120
# 82 102
# 26 82
# 93 108
# 41 99
# 123 84
# e
# unset multiplot
gpl do
reset
set size:[1.0,1.0]
set origin:[0.0,0.0]
set :multiplot
set size:[0.5,0.48]
set origin:[0.0,0.47]
unset :key
set xrange:-0.5..127.5
set yrange:-0.5..127.5
set :tics, :out
set :label, 1, "Luminance adjustment via 'cbrange'", at:[140,160], center:true
set title:'Lake Mendota, "or Wonk-sheck-ho-mik-la!"', offset:[0,-0.5]
set cbrange:"[*:*]"
plot blutux, with:"rgbimage"
unset label:1
set size:[0.5,0.48]
set origin:[0.5,0.47]
set title:'"Lucky I brought sunscreen."'
set cbrange:0..200
plot blutux, with:"rgbimage"
set size:[0.5,0.48]
set origin:[0.0,0.0]
set title:'Sunset on the Terrace'
set cbrange:0..400
a = Numo::Int16.cast(blutux)
a[true,true,0] *= 1.5
plot a, with:"rgbimage"
set size:[0.5,0.48]
set origin:[0.5,0.0]
set title:'Sultry evening'
set cbrange:0..400
circle = [[110],[110]]
points = [[10,38,82,26,93,41,123],[95,120,102,82,108,99,84]]
plot [blutux, with:"rgbimage"],
[*circle, w:"points", pt:7, ps:6, lt:-2],
[*points, w:"points", pt:7, ps:0.65, lt:-2]
unset :multiplot
end