回答編集履歴

2

d

2019/04/10 15:33

投稿

tiitoi
tiitoi

スコア21956

test CHANGED
@@ -56,10 +56,20 @@
56
56
 
57
57
 
58
58
 
59
- ```
59
+ ```output
60
60
 
61
61
  input\CCITT_1.TIF --> output\CCITT_1_resized.tif
62
62
 
63
63
  input\CCITT_2.TIF --> output\CCITT_2_resized.tif
64
64
 
65
65
  ```
66
+
67
+
68
+
69
+ 動作確認環境
70
+
71
+
72
+
73
+ * Python 3.6.3 Anaconda
74
+
75
+ * Windows 10

1

d

2019/04/10 15:33

投稿

tiitoi
tiitoi

スコア21956

test CHANGED
@@ -28,9 +28,11 @@
28
28
 
29
29
 
30
30
 
31
- os.makedirs(output_dir, exist_ok=True)
31
+ os.makedirs(output_dir, exist_ok=True) # 保存するディレクトリ
32
32
 
33
33
 
34
+
35
+ assert(os.path.exists(input_dir)), "directory '{}' not found".format(input_dir)
34
36
 
35
37
  for path in glob.glob(input_dir + "/*.tif"):
36
38
 
@@ -40,10 +42,24 @@
40
42
 
41
43
 
42
44
 
43
- save_name = '{}_resized.tif'.format(os.path.basename(path)) # 保存するファイル名
45
+ name, ext = os.path.splitext(os.path.basename(path)) # 拡張子を除いたファイル名
44
46
 
45
- save_path = os.path.join(output_dir, save_name) # 保存するパス
47
+ save_path = os.path.join(output_dir, '{}_resized.tif'.format(name)) # 保存するパス
46
48
 
47
49
  img.save(save_path) # 画像を save_path に保存する。
48
50
 
51
+
52
+
53
+ print('{} --> {}'.format(path, save_path))
54
+
49
55
  ```
56
+
57
+
58
+
59
+ ```
60
+
61
+ input\CCITT_1.TIF --> output\CCITT_1_resized.tif
62
+
63
+ input\CCITT_2.TIF --> output\CCITT_2_resized.tif
64
+
65
+ ```