Commit e54a3999 authored by Taddeüs Kroes's avatar Taddeüs Kroes

improc ass4: Updated usage of gauss.py.

parent 3895c9fd
......@@ -8,12 +8,6 @@ from scipy.ndimage import convolve, convolve1d
from time import time
from sys import argv, exit
def exit_with_usage():
"""Print an error message with the program's usage and exit the program."""
print 'Usage: python %s timer METHOD [ REPEAT ] | diff SCALE' \
' | der SCALE IORDER JORDER' % argv[0]
exit(1)
def Gauss(s):
"""Sample a two-dimensional Gaussian function of scale s."""
size = int(ceil(3 * s))
......@@ -80,13 +74,34 @@ def plot_kernel(W, ax):
ax.set_ylabel('x')
ax.set_zlabel('g(x, y)')
def exit_with_usage():
"""Print an error message with the program's usage and exit the program."""
print 'Usage: python %s ( 2d SCALE | 1d SCALE IORDER JORDER' \
' | timer METHOD [ REPEAT ] )' % argv[0]
exit(1)
if __name__ == '__main__':
if len(argv) < 2:
exit_with_usage()
F = imread('cameraman.png')
if argv[1] == 'der':
if argv[1] == '2d':
# Calculate and plot the convolution of the given scale
if len(argv) < 3:
exit_with_usage()
s = float(argv[2])
W = Gauss(s)
G = convolve(F, W, mode='nearest')
# Show the original image, kernel and convoluted image respectively
subplot(131)
imshow(F, cmap='gray')
plot_kernel(W, subplot(132, projection='3d'))
subplot(133)
imshow(G, cmap='gray')
elif argv[1] == '1d':
if len(argv) < 5:
exit_with_usage()
......@@ -96,10 +111,12 @@ if __name__ == '__main__':
iorder = int(argv[3])
jorder = int(argv[4])
G = gD(F, s, iorder, jorder)
# Create a 2D weight function for plotting purposes only
Fy = matrix([Gauss1(s, iorder)])
Fx = Fy if jorder == iorder else matrix([Gauss1(s, jorder)])
W = Fy.T * Fx
G = gD(F, s, iorder, jorder)
# Show the original image, kernel and convoluted image respectively
subplot(131)
......@@ -140,20 +157,7 @@ if __name__ == '__main__':
xlabel('s')
ylabel('time (s)')
plot(S, times, 'o-')
elif argv[1] == 'diff':
# Calculate and plot the convolution of the given scale
if len(argv) < 3:
else:
exit_with_usage()
s = float(argv[2])
W = Gauss(s)
G = convolve(F, W, mode='nearest')
# Show the original image, kernel and convoluted image respectively
subplot(131)
imshow(F, cmap='gray')
plot_kernel(W, subplot(132, projection='3d'))
subplot(133)
imshow(G, cmap='gray')
show()
......@@ -84,14 +84,14 @@ because the sum of the filter should be equal to 1, it is divided by its own
sum.
The result of the \texttt{Gauss} function is shown in figure
\ref{fig:gauss-diff}. The subplots respectively show the original image, the
\ref{fig:gauss-2d}. The subplots respectively show the original image, the
Gaussian kernel and the convolved image.
\begin{figure}[H]
\label{fig:gauss-diff}
\label{fig:gauss-2d}
\hspace{-5cm}
\includegraphics[scale=.6]{gauss_diff_5.pdf}
\caption{The result of \texttt{python gauss.py diff 5}.}
\includegraphics[scale=.6]{gauss_2d_5.pdf}
\caption{The result of \texttt{python gauss.py 2d 5}.}
\end{figure}
\subsection{Measuring Performance}
......
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