Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Changed classname to feature, made all the methods static

  • Loading branch information...
commit f8e7ac138b0667fbdf6ef178a5cc2bb49d0c23f9 1 parent f74768f
@swvist authored
Showing with 25 additions and 14 deletions.
  1. +25 −14 ocrn/feature.py
View
39 ocrn/feature.py
@@ -1,15 +1,21 @@
import Image as im
import numpy as np
-class data:
+class feature:
#Return a 10X10 array from a monochrome BMP Image
- def getImageArray(self,imagepath):

get_image_array is a better pick right?
http://www.python.org/dev/peps/pep-0008/#function-names

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
- image = im.open(imagepath)
- imagearray=np.asarray(image.crop(image.getbbox()).resize((10,10))).astype(float)
- return imagearray
+ @staticmethod
+ def getImageArray(imagepath):
+ try:
+ image = im.open(imagepath)
+ imagearray=np.asarray(image.crop(image.getbbox()).resize((10,10))).astype(float)
+ return imagearray
+ except IOError:
+ print "File Not Found"
+ return np.zeros((10,10))
- # Normalizes a 2D array cell.
- def normalizeArrayCell(self, array, x, y):
+ # Normalizes a 2D array cell.
+ @staticmethod
+ def normalizeArrayCell( 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):
@@ -19,22 +25,27 @@ def normalizeArrayCell(self, array, x, y):
# Returns a Normalized 2D Array from an Input Array.
# normalizeArrayCell is called for all non zero cells
- def getNormalizedArray(self, imagearray):
+ @staticmethod
+ def getNormalizedArray( imagearray):
nonzerocells = np.transpose(imagearray.nonzero())
for i in range (0, nonzerocells.shape[0]):
- self.normalizeArrayCell(imagearray, nonzerocells[i][0],nonzerocells[i][1])
+ feature.normalizeArrayCell(imagearray, nonzerocells[i][0],nonzerocells[i][1])
return imagearray
# Returns Normalized 2D array from an Image
- def getNormalizedImageArray(self, imagepath):
- return self.getNormalizedArray(self.getImageArray(imagepath))
+ @staticmethod
+ def getNormalizedImageArray( imagepath):
+ return feature.getNormalizedArray(feature.getImageArray(imagepath))
# Returns Feature Vector of an Image
- def getImageFeatureVector(self, imagepath):
- array = self.getNormalizedImageArray(imagepath)
+ @staticmethod
+ def getImageFeatureVector( imagepath):
+ array = feature.getNormalizedImageArray(imagepath)
vector = np.resize(array,(1,100))
return vector[0]
-
+if __name__ == "__main__":
+ np.set_printoptions(suppress=True)
+ print feature.getImageFeatureVector("../images/t33.bmp")
Please sign in to comment.
Something went wrong with that request. Please try again.