Commit 040c4edd authored by Julia Garriga Ferrer's avatar Julia Garriga Ferrer
Browse files

[core][imageregistration] Update h values

parent b8944c75
......@@ -26,7 +26,7 @@
__authors__ = ["J. Garriga"]
__license__ = "MIT"
__date__ = "16/06/2021"
__date__ = "17/06/2021"
import enum
......@@ -195,8 +195,9 @@ def improve_linear_shift(data, v, h, epsilon, steps, nimages=None, shift_approac
iData = numpy.random.choice(iData, nimages, False)
score = {}
utils.advancement_display(0, 2 * epsilon, "Finding shift")
for h_ in numpy.arange(h - epsilon, h + epsilon, 2 * epsilon / steps):
utils.advancement_display(0, h + epsilon, "Finding shift")
step = 2 * epsilon / steps
for h_ in numpy.arange(0, h + epsilon, step):
result = numpy.zeros(data[0].shape)
for iFrame in iData:
shift = h_ * v * iFrame
......@@ -205,12 +206,12 @@ def improve_linear_shift(data, v, h, epsilon, steps, nimages=None, shift_approac
# Compute score using normalized variance
# TODO: add more autofocus options
score[h_] = normalized_variance(result)
utils.advancement_display(h_ - epsilon, 2 * epsilon, "Finding shift")
utils.advancement_display(h_ + step, h + epsilon, "Finding shift")
optimal_h = max(score.keys(), key=(lambda k: score[k]))
return optimal_h
def shift_detection(data, h_max=0.5, steps=1000, shift_approach="linear"):
def shift_detection(data, steps, shift_approach="linear"):
"""
Finds the linear shift from a set of images.
......@@ -233,7 +234,7 @@ def shift_detection(data, h_max=0.5, steps=1000, shift_approach="linear"):
v = normalize(shift)
v_ = 2 * shift / len(data)
h = numpy.sqrt(v_[0]**2 + v_[1]**2)
epsilon = 0.5 * h
epsilon = 2 * h
h = improve_linear_shift(data, v, h, epsilon, steps, shift_approach=shift_approach)
return numpy.outer(h * v, numpy.arange(len(data)))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment