corrct.alignment.fitting
Fitting routines.
Created on Tue May 17 12:11:58 2022
@author: Nicola VIGANÒ, Computational Imaging group, CWI, The Netherlands, and ESRF - The European Synchrotron, Grenoble, France
Module Contents
Functions
Find the U shifts between two sets of lines, by means of the sum-of-absolute-difference (SAD). |
|
Find the VU shifts of the projected data, through cross-correlation. |
|
Find the ZYX shifts of the volume, through cross-correlation. |
|
Fit the rotation and scaling of an image against a reference image. This works best for larger rotation angles. |
|
Estimate the camera tilt angle based on correlation peak values between two images. |
|
Compute the values of a sine function. |
|
Fits a sinusoid to the given values. |
|
Extract a region around the maximum value. |
|
Compute the sub-pixel max position of the given function sampling. |
|
Extract a region around the maximum value. |
|
Compute the sub-pixel max position of the given function sampling. |
Data
API
- corrct.alignment.fitting.NDArrayFloat
None
- corrct.alignment.fitting.eps
None
- corrct.alignment.fitting.fit_shifts_u_sad(data_wu: corrct.alignment.fitting.NDArrayFloat, proj_wu: corrct.alignment.fitting.NDArrayFloat, search_range: int = 16, pad_u: bool = False, error_norm: int = 1, decimals: int = 2) corrct.alignment.fitting.NDArrayFloat [source]
Find the U shifts between two sets of lines, by means of the sum-of-absolute-difference (SAD).
Parameters
data_wu : NDArrayFloat The reference data. proj_wu : NDArrayFloat The other data. search_rage : int, optional The range in pixels of the search, by default 16 error_norm : int, optional The error norm to use, by default 1 decimals : int, optional The precision of the result, by default 2
Returns
NDArrayFloat A list of one shift for each row.
- corrct.alignment.fitting.fit_shifts_vu_xc(data_vwu: corrct.alignment.fitting.NDArrayFloat, proj_vwu: corrct.alignment.fitting.NDArrayFloat, pad_u: bool = False, normalize_fourier: bool = False, margin: int = 0, use_rfft: bool = True, stack_axis: int = -2, decimals: int = 2) corrct.alignment.fitting.NDArrayFloat [source]
Find the VU shifts of the projected data, through cross-correlation.
Parameters
data_vwu : NDArrayFloat The collected projection data. proj_vwu : NDArrayFloat The forward-projected images from the reconstruction. pad_u : bool, optional Pad the u coordinate. The default is False. normalize_fourier : bool, optional Whether to normalize the Fourier representation of the cross-correlation. The default is False. margin : int, optional The margin of the region to compare, the default is 0. use_rfft : bool, optional Whether to use the
rfft
transform in place of the complexfft
transform. The default is True. stack_axis : int, optional The axis along which the VU images are stacked. The default is -2. decimals : int, optional Decimals for the truncation of the sub-pixel The default is 2.Returns
NDArrayFloat The VU shifts.
- corrct.alignment.fitting.fit_shifts_zyx_xc(ref_vol_zyx: corrct.alignment.fitting.NDArrayFloat, rec_vol_zyx: corrct.alignment.fitting.NDArrayFloat, pad_zyx: bool = False, normalize_fourier: bool = True, use_rfft: bool = True, decimals: int = 2) corrct.alignment.fitting.NDArrayFloat [source]
Find the ZYX shifts of the volume, through cross-correlation.
Parameters
ref_vol_zyx : NDArrayFloat The reference volume. rec_vol_zyx : NDArrayFloat The reconstructed volume to register. pad_zyx : bool, optional Pad the ZYX coordinates. The default is False. normalize_fourier : bool, optional Whether to normalize the Fourier representation of the cross-correlation. The default is True. use_rfft : bool, optional Whether to use the
rfft
transform in place of the complexfft
transform. The default is True. decimals : int, optional Decimals for the truncation of the sub-pixel The default is 2.Returns
NDArrayFloat The ZYX shifts.
- corrct.alignment.fitting.fit_image_rotation_and_scale(img_1_vu: numpy.typing.NDArray, img_2_vu: numpy.typing.NDArray, pad_mode: Union[str, None] = None, window_type: str = 'hann', verbose: bool = False) tuple[float, float] [source]
Fit the rotation and scaling of an image against a reference image. This works best for larger rotation angles.
Parameters
img_1_vu : NDArray Reference image img_2_vu : NDArray Rotated and scaled image pad_mode : Union[str, None], optional Padding mode, by default None window_type : str, optional Windowing type (to cud the high frequency aliasing), by default “hann” verbose : bool, optional Whether to give verbose output, by default False
Returns
tuple[float, float] The rotation (in degrees) and scale of the second image with respect to the first
Raises
ValueError In case of mismatching shape of the two images.
- corrct.alignment.fitting.fit_camera_tilt_angle(img_1: numpy.typing.NDArray, img_2: numpy.typing.NDArray, pad_u: bool = False, fit_l1: bool = True, verbose: bool = False)[source]
Estimate the camera tilt angle based on correlation peak values between two images.
Parameters
img_1: NDArray The first image. img_2: NDArray The second image. pad_u: bool, optional Enable zero padding. Default is False. fit_l1: bool, optional Perform L1 norm fitting if True. Default is True. verbose: bool, optional Enable verbose output. Default is False.
Returns
tuple[float, float] Tuple containing the estimated center of rotation offset (pixels) and camera tilt angle (degrees).
- corrct.alignment.fitting.sinusoid(x: Union[corrct.alignment.fitting.NDArrayFloat, float], a: Union[corrct.alignment.fitting.NDArrayFloat, float], p: Union[corrct.alignment.fitting.NDArrayFloat, float], b: Union[corrct.alignment.fitting.NDArrayFloat, float]) corrct.alignment.fitting.NDArrayFloat [source]
Compute the values of a sine function.
Parameters
x : NDArrayFloat | float The independent variable. a : NDArrayFloat | float The amplitude of the sine. p : NDArrayFloat | float The phase of the sine. b : NDArrayFloat | float The bias of the sine.
Returns
NDArrayFloat The computed values.
- corrct.alignment.fitting.fit_sinusoid(angles: corrct.alignment.fitting.NDArrayFloat, values: corrct.alignment.fitting.NDArrayFloat, fit_l1: bool = False) tuple[float, float, float] [source]
Fits a sinusoid to the given values.
Parameters
angles : NDArrayFloat Angles where to evaluate the sinusoid. values : NDArrayFloat Values of the sinusoid. fit_l1 : bool, optional Whether to use l1 fit instead of the l2 fit, by default False
Returns
Tuple[float, float, float] The amplitude, phase and bias of the sinusoid.
- corrct.alignment.fitting.extract_peak_regions_1d(cc: corrct.alignment.fitting.NDArrayFloat, axis: int = -1, peak_radius: int = 1, cc_coords: Union[numpy.typing.ArrayLike, numpy.typing.NDArray, None] = None) tuple[corrct.alignment.fitting.NDArrayFloat, Optional[numpy.typing.NDArray]] [source]
Extract a region around the maximum value.
Parameters
cc: NDArrayFloat Correlation image. axis: int, optional Find the max values along the specified direction. The default is -1. peak_radius: int, optional The l_inf radius of the area to extract around the peak. The default is 1. cc_coords: ArrayLike, optional The coordinates of
cc
along the selected axis. The default is None.Returns
f_vals: NDArrayFloat The extracted function values. fc_ax: NDArrayFloat The coordinates of the extracted values, along the selected axis.
- corrct.alignment.fitting.refine_max_position_1d(f_vals: corrct.alignment.fitting.NDArrayFloat, f_x: Union[numpy.typing.ArrayLike, numpy.typing.NDArray, None] = None, return_vertex_val: bool = False, decimals: int = 2) Union[corrct.alignment.fitting.NDArrayFloat, tuple[corrct.alignment.fitting.NDArrayFloat, corrct.alignment.fitting.NDArrayFloat]] [source]
Compute the sub-pixel max position of the given function sampling.
Parameters
f_vals: NDArrayFloat Function values of the sampled points fx: ArrayLike, optional Coordinates of the sampled points return_vertex_val: boolean, option Enables returning the vertex values. Defaults to False.
Raises
ValueError In case position and values do not have the same size, or in case the fitted maximum is outside the fitting region.
Returns
float Estimated function max, according to the coordinates in fx.
- corrct.alignment.fitting.extract_peak_region_nd(cc: corrct.alignment.fitting.NDArrayFloat, peak_radius: int = 1, cc_coords: Optional[Sequence[Union[Sequence, numpy.typing.NDArray]]] = None) tuple[numpy.typing.NDArray, Optional[Sequence[numpy.typing.NDArray]]] [source]
Extract a region around the maximum value.
Parameters
cc: NDArrayFloat Correlation image. peak_radius: int, optional The l_inf radius of the area to extract around the peak. The default is 1. cc_coords: ArrayLike, optional The coordinates of
cc
. The default is None.Returns
f_vals: NDArrayFloat The extracted function values. f_coords: Sequence[NDArrayFloat] | None The coordinates of the extracted values.
- corrct.alignment.fitting.refine_max_position_2d(f_vals: corrct.alignment.fitting.NDArrayFloat, fy: Union[numpy.typing.ArrayLike, numpy.typing.NDArray, None] = None, fx: Union[numpy.typing.ArrayLike, numpy.typing.NDArray, None] = None) numpy.typing.NDArray [source]
Compute the sub-pixel max position of the given function sampling.
Parameters
f_vals: NDArrayFloat Function values of the sampled points fy: ArrayLike, optional Vertical coordinates of the sampled points fx: ArrayLike, optional Horizontal coordinates of the sampled points
Raises
ValueError In case position and values do not have the same size, or in case the fitted maximum is outside the fitting region.
Returns
tuple(float, float) Estimated (vertical, horizontal) function max, according to the coordinates in fy and fx.