automated_microscopy package

Submodules

automated_microscopy.drift_correction module

class automated_microscopy.drift_correction.drift_correction(lowres_PosList, highres_PosList, lowres_zspacing, highres_zspacing, highresShape_width, highresShape_height, timepoint, imageRepoLists, debugfilepath='path.txt')

Bases: object

This class provides the tools to guide high-resolution acquisition using low-resolution images (multi-scale microscopy) for self-driving microscopy over long time periods.

__init__(lowres_PosList, highres_PosList, lowres_zspacing, highres_zspacing, highresShape_width, highresShape_height, timepoint, imageRepoLists, debugfilepath='path.txt')

Initiate self-driving module

Parameters:
  • lowres_PosList – the list of position of the low resolution imaging

  • highres_PosList – the list of position of the high resolution imaging

  • lowres_zspacing – the plane spacing of the low resolution stacks

  • highres_zspacing – the plane spacing of the high resolution stacks

  • highresShape_width – width of image, convention: np.array(height, width) and cv2.function(width, height)

  • highresShape_height – height of image (here: highres max 2048)

  • lowresShape_width – width of image, convention: np.array(height, width) and cv2.function(width, height)

  • lowresShape_height – height of low res image (here: lowres max 5092)

  • filepath – (optional) filepath to logging the drift correction

calculate_Lateral_drift(PosNumberID)

Finds the new (current) lateral position of the region of interest (PosNumberID) in the corresponding low-resolution view by calling the template matching function.

Parameters:

PosNumber – unique ID of high-resolution region of interest to find (correct its position)

Returns:

(rownumber, columnnumber, crop_height, crop_width) - the new position of the region of interest in the low-resolution image.

calculate_axialdrift(PosNumber, image1, image2)

Calculates axial drift correction based on low-resolution view.

Parameters:
  • image1 – Maximum intensity projection in axial direction 1 (xz) around laterally corrected position.

  • image2 – Maximum intensity projection in axial direction 2 (yz) around laterally corrected position

  • PosNumber – Unique ID of high-resolution view to correct

Returns:

correction factor, if previous time-point images have been saved in the image repository.

calculate_pixelcoord_from_physicalcoordinates(coordinates_lowres, coordinates_highres, lowresshape)

Calulate pixel coordinates from physical stage coordinates (important at first timepoint to match region of interest to low-resolution data).

Parameters:
  • coordinates_lowres – stage coordinates of lowres image

  • coordinates_highres – stage coordinates of highres image

  • lowresshape – shape of low-resolution image

Returns:

(loc, pixel_width_highresInLowres, pixel_height_highresInLowres) with loc being the location and the new image width and height after scaling

find_closestLowResTile(PosNumber, return_number=False)

Find corresponding low resolution stack to selected (high-resolution) region of interest (PosNumber) (at the same angle).

Parameters:
  • PosNumber – unique ID of highres view (note: not index).

  • return_number – if True, return number e.g. 1, if False return string for filename “low_stack000”

Returns:

Based on the input of return_number, returns either the corresponding file name of the low resolution stack (e.g. “low_stack000”) which is closest to the high res stack or its number (e.g. “1”)

find_corresponsingHighResTiles(LowResPosNumber)

Find all high resolution stacks that are closest to a given low res view (at the same angle)

Parameters:

LowResPosNumber – position of the low resolution view in the lowres position list.

Returns:

list of all highres stacks PosNumbers which are assigned to low resolution stack.

indicate_driftcorrectionCompleted(PosNumber)

Indicate that correction for PosNumber has been finished by setting array value to 1.

Parameters:

PosNumber – unique ID of position

Returns:

update completed array

register_image(ref, mov, mode)

Register two images (ref, mov) to each other using StackReg.

Parameters:
  • ref – reference image

  • mov – moving image

  • mode – rigid (if mode==’rigid’), else translation

Returns:

lateral shift (xshift, yshift)

automated_microscopy.image_deposit module

class automated_microscopy.image_deposit.images_InMemory_class

Bases: object

Image repository class.

This class is generating an image repository with the (maximum intensity projection) images for calculations of drift correction, template matching and other smart microscopy applications.

__init__()

Initialize images_InMemory_class with empty placeholders.

addNewImage(whichlist, PosNumber, image)

