Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
U
uva
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
uva
Commits
81f843ff
Commit
81f843ff
authored
Nov 15, 2011
by
Sander Mathijs van Veen
Browse files
Options
Browse Files
Download
Plain Diff
fixed merge conflict
parents
13cc25ab
e5856ab2
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
13 additions
and
222 deletions
+13
-222
improc/ass4/gauss.py
improc/ass4/gauss.py
+13
-8
improc/ass4/report/jet_3.pdf
improc/ass4/report/jet_3.pdf
+0
-0
improc/ass4/report/jet_4.pdf
improc/ass4/report/jet_4.pdf
+0
-0
improc/ass4/report/report.tex
improc/ass4/report/report.tex
+0
-214
No files found.
improc/ass4/gauss.py
View file @
81f843ff
...
...
@@ -2,7 +2,7 @@
from
numpy
import
zeros
,
arange
,
meshgrid
,
array
,
matrix
from
math
import
ceil
,
exp
,
pi
,
sqrt
from
matplotlib.pyplot
import
imread
,
imshow
,
plot
,
xlabel
,
ylabel
,
show
,
\
subplot
,
xlim
,
savefig
subplot
,
xlim
,
savefig
,
axis
from
mpl_toolkits.mplot3d
import
Axes3D
from
scipy.ndimage
import
convolve
,
convolve1d
from
time
import
time
...
...
@@ -164,19 +164,24 @@ if __name__ == '__main__':
exit_with_usage
()
s
=
float
(
argv
[
2
])
subplot
(
331
)
subplot
(
331
,
title
=
'Fs'
)
imshow
(
gD
(
F
,
s
,
0
,
0
),
cmap
=
'gray'
)
subplot
(
334
)
axis
(
'off'
)
subplot
(
334
,
title
=
'Fsx'
)
imshow
(
gD
(
F
,
s
,
1
,
0
),
cmap
=
'gray'
)
subplot
(
335
)
axis
(
'off'
)
subplot
(
335
,
title
=
'Fsy'
)
imshow
(
gD
(
F
,
s
,
0
,
1
),
cmap
=
'gray'
)
subplot
(
337
)
axis
(
'off'
)
subplot
(
337
,
title
=
'Fsxx'
)
imshow
(
gD
(
F
,
s
,
2
,
0
),
cmap
=
'gray'
)
subplot
(
338
)
axis
(
'off'
)
subplot
(
338
,
title
=
'Fsxy'
)
imshow
(
gD
(
F
,
s
,
1
,
1
),
cmap
=
'gray'
)
subplot
(
339
)
axis
(
'off'
)
subplot
(
339
,
title
=
'Fsyy'
)
imshow
(
gD
(
F
,
s
,
0
,
2
),
cmap
=
'gray'
)
axis
(
'off'
)
else
:
exit_with_usage
()
...
...
improc/ass4/report/jet_3.pdf
deleted
100644 → 0
View file @
13cc25ab
File deleted
improc/ass4/report/jet_4.pdf
0 → 100644
View file @
81f843ff
File added
improc/ass4/report/report.tex
deleted
100644 → 0
View file @
13cc25ab
\documentclass
[10pt,a4paper]
{
article
}
\usepackage
[english]
{
babel
}
\usepackage
[utf8]
{
inputenc
}
\usepackage
{
amsmath,hyperref,graphicx,booktabs,float
}
% Paragraph indentation
\setlength
{
\parindent
}{
0pt
}
\setlength
{
\parskip
}{
1ex plus 0.5ex minus 0.2ex
}
\title
{
Image processing 4: Local Structure
}
\author
{
Sander van Veen
\&
Tadde
\"
us Kroes
\\
6167969
\&
6054129
}
\begin{document}
\maketitle
\section
{
Analytical Local Structure
}
\subsection
{
Derivatives
}
\label
{
sub:derivatives
}
We have been given the following function:
$$
f
(
x, y
)
=
A sin
(
Vx
)
+
B cos
(
Wy
)
$$
The partial derivatives
$
f
_
x, f
_
y, f
_{
xx
}
, f
_{
xy
}$
and
$
f
_{
yy
}$
can be
derived as follows:
\begin{table}
[H]
\begin{tabular}
{
rl
}
$
f
_
x
$
&
$
=
\frac
{
\delta
f
}{
\delta
x
}$
\\
&
$
=
A
\frac
{
\delta
}{
\delta
x
}
sin
(
Vx
)
+
B
\frac
{
\delta
}{
\delta
x
}
cos
(
Wy
)
$
\\
&
$
=
A cos
(
Vx
)
\cdot
V
+
B
\cdot
0
$
\\
&
$
=
AV cos
(
Vx
)
$
\\
&
\\
$
f
_
y
$
&
$
=
\frac
{
\delta
f
}{
\delta
y
}$
\\
&
$
=
A
\frac
{
\delta
}{
\delta
y
}
sin
(
Vx
)
+
B
\frac
{
\delta
}{
\delta
y
}
cos
(
Wy
)
$
\\
&
$
=
A
\cdot
0
-
B sin
(
Wy
)
\cdot
W
$
\\
&
$
=
-
BW sin
(
Wy
)
$
\\
&
\\
$
f
_{
xx
}$
&
$
=
\frac
{
\delta
f
_
x
}{
\delta
x
}$
\\
&
$
=
AV
\frac
{
\delta
}{
\delta
x
}
cos
(
Vx
)
$
\\
&
$
=
-
AV
^
2
sin
(
Vx
)
$
\\
&
\\
$
f
_{
xy
}$
&
$
=
\frac
{
\delta
f
_
x
}{
\delta
y
}
=
AV
\frac
{
\delta
}{
\delta
y
}
cos
(
Vx
)
=
0
$
\\
&
\\
$
f
_{
yy
}$
&
$
=
\frac
{
\delta
f
_
y
}{
\delta
y
}$
\\
&
$
=
-
BW
\frac
{
\delta
}{
\delta
y
}
sin
(
Wy
)
$
\\
&
$
=
-
BW
^
2
cos
(
Wy
)
$
\\
\end{tabular}
\end{table}
\pagebreak
\subsection
{
Plots
}
The following plots show
$
f
(
x, y
)
$
and its first and second derivatives. The
image on the left shows
$
f
_
x
$
and
$
f
_
y
$
. The image on the right shows
$
f
_{
xx
}$
and
$
f
_{
yy
}$
in a quiver plot over
$
f
(
x, y
)
$
. The arrows point towards the
largest increase of gray value, which means that the derivations in chapter
\ref
{
sub:derivatives
}
are correct.
\begin{figure}
[H]
\hspace
{
-2cm
}
\includegraphics
[scale=.8]
{
samples.pdf
}
\caption
{
Plots of
$
f
(
x, y
)
$
and its first and second derivatives.
}
\end{figure}
\section
{
Gaussian Convolution
}
\subsection
{
Implementation
}
All Gaussian functions are implemented in the file
\emph
{
gauss.py
}
. The
\texttt
{
Gauss
}
function fills a 2D array with the values of the 2D Gaussian
function
\footnote
{
\label
{
footnote:gaussian-filter
}
\url
{
http://en.wikipedia.org/wiki/Gaussian
\_
filter
}}
:
$$
g
_{
2
D
}
(
x, y
)
=
\frac
{
1
}{
2
\pi
\sigma
^
2
}
e
^{
-
\frac
{
x
^
2
+
y
^
2
}{
2
\sigma
^
2
}}$$
This function converges to zero, but never actually equals zero. The filter's
size is therefore chosen to be
$
\lceil
6
*
\sigma
\rceil
$
in each direction by
convention (since values for
$
x,y >
3
*
\sigma
$
are negligible). Finally,
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-2d
}
. The subplots respectively show the original image, the
Gaussian kernel and the convolved image.
\begin{figure}
[H]
\hspace
{
-5cm
}
\includegraphics
[scale=.6]
{
gauss
_
2d
_
5.pdf
}
\caption
{
The result of
\texttt
{
python gauss.py 2d 5
}
.
}
\label
{
fig:gauss-2d
}
\end{figure}
\subsection
{
Measuring Performance
}
We've timed the runtime of the
\texttt
{
Gauss
}
function for
$
\sigma
=
1
,
2
,
3
,
5
,
7
,
9
,
11
,
15
,
19
$
, the results are in figure
\ref
{
fig:times-2d
}
. The graph shows a computational complexity of
$
\mathcal
{
O
}
(
\sigma
^
2
)
$
.
\begin{figure}
[H]
\center
\includegraphics
[scale=.5]
{
gauss
_
times
_
2d.pdf
}
\caption
{
The result of
\texttt
{
python gauss.py timer 2d 5
}
(so, each
timing has been repeated 5 times and then averaged).
}
\label
{
fig:times-2d
}
\end{figure}
\section
{
Separable Gaussian Convolution
}
\subsection
{
Implementation
}
The
\texttt
{
Gauss1
}
function uses the 1D Gaussian
function
\ref
{
footnote:gaussian-filter
}
:
$$
g
_{
1
D
}
(
x
)
=
\frac
{
1
}{
\sqrt
{
2
\pi
}
\cdot
\sigma
}
e
^{
-
\frac
{
x
^
2
}{
2
\sigma
^
2
}}$$
This function returns a 1D array of kernel values, which is used by the
function
\texttt
{
convolve1d
}
. Using the separability property, the following
code snippets produce the same result:
\begin{verbatim}
W = Gauss1(s)
G = convolve1d(F, W, axis=0, mode='nearest')
G = convolve1d(G, W, axis=1, mode='nearest')
\end{verbatim}
as opposed to:
\begin{verbatim}
G = convolve(F, Gauss(s), mode='nearest')
\end{verbatim}
The timing results of the first code snippet are displayed in figure
\ref
{
fig:times-1d
}
. The graphs shows that the 1D convolution has a
computational complexity of
$
\mathcal
{
O
}
(
\sigma
)
$
, which is much faster than
the 2D convolution (certainly for higher scales).
\begin{figure}
[H]
\center
\includegraphics
[scale=.5]
{
gauss
_
times
_
1d.pdf
}
\caption
{
The result of
\texttt
{
python gauss.py timer 1d 50
}
.
}
\label
{
fig:times-1d
}
\end{figure}
\section
{
Gaussian Derivatives
}
\subsection
{
Separability
}
We can show analytically that all derivatives of the 2D Gaussian function
are separable as well:
\begin{table}
[H]
\begin{tabular}
{
rll
}
$
\frac
{
\delta
}{
\delta
x
}
\frac
{
\delta
}{
\delta
y
}
G
_{
2
D
}
(
x, y
)
$
&
$
=
\frac
{
\delta
}{
\delta
x
}
(
\frac
{
\delta
}{
\delta
y
}
(
G
_{
1
D
}
(
x
)
\cdot
G
_{
1
D
}
(
y
)))
$
&
$
G
_{
2
D
}
(
x, y
)
=
G
_{
1
D
}
(
x
)
\cdot
G
_{
1
D
}
(
y
)
$
is
given
\\
&
$
=
\frac
{
\delta
}{
\delta
x
}
(
G
_{
1
D
}
(
x
)
\cdot
\frac
{
\delta
}{
\delta
y
}
G
_{
1
D
}
(
y
))
$
&
because
$
G
_{
1
D
}
(
x
)
$
is
constant with respect to
$
y
$
\\
&
$
=
\frac
{
\delta
}{
\delta
x
}
G
_{
1
D
}
(
x
)
\cdot
\frac
{
\delta
}{
\delta
y
}
G
_{
1
D
}
(
y
)
$
&
\\
\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]
\center
\includegraphics
[scale=.4]
{
jet
_
3.pdf
}
\caption
{
The result of
\texttt
{
python gauss.py jet 3
}
.
}
\label
{
fig:jet
}
\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]
\hspace
{
-5cm
}
\includegraphics
[scale=.6]
{
canny
_
2
_
20
_
60.pdf
}
\caption
{
The result of
\texttt
{
python canny.py 2 20 60
}
.
}
\label
{
fig:canny
}
\end{figure}
\end{document}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment