nabu.estimation.tilt module¶
- class nabu.estimation.tilt.CameraTilt(vert_fft_width=False, horz_fft_width=False, verbose=False, logger=None, data_type=<class 'numpy.float32'>, extra_options=None)[source]¶
Bases:
CenterOfRotation
Alignment basic functions.
- Parameters:
vert_fft_width (boolean, optional) –
If True, restrict the vertical size to a power of 2:
>>> new_v_dim = 2 ** math.floor(math.log2(v_dim))
horz_fft_width (boolean, optional) –
If True, restrict the horizontal size to a power of 2:
>>> new_h_dim = 2 ** math.floor(math.log2(h_dim))
verbose (boolean, optional) – When True it will produce verbose output, including plots.
data_type (numpy.float32) – Computation data type.
- compute_angle(img_1: ndarray, img_2: ndarray, method='1d-correlation', roi_yxhw=None, median_filt_shape=None, padding_mode=None, peak_fit_radius=1, high_pass=None, low_pass=None)[source]¶
Find the camera tilt, given two opposite images.
This method finds the tilt between the camera pixel columns and the rotation axis, by performing a 1-dimensional correlation between two opposite images.
The output of this function, allows to compute motor movements for aligning the camera tilt.
- Parameters:
img_1 (numpy.ndarray) – First image
img_2 (numpy.ndarray) – Second image, it needs to have been flipped already (e.g. using numpy.fliplr).
method (str) –
Tilt angle computation method. Default is “1d-correlation” (traditional). All options are:
”1d-correlation”: fastest, but works best for small tilts
”fft-polar”: slower, but works well on all ranges of tilts
roi_yxhw ((2, ) or (4, ) numpy.ndarray, tuple, or array, optional) – 4 elements vector containing: vertical and horizontal coordinates of first pixel, plus height and width of the Region of Interest (RoI). Or a 2 elements vector containing: plus height and width of the centered Region of Interest (RoI). Default is None -> deactivated.
median_filt_shape ((2, ) numpy.ndarray, tuple, or array, optional) – Shape of the median filter window. Default is None -> deactivated.
padding_mode (str in numpy.pad's mode list, optional) –
Padding mode, which determines the type of convolution. If None or ‘wrap’ are passed, this resorts to the traditional circular convolution. If ‘edge’ or ‘constant’ are passed, it results in a linear convolution. Default is the circular convolution. All options are:
None | ‘constant’ | ‘edge’ | ‘linear_ramp’ | ‘maximum’ | ‘mean’ | ‘median’ | ‘minimum’ | ‘reflect’ | ‘symmetric’ |’wrap’
peak_fit_radius (int, optional) – Radius size around the max correlation pixel, for sub-pixel fitting. Minimum and default value is 1.
low_pass (float or sequence of two floats) – Low-pass filter properties, as described in nabu.misc.fourier_filters
high_pass (float or sequence of two floats) – High-pass filter properties, as described in nabu.misc.fourier_filters
- Raises:
ValueError – In case images are not 2-dimensional or have different sizes.
- Returns:
cor_offset_pix (float) – Estimated center of rotation position from the center of the RoI in pixels.
tilt_deg (float) – Estimated camera tilt angle in degrees.
Examples
The following code computes the center of rotation position for two given images in a tomography scan, where the second image is taken at 180 degrees from the first.
>>> radio1 = data[0, :, :] ... radio2 = np.fliplr(data[1, :, :]) ... tilt_calc = CameraTilt() ... cor_offset, camera_tilt = tilt_calc.compute_angle(radio1, radio2)
Or for noisy images:
>>> cor_offset, camera_tilt = tilt_calc.compute_angle(radio1, radio2, median_filt_shape=(3, 3))