In [211]:
    
im = Image.open('realcap/captcha (10).gif').convert('L')
X_im = np.asarray(im).copy()
uniques, counts = np.unique(X_im, return_counts=True)
uniques
    
    Out[211]:
In [212]:
    
from pylab import *
scatter(uniques, counts)
show()
    
    
In [213]:
    
X_im[X_im <= 150] = 0
X_im[X_im > 150] = 255
    
In [214]:
    
Image.fromarray(X_im)
    
    Out[214]:
In [274]:
    
r = util.RandomGenerateOneChar(y=1).convert('L')
    
In [275]:
    
r
    
    Out[275]:
In [276]:
    
X = np.asarray(r).astype('float64')
    
In [277]:
    
uniques, counts = np.unique(X, return_counts=True)
    
In [278]:
    
from pylab import *
scatter(uniques, counts)
show()
    
    
In [279]:
    
X[X <= 150] = 0
X[X > 150] = 255
    
In [242]:
    
Image.fromarray(X)
    
    Out[242]:
In [1]:
    
from PIL import Image, ImageFont, ImageDraw
from zheye import util
from random import randint
import numpy as np
%matplotlib inline
    
In [10]:
    
sample_size = 1000
    
In [11]:
    
X = []
Y = []
for i in range(sample_size):
    #direction = np.random.binomial(1, 0.5)
    #if direction == 0:
    #    direction = -1
    direction = -1
    
    ret = util.RandomGenerateOneChar(y=direction)
    tmp = np.asarray(ret.convert('L')).astype('float64')
    
    tmp[tmp <= 150] = -1
    # 黑色 
    tmp[tmp >  150] = 1
    # 白底
    
    X.append(tmp)
    
    if direction == 1:
        Y.append([1,0])
    else:
        Y.append([0,1])
X = np.array(X).astype("float64")
Y = np.array(Y).astype("uint8")
    
In [12]:
    
print Y[0]
    
    
In [13]:
    
Y.shape
    
    Out[13]:
In [14]:
    
X[0]
    
    Out[14]:
In [15]:
    
"""
mean = (X.sum(axis=0) /sample_size)
Image.fromarray(mean)
np.sum(mean)/mean.size
X = (X.astype("float64") - mean)/256
"""
""""""
    
    Out[15]:
In [16]:
    
X = np.expand_dims(X, axis=3)
X.shape
    
    Out[16]:
In [302]:
    
np.save('test_X', X)
np.save('test_Y', Y)
    
In [8]:
    
np.save('train_X', X)
np.save('train_Y', Y)
    
In [9]:
    
np.save('testF_X', X)
np.save('testF_Y', Y)
    
In [18]:
    
np.save('testT_X', X)
np.save('testT_Y', Y)