Commit 21c6a08e authored by Taddeüs Kroes's avatar Taddeüs Kroes

Removed a bunch of unused imports.

parent d98cdc83
import traceback, os.path import traceback
class Error: class Error:
def __init__(self, message=None): def __init__(self, message=None):
...@@ -7,11 +7,11 @@ class Error: ...@@ -7,11 +7,11 @@ class Error:
where_it_went_wrong = stack[1] where_it_went_wrong = stack[1]
if message: if message:
print message, "\n" print message, "\n"
print "Error in", origin_of_call[0], "on line", origin_of_call[1] print "Error in", origin_of_call[0], "on line", origin_of_call[1]
print " : ", origin_of_call[3], "\n" print " : ", origin_of_call[3], "\n"
# Inside try function, so -2 lines as exept and Error() are 2 lines # Inside try function, so -2 lines as exept and Error() are 2 lines
print "Function called in", where_it_went_wrong[0] print "Function called in", where_it_went_wrong[0]
print "around line", (where_it_went_wrong[1] - 2), "\n" print "around line", (where_it_went_wrong[1] - 2), "\n"
\ No newline at end of file
from GrayscaleImage import GrayscaleImage from GrayscaleImage import GrayscaleImage
from scipy.ndimage import convolve1d from scipy.ndimage import convolve1d
from pylab import ceil, zeros, pi, e, exp, sqrt, array from pylab import ceil, zeros, pi, exp, sqrt, array
class GaussianFilter: class GaussianFilter:
def __init__(self, scale): def __init__(self, scale):
self.scale = scale self.scale = scale
def gaussian(self, x): def gaussian(self, x):
'''Return the value of a 1D Gaussian function for a given x and scale''' '''Return the value of a 1D Gaussian function for a given x and scale'''
return exp(-(x ** 2 / (2 * self.scale ** 2))) / (sqrt(2 * pi) * self.scale) return exp(-(x ** 2 / (2 * self.scale ** 2))) / (sqrt(2 * pi) * self.scale)
...@@ -15,12 +15,12 @@ class GaussianFilter: ...@@ -15,12 +15,12 @@ class GaussianFilter:
'''Sample a one-dimensional Gaussian function of scale s''' '''Sample a one-dimensional Gaussian function of scale s'''
radius = int(ceil(3 * self.scale)) radius = int(ceil(3 * self.scale))
size = 2 * radius + 1 size = 2 * radius + 1
result = zeros(size) result = zeros(size)
# Sample the Gaussian function # Sample the Gaussian function
result = array([self.gaussian(x - radius) for x in xrange(size)]) result = array([self.gaussian(x - radius) for x in xrange(size)])
# The sum of all kernel values is equal to one # The sum of all kernel values is equal to one
result /= result.sum() result /= result.sum()
return result return result
...@@ -29,15 +29,15 @@ class GaussianFilter: ...@@ -29,15 +29,15 @@ class GaussianFilter:
kernel = self.get_1d_gaussian_kernel() kernel = self.get_1d_gaussian_kernel()
image = convolve1d(image.data, kernel, axis=0, mode='nearest') image = convolve1d(image.data, kernel, axis=0, mode='nearest')
return GrayscaleImage(None, convolve1d(image, kernel, axis=1, mode='nearest')) return GrayscaleImage(None, convolve1d(image, kernel, axis=1, mode='nearest'))
def filter(self, image): def filter(self, image):
kernel = self.get_1d_gaussian_kernel() kernel = self.get_1d_gaussian_kernel()
image.data = convolve1d(image.data, kernel, axis=0, mode='nearest') image.data = convolve1d(image.data, kernel, axis=0, mode='nearest')
image.data = convolve1d(image.data, kernel, axis=1, mode='nearest') image.data = convolve1d(image.data, kernel, axis=1, mode='nearest')
def get_scale(self): def get_scale(self):
return self.scale return self.scale
def set_scale(self, scale): def set_scale(self, scale):
self.scale = float(scale) self.scale = float(scale)
......
from copy import deepcopy
from Rectangle import Rectangle from Rectangle import Rectangle
from GrayscaleImage import GrayscaleImage
class LetterCropper: class LetterCropper:
def __init__(self, threshold = 0.9): def __init__(self, threshold = 0.9):
self.threshold = threshold self.threshold = threshold
def crop_to_letter(self, image): def crop_to_letter(self, image):
self.image = image self.image = image
self.determine_letter_bounds() self.determine_letter_bounds()
...@@ -24,10 +22,10 @@ class LetterCropper: ...@@ -24,10 +22,10 @@ class LetterCropper:
if y < min_y: min_y = y if y < min_y: min_y = y
if x > max_x: max_x = x if x > max_x: max_x = x
if y > max_y: max_y = y if y > max_y: max_y = y
self.letter_bounds = Rectangle( self.letter_bounds = Rectangle(
min_x, min_x,
min_y, min_y,
max_x - min_x , max_x - min_x ,
max_y - min_y max_y - min_y
) )
from pylab import array, zeros, inv, dot, svd, shape, floor from pylab import array, zeros, inv, dot, svd, floor
from xml.dom.minidom import parse from xml.dom.minidom import parse
from Error import Error
from Point import Point from Point import Point
from Character import Character from Character import Character
from GrayscaleImage import GrayscaleImage from GrayscaleImage import GrayscaleImage
from NormalizedCharacterImage import NormalizedCharacterImage from NormalizedCharacterImage import NormalizedCharacterImage
''' """
Creates a license plate object based on an XML file. The image should be Creates a license plate object based on an XML file. The image should be
placed in a folder 'images' the xml file in a folder 'xml' placed in a folder 'images' the xml file in a folder 'xml'
TODO: perhaps remove non required XML lookups TODO: perhaps remove non required XML lookups
''' """
class LicensePlate: class LicensePlate:
def __init__(self, folder_nr, file_nr): def __init__(self, folder_nr, file_nr):
......
from Histogram import Histogram from Histogram import Histogram
from numpy import zeros, byte
from math import ceil from math import ceil
class LocalBinaryPatternizer: class LocalBinaryPatternizer:
......
from GrayscaleImage import GrayscaleImage from GrayscaleImage import GrayscaleImage
from LocalBinaryPatternizer import LocalBinaryPatternizer from LocalBinaryPatternizer import LocalBinaryPatternizer
from LetterCropper import LetterCropper
from matplotlib.pyplot import imshow, subplot, show, axis, bar
from numpy import arange
image = GrayscaleImage("../images/test.png") image = GrayscaleImage("../images/test.png")
lbp = LocalBinaryPatternizer(image) lbp = LocalBinaryPatternizer(image)
histograms = lbp.create_features_vector() histograms = lbp.create_features_vector()
print histograms print histograms
\ No newline at end of file
from GrayscaleImage import GrayscaleImage from GrayscaleImage import GrayscaleImage
from NormalizedCharacterImage import NormalizedCharacterImage from NormalizedCharacterImage import NormalizedCharacterImage
from LetterCropper import LetterCropper
image = GrayscaleImage("../images/test10.png") image = GrayscaleImage("../images/test10.png")
normalized_character_image = NormalizedCharacterImage(image) normalized_character_image = NormalizedCharacterImage(image)
normalized_character_image.show() normalized_character_image.show()
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment