質問編集履歴
3
不必要な部分削除
test
CHANGED
File without changes
|
test
CHANGED
@@ -304,10 +304,6 @@
|
|
304
304
|
|
305
305
|
---> 23 print(np.nonzero(img[2]))
|
306
306
|
|
307
|
-
24
|
308
|
-
|
309
|
-
25 print('2')
|
310
|
-
|
311
307
|
|
312
308
|
|
313
309
|
IndexError: list index out of range
|
2
追記、質問への回答
test
CHANGED
File without changes
|
test
CHANGED
@@ -267,3 +267,49 @@
|
|
267
267
|
|
268
268
|
|
269
269
|
配列Dが自分が望むものっぽいので、取り出したいのですが、配列Dのみを取り出す場合、どのように書けば良いのでしょうか・・・?
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
```python
|
274
|
+
|
275
|
+
img = [np.array(Image.open('drive/My Drive/sb.png'))]
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
def sigmoid(x):
|
280
|
+
|
281
|
+
return 1 / (1 + np.exp(-x))
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
for i in range(1):
|
286
|
+
|
287
|
+
img[i] = 255 - img[i]
|
288
|
+
|
289
|
+
img[i] = (img[i] > 128) * 255
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
# 非ゼロ要素のインデックスを取得する
|
294
|
+
|
295
|
+
print(np.nonzero(img))
|
296
|
+
|
297
|
+
```
|
298
|
+
|
299
|
+
とすると、以上の結果が出力されますが、
|
300
|
+
|
301
|
+
print(np.nonzero(img[2]))
|
302
|
+
|
303
|
+
等としても
|
304
|
+
|
305
|
+
---> 23 print(np.nonzero(img[2]))
|
306
|
+
|
307
|
+
24
|
308
|
+
|
309
|
+
25 print('2')
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
IndexError: list index out of range
|
314
|
+
|
315
|
+
のエラーが出るため、配列の番号を変えるのではうまく行かないようです。
|
1
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -53,3 +53,217 @@
|
|
53
53
|
元の画像が大きすぎて、かつ全ピクセル情報が・・・により省略されて見れないので、
|
54
54
|
|
55
55
|
よく分からなくなりこんがらがっているのですが。
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
追記
|
64
|
+
|
65
|
+
![イメージ説明](73bb6ffa64558c6fa316994177ed25aa.png)
|
66
|
+
|
67
|
+
以下の画像(sb.png)から抽出したRGBの配列(途中から省略)にnonzero関数を使うと、
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
元の配列(配列A)
|
72
|
+
|
73
|
+
[array([[[ 0, 0, 0],
|
74
|
+
|
75
|
+
[ 0, 0, 0],
|
76
|
+
|
77
|
+
[ 0, 0, 0],
|
78
|
+
|
79
|
+
[ 0, 0, 0],
|
80
|
+
|
81
|
+
[ 0, 0, 0],
|
82
|
+
|
83
|
+
[ 0, 0, 0],
|
84
|
+
|
85
|
+
[ 0, 0, 0],
|
86
|
+
|
87
|
+
[ 0, 0, 0],
|
88
|
+
|
89
|
+
[ 0, 0, 0],
|
90
|
+
|
91
|
+
[ 0, 0, 0],
|
92
|
+
|
93
|
+
[ 0, 0, 0],
|
94
|
+
|
95
|
+
[ 0, 0, 0],
|
96
|
+
|
97
|
+
[ 0, 0, 0],
|
98
|
+
|
99
|
+
[ 0, 0, 0],
|
100
|
+
|
101
|
+
[ 0, 0, 0],
|
102
|
+
|
103
|
+
[255, 255, 255],
|
104
|
+
|
105
|
+
[255, 255, 255],
|
106
|
+
|
107
|
+
[255, 255, 255],
|
108
|
+
|
109
|
+
[255, 255, 255],
|
110
|
+
|
111
|
+
[255, 255, 255],
|
112
|
+
|
113
|
+
[ 0, 0, 0],
|
114
|
+
|
115
|
+
・・・
|
116
|
+
|
117
|
+
[ 0, 0, 0]],
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
[[ 0, 0, 0],
|
122
|
+
|
123
|
+
[ 0, 0, 0],
|
124
|
+
|
125
|
+
[ 0, 0, 0],
|
126
|
+
|
127
|
+
[ 0, 0, 0],
|
128
|
+
|
129
|
+
[ 0, 0, 0],
|
130
|
+
|
131
|
+
[ 0, 0, 0],
|
132
|
+
|
133
|
+
[ 0, 0, 0],
|
134
|
+
|
135
|
+
[ 0, 0, 0],
|
136
|
+
|
137
|
+
[ 0, 0, 0],
|
138
|
+
|
139
|
+
[ 0, 0, 0],
|
140
|
+
|
141
|
+
[ 0, 0, 0],
|
142
|
+
|
143
|
+
[ 0, 0, 0],
|
144
|
+
|
145
|
+
[255, 255, 255],
|
146
|
+
|
147
|
+
[255, 255, 255],
|
148
|
+
|
149
|
+
[255, 255, 255],
|
150
|
+
|
151
|
+
[255, 255, 255],
|
152
|
+
|
153
|
+
[255, 255, 255],
|
154
|
+
|
155
|
+
[255, 255, 255],
|
156
|
+
|
157
|
+
[255, 255, 255],
|
158
|
+
|
159
|
+
[255, 255, 255],
|
160
|
+
|
161
|
+
[255, 255, 255],
|
162
|
+
|
163
|
+
[255, 255, 255],
|
164
|
+
|
165
|
+
[255, 255, 255],
|
166
|
+
|
167
|
+
[ 0, 0, 0],
|
168
|
+
|
169
|
+
・・・
|
170
|
+
|
171
|
+
[ 0, 0, 0]],
|
172
|
+
|
173
|
+
・・・
|
174
|
+
|
175
|
+
以下略
|
176
|
+
|
177
|
+
(配列の横の数字1,2,3・・・は目安につけた)
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
以下のようになったのですが。
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
onezero適用後の、1つ目の配列(配列B)
|
186
|
+
|
187
|
+
(array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
188
|
+
|
189
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
190
|
+
|
191
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
192
|
+
|
193
|
+
・・・
|
194
|
+
|
195
|
+
以下略
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
2つ目の配列(配列C)
|
200
|
+
|
201
|
+
array([ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
|
202
|
+
|
203
|
+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
204
|
+
|
205
|
+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2,
|
206
|
+
|
207
|
+
・・・
|
208
|
+
|
209
|
+
以下略
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
3つ目の配列(配列D)
|
214
|
+
|
215
|
+
array([15, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 19, 12, 12,
|
216
|
+
|
217
|
+
12, 13, 13, 13, 14, 14, 14, 15, 15, 15, 16, 16, 16, 17, 17, 17, 18,
|
218
|
+
|
219
|
+
18, 18, 19, 19, 19, 20, 20, 20, 21, 21, 21, 22, 22, 22, 10, 10, 10,
|
220
|
+
|
221
|
+
11, 11, 11, 12, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 15, 16, 16,
|
222
|
+
|
223
|
+
16, 17, 17, 17, 18, 18, 18, 19, 19, 19, 20, 20, 20, 21, 21, 21, 22,
|
224
|
+
|
225
|
+
22, 22, 23, 23, 23, 24, 24, 24, 9, 9, 9, 10, 10, 10, 11, 11, 11,
|
226
|
+
|
227
|
+
12, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 15, 16, 16, 16, 17, 17,
|
228
|
+
|
229
|
+
17, 18, 18, 18, 19, 19, 19, 20, 20, 20, 21, 21, 21, 22, 22, 22, 23,
|
230
|
+
|
231
|
+
23, 23, 24, 24, 24, 25, 25, 25, 8, 8, 8, 9, 9, 9, 10, 10, 10,
|
232
|
+
|
233
|
+
11, 11, 11, 12, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 15, 16, 16,
|
234
|
+
|
235
|
+
16, 17, 17, 17, 18, 18, 18, 19, 19, 19, 20, 20, 20, 21, 21, 21, 22,
|
236
|
+
|
237
|
+
22, 22, 23, 23, 23, 24, 24, 24, 25, 25, 25, 26, 26, 26, 7, 7, 7,
|
238
|
+
|
239
|
+
8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 12, 13, 13,
|
240
|
+
|
241
|
+
13, 14, 14, 14, 15, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19,
|
242
|
+
|
243
|
+
19, 19, 20, 20, 20, 21, 21, 21, 22, 22, 22, 23, 23, 23, 24, 24, 24,
|
244
|
+
|
245
|
+
25, 25, 25, 26, 26, 26, 27, 27, 27, 6, 6, 6, 7, 7, 7, 8, 8,
|
246
|
+
|
247
|
+
・・・
|
248
|
+
|
249
|
+
以下略
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
4つ目の配列(配列E)
|
254
|
+
|
255
|
+
array([0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0,
|
256
|
+
|
257
|
+
1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1,
|
258
|
+
|
259
|
+
2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2,
|
260
|
+
|
261
|
+
0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0,
|
262
|
+
|
263
|
+
・・・
|
264
|
+
|
265
|
+
以下略
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
配列Dが自分が望むものっぽいので、取り出したいのですが、配列Dのみを取り出す場合、どのように書けば良いのでしょうか・・・?
|