Add an image newly to a selected list (whichlist) at position number PosNumber

Parameters:
  • whichlist – which list to add image - options: “current_lowRes_Proj”, “previous_lowresProj”, “current_highRes_Proj”, “previous_highRes_Proj”, “current_transmissionImage”, “previous_transmissionImage”, “current_highRes_Axial1Proj”, “previous_highRes_Axial1Proj”, “current_highRes_Axial2Proj”, “previous_highRes_Axial2Proj”, “current_transmissionAxial1Image”, “current_transmissionAxial2Image”,”previous_transmissionAxial1Image”, “previous_transmissionAxial2Image”

  • PosNumber – the corresponding position number

  • image – the image to add

image_retrieval(whichlist, PosNumber)

Get an image from a list.

Parameters:
  • whichlist – which list to retrieve image - options: “current_lowRes_Proj”, “previous_lowresProj”, “current_highRes_Proj”, “previous_highRes_Proj”, “current_transmissionImage”, “previous_transmissionImage”, “current_highRes_Axial1Proj”, “previous_highRes_Axial1Proj”, “current_highRes_Axial2Proj”, “previous_highRes_Axial2Proj”, “current_transmissionAxial1Image”, “current_transmissionAxial2Image”,”previous_transmissionAxial1Image”, “previous_transmissionAxial2Image”

  • PosNumber – what is the Position Number (PosNumber) associated with the image

Returns:

image, or if image is not found returns an array with value zero: np.array([0]) for easy checking

replaceImage(whichlist, PosNumber, image)

Replace an image at index PosNumber in the list “whichlist” with new image (image).

Parameters:
  • whichlist – which list to add image - options: “current_lowRes_Proj”, “previous_lowresProj”, “current_highRes_Proj”, “previous_highRes_Proj”, “current_transmissionImage”, “previous_transmissionImage”, “current_highRes_Axial1Proj”, “previous_highRes_Axial1Proj”, “current_highRes_Axial2Proj”, “previous_highRes_Axial2Proj”, “current_transmissionAxial1Image”, “current_transmissionAxial2Image”,”previous_transmissionAxial1Image”, “previous_transmissionAxial2Image”

  • PosNumber – the corresponding position number

  • image – the image to add

Returns:

updated list in class

reset()

Resets class to default value (without any images saved).

automated_microscopy.template_matching module

class automated_microscopy.template_matching.automated_templateMatching

Bases: object

This class provides the methods for template matching.

__init__()

Initiate the class with template matching methods

scaling_templateMatching(searchimage_sc, template_sc, scaling_factor, showimage=False)

Performs template matching across different scales.

Parameters:
  • searchimage – the big image, in which we want to find the template

  • template – highres image which we want to find in the low-res / big image

  • scaling_factor – if images have different scales, set it here

  • showimage – show image when executing template matching

Returns:

(row_number, column_number) of the max value of template matching

scaling_templateMatching_multiprocessing(searchimage_sc, template_sc, scaling_factor, showimage=False)

Performs template matching across different scales, accelerated by multiple processors (for each scale one process).

Parameters:
  • searchimage_sc – the big image, in which we want to find the template

  • template_sc – image which we want to find in the low-res / big image

  • scaling_factor – if images have different scales, set it here

  • showimage – show image when executing template matching

Returns:

(row_number, column_number) of the max value of template matching

simple_templateMatching(searchimage, template, scaling_factor, showimage=False)

Performs simple template matching

Parameters:
  • searchimage – the big image, in which we want to find the template

  • template – highres image which we want to find in the low-res / big image

  • scaling_factor – scaling of the highres image (template) to match image dimensions of low res image

  • showimage – show image when executing template matching

Returns:

(row_number, column_number) of the max value

template_processing_subprocess(lock, scale, template_resized, searchimage_sc, queue)

Function called by scaling_templateMatching_multiprocessing for multi-processed template matching. Updates queue with values

Parameters:
  • lock – lock for multi-processing

  • scale – current scale applied for multi-scale template matching

  • template_resized – image which we want to find in the low-res / big image

  • searchimage_sc – the big image, in which we want to find the template

  • queue – results queue of multi-processing

automated_microscopy.template_matching.random() x in the interval [0, 1).

Module contents