-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage_preprocessing.py
More file actions
59 lines (46 loc) · 1.37 KB
/
image_preprocessing.py
File metadata and controls
59 lines (46 loc) · 1.37 KB
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author: ritesh
# @Date: 2015-09-14 11:18:31
# @Last Modified by: ritesh
# @Last Modified time: 2015-09-15 10:12:42
import numpy as np
import scipy.misc
import pylab
from PIL import Image
def show_image(img):
pylab.imshow(img)
def save_img(img):
scipy.misc.imsave('outfile.jpg', img)
def get_img(img_name, img_size=256, batch_size=256):
target_shape = (img_size, img_size, 3)
img = scipy.misc.imread(img_name) # x*x*3
assert img.dtype == 'uint8', img_name
# assert False
if len(img.shape) == 2:
img = scipy.misc.imresize(img, (img_size, img_size))
img = np.asarray([img, img, img])
else:
if img.shape[2] > 3:
img = img[:, :, :3]
img = scipy.misc.imresize(img, target_shape)
img = np.rollaxis(img, 2)
if img.shape[0] != 3:
print img_name
return img
def convert_to_grey(img):
imfile = '3wolfmoon_new.jpg';
im = double(rgb2gray(imread(imfile))); # double and convert to grayscale
im = imresize(im,[20,20]); # change to 20 by 20 dimension
im = im(:); # unroll matrix to vector
im = im./max(im);
def wolfmoon_img():
img_name = "3wolfmoon_new.jpg"
img = get_img(img_name)
print img, type(img), img.shape
save_img(img)
def main():
wolfmoon_img()
convert_to_grey()
if __name__ == '__main__':
main()