dystrack.pipelines.center_of_mass#

Tracking/stabilizing simple samples based on the center of mass.

See also here.

dystrack.pipelines.center_of_mass.analyze_image(target_path, channel=None, method='intensity', gauss_sigma=3.0, count_reduction=0.5, await_write=2, warn_8bit=True, show=False, verbose=False)#

Compute new coordinates for the scope to track/stabilize tissues based on the center of mass of either intensity values directly or masks derived using simple masking methods.

The following masking methods are currently implemented:
  • “intensity”: get center of mass directly from intensity values; best for tracking sparsely labeled tissues

  • “otsu”: use Otsu’s method to threshold, then retain only the largest object and get the center of mass of its mask; best for tracking compact objects / densely labeled tissues.

  • “objct”: use object-count method to threshold, then retain only the largest object and get the center of mass of its mask; can succeed in some cases where Otsu is thrown off by structured background.

Parameters:
  • target_path (path-like) – Path to the image file that is to be analyzed.

  • channel (int, optional, default None) – Index of channel to use for masking in case of multi-channel images. If not specified, a single-channel image is assumed.

  • method (str, optional, default "intensity") – Masking method. One of “intensity”, “otsu”, or “objct”. See doc string header for details.

  • gauss_sigma (float, optional, default 3.0) – Sigma for Gaussian filter prior to masking.

  • count_reduction (float, optional, default 0.5) – Factor by which object count has to be reduced below its initial peak for a threshold value to be accepted. Only relevant if method is set to “objct”.

  • await_write (int, optional, default 2) – Seconds to wait between each check of the target file size to determine if the file is still being written to. Reducing this will shave off latency but increases the risk of race conditions.

  • warn_8bit (bool, optional, default True) – Whether to emit a warning when a non-8bit image was found and was down- converted to 8bit using min-max rescaling.

  • show (bool, optional, default False) – Whether to show the threshold plot and the mask. Default is False. Note that figures will be shown without blocking execution, so if many iterations are performed, many figures will be opened. Also, note that all figures will be closed when the python process exits.

  • verbose (bool, optional, default False) – If True, more information is printed.

Returns:

  • z_pos, y_pos, x_pos (floats) – New coordinates for the next acquisition. For 2D inputs, z_pos is 0.0.

  • img_msg (“_”) – A string output message; required by DySTrack but here unused and just set to “_”.

  • img_cache ({}) – A dictionary to be passed as keyword arguments to future calls to the pipeline; required by DySTrack but here unused and just set to {}.