MultichannelToRGB¶

class MultichannelToRGB(color_dict=None)[source]¶

Class to convert multi-channel images to RGB images.

Initialize the MultichannelToRGB converter.

Parameters:
  • color_dict (dict[str, tuple[float, float, float]] | None) – Dict of channel names with RGB colors for each channel. If not

  • provided

  • auto-generated. (a set of distinct colors will be)

Methods

generate_colors

Generate a set of visually distinct colors.

validate

Validate the input color_dict on first read from image.

__call__(image)[source]¶

Convert a multi-channel image to an RGB image.

Parameters:
  • image (np.ndarray) – Input image of shape (H, W, N)

  • self (MultichannelToRGB)

Returns:

RGB image of shape (H, W, 3)

Return type:

np.ndarray

generate_colors(n_channels)[source]¶

Generate a set of visually distinct colors.

Parameters:
Returns:

Array of RGB colors

Return type:

np.ndarray

validate(n)[source]¶

Validate the input color_dict on first read from image.

Checks that n is either equal to the number of colors provided, or is one less. In the latter case it is assumed that the last channel is background autofluorescence and is not in the tiff and we will drop it from the color_dict with a warning.

Parameters:
Return type:

None