回答編集履歴

2

d

2019/05/21 09:54

投稿

tiitoi
tiitoi

スコア21956

test CHANGED
@@ -28,7 +28,7 @@
28
28
 
29
29
 
30
30
 
31
- input_dir = Path('input') # 入力ディレクトリのパス、画像以外のファイルがない前提
31
+ input_dir = Path('input')
32
32
 
33
33
  output_dir = Path('output')
34
34
 
@@ -36,9 +36,9 @@
36
36
 
37
37
 
38
38
 
39
- before = (0, 0, 255) # 置換する色 (blue, green, red) の順
39
+ before = (0, 0, 255)
40
40
 
41
- after = (0, 0, 1) # 置換後の色 (blue, green, red) の順
41
+ after = (0, 0, 1)
42
42
 
43
43
 
44
44
 
@@ -50,11 +50,13 @@
50
50
 
51
51
 
52
52
 
53
- # を置換する。
53
+ # (0, 0, 255) (1, 0, 0) に置換する。
54
54
 
55
55
  idx_to_replace = (img == before).all(axis=2)
56
56
 
57
57
  img[idx_to_replace] = after
58
+
59
+ img[~idx_to_replace] = (0, 0, 0)
58
60
 
59
61
 
60
62
 

1

d

2019/05/21 09:54

投稿

tiitoi
tiitoi

スコア21956

test CHANGED
@@ -28,7 +28,7 @@
28
28
 
29
29
 
30
30
 
31
- input_dir = Path('input')
31
+ input_dir = Path('input') # 入力ディレクトリのパス、画像以外のファイルがない前提
32
32
 
33
33
  output_dir = Path('output')
34
34