<jupyter_start><jupyter_text>pad and resize image<jupyter_code>import os
import cv2
from glob import glob

WHITE = [255,255,255]
BLACK = [0,0,0]
def padding_img(img, hw_ratio=2.0):
    """
    hwight:width = hw_ratio  pad後画像を返す
    """
    size = img.shape
    if (size[0] % 2 == 1):
        img = img[:-1, :]
    if (size[1] % 2 == 1):
        img = img[:, :-1]
    padded_image = img
    if (size[0] > size[1]*hw_ratio):
        pad_size = int((size[0] - size[1]*hw_ratio) / 2)
        padded_image = cv2.copyMakeBorder(img, 0, 0, pad_size, pad_size, cv2.BORDER_CONSTANT, value=BLACK)
    if (size[0] < size[1]*hw_ratio):
        pad_size = int((size[1]*hw_ratio - size[0]) / 2)
        padded_image = cv2.copyMakeBorder(img, pad_size, pad_size, 0, 0, cv2.BORDER_CONSTANT, value=BLACK)

    return padded_image

def padding_imgs(input_dir, hw_ratio=2.0, output_dir=None):
    image_paths = glob(os.path.join(input_dir, "*"))    # ここjpeg以外でも大丈夫なように
    if (output_dir==None):
        output_dir = input_dir
    for image_path in image_paths:
#         print(image_path)
        img = cv2.imread(image_path)
        padded_image = padding_img(img, hw_ratio)
        filename = os.path.basename(image_path)
        output_path = os.path.join(output_dir, filename)
#         print(output_path)
        cv2.imwrite(output_path, padded_image)
images_dir = "/home/liquid/src/Person_reID_baseline_pytorch/data/test0/"
output_dir =  "/Users/ogura/Downloads/skinhead_test/padded/"<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1384820239680426, 'fraction_numerical': 0.03062583222370173, 'mean_word_length': 3.356521739130435, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '496293', 'license': 'MIT', 'n_tokens_mistral': 614, 'n_tokens_neox': 591, 'n_words': 103, 'path': 'resize.ipynb', 'repo_name': 'taroogura/Person_reID_baseline_pytorch', 'size': '1502'}