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
4769c728
Commit
4769c728
authored
Oct 06, 2011
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ImProc ass3: Added some comments.
parent
f0c1703f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
4 deletions
+9
-4
improc/ass3/intersect.py
improc/ass3/intersect.py
+9
-4
No files found.
improc/ass3/intersect.py
View file @
4769c728
...
...
@@ -3,14 +3,17 @@ from numpy import zeros
from
matplotlib.pyplot
import
imread
def
col2bin
(
color
):
"""Get the histogram bin coordinates of a color."""
return
tuple
(
map
(
lambda
x
:
round
(
x
-
1
),
color
))
def
domainIterator
(
image
):
"""Pixel iterator for colHist."""
for
x
in
xrange
(
image
.
shape
[
0
]):
for
y
in
xrange
(
image
.
shape
[
1
]):
yield
x
,
y
def
colHist
(
image
,
bins
,
model
):
"""Create the color histogram of an image."""
h
=
zeros
(
tuple
(
bins
))
use
=
image
.
astype
(
float
)
*
bins
...
...
@@ -25,20 +28,22 @@ def colHist(image, bins, model):
return
h
def
histogramIntersect
(
h1
,
h2
):
"""Calculate the intersection between two color histograms."""
if
h1
.
shape
!=
h2
.
shape
:
raise
ValueError
(
'
Shape mismatch between h1 and h2
.'
)
raise
ValueError
(
'
Histograms h1 and h2 are not aligned
.'
)
match
=
0
#print h1, h2
# Add the minimum of each bin to the result
for
r
in
xrange
(
h1
.
shape
[
0
]):
for
g
in
xrange
(
h1
.
shape
[
1
]):
for
b
in
xrange
(
h1
.
shape
[
2
]):
match
+=
min
(
h1
[
r
,
g
,
b
],
h2
[
r
,
g
,
b
])
# Normalize by dividing by the number of pixels
return
match
/
h2
.
sum
()
# Create table of intersections
# Create table of intersections
of images in the database
if
__name__
==
'__main__'
:
bins
=
[
8
]
*
3
db
=
map
(
lambda
x
:
imread
(
'database/%d.jpg'
%
x
),
range
(
1
,
21
))
...
...
@@ -46,7 +51,7 @@ if __name__ == '__main__':
for
i
,
im
in
enumerate
(
db
):
for
j
in
xrange
(
i
+
1
,
len
(
db
)):
#
print 'comparing', i, j
print
'comparing'
,
i
,
j
table
[
i
,
j
]
=
histogramIntersect
(
colHist
(
im
,
bins
,
'rgb'
),
colHist
(
db
[
j
],
bins
,
'rgb'
))
...
...
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