-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImage_Preprocess.py
41 lines (30 loc) · 1.12 KB
/
Image_Preprocess.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# -*- coding: utf-8 -*-
"""
Created on Tue Nov 19 18:03:50 2019
@author: Vandan
"""
## image_resizer.py
# Importing required libraries
import os
import numpy as np
from PIL import Image
# Defining an image size and image channel
# We are going to resize all our images to 128X128 size and since our images are colored images
# We are setting our image channels to 3 (RGB)
IMAGE_SIZE = 128
IMAGE_CHANNELS = 3
IMAGE_DIR = 'Color_Field_Painting/'
# Defining image dir path. Change this if you have different directory
images_path = IMAGE_DIR
training_data = []
# Iterating over the images inside the directory and resizing them using
# Pillow's resize method.
print('resizing...')
for filename in os.listdir(images_path):
path = os.path.join(images_path, filename)
image = Image.open(path).resize((IMAGE_SIZE, IMAGE_SIZE), Image.ANTIALIAS)
training_data.append(np.asarray(image))
training_data = np.reshape(training_data, (-1, IMAGE_SIZE, IMAGE_SIZE, IMAGE_CHANNELS))
training_data = training_data / 127.5 - 1
print('saving file...')
np.save('color_field_painting.npy', training_data)