ReinhardNormalizer

class ReinhardNormalizer[source]

Reinhard colour normalizer.

Normalize a patch colour to the target image using the method of:

Reinhard, Erik, et al. “Color transfer between images.” IEEE Computer graphics and applications 21.5 (2001): 34-41.

This class contains code inspired by StainTools [https://github.com/Peter554/StainTools] written by Peter Byfield.

target_means

Mean of each LAB channel.

Type:

float

target_stds

Standard deviation of each LAB channel.

Type:

float

Examples

>>> from tiatoolbox.tools.stainnorm import ReinhardNormalizer
>>> norm = ReinhardNormalizer()
>>> norm.fit(target_img)
>>> norm_img = norm.transform(src_img)

Initialize ReinhardNormalizer.

Methods

fit

Fit to a target image.

get_mean_std

Get mean and standard deviation of each channel.

lab_split

Convert from RGB uint8 to LAB and split into channels.

merge_back

Take separate LAB channels and merge back to give RGB uint8.

transform

Transform an image.

fit(target)[source]

Fit to a target image.

Parameters:
Return type:

None

get_mean_std(img)[source]

Get mean and standard deviation of each channel.

Parameters:
Returns:

  • float - Means:

    Mean values for each RGB channel.

  • float - Standard deviations:

    Standard deviation for each RGB channel.

Return type:

tuple

static lab_split(img)[source]

Convert from RGB uint8 to LAB and split into channels.

Parameters:

img (numpy.ndarray of type numpy.uint8) – Input image.

Returns:

  • float:

    L channel in LAB colour space.

  • float:

    A channel in LAB colour space.

  • float:

    B channel in LAB colour space.

Return type:

tuple

static merge_back(chan1, chan2, chan3)[source]

Take separate LAB channels and merge back to give RGB uint8.

Parameters:
  • chan1 (float) – L channel.

  • chan2 (float) – A channel.

  • chan3 (float) – B channel.

Returns:

Merged image.

Return type:

numpy.ndarray

transform(img)[source]

Transform an image.

Parameters:
Returns:

Colour normalized RGB image.

Return type:

numpy.ndarray of type numpy.float