teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

修正

2020/08/14 11:14

投稿

hanaaaa
hanaaaa

スコア5

title CHANGED
File without changes
body CHANGED
@@ -31,4 +31,65 @@
31
31
 
32
32
  .......
33
33
 
34
+ ```
35
+ ### 追記・全ソースコード
36
+ ```python
37
+ from pathlib import Path
38
+ from PIL import Image
39
+
40
+
41
+ for i in range(6): #F0001には6ファイルあったから6としているが、それぞれに合うようにしたい
42
+ pair2=(pair[i])
43
+ print(pair2)
44
+
45
+ for x in range(11):
46
+ img_dir1 = Path(pair2[0]) # 左側の画像があるディレクトリ
47
+ img_dir2 = Path(pair2[1]) # 右側の画像があるディレクトリ
48
+ output_dir = Path(f"fiw/data/F1-{x}") # 出力ディレクトリ
49
+ output_dir.mkdir(exist_ok=True)
50
+
51
+ def concat_h(img1, img2, color="black"):
52
+ dst = Image.new("RGB", (img1.width + img2.width, max(img1.height, img2.height)), color)
53
+ dst.paste(img1, (0, 0))
54
+ dst.paste(img2, (img1.width, 0)) #横に結合プログラム
55
+
56
+ return dst
57
+
58
+
59
+
60
+ for path1, path2 in itertools.product(img_dir1.iterdir(), img_dir2.iterdir()):
61
+ print(f"concat {path1} and {path2}")
62
+ img1 = Image.open(path1)
63
+ img2 = Image.open(path2)
64
+
65
+ dst = concat_h(img1, img2)
66
+
67
+ save_path = output_dir / f"{path1.stem}_{path2.stem}.jpg"
68
+ dst.save(save_path)
69
+
70
+
71
+
72
+
73
+ def concat_h(img2, img1, color="black"):
74
+ dst = Image.new("RGB", (img2.width + img1.width, max(img2.height, img1.height)), color)
75
+ dst.paste(img2, (0, 0))
76
+ dst.paste(img1, (img2.width, 0))
77
+
78
+ return dst
79
+ output_dir = Path(f"fiw/data/F1-{x+1}") # 出力ディレクトリ
80
+ output_dir.mkdir(exist_ok=True)
81
+
82
+
83
+ for path2, path1 in itertools.product(img_dir2.iterdir(), img_dir1.iterdir()):
84
+ print(f"concat {path2} and {path1}")
85
+ img1 = Image.open(path2)
86
+ img2 = Image.open(path1)
87
+
88
+ dst = concat_h(img1, img2)
89
+
90
+ save_path = output_dir / f"{path2.stem}_{path1.stem}.jpg"
91
+ dst.save(save_path)
92
+ x=x+1
93
+ i=i+1
94
+
34
95
  ```

1

修正

2020/08/14 11:14

投稿

hanaaaa
hanaaaa

スコア5

title CHANGED
File without changes
body CHANGED
@@ -26,6 +26,8 @@
26
26
                            ⬆
27
27
  ここの部分
28
28
  output_dir.mkdir(exist_ok=True)
29
+     
30
+      x=x+1
29
31
 
30
32
  .......
31
33