Commit 1cf0b95f authored by Taddeüs Kroes's avatar Taddeüs Kroes

improc ass4: Finished Gaussian Derivatives and Canny Edge Detector sections in report.

parent 23aeccb1
......@@ -14,10 +14,10 @@ def canny(F, s, Tl=None, Th=None):
image F. Optionally specify a low and high threshold (Tl and Th) for
hysteresis thresholding."""
# Noise reduction by a Gaussian filter
F = gD(F, s, 0, 0)
F = gD(F, 1.4, 0, 0)
# Find intensity gradient
W = Gauss1(1.4, 1)
W = Gauss1(s, 1)
Gx = convolve1d(F, W, axis=1, mode='nearest')
Gy = convolve1d(F, W, axis=0, mode='nearest')
G = zeros(F.shape)
......@@ -47,11 +47,12 @@ def canny(F, s, Tl=None, Th=None):
and (not in_image(nb, G) or g > G[nb]):
E[y, x] = g
# Only execute hysteresis thresholding if the thresholds are specified
# Only execute hysteresis thresholding if both thresholds are specified
if Tl is None or Th is None:
return E
# Hysteresis thresholding
# Scale the thresholds to the color range of the image
Tl *= (E.max() - E.min()) / 255
Th *= (E.max() - E.min()) / 255
T = zeros(F.shape, dtype=bool)
......@@ -64,7 +65,8 @@ def canny(F, s, Tl=None, Th=None):
E[0, x] = E[F.shape[0] - 1, x] = 0
def follow_nb(y, x):
"""Follow the neighbouring pixels of an edge pixel in E recursively."""
"""Follow the neighbouring pixels of an edge pixel in E recursively.
Add pixels with a value higher than Tl to the bitmap."""
if T[y, x]:
return
......
......@@ -167,4 +167,46 @@ are separable as well:
\end{tabular}
\end{table}
The separability property is used in the \texttt{gD} function, by calling the
\texttt{convolve1d} function separately for each direction. This implementation
yields the 2-jet of the cameraman image in figure \ref{fig:jet}.
\begin{figure}[H]
\label{fig:jet}
\center
\includegraphics[scale=.4]{jet_3.pdf}
\caption{The result of \texttt{python gauss.py jet 3}.}
\end{figure}
\section{Canny Edge detector}
The Canny Edge Detector is implemented in the file \emph{canny.py}. For the
algorithm, we used the Wiki
page\footnote{\url{http://en.wikipedia.org/wiki/Canny\_edge\_detector}}. The
different Wiki sections are marked by comments with similar descriptions. Since
the Wiki page is self-explanatory, we will not discuss the algorithm itself in
this report.
The program usage is as follows:
\begin{verbatim}
python canny.py SCALE [ LOWER_THRESHOLD HIGHER_THRESHOLD ]
\end{verbatim}
The scale is obviously used for finding the intensity gradient, and the
thresholds are used in the "Hysterisis thresholding" part. Note that the
thresholds are optional, because the assignment instructs to create a function
\texttt{canny(F, s)} without any arguments for thresholds. Therefore, we were
not sure whether to implement this section. If the thresholds are specified,
the resulting plot will contain an additional image containing a binary image
of edges. The thresholds can be specified in the range 0-255, they are scaled
down by the program to match the image's color range. An example execution of
edge detection on the cameraman image using a scale of 2, a lower threshold of
20 and a higher threshold of 60, can be viewed in figure \ref{fig:canny}
\begin{figure}[H]
\label{fig:canny}
\center
\includegraphics[scale=.5]{canny_2_20_60.pdf}
\caption{The result of \texttt{python canny.py 2 20 60}.}
\end{figure}
\end{document}
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