Image pre-processing

Functions

Collection of pre-processing methods for aligning images

valis.preprocessing.get_luminosity(img, **kwargs)[source]
Get luminosity of an RGB image

Converts and RGB image to the CAM16-UCS colorspace, extracts the luminosity, and then scales it between 0-255

Parameters

img (ndarray) – RGB image

Returns

lum – CAM16-UCS luminosity

Return type

ndarray

valis.preprocessing.match_histograms(src_image, ref_histogram, bins=256)[source]

Source: https://automaticaddison.com/how-to-do-histogram-matching-using-opencv/

This method matches the source image histogram to the reference signal :param image src_image: The original source image :param image ref_image: The reference image :return: image_after_matching :rtype: image (array)

valis.preprocessing.norm_img_stats(img, target_stats, mask=None)[source]

Normalize an image

Image will be normalized to have same stats as target_stats

Based on method in “A nonlinear mapping approach to stain normalization in digital histopathology images using image-specific color deconvolution.”, Khan et al. 2014

Assumes that img values range between 0-255

valis.preprocessing.standardize_colorfulness(img, c=0.2, h=0)[source]

Give image constant colorfulness and hue

Image is converted to cylindrical CAM-16UCS assigned a constant hue and colorfulness, and then coverted back to RGB.

Parameters
  • img (ndarray) – Image to be processed

  • c (int) – Colorfulness

  • h (int) – Hue, in radians (-pi to pi)

Returns

rgb2img with constant hue and colorfulness

Return type

ndarray

Classes

Base ImageProcesser

class valis.preprocessing.ImageProcesser(image, src_f, level, series)[source]

Process images for registration

ImageProcesser sub-classes processes images to single channel images which are then used in image registration.

Each ImageProcesser is initialized with an image, the path to the image, the pyramid level, and the series number. These values will be set during the registration process.

ImageProcesser must also have a process_image method, which is called during registration. As ImageProcesser has the image and and its relevant information (filename, level, series) as attributes, it should be able to access and modify the image as needed. However, one can also pass extra args and kwargs to process_image. As such, process_image will also need to accept args and kwargs.

image

Image to be processed

Type

ndarray

src_f

Path to slide/image.

Type

str

level

Pyramid level to be read.

Type

int

series

The series to be read.

Type

int

__init__(image, src_f, level, series)[source]
Parameters
  • image (ndarray) – Image to be processed

  • src_f (str) – Path to slide/image.

  • level (int) – Pyramid level to be read.

  • series (int) – The series to be read.

process_image(*args, **kwargs)[source]

Pre-process image for registration

Pre-process image for registration. Processed image should be a single channel uint8 image.

Returns

processed_img – Single channel processed copy of image

Return type

ndarray

ChannelGetter

class valis.preprocessing.ChannelGetter(image, src_f, level, series, *args, **kwargs)[source]

Bases: ImageProcesser

Select channel from image

__init__(image, src_f, level, series, *args, **kwargs)[source]
Parameters
  • image (ndarray) – Image to be processed

  • src_f (str) – Path to slide/image.

  • level (int) – Pyramid level to be read.

  • series (int) – The series to be read.

process_image(channel='dapi', adaptive_eq=True, *args, **kwaargs)[source]

Pre-process image for registration

Pre-process image for registration. Processed image should be a single channel uint8 image.

Returns

processed_img – Single channel processed copy of image

Return type

ndarray

ColorfulStandardizer

class valis.preprocessing.ColorfulStandardizer(image, src_f, level, series, *args, **kwargs)[source]

Bases: ImageProcesser

Standardize the colorfulness of the image

__init__(image, src_f, level, series, *args, **kwargs)[source]
Parameters
  • image (ndarray) – Image to be processed

  • src_f (str) – Path to slide/image.

  • level (int) – Pyramid level to be read.

  • series (int) – The series to be read.

process_image(c=0.2, invert=True, *args, **kwargs)[source]

Pre-process image for registration

Pre-process image for registration. Processed image should be a single channel uint8 image.

Returns

processed_img – Single channel processed copy of image

Return type

ndarray

Luminosity

class valis.preprocessing.Luminosity(image, src_f, level, series, *args, **kwargs)[source]

Bases: ImageProcesser

Get luminosity of an RGB image

__init__(image, src_f, level, series, *args, **kwargs)[source]
Parameters
  • image (ndarray) – Image to be processed

  • src_f (str) – Path to slide/image.

  • level (int) – Pyramid level to be read.

  • series (int) – The series to be read.

process_image(*args, **kwaargs)[source]

Pre-process image for registration

Pre-process image for registration. Processed image should be a single channel uint8 image.

Returns

processed_img – Single channel processed copy of image

Return type

ndarray