-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathInitData.py
59 lines (50 loc) · 1.65 KB
/
InitData.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
52
53
54
55
56
57
58
59
import torch
import torch.nn as nn
from torch.nn import init
from torch.autograd import Variable
import torchvision
import torchvision.transforms as T
import torch.optim as optim
from torch.utils.data import DataLoader
from torch.utils.data import sampler
import torchvision.datasets as dset
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
from PIL import Image
import os
import cv2
import argparse
X_train = None
image_size = 48
image_type = 'cloud'
image_number = 1000
parser = argparse.ArgumentParser(description='Image Size')
parser.add_argument('--size', help='size of image in pixels (always square)')
parser.add_argument('--type', help='type of image (geometric, cloud, etc)')
parser.add_argument('--number', help='number of images')
args = parser.parse_args()
if args.size is not None:
image_size = int(args.size)
if args.type is not None:
image_type = args.type
if args.number is not None:
image_number = int(args.number)
def load_file(filename):
if not os.path.exists(filename): return None
image = cv2.imread(filename)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image = cv2.resize(image, (image_size, image_size))
pixels = np.asarray(image)
print(pixels.shape)
return pixels
def save_data():
X = []
for i in range(image_number):
filename = "data/{}-data/{}.jpg".format(image_type, str(i).zfill(8))
pixels = load_file(filename)
if pixels is not None: X.append(pixels)
X_save = np.reshape(X, (len(X), -1))
np.savetxt("data/{}-raw/{}-data.txt".format(image_type, str(image_size)), X_save)
print("length of data: {}".format(len(X)))
save_data()