Commit 7a22a928 authored by Taddeüs Kroes's avatar Taddeüs Kroes

improc ass4: Source code cleanup.

parent e54a3999
......@@ -16,7 +16,7 @@ def Gauss(s):
t = float(s) ** 2
a = 1 / (2 * pi * t)
# Sample the Gaussian function
# Sample the 2D Gaussian function
for x in xrange(r):
for y in xrange(r):
W[x, y] = a * exp(-(((x - size) ** 2 + (y - size) ** 2) / (2 * t)))
......@@ -25,16 +25,16 @@ def Gauss(s):
return W / W.sum()
def f_gauss(x, s):
"""Return the 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 * s ** 2))) / (sqrt(2 * pi) * s)
def f_gauss_der_1(x, s):
"""Return the first derivative of the Gaussian function for a given x
"""Return the first derivative of the 1D Gaussian function for a given x
and scale."""
return -x * exp(-(x ** 2 / (2 * s ** 2))) / (sqrt(2 * pi) * s ** 3)
def f_gauss_der_2(x, s):
"""Return the second derivative of the Gaussian function for a given x
"""Return the second derivative of the 1D Gaussian function for a given x
and scale."""
return (x ** 2 - s ** 2) * exp(-(x ** 2 / (2 * s ** 2))) \
/ (sqrt(2 * pi) * s ** 5)
......@@ -58,11 +58,11 @@ def Gauss1(s, order=0):
def gD(F, s, iorder, jorder):
"""Create the Gaussian derivative convolution of image F."""
Fy = Gauss1(s, iorder)
Fx = Fy if jorder == iorder else Gauss1(s, jorder)
G = convolve1d(F, Fy, axis=0, mode='nearest')
Wy = Gauss1(s, iorder)
Wx = Wy if jorder == iorder else Gauss1(s, jorder)
G = convolve1d(F, Wy, axis=0, mode='nearest')
return convolve1d(G, Fx, axis=1, mode='nearest')
return convolve1d(G, Wx, axis=1, mode='nearest')
def plot_kernel(W, ax):
"""Create a 3D plot of a kernel."""
......
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