質問編集履歴
2
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -65,3 +65,125 @@
|
|
65
65
|
|
66
66
|
|
67
67
|
```
|
68
|
+
|
69
|
+
### 追記・全ソースコード
|
70
|
+
|
71
|
+
```python
|
72
|
+
|
73
|
+
from pathlib import Path
|
74
|
+
|
75
|
+
from PIL import Image
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
for i in range(6): #F0001には6ファイルあったから6としているが、それぞれに合うようにしたい
|
82
|
+
|
83
|
+
pair2=(pair[i])
|
84
|
+
|
85
|
+
print(pair2)
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
for x in range(11):
|
90
|
+
|
91
|
+
img_dir1 = Path(pair2[0]) # 左側の画像があるディレクトリ
|
92
|
+
|
93
|
+
img_dir2 = Path(pair2[1]) # 右側の画像があるディレクトリ
|
94
|
+
|
95
|
+
output_dir = Path(f"fiw/data/F1-{x}") # 出力ディレクトリ
|
96
|
+
|
97
|
+
output_dir.mkdir(exist_ok=True)
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
def concat_h(img1, img2, color="black"):
|
102
|
+
|
103
|
+
dst = Image.new("RGB", (img1.width + img2.width, max(img1.height, img2.height)), color)
|
104
|
+
|
105
|
+
dst.paste(img1, (0, 0))
|
106
|
+
|
107
|
+
dst.paste(img2, (img1.width, 0)) #横に結合プログラム
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
return dst
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
for path1, path2 in itertools.product(img_dir1.iterdir(), img_dir2.iterdir()):
|
120
|
+
|
121
|
+
print(f"concat {path1} and {path2}")
|
122
|
+
|
123
|
+
img1 = Image.open(path1)
|
124
|
+
|
125
|
+
img2 = Image.open(path2)
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
dst = concat_h(img1, img2)
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
save_path = output_dir / f"{path1.stem}_{path2.stem}.jpg"
|
134
|
+
|
135
|
+
dst.save(save_path)
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
def concat_h(img2, img1, color="black"):
|
146
|
+
|
147
|
+
dst = Image.new("RGB", (img2.width + img1.width, max(img2.height, img1.height)), color)
|
148
|
+
|
149
|
+
dst.paste(img2, (0, 0))
|
150
|
+
|
151
|
+
dst.paste(img1, (img2.width, 0))
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
return dst
|
156
|
+
|
157
|
+
output_dir = Path(f"fiw/data/F1-{x+1}") # 出力ディレクトリ
|
158
|
+
|
159
|
+
output_dir.mkdir(exist_ok=True)
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
for path2, path1 in itertools.product(img_dir2.iterdir(), img_dir1.iterdir()):
|
166
|
+
|
167
|
+
print(f"concat {path2} and {path1}")
|
168
|
+
|
169
|
+
img1 = Image.open(path2)
|
170
|
+
|
171
|
+
img2 = Image.open(path1)
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
dst = concat_h(img1, img2)
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
save_path = output_dir / f"{path2.stem}_{path1.stem}.jpg"
|
180
|
+
|
181
|
+
dst.save(save_path)
|
182
|
+
|
183
|
+
x=x+1
|
184
|
+
|
185
|
+
i=i+1
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
```
|
1
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -54,6 +54,10 @@
|
|
54
54
|
|
55
55
|
output_dir.mkdir(exist_ok=True)
|
56
56
|
|
57
|
+
|
58
|
+
|
59
|
+
x=x+1
|
60
|
+
|
57
61
|
|
58
62
|
|
59
63
|
.......
|