FocusStack Class

The FocusStack class is used to store (but not generate) a stack of images refocused to a range of distances or depths. An instance of this class is returned by methods such as Holo.depth_stack().

The class stores the images internally as a 3D numpy array. The depth corresponding to each index in the array is calculated based on the depthRange and numImages specified at instantiation, such that index 0 is the smallest depth, index (numImages - 1) is the largest depth, and the intermediate indices correspond to equally spaced depths inbetweeen.

Images can be added either by index (i.e. position in the stack) using add_idx or by their associated depth, in which case the add_depth method calculates the closest index to the specified depth. Both methods will overwrite existing data. Similarly, images can be retrieved using the get_index or get_depth methods, with get_depth returning the image stored at the index corresponding to the depth closest to the requested depth.

Instantiatation

FocusStack(img, depthRange, numImages)

img is a numpy array of the same size and data type as the images to be stored (the pixel values are irrelevant, this is used purely to initialise a 3D array to store the images). depthRange is a tuple of (min_depth, max_depth) that the class will store, and numImages is the number of images that will be stored, equally spaced within the depth range.

Note that FocusStack does not create the refocused images, it is used to store the output of a function such as Holo.depth_stack().

Methods

pyholoscope.FocusStack.add_idx(self, img, idx)

Adds an image to a specific index position.

Parameters:
imgndarray

image as a 2D numpy array

idxint

index position

pyholoscope.FocusStack.add_depth(self, img, depth)

Adds an image to index position closest to the the specifed depth.

Parameters:
imgndarray

image as a 2D numpy array

depthfloat

refocus depth of image

pyholoscope.FocusStack.depth_to_index(self, depth)

Returns the index closest to the specified depth.

Parameters:
depthfloat

depth to obtain closest index to

Returns:

int, index

pyholoscope.FocusStack.get_index(self, idx)

Returns the refocused image stored at the specified index.

Parameters:
idxint

index position to return image from

Returns:

ndarray, image

pyholoscope.FocusStack.get_depth(self, depth)

Returns the closest refocused image to the specifed depth.

Parameters:
depthfloat

depth to return image from

Returns:

ndarray, image

pyholoscope.FocusStack.get_depth_intensity(self, depth)

Returns the amplitude of the refocused image closest to the specified depth.

Parameters:
depthfloat

depth to return image from

Returns:

ndarray, image

pyholoscope.FocusStack.get_index_intensity(self, idx)

Return the amplitude of the refocused image at the specified index.

Parameters:
idxint

index position to return image from

Returns:

ndarray, image

pyholoscope.FocusStack.index_to_depth(self, idx)

Returns depth corresponding to the specified index.

Parameters:
idxint

index position

Returns:

float, depth

pyholoscope.FocusStack.write_intensity_to_tif(self, filename, autoContrast=True)

Writes the amplitudes of the stack of refocused images to a 16 bit tif stack If autoContrast == True, all images will be autoscaled (across the whole stack, not individually) to use the full bit depth.

Parameters:
filenamestr

path/file to save to, should have .tif extension.

Keyword Arguments:
autoContrastboolean

if True (default) images are autoscaled

pyholoscope.FocusStack.write_phase_to_tif(self, filename)

Writes the phases of the stack of refocused images to a 16 bit tif stack -pi is mapped to 0, pi is mapped to 255.

Parameters:
filenamestr

path/file to save to, should have .tif extension.