Commit 9eb7a31c by Nicola Vigano

### Alignment: added band-pass filter computation and perform filtering in correlation

```

Signed-off-by: Nicola VIGANÒ <nicola.vigano@esrf.fr>```
parent 3353b97e
 ... ... @@ -7,14 +7,16 @@ import numpy as np try: import scipy.special as spspe __have_scipy__ = True except ImportError: import math __have_scipy__ = False def get_lowpass_filter(img_shape, cutoff_par): """Computes a low pass filter with the erfc. def get_lowpass_filter(img_shape, cutoff_par=None): """Computes a low pass filter using the erfc function. Parameters ---------- ... ... @@ -38,7 +40,9 @@ def get_lowpass_filter(img_shape, cutoff_par): numpy.array_like The computed filter """ if isinstance(cutoff_par, (int, float)): if cutoff_par is None: return 1 elif isinstance(cutoff_par, (int, float)): cutoff_pix = cutoff_par cutoff_trans_fact = None else: ... ... @@ -69,13 +73,13 @@ def get_lowpass_filter(img_shape, cutoff_par): else: res = np.array(list(map(math.erfc, k_pos_rescaled))) / 2 else: res = np.exp(- (np.pi ** 2) * (r ** 2) * (cutoff_pix ** 2) * 2) res = np.exp(-(np.pi ** 2) * (r ** 2) * (cutoff_pix ** 2) * 2) return res def get_highpass_filter(img_shape, cutoff_par): """Computes a high pass filter with the erfc. def get_highpass_filter(img_shape, cutoff_par=None): """Computes a high pass filter using the erfc function. Parameters ---------- ... ... @@ -99,4 +103,41 @@ def get_highpass_filter(img_shape, cutoff_par): numpy.array_like The computed filter """ return 1 - get_lowpass_filter(img_shape, cutoff_par) if cutoff_par is None: return 1 else: return 1 - get_lowpass_filter(img_shape, cutoff_par) def get_bandpass_filter(img_shape, cutoff_lowpass=None, cutoff_highpass=None): """Computes a band pass filter using the erfc function. The cutoff structures should be formed as follows: - tuple of two floats: the first indicates the cutoff frequency, the second \ determines the width of the transition region, as fraction of the cutoff frequency. - one float -> it represents the sigma of a gaussian which acts as a filter or anti-filter (1 - filter). Parameters ---------- img_shape: tuple Shape of the image cutoff_lowpass: float or sequence of two floats Cutoff parameters for the low-pass filter cutoff_highpass: float or sequence of two floats Cutoff parameters for the high-pass filter Raises ------ ValueError In case of malformed cutoff_par Returns ------- numpy.array_like The computed filter """ return get_lowpass_filter(img_shape, cutoff_par=cutoff_lowpass) * get_highpass_filter( img_shape, cutoff_par=cutoff_highpass )