Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
XRD
darfix
Commits
977e4ece
Commit
977e4ece
authored
Jun 16, 2021
by
Julia Garriga Ferrer
Browse files
[core][imageregistration] Modify shift detection to work with higher values of shift
parent
f6ea0bec
Changes
1
Hide whitespace changes
Inline
Side-by-side
darfix/core/imageRegistration.py
View file @
977e4ece
...
...
@@ -26,7 +26,7 @@
__authors__
=
[
"J. Garriga"
]
__license__
=
"MIT"
__date__
=
"
2
6/0
5
/2021"
__date__
=
"
1
6/0
6
/2021"
import
enum
...
...
@@ -169,7 +169,7 @@ def normalize(x):
return
x
/
numpy
.
linalg
.
norm
(
x
)
def
improve_linear_shift
(
data
,
v
,
h
_max
,
h_
step
,
nimages
=
None
,
shift_approach
=
"linear"
):
def
improve_linear_shift
(
data
,
v
,
h
,
epsilon
,
step
s
,
nimages
=
None
,
shift_approach
=
"linear"
):
"""
Function to find the best shift between the images. It loops ``h_max * h_step`` times,
applying a different shift each, and trying to find the one that has the best result.
...
...
@@ -195,23 +195,22 @@ def improve_linear_shift(data, v, h_max, h_step, nimages=None, shift_approach="l
iData
=
numpy
.
random
.
choice
(
iData
,
nimages
,
False
)
score
=
{}
utils
.
advancement_display
(
0
,
h_max
,
"Finding shift"
)
for
h
in
numpy
.
arange
(
0
,
h_max
,
h_
step
):
utils
.
advancement_display
(
0
,
2
*
epsilon
,
"Finding shift"
)
for
h
_
in
numpy
.
arange
(
h
-
epsilon
,
h
+
epsilon
,
2
*
epsilon
/
step
s
):
result
=
numpy
.
zeros
(
data
[
0
].
shape
)
for
iFrame
in
iData
:
shift
=
h
*
v
*
iFrame
shift
=
h
_
*
v
*
iFrame
result
+=
apply_shift
(
data
[
iFrame
],
shift
,
shift_approach
)
# Compute score using normalized variance
# TODO: add more autofocus options
score
[
h
]
=
normalized_variance
(
result
)
utils
.
advancement_display
(
h
+
h_step
,
h_max
,
"Finding shift"
)
score
[
h_
]
=
normalized_variance
(
result
)
utils
.
advancement_display
(
h_
-
epsilon
,
2
*
epsilon
,
"Finding shift"
)
optimal_h
=
max
(
score
.
keys
(),
key
=
(
lambda
k
:
score
[
k
]))
return
optimal_h
def
shift_detection
(
data
,
h_max
=
0.5
,
h_
step
=
0.01
):
def
shift_detection
(
data
,
h_max
=
0.5
,
step
s
=
1000
,
shift_approach
=
"linear"
):
"""
Finds the linear shift from a set of images.
...
...
@@ -232,7 +231,10 @@ def shift_detection(data, h_max=0.5, h_step=0.01):
second_sum
+=
data
[
i
]
shift
=
find_shift
(
first_sum
,
second_sum
,
1000
)
v
=
normalize
(
shift
)
h
=
improve_linear_shift
(
data
,
v
,
h_max
,
h_step
)
v_
=
2
*
shift
/
len
(
data
)
h
=
numpy
.
sqrt
(
v_
[
0
]
**
2
+
v_
[
1
]
**
2
)
epsilon
=
0.5
*
h
h
=
improve_linear_shift
(
data
,
v
,
h
,
epsilon
,
steps
,
shift_approach
=
shift_approach
)
return
numpy
.
outer
(
h
*
v
,
numpy
.
arange
(
len
(
data
)))
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment