bioimageloader.base#

Define a base class and its interface

Dataset is the base of all datasets

MaskDataset is the base of datasets that have mask annotation

class bioimageloader.base.DatasetInterface[source]#

Dataset interface

Attributes
__repr__

Print info of dataset

__len__
__getitem__

Given index returns a dictionary of key(s) and array

acronym
root_dir

Path to root directory

file_list

A list of pathes to image files

Methods

get_image(key)

Get an image

abstract get_image(key)[source]#

Get an image

abstract class property acronym#

Assign acroym for a subclass dataset

abstract property root_dir#

Path to root directory

property file_list#

A list of pathes to image files

class bioimageloader.base.Dataset[source]#

Base to define common attributes and methods for [MaskDataset, …]

Notes

Required attributes in subclass
  • anno_dict

  • __getitem__()

  • get_image()

Attributes
__repr__

Print info of dataset

__len__

Length of dataset.

__iter__
root_dir

Path to root directory

output

Determine return(s) when called, fixed to ‘image’

transforms

Transform images and masks

num_samples

Number of calls that will override __len__

grayscaleoptional

Flag for grayscale conversion

grayscale_modeoptional

Determine grayscale mode one of {‘cv2’, ‘equal’, Sequence[float]}

num_channelsoptional

Number of image channels used for to_gray()

Methods

__getitem__(ind)

Get image

_drop_missing_pairs()

Drop images and reindex the anno list (dict)

to_gray(arr[, grayscale_mode, num_channels])

Convert bioimage to grayscale

property root_dir: pathlib.Path#

Path to root directory

property output: str#

Determine return(s) when called, fixed to ‘image’

property transforms: Optional[albumentations.core.composition.Compose]#

Transform images and masks

property num_samples: Optional[int]#

Number of calls that will override __len__

property grayscale: Optional[bool]#

Flag for grayscale conversion

property grayscale_mode: Optional[Union[str, Sequence[float]]]#

Determine grayscale mode one of {‘cv2’, ‘equal’, Sequence[float]}

property num_channels: Optional[int]#

Number of image channels used for to_gray()

static to_gray(arr: numpy.ndarray, grayscale_mode: Optional[Union[str, Sequence[float]]] = None, num_channels: int = 3) numpy.ndarray[source]#

Convert bioimage to grayscale

Parameters
arrimage array

Numpy image array whose shape is (h, w, 3)

grayscale_modestr or sequence of float, optional

Choose a strategy for gray conversion. Three options are availble. Either one of {‘cv2’, ‘equal’} or be a sequence of float numbers, which indicate linear weights of each channel.

num_channelsint

Explicitly set number of channels for grayscale_mode=’equal’.

class bioimageloader.base.MaskDataset[source]#

Base for datasets with mask annotation

Define __getitem__ method to load mask annotation paired with image. Pre-defined attributes are prefixed with a single underscore to distinguish them from those specific to a dataset. It is required to implement two methods: get_image() and get_mask() as well as acronym and _root_dir for each subclass.

See also

Dataset

super class

Notes

Required attributes in subclass
  • acronym

  • _root_dir

  • _output

  • _grayscale (optional)

  • _grayscale_mode (optional)

  • _num_channels (optional)

  • get_image()

  • get_mask() (optional)

Attributes
output

Determine return(s) when called

anno_dict

Dictionary of pathes to annotation files

Methods

__getitem__(ind)

Get image, mask, or both depending on output argument

property output: str#

Determine return(s) when called

property anno_dict: Dict[int, Any]#

Dictionary of pathes to annotation files

get_mask(key) numpy.ndarray[source]#

Get a mask

class bioimageloader.base.IterDataset(dataset: bioimageloader.base.Dataset)[source]#