CoolFace
Apppublic

Shingome/Image_Processing

sourceHugging Faceotherupdated 2y agoView on Hugging Face
0likes
prepare_image_for_dataset.py28 linesDownload Raw Back to src
1import numpy as np2from PIL import Image3 4 5# open image_for_dataset file6image_for_dataset = Image.open("./../img_for_dataset.jpg")7 8# change image9width, height = image_for_dataset.size10image_for_dataset = image_for_dataset.crop((0, 0, width // 8 * 8, height // 8 * 8))11image_for_dataset = image_for_dataset.convert('L')12image_for_dataset.show()13 14images = []15 16# images to arrays17for x in range(width):18    for y in range(height):19        image = image_for_dataset.crop((x, y, x + 8, y + 8))20        images.append(np.asarray(image))21 22# save crops_for_dataset23images_for_dateset = np.asarray(images)24 25print(np.shape(images))26 27np.save('./../images_for_dataset', images)28