Create a gist now

Instantly share code, notes, and snippets.

Embed
import os
from PIL import Image
import numpy as np
files = [f for f in os.listdir("handwriting/numbers/")]
files = ["handwriting/numbers/" + f for f in files]
STANDARD_SIZE = (50, 50)
def get_image_data(filename):
img = Image.open(filename)
img = img.getdata()
img = img.resize(STANDARD_SIZE)
img = map(list, img)
img = np.array(img)
s = img.shape[0] * img.shape[1]
img_wide = img.reshape(1, s)
return img_wide[0]
data = []
labels = []
print "extracting features..."
for f in files:
data.append(get_image_data(f))
labels.append(int(f.split(".")[0][-1]))
print "done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment