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
996861ca
Commit
996861ca
authored
Oct 09, 2011
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improc ass3: Added support for alternative color model HSV.
parent
5dcf393f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
20 deletions
+47
-20
improc/ass3/back_projection.py
improc/ass3/back_projection.py
+5
-7
improc/ass3/intersect.py
improc/ass3/intersect.py
+22
-13
improc/ass3/results_hsv.txt
improc/ass3/results_hsv.txt
+20
-0
improc/ass3/results_rgb.txt
improc/ass3/results_rgb.txt
+0
-0
No files found.
improc/ass3/back_projection.py
View file @
996861ca
...
...
@@ -66,9 +66,7 @@ def hbp(image, environment, bins, model, radius, mask=None):
b
=
zeros
(
environment
.
shape
[:
2
])
use
=
environment
.
astype
(
float
)
*
map
(
lambda
x
:
x
-
1
,
bins
)
if
model
==
'rgb'
:
use
/=
255
elif
model
==
'hsv'
:
if
model
==
'hsv'
:
for
p
in
domainIterator
(
image
):
use
[
p
]
=
rgb_to_hsv
(
*
use
[
p
].
tolist
())
...
...
@@ -92,16 +90,16 @@ def exclude_color(color, image):
if
__name__
==
'__main__'
:
print
'Reading images...'
waldo
=
imread
(
'waldo.tiff'
)
env
=
imread
(
'waldo_env.tiff'
)
waldo
=
imread
(
'waldo.tiff'
)
/
255.
env
=
imread
(
'waldo_env.tiff'
)
/
255.
# Use a mask to ignore the white background in the Waldo image
mask
=
exclude_color
([
255
]
*
3
,
waldo
)
# Execute the back projection algorithm
import
pickle
#
import pickle
b
=
hbp
(
waldo
,
env
,
[
64
]
*
3
,
'rgb'
,
15
,
mask
)
pickle
.
dump
(
b
,
open
(
'projection.dat'
,
'w'
))
#
pickle.dump(b, open('projection.dat', 'w'))
#b = pickle.load(open('projection.dat', 'r'))
w
,
h
=
waldo
.
shape
[:
2
]
...
...
improc/ass3/intersect.py
View file @
996861ca
#!/usr/bin/env python
from
numpy
import
zeros
from
matplotlib.pyplot
import
imread
from
colorsys
import
rgb_to_hsv
def
col2bin
(
color
):
"""Get the histogram bin coordinates of a color."""
...
...
@@ -21,18 +22,17 @@ def domainIterator(image, dim=2):
def
colHist
(
image
,
bins
,
model
,
mask
=
None
):
"""Create the color histogram of an image."""
h
=
zeros
(
bins
,
dtype
=
int
)
use
=
image
.
astype
(
float
)
# Multiply with the number of bins to normalize bin coordinates
use
=
image
.
astype
(
float
)
*
map
(
lambda
x
:
x
-
1
,
bins
)
if
model
==
'rgb'
:
use
/=
255
elif
model
==
'hsv'
:
# TODO: implement HSV color model
pass
else
:
if
model
==
'hsv'
:
for
p
in
domainIterator
(
image
):
use
[
p
]
=
rgb_to_hsv
(
*
use
[
p
].
tolist
())
elif
model
!=
'rgb'
:
raise
ValueError
(
'Color model "%s" is not supported.'
%
model
)
# Multiply with the number of bins to normalize bin coordinates
use
*=
map
(
lambda
x
:
x
-
1
,
bins
)
for
p
in
domainIterator
(
image
):
# Optionally use a mask over the image
if
mask
is
None
or
mask
[
p
]:
...
...
@@ -55,12 +55,22 @@ def histogramIntersect(h1, h2):
return
float
(
match
)
/
h2
.
sum
()
if
__name__
==
'__main__'
:
from
sys
import
argv
count
=
20
model
=
'rgb'
bins
=
[
64
]
*
3
# Usage: python intersect.py [ count [ model ] ]
if
len
(
argv
)
>
1
:
count
=
int
(
argv
[
1
])
if
len
(
argv
)
>
2
:
model
=
argv
[
2
]
# Create table of intersections of images in the database
print
'Creating histograms...'
hist
=
[
colHist
(
imread
(
'database/%d.jpg'
%
i
),
\
bins
,
'rgb'
)
for
i
in
xrange
(
1
,
4
)]
hist
=
[
colHist
(
imread
(
'database/%d.jpg'
%
i
)
/
255.
,
\
bins
,
model
)
for
i
in
xrange
(
1
,
count
+
1
)]
table
=
zeros
((
len
(
hist
),
len
(
hist
)),
dtype
=
int
)
...
...
@@ -68,7 +78,6 @@ if __name__ == '__main__':
table
[
i
,
i
]
=
100
for
j
in
xrange
(
i
+
1
,
len
(
hist
)):
print
'comparing %d, %d'
%
(
i
,
j
)
table
[
i
,
j
]
=
table
[
j
,
i
]
\
=
round
(
histogramIntersect
(
hist
[
i
],
hist
[
j
])
*
100
)
...
...
improc/ass3/results_hsv.txt
0 → 100644
View file @
996861ca
[[100 36 50 22 25 35 20 28 38 29 32 37 17 38 47 28 39 34 16 30]
[ 36 100 48 49 43 48 34 61 52 12 37 55 12 51 50 47 52 57 11 49]
[ 50 48 100 30 33 52 18 45 49 37 32 58 22 38 48 30 51 42 19 45]
[ 22 49 30 100 41 34 33 40 36 5 32 36 7 30 37 26 27 54 10 28]
[ 25 43 33 41 100 42 25 43 38 4 36 39 4 37 35 31 30 40 5 34]
[ 35 48 52 34 42 100 22 48 42 13 34 53 12 42 43 33 41 46 10 40]
[ 20 34 18 33 25 22 100 25 22 4 25 22 4 25 24 27 21 32 15 24]
[ 28 61 45 40 43 48 25 100 41 4 33 56 5 41 40 36 44 47 6 43]
[ 38 52 49 36 38 42 22 41 100 17 35 46 12 44 40 35 48 35 7 43]
[ 29 12 37 5 4 13 4 4 17 100 6 17 45 14 20 5 18 11 42 7]
[ 32 37 32 32 36 34 25 33 35 6 100 35 4 33 34 27 31 35 5 37]
[ 37 55 58 36 39 53 22 56 46 17 35 100 12 48 55 37 51 46 9 48]
[ 17 12 22 7 4 12 4 5 12 45 4 12 100 12 12 4 16 12 58 5]
[ 38 51 38 30 37 42 25 41 44 14 33 48 12 100 46 45 44 40 13 40]
[ 47 50 48 37 35 43 24 40 40 20 34 55 12 46 100 35 44 47 14 38]
[ 28 47 30 26 31 33 27 36 35 5 27 37 4 45 35 100 49 35 5 41]
[ 39 52 51 27 30 41 21 44 48 18 31 51 16 44 44 49 100 39 13 52]
[ 34 57 42 54 40 46 32 47 35 11 35 46 12 40 47 35 39 100 14 36]
[ 16 11 19 10 5 10 15 6 7 42 5 9 58 13 14 5 13 14 100 5]
[ 30 49 45 28 34 40 24 43 43 7 37 48 5 40 38 41 52 36 5 100]]
improc/ass3/results.txt
→
improc/ass3/results
_rgb
.txt
View file @
996861ca
File moved
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