stemtool.util package¶
Submodules¶
stemtool.util.fourier_reg module¶
-
stemtool.util.fourier_reg.dftregistration(buf1ft, buf2ft, usfac=1)[source]¶ Upsampled FFT registration between two images
Parameters: - buf1ft (ndarray) – Fourier transform of reference image, DC in (1,1) [DO NOT FFTSHIFT]
- buf2ft (ndarray) – Fourier transform of image to register, DC in (1,1) [DO NOT FFTSHIFT]
- usfac (int) – Upsampling factor (integer). Images will be registered to within 1/usfac of a pixel. For example usfac = 20 means the images will be registered within 1/20 of a pixel. (default = 1)
Returns: - row_shift (float) – Pixel shift in cartesian y direction
- col_shift (float) – Pixel shift in cartesian x direction
- error (float) – Translation invariant normalized RMS error between f and g
- phase_diff (float) – Global phase difference between the two images (should be zero if images are non-negative).
- registered_fft (ndarray) – Fourier transform of registered version of buf2ft, the global phase difference is compensated for.
Notes
Efficient subpixel image registration by crosscorrelation. This code gives the same precision as the FFT upsampled cross correlation in a small fraction of the computation time and with reduced memory requirements. It obtains an initial estimate of the crosscorrelation peak by an FFT and then refines the shift estimation by upsampling the DFT only in a small neighborhood of that estimate by means of a matrix-multiply DFT. With this procedure all the image points are used to compute the upsampled crosscorrelation.
References
[1] Manuel Guizar-Sicairos, Samuel T. Thurman, and James R. Fienup, “Efficient subpixel image registration algorithms,” Opt. Lett. 33, 156-158 (2008). Copyright (c) 2016, Manuel Guizar Sicairos, James R. Fienup, University of Rochester All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution
- Neither the name of the University of Rochester nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Examples
If you have two images im1 and im2, run as:
>>> row_shift,col_shift,phase_diff,error,registered_fft = dftregistration(np.fft.fft2(im1),np.fft.fft2(im2),upsampling)
You can test by reversing the order
>>> row_shift_r,col_shift_r,phase_diff,error,registered_fft = dftregistration(np.fft.fft2(im2),np.fft.fft2(im1),upsampling) >>> row_shift == -row_shift_r >>> True >>> col_shift == -col_shift_r >>> True
-
stemtool.util.fourier_reg.dftups(input_image, usfac=1, nor=0, noc=0, roff=0, coff=0)[source]¶ Upsampled discrete Fourier transform
Parameters: - input_image (ndarray) – Input image
- usfac (int, optional) – Upsampling Factor. Default is 1
- nor (int, optional) – Number of pixels in the output upsampled DFT, in units of upsampled pixels (default = size(in))
- noc (int, optional) – Number of pixels in the output upsampled DFT, in units of upsampled pixels (default = size(in))
- roff (int, optional) – Row offsets, allow to shift the output array to a region of interest on the DFT (default = 0)
- coff (int, optional) – Column offsets, allow to shift the output array to a region of interest on the DFT (default = 0)
Returns: out_fft – Upsampled Fourier transform
Return type: ndarray
Notes
Recieves DC in upper left corner, image center must be in [0,0] This code is intended to provide the same result as if the following operations were performed - Embed the array “input_image” in an array that is usfac times larger in each dimension. ifftshift to bring the center of the image to (1,1). - Take the FFT of the larger array - Extract an [nor, noc] region of the result. Starting with the [roff+1 coff+1] element. It achieves this result by computing the DFT in the output array without the need to zeropad. Much faster and memory efficient than the zero-padded FFT approach if [nor noc] are much smaller than [nr*usfac nc*usfac]
-
stemtool.util.fourier_reg.find_max_index(image)[source]¶ Find maxima in image
Parameters: image (ndarray) – Input image Returns: - ymax (int) – y-index position of maxima
- xmax (int) – x-index position of maxima
Notes
Finds the image maxima, and then locates the y and x indices corresponding to the maxima
Examples
>>> ym, xm = find_max_index(image)
-
stemtool.util.fourier_reg.first_max_index(image, order='C')[source]¶ First maxima in image
Parameters: - image (ndarray) – Input image
- order ({'C','F', 'A', 'K'},) – optional The elements of a are read using this index order. ‘C’ means to index the elements in row-major, C-style order, with the last axis index changing fastest, back to the first axis index changing slowest. ‘F’ means to index the elements in column-major, Fortran-style order, with the first index changing fastest, and the last index changing slowest. Note that the ‘C’ and ‘F’ options take no account of the memory layout of the underlying array, and only refer to the order of axis indexing. ‘A’ means to read the elements in Fortran-like index order if a is Fortran contiguous in memory, C-like order otherwise. ‘K’ means to read the elements in the order they occur in memory, except for reversing the data when strides are negative. By default, ‘C’ index order is used.
Returns: - ymax (int) – y-index position of maxima
- xmax (int) – x-index position of maxima
Notes
Finds the first image maxima if there are multiple points with the same maximum value, and then locates the y and x indices corresponding to the maxima
Examples
>>> ym, xm = first_max_index(image)
-
stemtool.util.fourier_reg.fourier_pad(imFT, outsize)[source]¶ Pad Fourier images
Parameters: - imFT (ndarray) – Input complex array with DC in [1,1]
- outsize (ndarray with (2,1) shape) – ny, nx of output size
Returns: imout – Output complex image with DC in [1,1]
Return type: ndarray
Notes
Pads or crops the Fourier transform to the desired ouput size. Taking care that the zero frequency is put in the correct place for the output for subsequent FT or IFT. Can be used for Fourier transform based interpolation, i.e. dirichlet kernel interpolation.
stemtool.util.gauss_utils module¶
-
stemtool.util.gauss_utils.fit_gaussian1D_mask(signal, position, mask_width, center_type='COM')[source]¶ Fit a 2D gaussian to a masked image based on the location of the mask, size of the mask and the type of the mask
Parameters: - signal (ndarray) – The 1D signal that will be fitted with the Gaussian
- position (float) – x center of the mask
- mask_width (float) – The size of the mask.
- center_type (str) – Center location for the first pass of the Gaussian. Default is COM, while the other options are minima or maxima.
Returns: popt – Refined X position, Standard deviation, Amplitude
Return type: tuple
Notes
This code uses the scipy.optimize.curve_fit module to fit a 1D Gaussian peak to masked data. mask_x refers to the initial starting position. Also, this can take in minima as a string for initializing Gaussian peaks.
See also
fit_gaussian2D_mask initialize_gauss1D gaussian_1D_function
Authors: Debangshu Mukherjee <mukherjeed@ornl.gov>
-
stemtool.util.gauss_utils.fit_gaussian2D_mask(image_data, mask_x, mask_y, mask_radius, mask_type='circular', center_type='COM')[source]¶ Fit a 2D gaussian to a masked image based on the location of the mask, size of the mask and the type of the mask
Parameters: - image_data (ndarray) – The image that will be fitted with the Gaussian
- mask_x (float) – x center of the mask
- mask_y (float) – y center of the mask
- mask_radius (float) – The size of the mask. For a circulat mask this refers to the mask radius, while for a square mask this refers to half the side of the square
- mask_type (str) – Default is circular, while the other option is square
- center_type (str) – Center location for the first pass of the Gaussian. Default is COM, while the other options are minima or maxima.
Returns: popt – Refined X position, Refined Y Position, Rotation angle of 2D Gaussian, Standard deviation(s), Amplitude
Return type: tuple
Notes
This code uses the scipy.optimize.curve_fit module to fit a 2D Gaussian peak to masked data. mask_x and mask_y refer to the initial starting positions. Also, this can take in minima as a string for initializing Gaussian peaks, which allows for atom column mapping in inverted contrast images too.
-
stemtool.util.gauss_utils.gauss2D(im_size, x0, y0, theta, sigma_x, sigma_y, amplitude)[source]¶ Return a 2D Gaussian function centered at x0, y0
Parameters: - im_size (tuple) – Size of the image where a Gaussian peak is to be generated
- x0 (float) – x center of Gaussian peak
- y0 (float) – y center of Gaussian peak
- theta (float) – Rotation of the 2D gaussian peak in radians
- sigma_x (float) – Standard deviation of the 2D Gaussian along x
- sigma_y (float) – Standard deviation of the 2D Gaussian along y
- amplitude (float) – Peak intensity
Returns: gauss2D – 2D Gaussian peak of shape im_size
Return type: ndarray
Notes
This returns a 2D ndarray with the the size as im_size, with a 2D gaussian function centered at (x0,y0) defined by the input parameters.
-
stemtool.util.gauss_utils.gaussian_1D_function(x, x0, sigma_x, amplitude)[source]¶ The underlying 1D Gaussian function
Parameters: - x (ndarray) – x positions
- x0 (float) – x center of Gaussian peak
- sigma_x (float) – Standard deviation of the 2D Gaussian along x
- amplitude (float) – Peak intensity
Returns: gaussvals – A Gausian peak centered at x0 based on the parameters given
Return type: ndarray
Notes
The Gaussian 1D function is calculated at every x position for a list of position values based on the parameters given.
-
stemtool.util.gauss_utils.gaussian_2D_function(xy, x0, y0, theta, sigma_x, sigma_y, amplitude)[source]¶ The underlying 2D Gaussian function
Parameters: - xy (tuple) – x and y positions
- x0 (float) – x center of Gaussian peak
- y0 (float) – y center of Gaussian peak
- theta (float) – Rotation of the 2D gaussian peak in radians
- sigma_x (float) – Standard deviation of the 2D Gaussian along x
- sigma_y (float) – Standard deviation of the 2D Gaussian along y
- amplitude (float) – Peak intensity
Returns: gaussvals – A Gausian peak centered at x0, y0 based on the parameters given
Return type: ndarray
Notes
The Gaussian 2D function is calculated at every x and y position for a list of position values based on the parameters given.
-
stemtool.util.gauss_utils.initialize_gauss1D(xx, yy, center_type='COM')[source]¶ Generate an approximate Gaussian based on signal
Parameters: - xx (ndarray) – X positions
- yy (ndarray) – Signal value at the positions
- center_type (str) – Default is COM which uses the center of mass of the given positions to generate the starting gaussian center. The other option is maxima which takes the maximum intensity value as the starting point.
Returns: gauss_ini – X_center, X_std, Amplitude
Return type: tuple
Notes
For a given list of x positions and corresponding signal values, this code returns a first pass approximation of a 1D Gaussian function. The center of the function can either be the center of mass or the intensity maxima, and is user defined.
-
stemtool.util.gauss_utils.initialize_gauss2D(xx, yy, zz, center_type='COM')[source]¶ Generate an approximate Gaussian based on image
Parameters: - xx (ndarray) – X positions
- yy (ndarray) – Y Positions
- zz (ndarray) – Image value at the positions
- center_type (str) – Default is COM which uses the center of mass of the given positions to generate the starting gaussian center. The other option is maxima which takes the maximum intensity value as the starting point.
Returns: gauss_ini – X_center, Y_center, Angle, X_std, Y_std, Amplitude
Return type: tuple
Notes
For a given list of x positions, y positions and corresponding intensity values, this code returns a first pass approximation of a Gaussian function. The center of the gaussian 2D function can either be the center of mass or the intensity maxima, and is user defined. The angle is always given as 0.
Authors: Debangshu Mukherjee <mukherjeed@ornl.gov>
stemtool.util.image_utils module¶
-
stemtool.util.image_utils.cross_corr(image_1, image_2, hybridizer=0, normal=True)[source]¶ Normalized Correlation, allowing for hybridization with cross correlation being the default output if no hybridization parameter is given
- image_1: ndarray
- First image
- image_2: ndarray
- Second image
- hybridizer: float
- Hybridization parameter between 0 and 1 0 is pure cross correlation 1 is pure phase correlation
- corr_hybrid: ndarray
- Complex valued correlation output
The cross-correlation theorem can be stated as: .. math:
G_c = G_1 imes G_2^*
where \(G_c\) is the Fourier transform of the cross correlated matrix and \(G_1\) and \(G_2\) are the Fourier transforms of \(g_1\) and \(g_2\) respectively, which are the original matrices. This is pure cross-correlation. Phase correlation can be expressed as: .. math:
G_c =
rac{G_1 imes G_2^*}{mid G_1 imes G_2^* mid}
Thus, we can now define a hybrid cross-correlation where .. math:
G_c =
rac{G_1 imes G_2^*}{mid G_1 imes G_2^* mid ^n}
If n is 0, we have cross correlation, and if n is 1 we have phase correlation.
- 1]_, Pekin, T.C., Gammer, C., Ciston, J., Minor, A.M. and Ophus, C.,
- 2017. Optimizing disk registration algorithms for nanobeam electron diffraction strain mapping. Ultramicroscopy, 176, pp.170-176.
sparse_division
Authors: Debangshu Mukherjee <mukherjeed@ornl.gov>
-
stemtool.util.image_utils.euclidean_dist(binary_image)[source]¶ Get Euclidean distance of every non-zero pixel from zero valued pixels
Parameters: binary_image (ndarray) – The image Returns: dist_map – The Euclidean distance map Return type: ndarray
-
stemtool.util.image_utils.get_mean_std(xlist, ylist, resolution=25, style='median')[source]¶ Get mean and standard deviation of a list of x and y values
Parameters: - xlist (ndarray) – (n,1) shape of x values
- ylist (ndarray) – (n,1) shape of x values
- resolution (float) – Optional value, default if 50 How finely sampled the final list is
Returns: - stdvals (ndarray) – First column is x values sampled at resolution Second Column is mean or median of corresponding y values Third column is the standard deviation
- Authors:
- Debangshu Mukherjee <mukherjeed@ornl.gov>
-
stemtool.util.image_utils.hanned_image(image)[source]¶ 2D hanning filter for images
Parameters: image (ndarray) – Original Image on which the Hanning filter is to be applied Returns: hanned_image – Image with the hanning filter applied Return type: ndarray Notes
Authors: Debangshu Mukherjee <mukherjeed@ornl.gov>
-
stemtool.util.image_utils.image_logarizer(image_orig, bit_depth=64)[source]¶ Normalized log of image
Parameters: - image_orig (ndarray) – Numpy array of real valued image
- bit_depth (int) – Bit depth of output image Default is 32
Returns: image_log – Normalized log
Return type: ndarray
Notes
Normalize the image, and scale it 2^0 to 2^bit_depth. Take log2 of the scaled image.
Authors: Debangshu Mukherjee <mukherjeed@ornl.gov>
-
stemtool.util.image_utils.image_normalizer(image_orig)[source]¶ Normalizing Image
Parameters: image_orig (ndarray) – ‘image_orig’ is the original input image to be normalized Returns: image_norm – Normalized Image Return type: ndarray Notes
We normalize a real valued image here so that it’s values lie between o and 1. This is done by first subtracting the minimum value of the image from the image itself, and then subsequently dividing the image by the maximum value of the subtracted image.
Authors: Debangshu Mukherjee <mukherjeed@ornl.gov>
-
stemtool.util.image_utils.make_circle(size_circ, center_x, center_y, radius)[source]¶ Make a circle
Parameters: - size_circ (ndarray) – 2 element array giving the size of the output matrix
- center_x (float) – x position of circle center
- center_y (float) – y position of circle center
- radius (float) – radius of the circle
Returns: - circle (ndarray) – p X q sized array where the it is 1 inside the circle and 0 outside
- Authors:
- Debangshu Mukherjee <mukherjeed@ornl.gov>
-
stemtool.util.image_utils.move_by_phase(image_to_move, x_pixels, y_pixels)[source]¶ Move Images with sub-pixel precision
Parameters: - image_to_move (ndarray) – Original Image to be moved
- x_pixels (float) – Pixels to shift in X direction
- y_pixels (float) – Pixels to Shift in Y direction
Returns: moved_image – Moved Image
Return type: ndarray
Notes
The underlying idea is that a shift in the real space is phase shift in Fourier space. So we take the original image, and take it’s Fourier transform. Also, we calculate how much the image shifts result in the phase change, by calculating the Fourier pixel dimensions. We then multiply the FFT of the image with the phase shift value and then take the inverse FFT.
Authors: Debangshu Mukherjee <mukherjeed@ornl.gov>
-
stemtool.util.image_utils.reduce_precision_xy(xy, reducer)[source]¶ Reduce the precison of an xy array along both the x and y axes.
Parameters: - xy (ndarray) – The first column is the x dimension, while the second column is the y dimension
- reducer (tuple) – The precison reducers along the individual dimensions
Returns: xyprec – Reduced precision array
Return type: ndarray
-
stemtool.util.image_utils.remove_dead_pixels(image_orig, iter_count=1, level=10000)[source]¶ Remove dead pixels
Parameters: - image_orig (ndarray) – Numpy array of real valued image
- iter_count (int) – Number of iterations to run the process. Default is 1
- level (int,float) – Ratio of minima pixels to total pixels. Default is 10,000
Returns: image_orig – Image with dead pixels converted
Return type: ndarray
Notes
Subtract the minima from the image, and if the number of pixels with minima values is less than the 1/level of the total pixels, then those are decided to be dead pixels. Iterate if necessary
Authors: Debangshu Mukherjee <mukherjeed@ornl.gov>
-
stemtool.util.image_utils.sparse_division(sparse_numer, sparse_denom, bit_depth=32)[source]¶ Divide two sparse matrices element wise to prevent zeros
Parameters: - spase_numer (ndarray) – Numpy array of real valued numerator
- sparse_denom (ndarray) – Numpy array of real valued denominator
- bit_depth (int) – Bit depth of output image Default is 32
Returns: divided_matrix – Quotient matrix
Return type: ndarray
Notes
Decide on a bit depth below which the values in the denominator are just noise, as they are below the bit depth. Do the same for the numerator. Turn those values to 1 in the denominator and 0 in the numerator. Then in the quotient matrix, turn the denominator values below the threshold to 0 too.
Authors: Debangshu Mukherjee <mukherjeed@ornl.gov>
stemtool.util.pnccd module¶
-
stemtool.util.image_utils.array_rms(arr)[source]
-
stemtool.util.image_utils.circle_function(xy, x0, y0, radius)[source]
-
stemtool.util.image_utils.cp_image_sat(comp_image)[source]
-
stemtool.util.image_utils.cp_image_val(comp_image)[source]
-
stemtool.util.image_utils.cross_corr(image_1, image_2, hybridizer=0, normal=True)[source] Normalized Correlation, allowing for hybridization with cross correlation being the default output if no hybridization parameter is given
- image_1: ndarray
- First image
- image_2: ndarray
- Second image
- hybridizer: float
- Hybridization parameter between 0 and 1 0 is pure cross correlation 1 is pure phase correlation
- corr_hybrid: ndarray
- Complex valued correlation output
The cross-correlation theorem can be stated as: .. math:
G_c = G_1 imes G_2^*
where \(G_c\) is the Fourier transform of the cross correlated matrix and \(G_1\) and \(G_2\) are the Fourier transforms of \(g_1\) and \(g_2\) respectively, which are the original matrices. This is pure cross-correlation. Phase correlation can be expressed as: .. math:
G_c =
rac{G_1 imes G_2^*}{mid G_1 imes G_2^* mid}
Thus, we can now define a hybrid cross-correlation where .. math:
G_c =
rac{G_1 imes G_2^*}{mid G_1 imes G_2^* mid ^n}
If n is 0, we have cross correlation, and if n is 1 we have phase correlation.
- 1]_, Pekin, T.C., Gammer, C., Ciston, J., Minor, A.M. and Ophus, C.,
- 2017. Optimizing disk registration algorithms for nanobeam electron diffraction strain mapping. Ultramicroscopy, 176, pp.170-176.
sparse_division
Authors: Debangshu Mukherjee <mukherjeed@ornl.gov>
-
stemtool.util.image_utils.cross_corr_unpadded(image_1, image_2, normal=True)[source]
-
stemtool.util.image_utils.euclidean_dist(binary_image)[source] Get Euclidean distance of every non-zero pixel from zero valued pixels
Parameters: binary_image (ndarray) – The image Returns: dist_map – The Euclidean distance map Return type: ndarray
-
stemtool.util.image_utils.fit_circle(image_data, med_factor=50)[source]
-
stemtool.util.image_utils.get_mean_std(xlist, ylist, resolution=25, style='median')[source] Get mean and standard deviation of a list of x and y values
Parameters: - xlist (ndarray) – (n,1) shape of x values
- ylist (ndarray) – (n,1) shape of x values
- resolution (float) – Optional value, default if 50 How finely sampled the final list is
Returns: - stdvals (ndarray) – First column is x values sampled at resolution Second Column is mean or median of corresponding y values Third column is the standard deviation
- Authors:
- Debangshu Mukherjee <mukherjeed@ornl.gov>
-
stemtool.util.image_utils.hanned_image(image)[source] 2D hanning filter for images
Parameters: image (ndarray) – Original Image on which the Hanning filter is to be applied Returns: hanned_image – Image with the hanning filter applied Return type: ndarray Notes
Authors: Debangshu Mukherjee <mukherjeed@ornl.gov>
-
stemtool.util.image_utils.hsv_overlay(data, image, color, climit=None, bit_depth=8)[source]
-
stemtool.util.image_utils.image_logarizer(image_orig, bit_depth=64)[source] Normalized log of image
Parameters: - image_orig (ndarray) – Numpy array of real valued image
- bit_depth (int) – Bit depth of output image Default is 32
Returns: image_log – Normalized log
Return type: ndarray
Notes
Normalize the image, and scale it 2^0 to 2^bit_depth. Take log2 of the scaled image.
Authors: Debangshu Mukherjee <mukherjeed@ornl.gov>
-
stemtool.util.image_utils.image_normalizer(image_orig)[source] Normalizing Image
Parameters: image_orig (ndarray) – ‘image_orig’ is the original input image to be normalized Returns: image_norm – Normalized Image Return type: ndarray Notes
We normalize a real valued image here so that it’s values lie between o and 1. This is done by first subtracting the minimum value of the image from the image itself, and then subsequently dividing the image by the maximum value of the subtracted image.
Authors: Debangshu Mukherjee <mukherjeed@ornl.gov>
-
stemtool.util.image_utils.is_odd(num)[source]
-
stemtool.util.image_utils.make_circle(size_circ, center_x, center_y, radius)[source] Make a circle
Parameters: - size_circ (ndarray) – 2 element array giving the size of the output matrix
- center_x (float) – x position of circle center
- center_y (float) – y position of circle center
- radius (float) – radius of the circle
Returns: - circle (ndarray) – p X q sized array where the it is 1 inside the circle and 0 outside
- Authors:
- Debangshu Mukherjee <mukherjeed@ornl.gov>
-
stemtool.util.image_utils.move_by_phase(image_to_move, x_pixels, y_pixels)[source] Move Images with sub-pixel precision
Parameters: - image_to_move (ndarray) – Original Image to be moved
- x_pixels (float) – Pixels to shift in X direction
- y_pixels (float) – Pixels to Shift in Y direction
Returns: moved_image – Moved Image
Return type: ndarray
Notes
The underlying idea is that a shift in the real space is phase shift in Fourier space. So we take the original image, and take it’s Fourier transform. Also, we calculate how much the image shifts result in the phase change, by calculating the Fourier pixel dimensions. We then multiply the FFT of the image with the phase shift value and then take the inverse FFT.
Authors: Debangshu Mukherjee <mukherjeed@ornl.gov>
-
stemtool.util.image_utils.phase_color(phase_image)[source]
-
stemtool.util.image_utils.reduce_precision_xy(xy, reducer)[source] Reduce the precison of an xy array along both the x and y axes.
Parameters: - xy (ndarray) – The first column is the x dimension, while the second column is the y dimension
- reducer (tuple) – The precison reducers along the individual dimensions
Returns: xyprec – Reduced precision array
Return type: ndarray
-
stemtool.util.image_utils.remove_dead_pixels(image_orig, iter_count=1, level=10000)[source] Remove dead pixels
Parameters: - image_orig (ndarray) – Numpy array of real valued image
- iter_count (int) – Number of iterations to run the process. Default is 1
- level (int,float) – Ratio of minima pixels to total pixels. Default is 10,000
Returns: image_orig – Image with dead pixels converted
Return type: ndarray
Notes
Subtract the minima from the image, and if the number of pixels with minima values is less than the 1/level of the total pixels, then those are decided to be dead pixels. Iterate if necessary
Authors: Debangshu Mukherjee <mukherjeed@ornl.gov>
-
stemtool.util.image_utils.sane_colorbar(mappable)[source]
-
stemtool.util.image_utils.sobel_circle(image)[source]
-
stemtool.util.image_utils.sparse_division(sparse_numer, sparse_denom, bit_depth=32)[source] Divide two sparse matrices element wise to prevent zeros
Parameters: - spase_numer (ndarray) – Numpy array of real valued numerator
- sparse_denom (ndarray) – Numpy array of real valued denominator
- bit_depth (int) – Bit depth of output image Default is 32
Returns: divided_matrix – Quotient matrix
Return type: ndarray
Notes
Decide on a bit depth below which the values in the denominator are just noise, as they are below the bit depth. Do the same for the numerator. Turn those values to 1 in the denominator and 0 in the numerator. Then in the quotient matrix, turn the denominator values below the threshold to 0 too.
Authors: Debangshu Mukherjee <mukherjeed@ornl.gov>