estimate_flat_distortion does not work for all image sizes
Trying the following code with different image sizes:
from nabu.estimation.distortion import estimate_flat_distortion
from scipy.ndimage import zoom
from scipy.misc import face
tmp1 = zoom(face()[:,:,0],4)[:2500,:2500]
v = estimate_flat_distortion(tmp1, tmp1, tile_size=100, padding_mode='constant')
This gives an error:
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
Input In [2], in <cell line: 5>()
3 from scipy.misc import face
4 tmp1 = zoom(face()[:,:,0],4)[:2500,:2500]
----> 5 v = estimate_flat_distortion(tmp1, tmp1, tile_size=100, padding_mode='constant')
File /mnt/multipath-shares/scisoft/users/favre/dev/pynx-py38-power9-env/lib/python3.8/site-packages/nabu/estimation/distortion.py:51, in estimate_flat_distortion(flat, image, tile_size, interpolation_kind, padding_mode, correction_spike_threshold, logger)
49 for ic, c in enumerate(starts_c):
50 try:
---> 51 coeff_v, coeff_h, shifts_vh_per_img = shift_finder.find_shift(
52 np.array([image[r : r + tile_size, c : c + tile_size], flat[r : r + tile_size, c : c + tile_size]]),
53 np.array([0, 1]),
54 return_shifts=True,
55 low_pass=(1.0, 0.3),
56 high_pass=(tile_size, tile_size * 0.3),
57 )
58 cor1[ir, ic], cor2[ir, ic] = shifts_vh_per_img[1]
60 except ValueError as e:
File /mnt/multipath-shares/scisoft/users/favre/dev/pynx-py38-power9-env/lib/python3.8/site-packages/nabu/estimation/translation.py:183, in DetectorTranslationAlongBeam.find_shift(self, img_stack, img_pos, roi_yxhw, median_filt_shape, padding_mode, peak_fit_radius, high_pass, low_pass, return_shifts, use_adjacent_imgs)
180 plt.show(block=False)
182 if return_shifts:
--> 183 return coeffs_v[1], coeffs_h[1], shifts_vh
184 else:
185 return coeffs_v[1], coeffs_h[1]
IndexError: index 1 is out of bounds for axis 0 with size 1
More generally with an image size of (n, n), it works until 2400 but fails after (no idea why).
(I also had an issue with an asymmetric size but can't reproduce it now..)