histomicstk.preprocessing.color_conversion

This package contains utility functions to convert images between different color spaces.

histomicstk.preprocessing.color_conversion.lab_mean_std(im_input, mask_out=None)[source]

Compute the mean and standard deviation of the intensities.

… of each channel of the given RGB image in LAB color space. The outputs of this function is for reinhard normalization.

Parameters
  • im_input (array_like) – An RGB image

  • mask_out (array_like) – if not None, uses numpy masked array functionality to only keep non-masked areas when calculating mean and standard deviation.

Returns

  • mean_lab (array_like) – A 3-element array containing the mean of each channel of the input RGB in LAB color space.

  • std_lab (array_like) – A 3-element array containing the standard deviation of each channel of the input RGB in LAB color space.

  • mask_out (array_like, default is None) – if not None, should be (m, n) boolean numpy array. This method uses numpy masked array functionality to only use non-masked areas in calculations. This is relevant because elements like blood, sharpie marker, white space, etc would throw off the reinhard normalization by affecting the mean and stdev. Ideally, you want to exclude these elements from both the target image (from which you calculate target_mu and target_sigma) and from the source image to be normalized.

See also

histomicstk.preprocessing.color_conversion.rgb_to_lab, histomicstk.preprocessing.color_conversion.reinhard

References

1

E. Reinhard, M. Adhikhmin, B. Gooch, P. Shirley, “Color transfer between images,” in IEEE Computer Graphics and Applications, vol.21, no.5,pp.34-41, 2001.

2

D. Ruderman, T. Cronin, and C. Chiao, “Statistics of cone responses to natural images: implications for visual coding,” J. Opt. Soc. Am. A vol.15, pp.2036-2045, 1998.

histomicstk.preprocessing.color_conversion.lab_to_rgb(im_lab)[source]

Transforms an image from LAB to RGB color space

Parameters

im_lab (array_like) – An image in LAB color space

Returns

im_rgb – The RGB representation of the input image ‘im_lab’.

Return type

array_like

References

3

D. Ruderman, T. Cronin, and C. Chiao, “Statistics of cone responses to natural images: implications for visual coding,” J. Opt. Soc. Am. A 15, 2036-2045 (1998).

histomicstk.preprocessing.color_conversion.od_to_rgb(im_od)[source]

Transforms input optical density image im_od into RGB space

Parameters

im_od (array_like) – A floating-point image of optical density values obtained from rgb_to_od.

Returns

im_rgb – A floating-point multi-channel image with intensity values in the range [0, 255].

Return type

array_like

histomicstk.preprocessing.color_conversion.rgb_to_hsi(im)[source]

Convert to HSI the RGB pixels in im.

Adapted from https://en.wikipedia.org/wiki/HSL_and_HSV#Hue_and_chroma.

histomicstk.preprocessing.color_conversion.rgb_to_lab(im_rgb)[source]

Transforms an image from RGB to LAB color space

Parameters

im_rgb (array_like) – An RGB image

Returns

im_lab – LAB representation of the input image im_rgb.

Return type

array_like

References

4

D. Ruderman, T. Cronin, and C. Chiao, “Statistics of cone responses to natural images: implications for visual coding,” J. Opt. Soc. Am. A vol.15, pp.2036-2045, 1998.

histomicstk.preprocessing.color_conversion.rgb_to_od(im_rgb)[source]

Transforms input RGB image im_rgb into optical density space for color deconvolution.

Parameters

im_rgb (array_like) – A floating-point RGB image with intensity ranges of [0, 255].

Returns

im_od – A floating-point image of corresponding optical density values.

Return type

array_like

histomicstk.preprocessing.color_conversion.rgb_to_sda(im_rgb, I_0, allow_negatives=False)[source]

Transform input RGB image or matrix im_rgb into SDA (stain darkness) space for color deconvolution.

Parameters
  • im_rgb (array_like) – Image (MxNx3) or matrix (3xN) of pixels

  • I_0 (float or array_like) – Background intensity, either per-channel or for all channels

  • allow_negatives (bool) – If False, would-be negative values in the output are clipped to 0

Returns

im_sda – Shaped like im_rgb, with output values 0..255 where im_rgb >= 1

Return type

array_like

Note

For compatibility purposes, passing I_0=None invokes the behavior of rgb_to_od.

histomicstk.preprocessing.color_conversion.sda_to_rgb(im_sda, I_0)[source]

Transform input SDA image or matrix im_sda into RGB space. This is the inverse of rgb_to_sda with respect to the first parameter

Parameters
  • im_sda (array_like) – Image (MxNx3) or matrix (3xN) of pixels

  • I_0 (float or array_like) – Background intensity, either per-channel or for all channels

Note

For compatibility purposes, passing I_0=None invokes the behavior of od_to_rgb.