The methods described in this section are only available for two-dimensional
signals in the
Signal registration and alignment
# Estimate shifts, then align the images >>> shifts = s.estimate_shift2D() >>> s.align2D(shifts=shifts) # Estimate and align in a single step >>> s.align2D()
s.align2D() will modify the data in-place. If you don’t want
to modify your original data, first take a copy before aligning.
Sub-pixel accuracy can be achieved in two ways:
for multi-dimensional datasets only, using the statistical method [Schaffer2004], by setting the
referencekeyword argument to
# skimage upsampling method >>> shifts = s.estimate_shift2D(sub_pixel_factor=20) # stat method >>> shifts = s.estimate_shift2D(reference="stat") # combined upsampling and statistical method >>> shifts = s.estimate_shift2D(reference="stat", sub_pixel_factor=20)
If you have a large stack of images, you can perform the image alignment step in
parallel by passing
parallel=True. You can control the number of threads used
max_workers argument. See the map documentation
for more information.
# Estimate shifts >>> shifts = s.estimate_shift2D() # Align images in parallel using 4 threads >>> s.align2D(shifts=shifts, parallel=True, max_workers=4)
Cropping an image
crop_image() method crops the
image in-place e.g.:
>>> im = hs.datasets.example_signals.object_hologram() >>> imc = im.crop(left=120, top=300, bottom=560) # im is cropped in-place
Cropping in HyperSpy is performed using the Signal indexing syntax. For example, to crop an image:
>>> im = hs.datasets.example_signals.object_hologram() >>> # im is not cropped, imc is a "cropped view" of im >>> imc = im.isig[120.:, 300.:560.]
It is possible to crop interactively using Region Of Interest (ROI). For example:
>>> im = hs.datasets.example_signals.object_hologram() >>> roi = hs.roi.RectangularROI(left=120, right=460., top=300, bottom=560) >>> im.plot() >>> imc = roi.interactive(im) >>> imc.plot()
Add a linear ramp
A linear ramp can be added to the signal via the
add_ramp() method. The parameters
ramp_x and ramp_y dictate the slope of the ramp in x- and y direction,
while the offset is determined by the offset parameter. The fulcrum of the
linear ramp is at the origin and the slopes are given in units of the axis
with the according scale taken into account. Both are available via the
AxesManager of the signal.
New in version 1.6.
find_peaks() method provides access
to a number of algorithms for peak finding in two dimensional signals. The
methods available are:
Maximum based peak finder
>>> s.find_peaks(method='local_max') >>> s.find_peaks(method='max') >>> s.find_peaks(method='minmax')
These methods search for peaks using maximum (and minimum) values in the
image. There all have a
distance parameter to set the minimum distance
between the peaks.
'local_max'method uses the
thresholdparameters are mapped to
'max'method uses the
find_peaks_max()function to search for peaks higher than
alpha * sigma, where
alphais parameters and
sigmais the standard deviation of the image. It also has a
distanceparameters to set the minimum distance between peaks.
'minmax'method uses the
find_peaks_minmax()function to locate the positive peaks in an image by comparing maximum and minimum filtered images. Its
thresholdparameter defines the minimum difference between the maximum and minimum filtered images.
Zaeferrer peak finder
This algorithm was developed by Zaefferer [Zaefferer2000].
It is based on a gradient threshold followed by a local maximum search within a square window,
which is moved until it is centered on the brightest point, which is taken as a
peak if it is within a certain distance of the starting point. It uses the
find_peaks_zaefferer() function, which can take
distance_cutoff as parameters. See
find_peaks_zaefferer() function documentation
for more details.
Ball statistical peak finder
Described by White [White2009], this method is based on finding points that
have a statistically higher value than the surrounding areas, then iterating
between smoothing and binarising until the number of peaks has converged. This
method can be slower than the others, but is very robust to a variety of image types.
It uses the
find_peaks_stat() function, which can take
convergence_ratio as parameters. See the
find_peaks_stat() function documentation for more
Matrix based peak finding
>>> s.find_peaks(method='laplacian_of_gaussians') >>> s.find_peaks(method='difference_of_gaussians')
These methods are essentially wrappers around the
Laplacian of Gaussian (
skimage.feature.blob_log()) or the difference
of Gaussian (
skimage.feature.blob_dog()) methods, based on stacking
the Laplacian/difference of images convolved with Gaussian kernels of various
standard deviations. For more information, see the example in the
>>> x, y = np.meshgrid(np.arange(-2, 2.5, 0.5), np.arange(-2, 2.5, 0.5)) >>> template = hs.model.components2D.Gaussian2D().function(x, y) >>> s.find_peaks(method='template_matching', template=template)
Many of the peak finding algorithms implemented here have a number of tunable parameters that significantly affect their accuracy and speed. The GUIs can be used to set to select the method and set the parameters interactively:
Several widgets are available:
The method selector is used to compare different methods. The last-set parameters are maintained.
The parameter adjusters will update the parameters of the method and re-plot the new peaks.
Some methods take significantly longer than others, particularly where there are a large number of peaks to be found. The plotting window may be inactive during this time.