Commit 5cced020 authored by Jayke Meijer's avatar Jayke Meijer

Added function to Filter noise from image. Is just a gaussian blur at the...

Added function to Filter noise from image. Is just a gaussian blur at the moment, but can possibly be made more advanced.
parent 58c4dac2
from scipy.ndimage import convolve1d
from pylab import ceil, zeros, pi, e, exp, sqrt, array
def f(x, s):
"""Return the value of a 1D Gaussian function for a given x and scale."""
return exp(-(x ** 2 / (2 * s ** 2))) / (sqrt(2 * pi) * s)
def gauss1(s, order=0):
"""Sample a one-dimensional Gaussian function of scale s."""
s = float(s)
r = int(ceil(3 * s))
size = 2 * r + 1
W = zeros(size)
# Sample the Gaussian function
W = array([f(x - r, s) for x in xrange(size)])
if not order:
# Make sure that the sum of all kernel values is equal to one
W /= W.sum()
return W
def filterNoise(image, s):
'''Apply a gaussian blur to an image, to suppress noise.'''
filt = gauss1(s)
image = convolve1d(image.data, filt, axis=0, mode='nearest')
return convolve1d(image, filt, axis=1, mode='nearest')
from FilterNoise import filterNoise
from GrayscaleImage import GrayscaleImage
# Get the image
image = GrayscaleImage('../images/plate.png')
output_image = filterNoise(image, 1.4)
# Show the licenseplate
output_image = GrayscaleImage(None, output_image)
output_image.show()
from GetPlate import getPlateAt from GetPlate import getPlateAt
from pylab import imread, imshow, show, figure
from GrayscaleImage import GrayscaleImage from GrayscaleImage import GrayscaleImage
# Define the coordinates of the licenseplate # Define the coordinates of the licenseplate
......
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