toupy.utils package¶
Submodules¶
toupy.utils.FFT_utils module¶
- toupy.utils.FFT_utils.fastfftn(input_array, **kwargs)[source]¶
Auxiliary function to use pyFFTW. It does the align, planning and apply FFTW transform
- Parameters
input_array (array_like) – Array to be FFTWed
- Returns
fftw_array – Fourier transformed array
- Return type
array_like
- toupy.utils.FFT_utils.fastifftn(input_array, **kwargs)[source]¶
Auxiliary function to use pyFFTW. It does the align, planning and apply inverse FFTW transform
- Parameters
input_array (array_like) – Array to be FFTWed
- Returns
ifftw_array – Inverse Fourier transformed array
- Return type
array_like
- toupy.utils.FFT_utils.padfft(input_array, pad_mode='reflect')[source]¶
Auxiliary function to pad arrays for Fourier transforms. It accepts 1D and 2D arrays.
- Parameters
input_array (array_like) – Array to be padded
mode (str) – Padding mode to treat the array borders. See
numpy.pad
for modes. The default value is reflect.
- Returns
array_pad (array_like) – Padded array
N_pad (array_like) – padded frequency coordinates
padw (int, list of ints) – pad width
toupy.utils.array_utils module¶
- toupy.utils.array_utils.create_circle(inputimg)[source]¶
Create circle with apodized edges
- Parameters
inputimg (array_like) – Input image from which to calculate the circle
- Returns
t – Array containing the circle
- Return type
array_like
- toupy.utils.array_utils.create_mask_borders(tomogram, mask_array, threshold=4e-07)[source]¶
Create mask for border of tomographic volume
- Parameters
tomogram (array_like) – Input volume
mask (bool array_like) – Input mask
threshold (float, optional) – Threshold value. The default value is
4e-7
.
- Returns
mask_array – Masked array
- Return type
array_like
- toupy.utils.array_utils.cropROI(input_array, roi=[])[source]¶
Crop ROI
- Parameters
input_array (array_like) – Input image to be cropped
roi (list of int) – ROI of interest. roi should be [top, bottom, left, right]
- Returns
Cropped image
- Return type
array_like
- toupy.utils.array_utils.fract_hanning(outputdim, unmodsize)[source]¶
Creates a square hanning window if unmodsize = 0 (or ommited), otherwise the output array will contain an array of ones in the center and cosine modulation on the edges, the array of ones will have DC in upper left corner.
- toupy.utils.array_utils.fract_hanning_pad(outputdim, filterdim, unmodsize)[source]¶
Creates a square hanning window if unmodsize = 0 (or ommited), otherwise the output array will contain an array of ones in the center and cosine modulation on the edges, the array of ones will have DC in upper left corner.
- Parameters
- Returns
Square array containing a fractional separable Hanning window with DC in upper left corner.
- Return type
array_like
- toupy.utils.array_utils.gauss_kern(size, sizey=None)[source]¶
Returns a normalized 2D gauss kernel array for convolutions
- Parameters
- Returns
Normalized kernel
- Return type
array_like
Notes
- toupy.utils.array_utils.hanning_apod1D(window_size, apod_width)[source]¶
Create 1D apodization window using Hanning window
- toupy.utils.array_utils.hanning_apodization(window_size, apod_width)[source]¶
Create apodization window using Hanning window
- toupy.utils.array_utils.mask_borders(imgarray, mask_array, threshold=4e-07)[source]¶
Mask borders using the gradient
- Parameters
imgarray (array_like) – Input image
mask_array (bool array_like) – Input mask
threshold (float, optional) – Threshold value. The default value is
4e-7
.
- Returns
mask_array – Masked array
- Return type
array_like
- toupy.utils.array_utils.padarray_bothsides(input_array, newshape, padmode='edge')[source]¶
Pad array in both sides
- toupy.utils.array_utils.polynomial1d(x, order=1, w=1)[source]¶
Generates a 1D orthonormal polynomial base.
- Parameters
- Returns
polyseries – Orthonormal polymonial up to order
- Return type
array_like
Note
Inspired by legendrepoly1D_2.m created by Manuel Guizar in March 10,2009
- toupy.utils.array_utils.projectpoly1d(func1d, order=1, w=1)[source]¶
Projects a 1D function onto orthonormalized base
- Parameters
- Returns
projfunc1d – Projected 1D funtion on orthonormal base
- Return type
array_like
Note
Inspired by projectleg1D_2.m created by Manuel Guizar in March 10,2009
- toupy.utils.array_utils.radtap(X, Y, tappix, zerorad)[source]¶
Creates a central cosine tapering for beam. It receives the X and Y coordinates, tappix is the extent of tapering, zerorad is the radius with no data (zeros).
- toupy.utils.array_utils.replace_bad(input_stack, list_bad=[], temporary=False)[source]¶
correcting bad projections before unwrapping
- toupy.utils.array_utils.sharpening_image(input_image, filter_size=3, alpha=30)[source]¶
Sharpen image with a median filter
- toupy.utils.array_utils.smooth1d(x, window_len=11, window='hanning')[source]¶
Smooth the data using a window with requested size.
This method is based on the convolution of a scaled window with the signal. The signal is prepared by introducing reflected copies of the signal (with the window size) in both ends so that transient parts are minimized in the begining and end part of the output signal.
- Parameters
- Returns
y – The smoothed signal
- Return type
array_like
Example
>>> import numpy as np >>> t=np.linspace(-2,2,0.1) >>> x=np.sin(t)+np.random.randn(len(t))*0.1 >>> y=smooth(x)
Notes
see also: numpy.hanning, numpy.hamming, numpy.bartlett, numpy.blackman, numpy.convolve
scipy.signal.lfilter
Adapted from : https://scipy-cookbook.readthedocs.io/items/SignalSmooth.html from: http://scipy.org/Cookbook/SignalSmooth
- toupy.utils.array_utils.smooth2d(im, n, ny=None)[source]¶
Blurs the image by convolving with a gaussian kernel of typical
size n. The optional keyword argument ny allows for a different size in the y direction.
- Parameters
im (array_like) – Input image
n (int, optional) – Typical size of the gaussian kernel
n – Size in the y direction if not squared
- Returns
improc – Smoothed image
- Return type
array_like
Notes
- toupy.utils.array_utils.smooth_image(input_image, filter_size=3)[source]¶
Smooth image with a median filter
- Parameters
input_image (array_like) – Image to be smoothed
filter_size (int) – Size of the filter
- Returns
Smoothed image
- Return type
array_like
- toupy.utils.array_utils.sort_array(input_array, ref_array)[source]¶
Sort array based on another array
- Parameters
input_array (array_like) – Array to be sorted
ref_array (array_like) – Array on which the sorting will be based
- Returns
sorted_input_array (array_like) – Sorted input array
sorted_ref_array (array_like) – Sorted reference array
toupy.utils.converter_utils module¶
- toupy.utils.converter_utils.convert_to_beta(input_img, energy, voxelsize, apply_log=False)[source]¶
Converts the image gray-levels from amplitude to beta
- toupy.utils.converter_utils.convert_to_delta(input_img, energy, voxelsize)[source]¶
Converts the image gray-levels from phase-shifts to delta
- toupy.utils.converter_utils.convert_to_mu(input_img, wavelen)[source]¶
Converts the image gray-levels from absoption index Beta to linear attenuation coefficient mu
toupy.utils.fit_utils module¶
- toupy.utils.fit_utils.model_erf(t, *coeffs)[source]¶
Model for the erf fitting
P0 + P1*t + (P2/2)*(1-erf(sqrt(2)*(x-P3)/(P4)))
- toupy.utils.fit_utils.model_tanh(t, *coeffs)[source]¶
Model for the erf fitting
P0 + P1*t + (P2/2)*(1-tanh(sqrt(2)*(x-P3)/P4))
toupy.utils.funcutils module¶
- toupy.utils.funcutils.deprecated(func)[source]¶
This is a decorator which can be used to mark functions as deprecated. It will result in a warning being emitted when the function is used.
- toupy.utils.funcutils.progbar(curr, total, textstr='')[source]¶
Create a progress bar for for-loops.
toupy.utils.plot_utils module¶
- class toupy.utils.plot_utils.RegisterPlot(**params)[source]¶
Bases:
object
Display plots during registration
- plotshorizontal(recons, sinoorig, sinocurr, sinocomp, deltaslice, metric_error, count)[source]¶
Display plots during the horizontal registration
- class toupy.utils.plot_utils.ShowProjections[source]¶
Bases:
object
Show projections and probe
- toupy.utils.plot_utils.animated_image(stack_array, *args)[source]¶
Iterative plot of the images using animation module of Matplotlib
- Parameters
stack_array (ndarray) – Array containing the stack of images to animate. The first index corresponds to the image number in the sequence of images.
args[0] (list of ints) – Row limits to display
args[1] (list of ints) – Column limits to display
- toupy.utils.plot_utils.autoscale_y(ax, margin=0.1)[source]¶
This function rescales the y-axis based on the data that is visible given the current xlim of the axis.
- toupy.utils.plot_utils.display_slice(recons, colormap='bone', vmin=None, vmax=None)[source]¶
Display tomographic slice
- toupy.utils.plot_utils.isnotebook()[source]¶
Check if code is executed in the IPython notebook. This is important because jupyter notebook does not support iterative plots
- toupy.utils.plot_utils.iterative_show(stack_array, limrow=[], limcol=[], airpixel=[], onlyroi=False, colormap='bone', vmin=None, vmax=None)[source]¶
Iterative plot of the images
- Parameters
stack_array (ndarray) – Array containing the stack of images to animate. The first index corresponds to the image number in the sequence of images.
limrow (list of ints) – Limits of rows in the format [begining, end]
limcol (list of ints) – Limits of cols in the format [begining, end]
airpixel (list of ints) – Position of pixel in the air/vacuum
onlyroi (bool) – If True, it displays only the ROI. If False, it displays the entire image.
colormap (str, optional) – Colormap name. The default value is
bone
vmin (float, None, optional) – Minimum gray-level. The default value is
None
vmax (float, None, optional) – Maximum gray-level. The default value is
None