OpenCVを使用して100×100ピクセルの画像をまとめて出力するスクリプトです。
import numpy as np
import matplotlib.pyplot as plt
import cv2
total_rows = 20 # 画像を配置する行数
total_cols = 30 # 画像を配置する列数
image_size = 100 # 1枚の画像のサイズ
num_images = 588
# まとめる画像のサイズを計算
result_image = np.zeros((total_rows * image_size, total_cols * image_size, 3), dtype=np.uint8)
# 画像をまとめる処理
for i in range(total_rows):
for j in range(total_cols):
image_index = i * total_cols + j # 画像のインデックス
if image_index <num_images:
image_path = f'images/{image_index+1}.png' # 画像のパスを適切に設定
print(image_path)
# 画像を読み込んでリサイズ
img = cv2.imread(image_path)
img = cv2.resize(img, (image_size, image_size))
# まとめる画像に配置
result_image[i * image_size: (i + 1) * image_size,
j * image_size: (j + 1) * image_size] = img
plt.axis('off')
# まとめた画像を保存
cv2.imwrite('combined_image.png', result_image)

