def transform(self, image_string):
 	#we need to decode the image from base64
 	image_string = base64.decodestring(image_string)
     #since we're seing this as a JSON string, we use StringIO so it acts like a file
 	img = StringIO(image_string)
     img = Image.open(img)
     img = img.resize(self.STANDARD_SIZE)
     img = list(img.getdata())
     img = map(list, img)
     img = np.array(img)
     s = img.shape[0] * img.shape[1]
     img_wide = img.reshape(1, s)
     return self.pca.transform(img_wide[0])
Example #2
0
def string_to_img(image_string):
    print "called string_to_image"
    #we need to decode the image from base64
    image_string = base64.decodestring(image_string)
    #since we're seing this as a JSON string, we use StringIO so it acts like a file
    img = StringIO(image_string)
    img = PIL.Image.open(img)
    img = img.resize(STANDARD_SIZE)
    img = list(img.getdata())
    img = map(list, img)
    img = np.array(img)
    s = img.shape[0] * img.shape[1]
    img_wide = img.reshape(1, s)
    return pca.transform(img_wide[0])