質問編集履歴
1
補足致しましたー。
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,134 +16,506 @@
|
|
16
16
|
|
17
17
|
https://qiita.com/ka10ryu1/items/015c6a6a5fa287a47828
|
18
18
|
|
19
|
-
という記事に、画像等分割のコードが書かれていたのですが、
|
19
|
+
という記事に、画像等分割のコードが書かれていたのですが、
|
20
|
-
|
20
|
+
|
21
|
-
|
21
|
+
回答を元に変更すると、これできてるんですかね?コードは以下です。
|
22
22
|
|
23
23
|
|
24
24
|
|
25
25
|
```python
|
26
26
|
|
27
|
+
from google.colab import drive
|
28
|
+
|
29
|
+
drive.mount('/content/drive')
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
import sys
|
34
|
+
|
27
|
-
|
35
|
+
import numpy as np
|
36
|
+
|
37
|
+
|
38
|
+
|
28
|
-
|
39
|
+
sys.path.append('/content/drive/My Drive')
|
40
|
+
|
41
|
+
|
42
|
+
|
29
|
-
|
43
|
+
from PIL import Image
|
44
|
+
|
30
|
-
|
45
|
+
from IPython.display import display
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
# PILで開いたうえでデータをNumpy形式にする
|
50
|
+
|
51
|
+
# (例えばJPEGは圧縮されていてNumpyな配列になっていないので、
|
52
|
+
|
53
|
+
# そこからNumpyのデータ空間(?)に持ってくる必要がある)
|
54
|
+
|
55
|
+
img = Image.open("drive/My Drive/mnist_dataset/rei.jpeg")
|
56
|
+
|
57
|
+
img = img.resize((30, 30))
|
58
|
+
|
59
|
+
img = np.asarray(img)
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
size = 5
|
64
|
+
|
65
|
+
|
66
|
+
|
31
|
-
|
67
|
+
v_size = img.shape[0] // size * size
|
32
|
-
|
68
|
+
|
33
|
-
|
69
|
+
h_size = img.shape[1] // size * size
|
34
|
-
|
70
|
+
|
35
|
-
|
71
|
+
img = img[:v_size, :h_size]
|
36
|
-
|
37
|
-
|
38
|
-
|
72
|
+
|
73
|
+
|
74
|
+
|
39
|
-
|
75
|
+
v_split = img.shape[0] // size
|
40
|
-
|
76
|
+
|
41
|
-
|
77
|
+
h_split = img.shape[1] // size
|
42
|
-
|
78
|
+
|
43
|
-
|
79
|
+
out_img = []
|
44
|
-
|
80
|
+
|
45
|
-
|
81
|
+
[out_img.extend(np.hsplit(h_img, h_split))
|
46
|
-
|
82
|
+
|
47
|
-
|
83
|
+
for h_img in np.vsplit(img, v_split)]
|
48
|
-
|
84
|
+
|
85
|
+
|
86
|
+
|
49
|
-
|
87
|
+
print(out_img)
|
50
88
|
|
51
89
|
```
|
52
90
|
|
53
|
-
|
91
|
+
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
92
|
+
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
```python
|
62
|
-
|
63
|
-
from google.colab import drive
|
64
|
-
|
65
|
-
drive.mount('/content/drive')
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
import sys
|
70
|
-
|
71
|
-
import numpy as np
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
sys.path.append('/content/drive/My Drive')
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
import ActivationFunction as AF
|
80
|
-
|
81
|
-
from PIL import Image
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
tefilename = "test2.png"
|
86
|
-
|
87
|
-
teimg = Image.open("drive/My Drive/mnist_dataset/" + tefilename)
|
88
|
-
|
89
|
-
teimg = teimg.resize((100, 100))
|
90
|
-
|
91
|
-
img = np.asarray(teimg)
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
v_size = img.shape[0]
|
96
|
-
|
97
|
-
h_size = img.shape[1]
|
98
|
-
|
99
|
-
img = img[:v_size, :h_size]
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
v_split = img.shape[0]
|
104
|
-
|
105
|
-
h_split = img.shape[1]
|
106
|
-
|
107
|
-
out_img = []
|
108
|
-
|
109
|
-
[out_img.extend(np.hsplit(h_img, h_split))
|
110
|
-
|
111
|
-
for h_img in np.vsplit(img, v_split)]
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
print(out_img)
|
116
|
-
|
117
|
-
```
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
出力結果は
|
93
|
+
出力結果は以下です。
|
94
|
+
|
95
|
+
|
122
96
|
|
123
97
|
Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount("/content/drive", force_remount=True).
|
124
98
|
|
125
|
-
[array([[[25
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
[
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
99
|
+
[array([[[254, 255, 255],
|
100
|
+
|
101
|
+
[254, 255, 255],
|
102
|
+
|
103
|
+
[255, 255, 255],
|
104
|
+
|
105
|
+
[255, 255, 255],
|
106
|
+
|
107
|
+
[255, 255, 255]],
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
[[240, 254, 255],
|
112
|
+
|
113
|
+
[240, 254, 255],
|
114
|
+
|
115
|
+
[242, 254, 255],
|
116
|
+
|
117
|
+
[244, 254, 255],
|
118
|
+
|
119
|
+
[244, 254, 255]],
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
[[210, 244, 254],
|
124
|
+
|
125
|
+
[211, 244, 253],
|
126
|
+
|
127
|
+
[214, 245, 253],
|
128
|
+
|
129
|
+
[217, 246, 252],
|
130
|
+
|
131
|
+
[219, 246, 251]],
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
[[165, 229, 252],
|
136
|
+
|
137
|
+
[168, 229, 251],
|
138
|
+
|
139
|
+
[173, 231, 249],
|
140
|
+
|
141
|
+
[178, 233, 247],
|
142
|
+
|
143
|
+
[182, 233, 244]],
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
[[117, 210, 249],
|
148
|
+
|
149
|
+
[120, 209, 247],
|
150
|
+
|
151
|
+
[127, 211, 243],
|
152
|
+
|
153
|
+
[136, 213, 237],
|
154
|
+
|
155
|
+
[143, 210, 229]]], dtype=uint8), array([[[252, 255, 255],
|
156
|
+
|
157
|
+
[249, 255, 255],
|
158
|
+
|
159
|
+
[244, 255, 255],
|
160
|
+
|
161
|
+
[239, 255, 255],
|
162
|
+
|
163
|
+
[236, 255, 255]],
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
[[242, 254, 254],
|
168
|
+
|
169
|
+
[239, 254, 254],
|
170
|
+
|
171
|
+
[235, 254, 254],
|
172
|
+
|
173
|
+
[231, 254, 254],
|
174
|
+
|
175
|
+
[229, 254, 254]],
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
[[218, 246, 250],
|
180
|
+
|
181
|
+
[217, 246, 249],
|
182
|
+
|
183
|
+
[215, 244, 249],
|
184
|
+
|
185
|
+
[213, 244, 249],
|
186
|
+
|
187
|
+
[211, 243, 251]],
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
[[183, 232, 240],
|
192
|
+
|
193
|
+
[185, 230, 238],
|
194
|
+
|
195
|
+
[187, 227, 238],
|
196
|
+
|
197
|
+
[187, 225, 238],
|
198
|
+
|
199
|
+
[188, 223, 241]],
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
[[149, 205, 220],
|
204
|
+
|
205
|
+
[155, 201, 214],
|
206
|
+
|
207
|
+
[161, 196, 212],
|
208
|
+
|
209
|
+
[164, 193, 212],
|
210
|
+
|
211
|
+
[167, 190, 216]]], dtype=uint8), array([[[232, 255, 255],
|
212
|
+
|
213
|
+
[231, 255, 255],
|
214
|
+
|
215
|
+
[233, 255, 255],
|
216
|
+
|
217
|
+
[234, 255, 255],
|
218
|
+
|
219
|
+
[236, 255, 255]],
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
[[226, 254, 255],
|
224
|
+
|
225
|
+
[225, 254, 255],
|
226
|
+
|
227
|
+
[227, 254, 255],
|
228
|
+
|
229
|
+
[228, 254, 255],
|
230
|
+
|
231
|
+
[229, 252, 255]],
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
[[210, 243, 253],
|
236
|
+
|
237
|
+
[210, 244, 255],
|
238
|
+
|
239
|
+
[212, 245, 255],
|
240
|
+
|
241
|
+
[213, 246, 255],
|
242
|
+
|
243
|
+
[213, 245, 254]],
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
[[188, 224, 246],
|
248
|
+
|
249
|
+
[189, 226, 250],
|
250
|
+
|
251
|
+
[191, 228, 253],
|
252
|
+
|
253
|
+
[191, 230, 252],
|
254
|
+
|
255
|
+
[190, 230, 249]],
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
[[168, 191, 222],
|
260
|
+
|
261
|
+
[169, 193, 228],
|
262
|
+
|
263
|
+
[170, 196, 231],
|
264
|
+
|
265
|
+
[168, 199, 230],
|
266
|
+
|
267
|
+
[165, 200, 225]]], dtype=uint8), array([[[237, 251, 255],
|
268
|
+
|
269
|
+
・・・
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
[[141, 92, 58],
|
274
|
+
|
275
|
+
[142, 92, 56],
|
276
|
+
|
277
|
+
[143, 92, 53],
|
278
|
+
|
279
|
+
[144, 93, 49],
|
280
|
+
|
281
|
+
[144, 93, 48]],
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
[[106, 126, 71],
|
286
|
+
|
287
|
+
[107, 126, 69],
|
288
|
+
|
289
|
+
[106, 126, 66],
|
290
|
+
|
291
|
+
[105, 128, 62],
|
292
|
+
|
293
|
+
[105, 128, 61]],
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
[[ 74, 142, 74],
|
298
|
+
|
299
|
+
[ 75, 142, 73],
|
300
|
+
|
301
|
+
[ 73, 143, 69],
|
302
|
+
|
303
|
+
[ 71, 145, 66],
|
304
|
+
|
305
|
+
[ 70, 145, 65]],
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
[[ 44, 147, 72],
|
310
|
+
|
311
|
+
[ 44, 147, 71],
|
312
|
+
|
313
|
+
[ 42, 149, 68],
|
314
|
+
|
315
|
+
[ 38, 151, 65],
|
316
|
+
|
317
|
+
[ 37, 151, 64]]], dtype=uint8), array([[[255, 225, 217],
|
318
|
+
|
319
|
+
[255, 227, 219],
|
320
|
+
|
321
|
+
[255, 232, 225],
|
322
|
+
|
323
|
+
[255, 238, 232],
|
324
|
+
|
325
|
+
[255, 239, 236]],
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
[[242, 151, 141],
|
330
|
+
|
331
|
+
[241, 152, 142],
|
332
|
+
|
333
|
+
[238, 156, 148],
|
334
|
+
|
335
|
+
[235, 161, 155],
|
336
|
+
|
337
|
+
[234, 163, 160]],
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
[[213, 60, 49],
|
342
|
+
|
343
|
+
[211, 61, 50],
|
344
|
+
|
345
|
+
[207, 61, 53],
|
346
|
+
|
347
|
+
[202, 62, 58],
|
348
|
+
|
349
|
+
[202, 64, 65]],
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
[[206, 10, 0],
|
354
|
+
|
355
|
+
[204, 10, 0],
|
356
|
+
|
357
|
+
[199, 8, 2],
|
358
|
+
|
359
|
+
[194, 7, 6],
|
360
|
+
|
361
|
+
[194, 8, 12]],
|
362
|
+
|
363
|
+
|
364
|
+
|
365
|
+
[[226, 8, 2],
|
366
|
+
|
367
|
+
[225, 8, 2],
|
368
|
+
|
369
|
+
[222, 6, 4],
|
370
|
+
|
371
|
+
[219, 3, 7],
|
372
|
+
|
373
|
+
[218, 2, 10]]], dtype=uint8), array([[[255, 235, 239],
|
374
|
+
|
375
|
+
[255, 234, 242],
|
376
|
+
|
377
|
+
[255, 236, 249],
|
378
|
+
|
379
|
+
[255, 237, 253],
|
380
|
+
|
381
|
+
[254, 235, 251]],
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
[[233, 162, 166],
|
386
|
+
|
387
|
+
[234, 162, 171],
|
388
|
+
|
389
|
+
[235, 165, 179],
|
390
|
+
|
391
|
+
[235, 166, 182],
|
392
|
+
|
393
|
+
[230, 162, 177]],
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
[[204, 66, 72],
|
398
|
+
|
399
|
+
[206, 68, 78],
|
400
|
+
|
401
|
+
[210, 70, 84],
|
402
|
+
|
403
|
+
[210, 70, 85],
|
404
|
+
|
405
|
+
[200, 63, 76]],
|
406
|
+
|
407
|
+
|
408
|
+
|
409
|
+
[[197, 10, 18],
|
410
|
+
|
411
|
+
[200, 12, 23],
|
412
|
+
|
413
|
+
[205, 14, 28],
|
414
|
+
|
415
|
+
[205, 15, 28],
|
416
|
+
|
417
|
+
[194, 7, 17]],
|
418
|
+
|
419
|
+
|
420
|
+
|
421
|
+
[[220, 2, 12],
|
422
|
+
|
423
|
+
[222, 3, 14],
|
424
|
+
|
425
|
+
[225, 6, 16],
|
426
|
+
|
427
|
+
[225, 8, 15],
|
428
|
+
|
429
|
+
[218, 3, 6]]], dtype=uint8), array([[[254, 232, 244],
|
430
|
+
|
431
|
+
[252, 230, 234],
|
432
|
+
|
433
|
+
[242, 236, 224],
|
434
|
+
|
435
|
+
[220, 238, 207],
|
436
|
+
|
437
|
+
[169, 215, 164]],
|
438
|
+
|
439
|
+
|
440
|
+
|
441
|
+
[[222, 154, 164],
|
442
|
+
|
443
|
+
[215, 152, 155],
|
444
|
+
|
445
|
+
[207, 163, 152],
|
446
|
+
|
447
|
+
[192, 174, 147],
|
448
|
+
|
449
|
+
[154, 168, 125]],
|
450
|
+
|
451
|
+
|
452
|
+
|
453
|
+
[[183, 51, 59],
|
454
|
+
|
455
|
+
[170, 50, 50],
|
456
|
+
|
457
|
+
[164, 67, 58],
|
458
|
+
|
459
|
+
[157, 88, 68],
|
460
|
+
|
461
|
+
[138, 103, 70]],
|
462
|
+
|
463
|
+
|
464
|
+
|
465
|
+
[[175, 0, 0],
|
466
|
+
|
467
|
+
[160, 0, 0],
|
468
|
+
|
469
|
+
[155, 12, 4],
|
470
|
+
|
471
|
+
[151, 37, 22],
|
472
|
+
|
473
|
+
[143, 61, 39]],
|
474
|
+
|
475
|
+
|
476
|
+
|
477
|
+
[[206, 0, 0],
|
478
|
+
|
479
|
+
[197, 0, 0],
|
480
|
+
|
481
|
+
[191, 7, 1],
|
482
|
+
|
483
|
+
[185, 25, 16],
|
484
|
+
|
485
|
+
[177, 45, 35]]], dtype=uint8), array([[[ 96, 178, 106],
|
486
|
+
|
487
|
+
[ 45, 157, 68],
|
488
|
+
|
489
|
+
[ 25, 160, 60],
|
490
|
+
|
491
|
+
[ 18, 171, 62],
|
492
|
+
|
493
|
+
[ 14, 173, 63]],
|
494
|
+
|
495
|
+
|
496
|
+
|
497
|
+
[[102, 153, 92],
|
498
|
+
|
499
|
+
[ 69, 152, 77],
|
500
|
+
|
501
|
+
[ 63, 172, 87],
|
502
|
+
|
503
|
+
[ 67, 195, 103],
|
504
|
+
|
505
|
+
[ 64, 202, 108]],
|
506
|
+
|
507
|
+
|
508
|
+
|
509
|
+
・・・
|
510
|
+
|
511
|
+
|
512
|
+
|
513
|
+
[[255, 252, 255],
|
514
|
+
|
515
|
+
[255, 252, 255],
|
516
|
+
|
517
|
+
[255, 250, 255],
|
518
|
+
|
519
|
+
[255, 249, 255],
|
520
|
+
|
521
|
+
[255, 249, 255]]], dtype=uint8)]
|