Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Autocnet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
aflab
astrogeology
Autocnet
Commits
b78574a9
Commit
b78574a9
authored
3 years ago
by
Adam Paquette
Committed by
acpaquette
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Update to use scikit-image 0.19 when it is released
parent
579cccd0
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
autocnet/matcher/mutual_information.py
+7
-51
7 additions, 51 deletions
autocnet/matcher/mutual_information.py
autocnet/matcher/tests/test_mutual_information.py
+2
-13
2 additions, 13 deletions
autocnet/matcher/tests/test_mutual_information.py
environment.yml
+1
-1
1 addition, 1 deletion
environment.yml
with
10 additions
and
65 deletions
autocnet/matcher/mutual_information.py
+
7
−
51
View file @
b78574a9
...
@@ -3,55 +3,10 @@ from math import floor
...
@@ -3,55 +3,10 @@ from math import floor
import
numpy
as
np
import
numpy
as
np
from
scipy.ndimage.measurements
import
center_of_mass
from
scipy.ndimage.measurements
import
center_of_mass
from
skimage.metrics
import
normalized_mutual_information
def
mutual_information
(
t1
,
t2
,
**
kwargs
):
"""
Computes the correlation coefficient between two images using a histogram
comparison (Mutual information for joint histograms). The corr_map coefficient
will be between 0 and 4
Parameters
----------
t1 : ndarray
First image to use in the histogram comparison
t2 : ndarray
Second image to use in the histogram comparison
Returns
-------
: float
Correlation coefficient computed between the two images being compared
between 0 and 4
See Also
--------
numpy.histogram2d : for the kwargs that can be passed to the comparison
"""
if
np
.
isnan
(
t1
).
any
()
or
np
.
isnan
(
t2
).
any
():
print
(
'
Unable to process due to NaN values in the input data
'
)
return
if
t1
.
shape
!=
t2
.
shape
:
print
(
'
Unable compute MI. Image sizes are not identical.
'
)
return
hgram
,
x_edges
,
y_edges
=
np
.
histogram2d
(
t1
.
ravel
(),
t2
.
ravel
(),
**
kwargs
)
# Convert bins counts to probability values
pxy
=
hgram
/
float
(
np
.
sum
(
hgram
))
px
=
np
.
sum
(
pxy
,
axis
=
1
)
# marginal for x over y
py
=
np
.
sum
(
pxy
,
axis
=
0
)
# marginal for y over x
px_py
=
px
[:,
None
]
*
py
[
None
,
:]
# Broadcast to multiply marginals
# Now we can do the calculation using the pxy, px_py 2D arrays
nzs
=
pxy
>
0
# Only non-zero pxy values contribute to the sum
return
np
.
sum
(
pxy
[
nzs
]
*
np
.
log
(
pxy
[
nzs
]
/
px_py
[
nzs
]))
def
mutual_information_match
(
d_template
,
s_image
,
subpixel_size
=
3
,
def
mutual_information_match
(
d_template
,
s_image
,
subpixel_size
=
3
,
func
=
N
on
e
,
**
kwargs
):
func
=
normalized_mutual_informati
on
,
**
kwargs
):
"""
"""
Applys the mutual information matcher function over a search image using a
Applys the mutual information matcher function over a search image using a
defined template
defined template
...
@@ -82,15 +37,16 @@ def mutual_information_match(d_template, s_image, subpixel_size=3,
...
@@ -82,15 +37,16 @@ def mutual_information_match(d_template, s_image, subpixel_size=3,
The y offset
The y offset
max_corr : float
max_corr : float
The strength of the correlation
in the range [0, 4].
The strength of the correlation
corr_map : ndarray
corr_map : ndarray
Map of corrilation coefficients when comparing the template to
Map of corrilation coefficients when comparing the template to
locations within the search area
locations within the search area
"""
if
func
==
None
:
See Also
func
=
mutual_information
--------
skimage.metrics.normalized_mutual_information : for the kwargs that can be passed to the matcher
"""
image_size
=
s_image
.
shape
image_size
=
s_image
.
shape
template_size
=
d_template
.
shape
template_size
=
d_template
.
shape
...
...
This diff is collapsed.
Click to expand it.
autocnet/matcher/tests/test_mutual_information.py
+
2
−
13
View file @
b78574a9
...
@@ -9,17 +9,6 @@ import numpy as np
...
@@ -9,17 +9,6 @@ import numpy as np
from
..
import
mutual_information
from
..
import
mutual_information
def
test_good_mi
():
test_image1
=
np
.
array
([[
i
for
i
in
range
(
50
)]
for
j
in
range
(
50
)])
corrilation
=
mutual_information
.
mutual_information
(
test_image1
,
test_image1
)
assert
corrilation
==
pytest
.
approx
(
2.30258509299404
)
def
test_bad_mi
():
test_image1
=
np
.
array
([[
i
for
i
in
range
(
50
)]
for
j
in
range
(
50
)])
test_image2
=
np
.
ones
((
50
,
50
))
corrilation
=
mutual_information
.
mutual_information
(
test_image1
,
test_image2
)
assert
corrilation
==
pytest
.
approx
(
0
)
def
test_mutual_information
():
def
test_mutual_information
():
d_template
=
np
.
array
([[
i
for
i
in
range
(
50
,
100
)]
for
j
in
range
(
50
)])
d_template
=
np
.
array
([[
i
for
i
in
range
(
50
,
100
)]
for
j
in
range
(
50
)])
s_image
=
np
.
ones
((
100
,
100
))
s_image
=
np
.
ones
((
100
,
100
))
...
@@ -27,8 +16,8 @@ def test_mutual_information():
...
@@ -27,8 +16,8 @@ def test_mutual_information():
s_image
[
25
:
75
,
25
:
75
]
=
d_template
s_image
[
25
:
75
,
25
:
75
]
=
d_template
x_offset
,
y_offset
,
max_corr
,
corr_map
=
mutual_information
.
mutual_information_match
(
d_template
,
s_image
,
bins
=
20
)
x_offset
,
y_offset
,
max_corr
,
corr_map
=
mutual_information
.
mutual_information_match
(
d_template
,
s_image
,
bins
=
20
)
assert
x_offset
==
0.01
711861257171421
assert
x_offset
==
0.01
0530473741837909
assert
y_offset
==
0.0
assert
y_offset
==
0.0
assert
max_corr
==
2.
9755967600033015
assert
max_corr
==
2.
0
assert
corr_map
.
shape
==
(
51
,
51
)
assert
corr_map
.
shape
==
(
51
,
51
)
assert
np
.
min
(
corr_map
)
>=
0.0
assert
np
.
min
(
corr_map
)
>=
0.0
This diff is collapsed.
Click to expand it.
environment.yml
+
1
−
1
View file @
b78574a9
...
@@ -34,7 +34,7 @@ dependencies:
...
@@ -34,7 +34,7 @@ dependencies:
-
pytest-cov
-
pytest-cov
-
pytest-mock
-
pytest-mock
-
richdem
-
richdem
-
scikit-image>=0.1
7
-
scikit-image>=0.1
9
-
scikit-learn
-
scikit-learn
-
scipy<=1.2.1
-
scipy<=1.2.1
-
shapely
-
shapely
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment