bioimageloader.utils#
Classic utils module
- class bioimageloader.utils.MaskDatasetProto(*args, **kwargs)[source]#
Static typing protocol for MaskDataset
- bioimageloader.utils.random_label_cmap(n=65536, h=(0, 1), l=(0.4, 1), s=(0.2, 0.8))[source]#
Random color map for labels (credit: StarDist team) [1]
Need matplotlib
- bioimageloader.utils.imread_asarray(p: pathlib.Path, dtype=None) numpy.ndarray [source]#
Read an image using PIL then convert it into numpy array
- bioimageloader.utils.rle_decoding_inseg(size: Union[tuple, list], run_lengths: List[List[int]]) numpy.ndarray [source]#
Decoding RLE (Run Length Encoding). Output binary mask. If you want each instance have different values, use rle_decoding_inseg(), instead.
- Parameters
- sizelist or tuple
Shape of the original image array (height, width)
- run_lengthslist
List of run length encodings
- valint or float
Constant value for all encoded pixels
- Returns
- decodednumpy.ndarray
Decoded image array
- bioimageloader.utils.random_split_dataset(dataset: bioimageloader.utils.MaskDatasetProto, lengths: Sequence[int]) List[bioimageloader.base.MaskDataset] [source]#
Randomly split dataset and return subsets
- bioimageloader.utils.split_dataset_by_indices(dataset: bioimageloader.utils.MaskDatasetProto, indices: Sequence[int]) List[bioimageloader.base.MaskDataset] [source]#
Split dataset given indices
- bioimageloader.utils.stack_channels(imread_handler: Callable[[pathlib.Path], numpy.ndarray], p_lst: List[pathlib.Path], *axis_order: int) numpy.ndarray [source]#
Take a list of multi-channel images whose channels are separated in each file and read them in specified order.
The order of channels follows the order of each list by default. If *axis_order is explicitely given, the function will put channels in that order.
- Parameters
- imread_handlerCallable
Func to read images e.g.) PIL.Image.open
- p_lstlist of file path
A list of file path. Each element refers to one channel.
- axis_orderint(s)
Additional arguments to indicate the order of channels. It should match the number of channels of the return. For example, 3 arguments if num_channels <= 3, else n arguments elif num_channels=`n`
- bioimageloader.utils.stack_channels_to_rgb(imread_handler: Callable[[pathlib.Path], numpy.ndarray], p_lst: List[pathlib.Path], *axis_order: int) numpy.ndarray [source]#
Many transforms work for either RGB or gray scale images. Having RGB is also helpful for visualization.
Take a list of multi-channel images whose channels are separated in each file and read them in specified order. If the number of channels is less than or equal to 3, then array will be assumed as a RGB image. Otherwise, it it returns an array with the same number of channels of the input.
The order of channels follows the order of each list by default. If *axis_order is explicitely given, the function will put channels in that order.
- Parameters
- imread_handlerCallable
Func to read images e.g.) PIL.Image.open | tifffile.imread
- p_lsta list of Paths
A list of Path objects. Each element refers to one channel
- axis_orderint(s)
Additional arguments to indicate the order of channels. It should match the number of channels of the return. For example, 3 arguments if num_channels <= 3, else n arguments elif num_channels=`n`
- bioimageloader.utils.bundle_list(lst: List[bioimageloader.utils.T], bundle_size: int) List[List[bioimageloader.utils.T]] [source]#
Reshape a list given the repetition step size
- bioimageloader.utils.expand_to_rgb(image: numpy.ndarray, dtype: Optional[str] = None) numpy.ndarray [source]#
Expand axis of image that has 2 channels to have 3 channels mainly for visualization
- bioimageloader.utils.get_dataset_from_directory(root_dir: str, *, output: Optional[str] = None, transforms: Optional[albumentations.core.composition.Compose] = None, num_samples: Optional[int] = None, grayscale: Optional[bool] = None, grayscale_mode: Optional[Union[str, Sequence[float]]] = None) bioimageloader.base.Dataset [source]#
Construct MaskDataset by assuming the structure of given directory
>>> case1/ ├── image00.tif ├── image01.tif ├── image02.tif ├── image03.tif ├── image04.tif ├── image05.tif ├── image06.tif ├── image07.tif ├── image08.tif └── image09.tif
- bioimageloader.utils.get_maskdataset_from_directory(root_dir: str, *, image_dir: Optional[str] = None, label_dir: Optional[str] = None, output: Optional[str] = None, transforms: Optional[albumentations.core.composition.Compose] = None, num_samples: Optional[int] = None, grayscale: Optional[bool] = None, grayscale_mode: Optional[Union[str, Sequence[float]]] = None) bioimageloader.base.MaskDataset [source]#
Construct MaskDataset by assuming the structure of given directory
>>> case3/ ├── images │ ├── 00.png │ ├── 01.png │ ├── 02.png │ ├── 03.png │ └── 04.png └── labels ├── 00.tif ├── 01.tif ├── 02.tif ├── 03.tif └── 04.tif