-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage_prescale.py
executable file
·38 lines (30 loc) · 1000 Bytes
/
image_prescale.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
import numpy as np
import os, os.path
from flask import jsonify, json
import resize
def readImageFrom(imageaddress):
imagedir = resize.image_resize(imageaddress,114)
X = np.array(imagedir, dtype = 'float32')
return X
def imageProcessing(imageaddress):
inputImage = readImageFrom(imageaddress)
#type casting, and scaling
inputImage = np.float32(inputImage)
inputImage = inputImage/255.0
#centering
inputImage_mean = np.mean(inputImage)
inputImage = np.subtract(inputImage, inputImage_mean)
#normalization
inputImage = inputImage/np.std(inputImage)
return inputImage
def createJSON(imageaddress):
np_image = imageProcessing(imageaddress)
np_image = np.resize(np_image, [114,114,3])
processed_image = np_image.tolist()
image_dic = {}
image_dic['input'] = processed_image
imageList = []
imageList.append(image_dic)
instanceWrapper = {}
instanceWrapper['instances'] = imageList
return instanceWrapper