paralleldomain.utilities.color_matcher

Contains classes for statistical matching of image color statistics. This is one of the simplest and least artifact causing image style transfer techniques. We found that properly calibrated hue transform improves performance across several tasks.

class ColorMatcher(transformation_matrix)

Precomputed transform that can be applied to images to match the color distributions of two datasets.

Parameters:

transformation_matrix (ndarray) –

__matmul__(other)

Applies the color matching to a rgb/rgba image

Parameters:

other (ndarray) – the image as numpy array

Return type:

ndarray

Returns:

the color transformed image

static from_distributions(source, target)

Calculates the color transform from source to target distribution

Return type:

ColorMatcher

Parameters:
class GaussianColorDistribution

Tracks per channel mean and variance in LAB space

static from_dataset(dataset, use_tqdm=True, max_samples=-1)

Calculates color statistics of images in a dataset

Parameters:
  • dataset (Dataset) – the dataset instance

  • use_tqdm (bool) – shows a progress bar if true

  • max_samples (int) – number of images that are used to calculate images. It takes all images if set to -1

Return type:

GaussianColorDistribution

Returns:

The color distribution object

static from_folder(image_folder, use_tqdm=True)

Calculates color statistics of all images in a folder. Note that this only works on flat folders right now

Parameters:
  • image_folder (Union[str, AnyPath]) – folder with images

  • use_tqdm (bool) – shows a progress bar if true

Return type:

GaussianColorDistribution

Returns:

The color distribution object

static from_image_stream(image_stream, use_tqdm=True)

Calculates the statistics of all images in the given image stream

Parameters:
  • image_stream (Iterator[ndarray]) – Iterator over rgb images

  • use_tqdm (bool) – shows a progress bar if true

Return type:

GaussianColorDistribution

Returns:

The color distribution object

update(x, mask=None)

adds the image colors to the color statistics

Parameters:
  • x (ndarray) – image in rgb

  • mask (Optional[ndarray]) – a binary mask in the shape of the image. If provided, the color distribution is only update with pixels that fall within the mask.

Return type:

None

property to_distribution: ndarray

Transformation that can be used to transform a color value from a unit distribution into this distribution

Returns:

4x4 transformation matrix

property to_unit_distribution: ndarray

Transformation that can be used to transform a color value from this distribution into a unit distribution

Returns:

4x4 transformation matrix