forked from kame-hame-haa/generatorNeuralNetwork
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage_resize.py
51 lines (39 loc) · 1.21 KB
/
image_resize.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
42
43
44
45
46
47
48
49
50
51
import tensorflow as tf
from PIL import Image
import os, os.path
import skimage
from skimage import data, transform, io
import numpy as np
import matplotlib.pyplot as plt
train_data_directory = "./ourDataset/training"
test_data_directory = "./ourDataset/test"
def load_data(data_directory):
imag = []
valid_images = ".png"
for f in os.listdir(data_directory):
ext = os.path.splitext(f)[1]
if ext.lower() not in valid_images:
continue
imag.append(skimage.data.imread(os.path.join(data_directory, f)))
return imag
images = load_data(train_data_directory)
imagearr = np.array(images)
print(imagearr.size)
print(imagearr.ndim)
pokemon = [0, 1, 2, 3]
for i in range(len(pokemon)):
plt.subplot(2, 2, i+1)
plt.axis('off')
plt.imshow(images[pokemon[i]])
plt.subplots_adjust(wspace=0.5)
plt.show()
# Rescale the images in the `images` array
images28 = [transform.resize(image, (28, 28)) for image in images]
for i in range(len(pokemon)):
plt.subplot(2, 2, i+1)
plt.axis('off')
plt.imshow(images28[pokemon[i]])
plt.subplots_adjust(wspace=0.5)
plt.show()
for i in range(len(images28)):
skimage.io.imsave("./save/pokemon{0}.png".format(i), images28[i])