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 depth_range and num_images specified at instantiation, such that index 0 is the smallest depth, index (num_images - 1) is the largest depth, and the intermediate indices correspond to equally spaced depths in between.

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.

class pyholoscope.FocusStack(img, depth_range, num_depths)
__init__(img, depth_range, num_depths)

Initialise instance of FocusStack class.

Arguments:
imgnumpy.ndarray

example image of the correct size and type, 2D numpy array

num_depths(float, float)

tuple of min depth and max depth in stack

num_depthsint

number of images to be stored in stack

add_depth(img, depth)

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

Arguments:
imgndarray

image as a 2D numpy array

depthfloat

refocus depth of image

add_idx(img, idx)

Adds an image to a specific index position.

Arguments:
imgndarray

image as a 2D numpy array

idxint

index position

depth_to_index(depth)

Returns the index closest to the specified depth.

Arguments:
depthfloat

depth to obtain closest index to

Returns:

int : index

get_depth(depth)

Returns the closest refocused image to the specifed depth.

Arguments:
depthfloat

depth to return image from

Returns:

numpy.ndarray : image

get_depth_intensity(depth)

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

Arguments:
depthfloat

depth to return image from

Returns:

numpy.ndarray : image

get_index(idx)

Returns the refocused image stored at the specified index.

Arguments:
idxint

index position to return image from

Returns:

numpy.ndarray : image

get_index_intensity(idx)

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

Arguments:
idxint

index position to return image from

Returns:

numpy.ndarray : image

index_to_depth(idx)

Returns depth corresponding to the specified index.

Arguments:
idxint

index position

Returns:

float : depth

write_intensity_to_tif(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.

Arguments:
filenamestr

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

Keyword Arguments:
autoContrastboolean

if True (default) images are autoscaled

write_phase_to_tif(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.

Arguments:
filenamestr

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