Commit 977e4ece by Julia Garriga Ferrer

### [core][imageregistration] Modify shift detection to work with higher values of shift

parent f6ea0bec
 ... ... @@ -26,7 +26,7 @@ __authors__ = ["J. Garriga"] __license__ = "MIT" __date__ = "26/05/2021" __date__ = "16/06/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, steps, 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 / steps): 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, steps=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))) ... ...
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!