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)

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 seperate LAB channels and merge back to give RGB uint8.

transform

Transform an image.

fit(target)[source]

Fit to a target image.

Parameters

target (numpy.ndarray of type numpy.uint8) – target image.

get_mean_std(img)[source]

Get mean and standard deviation of each channel.

Parameters

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

Returns

mean values for each RGB channel. stds (float): standard deviation for each RGB channel.

Return type

means (float)

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

L. chan2 (float): A. chan3 (float): B.

Return type

chan1 (float)

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

Take seperate 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

ndarray uint8

transform(img)[source]

Transform an image.

Parameters

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

Returns

colour normalized RGB

image.

Return type

numpy.ndarray of type numpy.float