added plotting capabilities and tests (note: no colorbar yet for colorized plt)

This commit is contained in:
Maddie Cain
2019-04-08 03:56:23 -04:00
parent d0897f1dff
commit 8aeb25bb41
4 changed files with 199 additions and 25 deletions
+9 -10
View File
@@ -7,10 +7,10 @@ from CDTools.tools import cmath
def centroid(im, dims=2):
"""Returns the centroid of an image or a stack of images
By default, the last two dimensions are used in the calculation
and the remainder of the dimensions are passed through.
Beware that the meaning of the centroid is not well defined if your
image contains values less than 0
@@ -34,14 +34,14 @@ def centroid(im, dims=2):
def centroid_sq(im, dims=2, comp=False):
"""Returns the centroid of the square of an image or stack of images
By default, the last two dimensions are used in the calculation
and the remainder of the dimensions are passed through.
If the "comp" flag is set, it will be assumed that the last dimension
represents the real and imaginary part of a complex number, and the
centroid will be calculated for the magnitude squared of those numbers
Args:
im (t.Tensor) : An image or stack of images to calculate from
dims (int) : Default 2, how many trailing dimensions to calculate for
@@ -56,13 +56,13 @@ def centroid_sq(im, dims=2, comp=False):
return centroid(im_sq, dims=dims)
def find_subpixel_shift(im1, im2, search_around=(0,0), resolution=10):
"""Calculates the subpixel shift between two images by maximizing the autocorrelation
This function only searches in a 2 pixel by 2 pixel box around the
specified search_around parameter. The calculation is done using the
approach outlined in "Efficient subpixel image registration algorithms",
approach outlined in "Efficient subpixel image registration algorithms",
Optics Express (2008) by Manual Guizar-Sicarios et al.
Args:
@@ -77,7 +77,7 @@ def find_pixel_shift(im1, im2):
This function simply takes the circular correlation with an FFT and
returns the position of the maximum of that correlation
Args:
im1 (t.Tensor): The first real or complex-valued torch tensor
im2 (t.Tensor): The second real or complex-valued torch tensor
@@ -93,10 +93,9 @@ def find_shift(im1, im2, resolution=10):
This function starts by calculating the maximum shift to integer
pixel resolution, and then searchers the nearby area to calculate a
subpixel shift
Args:
im1 (t.Tensor): The first real or complex-valued torch tensor
im2 (t.Tensor): The second real or complex-valued torch tensor
resolution (int): Default is 10, the resolution to calculate to in units of 1/n
"""