Granule Detection#

The first step is to locate the granule within the frame. As these are from microscopy images, we assume that the background of the image will be dark and the granules bright regions.

As the granules are much typically much brighter than the cytoplasm within the cell, a simple thresholding method works will in most cases. However, particularly in the case of transfected cells, the cytoplasm of one cell may be brighter than the granules in another cell, which makes threshold based detection of all the granules impossible.

Therefore, by default this uses the Difference of Gaussian (DoG) method, with the core implementation is provided by scikit image. This is a much more robust method to detect bright granules among a noisy background.

We also provide the Laplacian of Gaussian method, this avoids some of the approximations made in the DoG method and so is better at detecting smaller granules (10s of pixels total area). However, the runtime scales poorly when detecting larger granules and the smaller granules detected by the LoG method are too small for accurate fluctuation analysis, so DoG is typically for that case.

Both the DoG and LoG methods require an estimate of the expected of the granule size to be detected; if the microscope file contains PhysicalSize of a pixel we choose sensible defaults for stress granules

Implementation#

This provides a GranuleDetector_DoG class that takes a Frame object, label_granules detects the granules within the image and creates a mask array with 0 for the background and 1 for the granules foreground, labelled_granules is an array with the same shape of the input image, with a unique image for each granule. Granules in contact from the boundary are removed.

Source#

Locate the granules within the MicroscopeFrame.

Outline#

We provide two methods to locate the granule within the Frame.

flickerprint.common.granule_locator.DoG()#

Difference of Gaussian - this

flickerprint.common.granule_locator.Objects()#
-------
flickerprint.common.granule_locator.Granule()#

An image of the granule and the surrounding area, along with the location and other metadata, including a rough estimate of the granule boundary.

class flickerprint.common.granule_locator.Granule(im_data, property_row, padding=5)#

Container for a crop of the the microscope image containing the granule.

Extends the crop from the granule detection by padding pixels to help with boundary drawing. This retains the metadata from the microscope frame.

class flickerprint.common.granule_locator.GranuleDetector(frame: MicroscopeFrame)#

Detector for the granules in the image.

mask#

A binary image, with pixels belonging to a granules 1, and background 0.

Type:

np.ndarray, dtype=bool

labelled_granules#

An image with each the extent of granule given as an unique integer, 0 corresponds to the background.

Type:

np.ndarray, dtype=int

Parameters:
  • Frame (MicroscopeFrame) – Current MicroscopeFrame

  • min_size (float = 0.3) – Smallest size of granule to detect. If a pixel size is provided then this will be assumed to be in μm, otherwise this will be in pixels.

  • max_size (float = 3.0) – Largest granule to detect. See above.

  • processed_image (the processed version of the image to be used for granule detection)

granules:

Iterator of Granule objects

labelGranules:

Create the labelled_granules array from the starting image. This should perform all steps required to generate Granules.

plot:

Show the detection of granules within the frame.

granules(padding=5) Iterator[Granule]#

Iterator for the granules detected by in this frame.

labelGranules()#

Label the granules within the images.

This creates an integer array with each granules labeled with a difference integer.

plot(ax=None, save_path: Path | None = None, cmap='viridis')#

Show the labelled granules within the image.

If no ax is provided then create a new matplotlib axis and save to save_path.

exception flickerprint.common.granule_locator.GranuleNotFoundError#

Raise this Exception if no granules are found.

This can be useful to explicitly catch awkward edge cases where empty arrays of granules will cause troubles.

with_traceback()#

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

flickerprint.common.granule_locator.thresholdDetector()#

Otsu based detection.