Skip to content

Instantly share code, notes, and snippets.

@LouiS0616
Created January 9, 2019 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LouiS0616/915470970892de3df0f8228af2508e3f to your computer and use it in GitHub Desktop.
Save LouiS0616/915470970892de3df0f8228af2508e3f to your computer and use it in GitHub Desktop.
from pathlib import Path
import cv2
import numpy as np
from tqdm import tqdm
def main(filename):
# 画像を読み込む
img = cv2.imread(filename)
assert img is not None, f'Cannot open {filename}'
# フォルダの作成
dst_filename_stem = Path(filename).stem
(Path('.') / dst_filename_stem).mkdir()
# 画像のリサイズ
height, width, _ = img.shape
img = cv2.resize(img, (width//4, height//4))
# 画像の分割 & 保存
strips = np.split(img, 12, axis=1)
for i in range(8):
work = strips[i:] + strips[:i]
dst = np.hstack(work)
cv2.imwrite(f'{dst_filename_stem}/{i:02d}.jpg', dst)
if __name__ == '__main__':
root = Path(r'...')
for img_file in tqdm(root.glob('*/*.jpg')):
img_file = str(img_file.resolve())
main(img_file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment