hyperspy.utils.peakfinders2D module
- hyperspy.utils.peakfinders2D._fast_mean(X)
JIT-compiled mean of array.
- Parameters:
X (
numpy.ndarray
) – Input array.- Returns:
mean – Mean of X.
- Return type:
Notes
Used by scipy.ndimage.generic_filter in the find_peaks_stat method to reduce overhead of repeated Python function calls. See https://github.com/scipy/scipy/issues/8916 for more details.
- hyperspy.utils.peakfinders2D._fast_std(X)
JIT-compiled standard deviation of array.
- Parameters:
X (
numpy.ndarray
) – Input array.- Returns:
std – Standard deviation of X.
- Return type:
Notes
Used by scipy.ndimage.generic_filter in the find_peaks_stat method to reduce overhead of repeated Python function calls. See https://github.com/scipy/scipy/issues/8916 for more details.
- hyperspy.utils.peakfinders2D.clean_peaks(peaks)
Sort array of peaks and deal with no peaks being found.
- Parameters:
peaks (
numpy.ndarray
) – Array of found peaks.- Returns:
peaks (
numpy.ndarray
) – Sorted array, first by peaks[:,1] (y-coordinate) then by peaks[:,0] (x-coordinate), of found peaks.NO_PEAKS (str) – Flag indicating no peaks found.
- hyperspy.utils.peakfinders2D.find_local_max(z, **kwargs)
Method to locate positive peaks in an image by local maximum searching.
This function wraps
skimage.feature.peak_local_max()
function and sorts the results for consistency with other peak finding methods.- Parameters:
z (
numpy.ndarray
) – Array of image intensities.**kwargs (dict) – Keyword arguments to be passed to the
peak_local_max
method of thescikit-image
library. See its documentation for details https://scikit-image.org/docs/dev/api/skimage.feature.html#peak-local-max
- Returns:
peaks – Peak pixel coordinates.
- Return type:
numpy.ndarray
of shape (n_peaks, 2)
- hyperspy.utils.peakfinders2D.find_peaks_dog(z, min_sigma=1.0, max_sigma=50.0, sigma_ratio=1.6, threshold=0.2, overlap=0.5, exclude_border=False)
Method to locate peaks via the Difference of Gaussian Matrices method.
This function wraps
skimage.feature.blob_dog()
function and sorts the results for consistency with other peak finding methods.- Parameters:
z (
numpy.ndarray
) – 2-d array of intensitiesmin_sigma – Additional parameters to be passed to the algorithm. See blob_dog documentation for details: https://scikit-image.org/docs/dev/api/skimage.feature.html#blob-dog
max_sigma – Additional parameters to be passed to the algorithm. See blob_dog documentation for details: https://scikit-image.org/docs/dev/api/skimage.feature.html#blob-dog
sigma_ratio – Additional parameters to be passed to the algorithm. See blob_dog documentation for details: https://scikit-image.org/docs/dev/api/skimage.feature.html#blob-dog
threshold – Additional parameters to be passed to the algorithm. See blob_dog documentation for details: https://scikit-image.org/docs/dev/api/skimage.feature.html#blob-dog
overlap – Additional parameters to be passed to the algorithm. See blob_dog documentation for details: https://scikit-image.org/docs/dev/api/skimage.feature.html#blob-dog
exclude_border – Additional parameters to be passed to the algorithm. See blob_dog documentation for details: https://scikit-image.org/docs/dev/api/skimage.feature.html#blob-dog
- Returns:
peaks – Peak pixel coordinates.
- Return type:
numpy.ndarray
of shape (n_peaks, 2)
Notes
- While highly effective at finding even very faint peaks, this method is
sensitive to fluctuations in intensity near the edges of the image.
- hyperspy.utils.peakfinders2D.find_peaks_log(z, min_sigma=1.0, max_sigma=50.0, num_sigma=10, threshold=0.2, overlap=0.5, log_scale=False, exclude_border=False)
Method to locate peaks via the Laplacian of Gaussian Matrices method.
This function wraps
skimage.feature.blob_log()
function and sorts the results for consistency with other peak finding methods.- Parameters:
z (
numpy.ndarray
) – Array of image intensities.min_sigma – Additional parameters to be passed to the
blob_log
method of thescikit-image
library. See its documentation for details: https://scikit-image.org/docs/dev/api/skimage.feature.html#blob-logmax_sigma – Additional parameters to be passed to the
blob_log
method of thescikit-image
library. See its documentation for details: https://scikit-image.org/docs/dev/api/skimage.feature.html#blob-lognum_sigma – Additional parameters to be passed to the
blob_log
method of thescikit-image
library. See its documentation for details: https://scikit-image.org/docs/dev/api/skimage.feature.html#blob-logthreshold – Additional parameters to be passed to the
blob_log
method of thescikit-image
library. See its documentation for details: https://scikit-image.org/docs/dev/api/skimage.feature.html#blob-logoverlap – Additional parameters to be passed to the
blob_log
method of thescikit-image
library. See its documentation for details: https://scikit-image.org/docs/dev/api/skimage.feature.html#blob-loglog_scale – Additional parameters to be passed to the
blob_log
method of thescikit-image
library. See its documentation for details: https://scikit-image.org/docs/dev/api/skimage.feature.html#blob-logexclude_border – Additional parameters to be passed to the
blob_log
method of thescikit-image
library. See its documentation for details: https://scikit-image.org/docs/dev/api/skimage.feature.html#blob-log
- Returns:
peaks – Peak pixel coordinates.
- Return type:
numpy.ndarray
of shape (n_peaks, 2)
- hyperspy.utils.peakfinders2D.find_peaks_max(z, alpha=3.0, distance=10)
Method to locate positive peaks in an image by local maximum searching.
- Parameters:
- Returns:
peaks – Peak pixel coordinates.
- Return type:
numpy.ndarray
of shape (n_peaks, 2)
- hyperspy.utils.peakfinders2D.find_peaks_minmax(z, distance=5.0, threshold=10.0)
Method to locate the positive peaks in an image by comparing maximum and minimum filtered images.
- Parameters:
z (numpy.ndarray) – Matrix of image intensities.
distance (float) – Expected distance between peaks.
threshold (float) – Minimum difference between maximum and minimum filtered images.
- Returns:
peaks – Peak pixel coordinates.
- Return type:
numpy.ndarray
of shape (n_peaks, 2)
- hyperspy.utils.peakfinders2D.find_peaks_stat(z, alpha=1.0, window_radius=10, convergence_ratio=0.05)
Method to locate positive peaks in an image based on statistical refinement and difference with respect to mean intensity.
- Parameters:
z (
numpy.ndarray
) – Array of image intensities.alpha (float) – Only maxima above alpha * sigma are found, where sigma is the local, rolling standard deviation of the image.
window_radius (int) – The pixel radius of the circular window for the calculation of the rolling mean and standard deviation.
convergence_ratio (float) – The algorithm will stop finding peaks when the proportion of new peaks being found is less than convergence_ratio.
- Returns:
peaks – Peak pixel coordinates.
- Return type:
numpy.ndarray
of shape (n_peaks, 2)
Notes
Implemented as described in the PhD thesis of Thomas White, University of Cambridge, 2009, with minor modifications to resolve ambiguities.
The algorithm is as follows:
Adjust the contrast and intensity bias of the image so that all pixels have values between 0 and 1.
For each pixel, determine the mean and standard deviation of all pixels inside a circle of radius 10 pixels centered on that pixel.
If the value of the pixel is greater than the mean of the pixels in the circle by more than one standard deviation, set that pixel to have an intensity of 1. Otherwise, set the intensity to 0.
Smooth the image by convovling it twice with a flat 3x3 kernel.
Let k = (1/2 - mu)/sigma where mu and sigma are the mean and standard deviations of all the pixel intensities in the image.
For each pixel in the image, if the value of the pixel is greater than mu + k*sigma set that pixel to have an intensity of 1. Otherwise, set the intensity to 0.
Detect peaks in the image by locating the centers of gravity of regions of adjacent pixels with a value of 1.
Repeat #4-7 until the number of peaks found in the previous step converges to within the user defined convergence_ratio.
- hyperspy.utils.peakfinders2D.find_peaks_xc(z, template, distance=5, threshold=0.5, **kwargs)
Find peaks in the cross correlation between the image and a template by using the
find_peaks_minmax()
function to find the peaks on the cross correlation result obtained using theskimage.feature.match_template()
function.- Parameters:
z (
numpy.ndarray
) – Array of image intensities.template (numpy.ndarray (square)) – Array containing a single bright disc, similar to those to detect.
distance (float) – Expected distance between peaks.
threshold (float) – Minimum difference between maximum and minimum filtered images.
**kwargs (dict) – Keyword arguments to be passed to the
skimage.feature.match_template()
function.
- Returns:
peaks – Array of peak coordinates.
- Return type:
numpy.ndarray
of shape (n_peaks, 2)
- hyperspy.utils.peakfinders2D.find_peaks_zaefferer(z, grad_threshold=0.1, window_size=40, distance_cutoff=50.0)
Method to locate positive peaks in an image based on gradient thresholding and subsequent refinement within masked regions.
- Parameters:
z (
numpy.ndarray
) – Matrix of image intensities.grad_threshold (float) – The minimum gradient required to begin a peak search.
window_size (int) – The size of the square window within which a peak search is conducted. If odd, will round down to even. The size must be larger than 2.
distance_cutoff (float) – The maximum distance a peak may be from the initial high-gradient point.
- Returns:
peaks – Peak pixel coordinates.
- Return type:
numpy.ndarray
of shape (n_peaks, 2)
Notes
Implemented as described in Zaefferer “New developments of computer-aided crystallographic analysis in transmission electron microscopy” J. Ap. Cryst. This version by Ben Martineau (2016)