Przeglądaj źródła

Added function to Filter noise from image. Is just a gaussian blur at the moment, but can possibly be made more advanced.

Jayke Meijer 14 lat temu
rodzic
commit
5cced02076
4 zmienionych plików z 40 dodań i 1 usunięć
  1. BIN
      images/plate.png
  2. 29 0
      src/FilterNoise.py
  3. 11 0
      src/FilterNoiseTest.py
  4. 0 1
      src/GetPlateTest.py

BIN
images/plate.png


+ 29 - 0
src/FilterNoise.py

@@ -0,0 +1,29 @@
+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')

+ 11 - 0
src/FilterNoiseTest.py

@@ -0,0 +1,11 @@
+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()

+ 0 - 1
src/testGetPlate.py → src/GetPlateTest.py

@@ -1,5 +1,4 @@
 from GetPlate import getPlateAt
-from pylab import imread, imshow, show, figure
 from GrayscaleImage import GrayscaleImage
 
 # Define the coordinates of the licenseplate