import cv2
import math
import matplotlib.pyplot as plt
%matplotlib inline
# 指定パスのファイルを一括取得
import glob
import re
def show_all_img(img_path, size):
#img_path:画像の格納されたパスを指定
#サイズ
plt.figure(figsize=size)
#拡張子がpng, jpgのファイルを抽出
img_file_names = [p for p in glob.glob('{}/**'.format(img_path), recursive=True)
if re.search('.*(.png|.jpg)', p)]
img_dic = {}
for i in img_file_names:
img_dic[i] = cv2.cvtColor(cv2.imread(i), cv2.COLOR_BGR2RGB)
rows = math.ceil(math.sqrt(img_file_num))
cols = rows
for i,k in enumerate(img_dic.keys()):
plt.subplot(rows,cols,i+1)
plt.title(k)
plt.imshow(img_dic[k])
#####
img_path = "./data"
show_all_img(img_path, (15, 10))
More than 3 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme