ActImgBinary#

Warning

This library and its documentation are still under development.

This section documents the ActImgBinary class, its methods, and helpers.

ActImgBinary class and attributes#

meshure.actimg_binary.ActImgBinary(image_stack: ndarray = None, title: str = None, shape: tuple = None, depth: int = None, deconvolved: bool = None, resolution: float = None, meta: dict = None, manipulated_stack: array = None, manipulated_depth: int = 0, binary_mesh: ndarray = None) None#

ActImgBinary is a class which helps quantify the actin mesh in binary images. … .. attribute:: binary_mesh

type:

np.array=None

ActImgBinary methods#

meshure.actimg_binary.ActImgBinary.surface_area(self, n_dilations_erosions: tuple = (3, 4), closing_structure: bool | None = None, extra_dilate_fill: bool = True, verbose: bool = False, return_outpt: bool = False)#

Returns the surface area and associated units. Note: the algorithm uses serial dilations to include the periphery of the cell even if the cell boundary is discontinuous. The dilations are followed by an equivalent number of serial erosions to avoid overestimating the cell area. Note: it is assumed that the largest object in the field of view is the cell which is to be segmented.

Return type:

if the cell is not segmented, this is recorded separately

meshure.actimg_binary.ActImgBinary.mesh_density(self, verbose: bool = False, return_outpt: bool = False)#

Returns the mesh density as a % value. This is defined as the percentage of the mesh / filled_cell_surface Note: the outline is included in the calculation. This does not necessarily match the image signal in the case of discontinuous cell surfaces.

meshure.actimg_binary.ActImgBinary.peripheral_mesh_density(self, verbose: bool = False, return_outpt: bool = False)#

Returns the peripheral mesh density as a % value. This is defined as [ 100 * actin_mesh_area / (filled_cell_surface - largest hole in cell) ] Note: the outline is included in the calculation.

meshure.actimg_binary.ActImgBinary.mesh_holes_area(self, unit: str = 'um', saturation_area: float | None = None, visualise: bool = False, return_outp: bool = False, scale_bar: bool = True, bar_locate: str = 'upper left')#

Returns the labels by area and visualises mesh holes coloured by area size with specified unit and saturation

meshure.actimg_binary.ActImgBinary.visualise_segmentation(self, save: bool = False, dest_dir: str = '/home/docs/checkouts/readthedocs.org/user_builds/actinmeshure/checkouts/latest/docs/source', scale_bar: bool = True, bar_locate: str = 'upper left')#

Visualise the segmentation steps: binary mesh, cell surface, mesh holes.

Parameters:
  • save (bool=False) – Save plot to dest_dir. Displayed but not saved by default.

  • dest_dir (str=os.getcwd()) – Directory to save plot in (defaults to current working directory)

  • colmap (str='inferno') – Change color map (passed to cmap argument) in matplotlib.pyplot. Perceptually uniform colour map used by default.

  • scale_bar (bool=True) – Adding a scale bar to images by default (provided, resolution is available).

  • bar_locate (str='upper_left') – Position of scale bar; upper left by default.

Returns:

A tiled plot of three panels: binary mesh (mask), cell surface (filled cell contour), mesh holes (inverted mask).

Return type:

matplotlib.pyplot

meshure.actimg_binary.ActImgBinary.quantify_mesh(self)#
meshure.actimg_binary.ActImgBinary.save_estimated_parameters(self, dest_dir: str = '/home/docs/checkouts/readthedocs.org/user_builds/actinmeshure/checkouts/latest/docs/source')#

Saves estimated parameters in JSON and CSV format.

Parameters:

dest_dir (str or Path) – Path of destination where the JSON file should be saved; defaults to current working directory.

Return type:

A JSON and/or CSV file with the estimated parameters in the ActImgBinary object and the resolution-related parameters from self.resolution.

meshure.actimg_binary.ActImgBinary.save_log(self, dest_dir: str = '/home/docs/checkouts/readthedocs.org/user_builds/actinmeshure/checkouts/latest/docs/source', dest_file: str | None = None)#

ActImgBinary hidden methods#

meshure.actimg_binary.ActImgBinary._get_contour(self, img_in=None, n_dilations: int = 0, closing_structure: any | None = None, return_outpt: bool = False)#

Returns the longest contour as a mask, all contours detected, and the index of the longest contour. Note: close and dilate image serially to ensure robustness to small gaps and inconsistencies in cell boundary; find contours and the index of the longest contour; map contours onto self mask. Default behaviour: copy binary mesh and get largest contour = cell surface. Note: there is a 1 pixel additional margin because get_boundaries returns a float index (half a pixel is permissible); therefore, the boundary is two-pixels thick, rounding up and down. …

Parameters:
  • n_dilations=3 – Number of serial dilations, can be adjusted to avoid introducing artifacts.

  • closing_structure (array-like, =None) – Structure used to fill in small, presumably unwanted gaps in original segmentation.

Returns:

  • contour_img (np.ndarray (m, n)) – A mask with the longest contour (=1).

  • contours (list of np.ndarrays) – A list of all detected contours.

  • (contour_ceil, contour_floor) (tuple of np.ndarrays) – Rounded coordinates mapped onto contour_img.

  • ind_max (int) – The index of the longest contour in contours.

meshure.actimg_binary.ActImgBinary._fill_contour_img(self, img_in=None, n_erosions: int = 2, extra_dilate_fill: bool = True, return_outpt: bool = False)#

Returns a filled mask of the cell surface. Uses serial erosions to avoid artifacts.

Parameters:
  • contour_img (np.ndarray) – Binary mask of a cell contour, output of _get_contour()

  • n_erosions (bool=4) – Number of serial erosions which prevent the creation of artifacts. Should be one more than the ones introduced in _get_contour() for greatest degree of accuracy.

  • extra_dilate_fill (bool=True) – An optional additional dilation and filling step to capture any small areas which may be otherwise missed.

Returns:

eroded_contour_img – A mask with the filled and thinned cell surface; mapped to filled_contour_img attribute.

Return type:

nd.array (m,n)

meshure.actimg_binary.ActImgBinary._check_boundaries(self, img_in=None, contour_in=None, return_outpt: bool = False)#

Check if contour touches image boundaries. If yes, check how many points are touching a given boundary. If < 5 points are touching the boundary, their range will be used to fill (min, max). If > 5 points are touching the boundary on one axis, segmentation will fail. If the surface area is too large or too small, this will be raised appropriately.

Parameters:

contour_img (np.ndarray (m,n)) – A mask with the longest contour (=1); returned by _get_contour().

Returns:

log – A log detailing the kind of error expected in case of unsuccessful mesh segmentation.

Return type:

dict

meshure.actimg_binary.ActImgBinary._clean_up_surface(self, close_very_small_holes: bool = True, return_outpt: bool = False)#

Returns a cell surface that has been cleaned up with dilation/erosion artifacts.

meshure.actimg_binary.ActImgBinary._get_img_time(self, time_units: str = 'min')#

Return the time of the cell image from the title.

Only works with titles where information is split with ‘_’.

Parameters:

time_units (str='min') – Units which are taken as a key word.

Returns:

img_time – Time condition associated with image file, e.g. 3min.

Return type:

str

ActImgBinary helpers#

meshure.actimg_binary.get_ActImgBinary(actimg)#

Returns an ActImgBinary instance given a related ActImg.

Parameters:

actimg (ActImg) – An instance of the ActImg class.