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
5c02b43b
Commit
5c02b43b
authored
Oct 09, 2011
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improc ass3: Added backprojection section to report.
parent
d87980d0
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
94 additions
and
8 deletions
+94
-8
improc/ass3/back_projection.py
improc/ass3/back_projection.py
+11
-7
improc/ass3/report/found_waldo.png
improc/ass3/report/found_waldo.png
+0
-0
improc/ass3/report/k-means.png
improc/ass3/report/k-means.png
+0
-0
improc/ass3/report/mask.png
improc/ass3/report/mask.png
+0
-0
improc/ass3/report/report.tex
improc/ass3/report/report.tex
+83
-1
improc/ass3/report/waldo_diff.png
improc/ass3/report/waldo_diff.png
+0
-0
No files found.
improc/ass3/back_projection.py
View file @
5c02b43b
...
...
@@ -59,17 +59,21 @@ def hbp(image, environment, bins, model, radius, mask=None):
for
c
in
domainIterator
(
R
,
3
):
if
I
[
c
]
!=
0
:
R
[
c
]
=
float
(
M
[
c
])
/
float
(
I
[
c
])
R
[
c
]
=
float
(
M
[
c
])
/
I
[
c
]
# Create back projection
print
'Creating back projection...'
b
=
zeros
(
environment
.
shape
[:
2
])
use
=
environment
.
astype
(
float
)
*
map
(
lambda
x
:
x
-
1
,
bins
)
# Apply color model
use
=
environment
.
astype
(
float
)
if
model
==
'hsv'
:
for
p
in
domainIterator
(
image
):
use
[
p
]
=
rgb_to_hsv
(
*
use
[
p
].
tolist
())
use
*=
map
(
lambda
x
:
x
-
1
,
bins
)
# Create back projection
print
'Creating back projection...'
b
=
zeros
(
environment
.
shape
[:
2
])
for
p
in
domainIterator
(
b
):
b
[
p
]
=
min
(
R
[
col2bin
(
use
[
p
])],
1.
)
...
...
@@ -98,7 +102,7 @@ if __name__ == '__main__':
# Execute the back projection algorithm
#import pickle
b
=
hbp
(
waldo
,
env
,
[
64
]
*
3
,
'rgb'
,
15
,
mask
)
b
=
hbp
(
waldo
,
env
,
[
32
]
*
3
,
'rgb'
,
10
,
mask
)
#pickle.dump(b, open('projection.dat', 'w'))
#b = pickle.load(open('projection.dat', 'r'))
...
...
@@ -116,7 +120,7 @@ if __name__ == '__main__':
# Experimental: use K-means to locate clusters, and draw a rectangle
# with the size of the model image around each cluster
print
'Locating peaks...'
peaks
=
find_peaks
(
b
,
.
7
5
,
sqrt
(
w
**
2
+
h
**
2
))
peaks
=
find_peaks
(
b
,
.
2
5
,
sqrt
(
w
**
2
+
h
**
2
))
print
'Done'
subplot
(
121
)
...
...
improc/ass3/report/found_waldo.png
View replaced file @
d87980d0
View file @
5c02b43b
2.54 MB
|
W:
|
H:
2.51 MB
|
W:
|
H:
2-up
Swipe
Onion skin
improc/ass3/report/k-means.png
View replaced file @
d87980d0
View file @
5c02b43b
2.59 MB
|
W:
|
H:
2.69 MB
|
W:
|
H:
2-up
Swipe
Onion skin
improc/ass3/report/mask.png
0 → 100644
View file @
5c02b43b
39.8 KB
improc/ass3/report/report.tex
View file @
5c02b43b
...
...
@@ -40,4 +40,86 @@ model, since it not possible to generate ... We chose the HSV color model.
% Does your model improve the results compared with the RGB model?
\section
{
Histogram Backprojection
}
\subsection
{
Finding Waldo
}
The assignment is to find Waldo (
\emph
{
waldo.png
}
) in a large image containing
Waldo and many other characters (
\emph
{
waldo
\_
env.png
}
) using Histogram Backprojection.
The idea of Histogram Backprojection is explained in the paper by Swain and Ballard,
so we will not explain it here. The algorithm as described in the paper is as follows:
Given histograms
$
M
$
(model, Waldo) and
$
I
$
(environment), create the back projection
$
b
$
in the following steps:
\begin{enumerate}
\item
for each histogram bin
$
j
$
do
$
R
_
j :
=
frac
{
M
_
j
}{
I
_
j
}$
\item
for each
$
x, y
$
do
$
b
_{
x,y
}
:
=
min
(
R
_{
h
(
c
_{
x,y
}
)
}
,
1
)
$
\item
$
b :
=
D
^
r
*
b
$
\item
$
(
x
_
t, y
_
t
)
:
=
loc
(
max
_{
x,y
}
, b
_{
x,y
}
)
$
\end{enumerate}
However, the assignment tells us to only implement steps 1-3.
\subsection
{
Mask
}
The algorithm is implemented in
\emph
{
back
\_
projection.py
}
. First, a mask is created
to ignore the white background in the
\emph
{
waldo.png
}
. This is needed because the
white color is not part of Waldo himself,. In fact, Waldo in the
\emph
{
waldo
\_
env.png
}
has a yellowish background behind him. The usage of a mask is simple: if the mask value
of a pixel is
\texttt
{
False
}
, the pixel's color is discarded in the creation of the
color histogram. The mask for Waldo is created by discarding all pixels with RGB
color (255, 255, 255), which has the following result:
\begin{figure}
[h]
\label
{
fig:mask
}
\includegraphics
{
mask.png
}
\caption
{
The mask used to ignore the white background in
\emph
{
waldo.png
}
.
}
\end{figure}
\subsection
{
Basic algorithm
}
The algorithm is implemented in the function
\texttt
{
hbp
}
:
First,
$
M
$
and
$
I
$
are created using
\texttt
{
colHist
}
.
$
R
$
is then created by
division (step 1). Afterwards, the back projection is created using the loop in step 2.
Finally, a convolution function is used to soften the back projection. To create the
convolution, we have used the function
\texttt
{
scipy.ndimage.correlate
}
with a circular
weight mask.
The following result is generated with 64 bins in each color dimension and a convolution
radius of 15 pixels:
\begin{figure}
[h]
\hspace
{
-4cm
}
\includegraphics
[width=20cm]
{
found
_
waldo.png
}
\caption
{
\emph
{
found
\_
waldo.png
}
: Back projection of Waldo in the larger image, the
red spot is Waldo's location.
}
\end{figure}
This result is created in roughly 27 seconds on a laptop from 2009.
\subsection
{
Experimental cluster detection using K-means
}
In addition to the assignment, we thought it would be interesting to be able to draw a
rectangle around possible occurences of Waldo in the image. Therefore, we created the
function
\texttt
{
find
\_
peaks
}
, which returns a number of possible locations averages.
To do this, we eliminate all pixels in the back projection which are below a certain
threshold (which is given as e number from 0 to 1, and then multiplied by the maximum
value in the projection). This leaves us with a number of pixels clusters, of which we
can calculate the centers using K-means
algorithm
\footnote
{
\url
{
http://en.wikipedia.org/wiki/K-means
\_
clustering
}}
(function
\texttt
{
scipy.cluster.vq.kmeans
}
). To find the initial estimators, we find all pixels
that are further away from all other estimators than the diagonal of the model image
(
\emph
{
waldo.png
}
). Around each center pixel, a rectangle with the size of the model
image is drawn over the larger image. With 32 bins in each color dimension, a threshold
of 0.25 and a convolution radius of 10 pixels, the result is as follows:
\begin{figure}
[h]
\hspace
{
-4cm
}
\includegraphics
[width=20cm]
{
k-means.png
}
\caption
{
\emph
{
k-means.png
}
: Multiple possible locations using a low threshold
and convolution radius.
}
\end{figure}
\end{document}
\ No newline at end of file
improc/ass3/report/waldo_diff.png
deleted
100644 → 0
View file @
d87980d0
163 KB
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