Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

Commit

Permalink
Data class for input to the network
Browse files Browse the repository at this point in the history
  • Loading branch information
nxvipin committed Nov 12, 2011
1 parent 5705188 commit d4ebb87
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions ocrn/data.py
@@ -0,0 +1,33 @@
import Image as im
import numpy as np

class data:
#Return a 10X10 array from a monochrome BMP Image
def getImageArray(self,imagepath):
image = im.open(imagepath)
imagearray=np.asarray(image.crop(image.getbbox()).resize((10,10))).astype(float)
return imagearray

# Normalizes a 2D array cell.
def normalizeArrayCell(self, array, x, y):
for c in range(1,5):
for i in range(x-c,x+c+1):
for j in range(y-c, y+c+1):
if i<=9 and i>=0 and j<=9 and j>=0:
if array[i,j] < array[x,y] and array[i,j] < array[x,y]-0.2*c:
array[i,j]=array[x,y]-0.2*c

# Returns a Normalized 2D Array.
# normalizeArrayCell is called for all non zero cells
def getNormalizedArray(self, imagearray):
nonzerocells = np.transpose(imagearray.nonzero())
for i in range (0, nonzerocells.shape[0]):
self.normalizeArrayCell(imagearray, nonzerocells[i][0],nonzerocells[i][1])
return imagearray


if __name__ == "__main__":
d = data()
np.set_printoptions(suppress=True)
print d.getNormalizedArray(d.getImageArray("../images/t1.bmp"))

0 comments on commit d4ebb87

Please sign in to comment.