wormpose.dataset.image_processing.image_utils

Image processing example implementation for segmenting the worm in an image

class wormpose.dataset.image_processing.image_utils.ConstantThreshold(threshold_value)[source]

Threshold function that always returns the same threshold

class wormpose.dataset.image_processing.image_utils.OtsuThreshold(blur_kernel)[source]

Calculates automatic Otsu threshold on the blurred frame

Creates an Otsu threshold operation with a preprocessing gaussian blur

Parameters

blur_kernel – Gaussian Kernel Size for the blur operation before the Otsu threshold method to split background and foreground. [height width]. height and width should be odd and can have different values.

wormpose.dataset.image_processing.image_utils.segment_foreground(frame: numpy.ndarray, foreground_close_struct_element, foreground_dilate_struct_element, threshold_fn: Callable[numpy.ndarray, int], is_foreground_lighter_than_background: bool)[source]

Processes a frame to isolate the object of interest (worm) from the background

Parameters
  • frame – image to process

  • foreground_close_struct_element – morphological element to close holes in the foreground mask

  • foreground_dilate_struct_element – morphological element to expand the foreground mask

  • threshold_fn – function that will return the threshold to separate foreground from background in a frame

  • is_foreground_lighter_than_background – set to True if the foreground object of interest is lighter (pixel values are on average higher) than the background

Returns

segmentation mask with values of 1 for the worm object and 0 for the background, and average value of the background pixels