Commit 3ce74ceb authored by Taddeüs Kroes's avatar Taddeüs Kroes

improc ass4: Fixed function for Gaussian filter.

parent 4b7f8708
#!/usr/bin/env python
from matplotlib.pyplot import imread, imshow, subplot, show
from numpy import arctan2, zeros, append, pi#, argmax
from numpy import arctan2, zeros, append, pi
from numpy.linalg import norm
from scipy.ndimage import convolve1d
from gauss import Gauss1, gD
......@@ -9,11 +9,6 @@ def in_image(p, F):
"""Check if given pixel coordinates p are within the bound of image F."""
return p[0] >= 0 and p[1] >= 0 and p[0] < F.shape[0] and p[1] < F.shape[1]
#def zero_crossing(a, b, F):
# """Cech if there is a zero crossing point between F[a] and F[b]."""
# return in_image(a, F) and in_image(b, F) \
# and ((F[a] < 0 and F[b] > 0) or (F[a] > 0 and F[b] < 0))
def canny(F, s, Tl=None, Th=None):
"""Apply the Canny Edge Detection algorithm with Gauss scale s to an
image F. Optionally specify a low and high threshold (Tl and Th) for
......@@ -36,20 +31,6 @@ def canny(F, s, Tl=None, Th=None):
G[p] = norm(append(Gx[p], Gy[p]))
A[p] = int(round(arctan2(Gy[p], Gx[p]) * 4 / pi + 1)) % 4
#p = (x, y)
#compare = [(x, y - 1), (x, y + 1), (x + 1, y - 1), \
# (x - 1, y + 1), (x - 1, y), (x + 1, y), \
# (x - 1, y - 1), (x + 1, y + 1)]
#norms = zeros(8)
#for i, c in enumerate(compare):
# if zero_crossing(p, c, F):
# norms[i] = abs(F[p]) + abs(F[c])
#m = argmax(norms)
#G[p] = norms[m]
#A[p] = m >> 1
# Non-maximum suppression
E = zeros(F.shape)
......
#!/usr/bin/env python
from numpy import zeros, arange, pi, e, ceil, meshgrid, array, dot
from numpy import zeros, arange, meshgrid, array, dot
from math import ceil, exp, pi, sqrt
from matplotlib.pyplot import imread, imshow, plot, xlabel, ylabel, show, \
subplot, xlim, savefig
from mpl_toolkits.mplot3d import Axes3D
......@@ -30,14 +31,14 @@ def Gauss(s):
return W / W.sum()
def f_gauss(x, s):
return e ** -(x ** 2 / (2 * s ** 2)) / (2 * pi * s ** 2)
return exp(-(x ** 2 / (2 * s ** 2))) / (sqrt(2 * pi) * s)
def f_gauss_der_1(x, s):
return -x * e ** -(x ** 2 / (2 * s ** 2)) / (2 * pi * s ** 4)
return -x * exp(-(x ** 2 / (2 * s ** 2))) / (sqrt(2 * pi) * s ** 3)
def f_gauss_der_2(x, s):
return (x ** 2 - s ** 2) * e ** -(x ** 2 / (2 * s ** 2)) \
/ (2 * pi * s ** 6)
return (x ** 2 - s ** 2) * exp(-(x ** 2 / (2 * s ** 2))) \
/ (sqrt(2 * pi) * s ** 5)
def Gauss1(s, order=0):
"""Sample a one-dimensional Gaussian function of scale s."""
......
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