Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Data class for input to the network

  • Loading branch information...
commit d4ebb871736c3329566f33c112270f153c412534 1 parent 5705188
Vipin Nair authored
Showing with 33 additions and 0 deletions.
  1. +33 −0 ocrn/data.py
33 ocrn/data.py
View
@@ -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"))
+
Please sign in to comment.
Something went wrong with that request. Please try again.