toupy.registration package¶
Submodules¶
toupy.registration.registration module¶
- toupy.registration.registration.alignprojections_horizontal(sinogram, theta, shiftstack, **params)[source]¶
Function to align projections by tomographic consistency 1, 2. It relies on having already aligned the vertical direction. The code aligns using the consistency before and after tomographic combination of projections.
- Parameters
sinogram (array_like) – Sinogram derivative, the second index should be the angle
theta (array_like) – Reconstruction angles (in degrees). Default: m angles evenly spaced between 0 and 180 (if the shape of radon_image is (N, M)).
shiftstack (array_like) – Array with initial estimates of positions
params (dict) – Container with parameters for the registration
params["pixtol"] (float) – Tolerance for alignment, which is also used as a search step
params["alignx"] (bool) – True or False to activate align x using center of mass (default= False, which means align y only)
params["shiftmeth"] (str) – Shift images with fourier method (default). The options are linear -> Shift images with linear interpolation (default); fourier -> Fourier shift or spline -> Shift images with spline interpolation.
params["circle"] (bool) – Use a circular mask to eliminate corners of the tomogram
params["filtertype"] (str) – Filter to use for FBP
params["freqcutoff"] (float) – Frequency cutoff for tomography filter (between 0 and 1)
params["cliplow"] (float) – Minimum value in tomogram
params["cliphigh"] (float) – Maximum value in tomogram
- Returns
shiftstack (array_like) – Corrected object positions
alinedsinogram (array_like) – Array containting the aligned sinogram
References
- 1
Guizar-Sicairos, M., et al., “Quantitative interior x-ray nanotomography by a hybrid imaging technique,” Optica 2, 259-266 (2015).
- 2
da Silva, J. C., et al., “High energy near-and far-field ptychographic tomography at the ESRF,” Proc. SPIE 10391, Developments in X-Ray Tomography XI, 1039106 (2017).
- toupy.registration.registration.alignprojections_vertical(input_stack, shiftstack, **params)[source]¶
Vertical alignment of projections using mass fluctuation approach 3, 4. It relies on having air on both sides of the sample (non local tomography). It performs a local search in y, so convergence issues can be addressed by giving an approximate initial guess for a possible drift via shiftstack
- Parameters
input_stack (array_like) – Stack of projections
limrow (list of ints) – Limits of window of interest in y
limcol (list of ints) – Limits of window of interest in x
shiftstack (array_like) – Array of initial estimates for object motion (2,n)
params (dict) – Container with parameters for the registration
params['pixtol'] (float) – Tolerance for alignment, which is also used as a search step
params['polyorder'] (int) – Specify the polynomial order of bias removal. For example: polyorder = 1 -> mean, polyorder = 2 -> linear).
params['alignx'] (bool) – True or False to activate align x using center of mass (default= False, which means align y only)
params['shiftmeth'] (str) – Shift images with fourier method (default). The options are linear -> Shift images with linear interpolation (default); fourier -> Fourier shift or spline -> Shift images with spline interpolation.
- Returns
shiftstack (array_like) – Corrected bject positions
input_stack (array_like) – Aligned stack of the projections
References
- 3
Guizar-Sicairos, M., et al. , “Phase tomography from x-ray coherent diffractive imaging projections,” Opt. Express 19, 21345-21357 (2011).
- 4
da Silva, J. C., et al. “High energy near-and far-field ptychographic tomography at the ESRF,” Proc. SPIE 10391, Developments in X-Ray Tomography XI, 1039106 (2017)
- toupy.registration.registration.center_of_mass_stack(input_stack, lims, shiftstack, shift_method='fourier')[source]¶
Calculates the center of the mass for each projection in the stack and returns a stack of centers of mass (row, col) i.e., returns shiftstack[1] If the array is zero, it return the center of mass at 0.
- toupy.registration.registration.compute_aligned_horizontal(input_stack, shiftstack, shift_method='linear')[source]¶
Compute the alignment of the stack on at the horizontal direction
- Parameters
input_array (array_like) – Stack of images to be shifted
shiftstack (array_like) – Array of initial estimates for object motion (2,n) The estimates for vertical movement will be changed to 0
shift_method (str (default linear)) – Name of the shift method. Options: ‘linear’, ‘fourier’, ‘spline’
- Returns
output_stack – 2D function containing the stack of aligned images
- Return type
array_like
- toupy.registration.registration.compute_aligned_sino(input_sino, shiftslice, shift_method='linear')[source]¶
Compute the aligned sinogram given the correction for object positions
- Parameters
input_sino (array_like) – Input sinogram to be shifted
shiftslice (array_like) – Array of estimates for object motion (1,n)
shift_method (str (default linear)) – Name of the shift method. Options: ‘linear’, ‘fourier’, ‘spline’
- Returns
output_sino – 2D function containing the aligned sinogram
- Return type
array_like
- toupy.registration.registration.compute_aligned_stack(input_stack, shiftstack, shift_method='linear')[source]¶
Compute the aligned stack given the correction for object positions
- Parameters
input_array (array_like) – Stack of images to be shifted
shiftstack (array_like) – Array of initial estimates for object motion (2,n)
shift_method (str (default linear)) – Name of the shift method. Options: ‘linear’, ‘fourier’, ‘spline’
- Returns
output_stack – 2D function containing the stack of aligned images
- Return type
array_like
- toupy.registration.registration.estimate_rot_axis(input_array, theta, **params)[source]¶
Initial estimate of the rotation axis
- toupy.registration.registration.oneslicefordisplay(sinogram, theta, **params)[source]¶
Calculate one slice for display.
- Parameters
sinogram (array_like) – Sinogram derivative, the second index should be the angle
theta (array_like) – Reconstruction angles (in degrees). Default: m angles evenly spaced between 0 and 180 (if the shape of radon_image is (N, M)).
params (dict) – Container with parameters for the registration.
params["filtertype"] (str) – Filter to use for FBP
params["freqcutoff"] (float) – Frequency cutoff for tomography filter (between 0 and 1)
- toupy.registration.registration.refine_horizontalalignment(input_stack, theta, shiftstack, **params)[source]¶
Refine horizontal alignment. Please, see the description of each parameter in
alignprojections_horizontal()
.
- toupy.registration.registration.register_2Darrays(image1, image2)[source]¶
Image registration. Register two images using phase cross correlations.
- Parameters
image1 (array_like) – Image of reference
image2 (array_like) – Image to be shifted relative to image1
- Returns
shift (list of floats) – List of shifts applied, with the row shift in the 1st dimension and the column shift in the 2nd dimension.
diffphase (float) – Difference of phase between the two images
offset_image2 (array_like) – Shifted image2 relative to image1
- toupy.registration.registration.tomoconsistency_multiple(input_stack, theta, shiftstack, **params)[source]¶
Apply tomographic consistency alignement on multiple slices. By default is implemented over 10 slices.
- Parameters
Input_stack (array_like) – Stack of projections
theta (array_like) – Reconstruction angles (in degrees). Default: m angles evenly spaced between 0 and 180 (if the shape of radon_image is (N, M)).
shiftstack (array_like) – Array with initial estimates of positions
params (dict) – Dictionary with additional parameters for the alignment. Please, see the description of each parameter in
alignprojections_horizontal()
.
- Returns
shiftstack – Average of the object shifts over 10 slices
- Return type
array_like
- toupy.registration.registration.vertical_fluctuations(input_stack, lims, shiftstack, shift_method='fourier', polyorder=2)[source]¶
Calculate the vertical fluctuation functions of a stack
- Parameters
input_array (array_like) – Stack of images to be shifted
lims (list of ints) – Limits of rows and columns to be considered. lims=[limrow,limcol]
shiftstack (array_like) – Array of initial estimates for object motion (2,n)
shift_method (str, optional) – Name of the shift method. Options: ‘linear’, ‘fourier’, ‘spline’. The default method is ‘linear’.
polyorder (int, optional) – Order of the polynomial to remove bias from the mass fluctuation function. The default value is 2.
- Returns
vert_fluct – 2D function containing the mass fluctuation after shift and bias removal for the stack of images
- Return type
array_like
- toupy.registration.registration.vertical_shift(input_array, lims, vstep, maxshift, shift_method='linear', polyorder=2)[source]¶
Calculate the vertical shift of an array
- Parameters
input_array (array_like) – Image to be shifted
lims (list of ints) – Limits of rows and columns to be considered. lims=[limrow,limcol]
vstep (float) – Amount to shift the input_array vertically
maxshift (float) – Maximum value of the shifts in order to avoid border problems
shift_method (str, optional) – Name of the shift method. Options: ‘linear’, ‘fourier’, ‘spline’. The default method is ‘linear’.
polyorder (int, optional) – Order of the polynomial to remove bias from the mass fluctuation function. The default value is 2.
- Returns
shift_cal – 1D function containing the mass fluctuation after shift and bias removal
- Return type
array_like
toupy.registration.shift module¶
- class toupy.registration.shift.ShiftFunc(**params)[source]¶
Bases:
Variables
Collections of shift fuctions
- __call__(*args)[source]¶
Implement the shifts
- Parameters
*args –
- args[0]array_like
Input array
- args[1]int or tuple
Shift amplitude
- args[2]str (optional)
Padding mode if necessary
- args[3]bool (optional)
True for complex output or False for real output
- shift_fft(input_array, shift)[source]¶
Performs pixel and subpixel shift (with wraping) using pyFFTW.
Since FFTW has efficient functions for array sizes which can be decompose in prime factor, the input_array is padded to the next fast size given by pyFFTW.next_fast_len. The padding is done in mode = ‘reflect’ by default to reduce border artifacts.
- Parameters
- Returns
output_array – Shifted image
- Return type
array_like
- shift_linear(input_array, shift)[source]¶
Shifts an image with wrap around and bilinear interpolation
- Parameters
- Returns
output_array – Shifted image
- Return type
array_like