LOWESS_reference#

pyrost.bin.LOWESS_reference(I_n: numpy.ndarray, W: numpy.ndarray, u: numpy.ndarray, di: numpy.ndarray, dj: numpy.ndarray, ds_y: float, ds_x: float, hval: float, return_nm0: bool = True, num_threads: int = 1)#

Generate an unabberated reference image of the sample based on the pixel mapping u and the measured data I_n using the Local Weighted Linear Regression (LOWESS).

Parameters
  • I_n (numpy.ndarray) – Measured intensity frames.

  • W (numpy.ndarray) – Measured frames’ white-field.

  • u (numpy.ndarray) – The discrete geometrical mapping of the detector plane to the reference image.

  • di (numpy.ndarray) – Initial sample’s translations along the vertical detector axis in pixels.

  • dj (numpy.ndarray) – Initial sample’s translations along the horizontal detector axis in pixels.

  • ds_y (float) – Sampling interval of reference image in pixels along the vertical axis.

  • ds_x (float) – Sampling interval of reference image in pixels along the horizontal axis.

  • hval (float) – Gaussian kernel bandwidth in pixels.

  • return_nm0 (bool) – If True, also returns the lower bounds (n0, m0) of the reference image in pixels.

  • num_threads (int) – Number of threads.

Returns

  • I0 : Reference image array.

  • n0 : The lower bounds of the vertical detector axis of the reference image at the reference frame in pixels. Only provided if return_nm0 is True.

  • m0 : The lower bounds of the horizontal detector axis of the reference image at the reference frame in pixels. Only provided if return_nm0 is True.

Return type

A tuple of three elements (I0, n0, m0). The elements are the following

Notes

The pixel mapping u maps the intensity measurements from the detector plane to the reference plane as follows:

\[i_{ref}[n, i, j] = u[0, i, j] + di[n], \; j_{ref}[n, i, j] = u[1, i, j] + dj[n]\]

The reference image profile \(I_{ref}[ii, jj]\) is obtained with the LOWESS regression extimator as follows:

\[I_{ref}[i, j] = \frac{\sum_{n, i^{\prime}, j^{\prime}} K[i - i_{ref}[n, i^{\prime}, j^{\prime}], j - j_{ref}[n, i^{\prime}, j^{\prime}], h] \; r_{IW}[n, a^{IW}, b^{IW}_i, b^{IW}_j]} {\sum_{n, i^{\prime}, j^{\prime}} K[i - i_{ref}[n, i^{\prime}, j^{\prime}], j - j_{ref}[n, i^{\prime}, j^{\prime}], h] \; r_{WW}[n, a^{WW}, b^{WW}_i, b^{WW}_j]}\]

where \(r_{IW}[n, a, b_i, b_j]\) and \(r_{WW}[n, a, b_i, b_j]\) are the residuals at the pixel \(i, j\) with linear coefficients defined with the least squares approach:

\[r_{IW}[n, a, b_i, b_j] = I[n, i^{\prime}, j^{\prime}] W[i^{\prime}, j^{\prime}] - a - b_i (i - i_{ref}[n, i^{\prime}, j^{\prime}) - b_j (j - j_{ref}[n, i^{\prime}, j^{\prime})\]
\[r_{WW}[n, a, b_i, b_j] = W^2[i^{\prime}, j^{\prime}] - a - b_i (i - i_{ref}[n, i^{\prime}, j^{\prime}) - b_j (j - j_{ref}[n, i^{\prime}, j^{\prime})\]

and \(K[i, j, h] = \frac{1}{\sqrt{2 \pi}} \exp(-\frac{i^2 + j^2}{h})\) is the Gaussian kernel.