Image pre-processing
Functions
Collection of pre-processing methods for aligning images
- valis.preprocessing.create_tissue_mask_from_multichannel(img, kernel_size=3)[source]
Get foreground of multichannel imaage
- valis.preprocessing.create_tissue_mask_from_rgb(img, brightness_q=0.99, kernel_size=3, gray_thresh=0.075, light_gray_thresh=0.875, dark_gray_thresh=0.7)[source]
Create mask that only covers tissue
Also remove dark regions on the edge of the slide, which could be artifacts
- Parameters:
- Returns:
tissue_mask (ndarray) – Mask covering tissue
concave_tissue_mask (ndarray) – Similar to tissue_mask, but each region is replaced by a concave hull. Covers more area
- 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.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.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
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
ChannelGetter
- class valis.preprocessing.ChannelGetter(image, src_f, level, series, *args, **kwargs)[source]
Bases:
ImageProcesser
Select channel from image
ColorfulStandardizer
- class valis.preprocessing.ColorfulStandardizer(image, src_f, level, series, *args, **kwargs)[source]
Bases:
ImageProcesser
Standardize the colorfulness of the image
StainFlattener
BgColorDistance
- class valis.preprocessing.BgColorDistance(image, src_f, level, series, *args, **kwargs)[source]
Bases:
ImageProcesser
Calculate distance between each pixel and the background color
Luminosity
- class valis.preprocessing.Luminosity(image, src_f, level, series, *args, **kwargs)[source]
Bases:
ImageProcesser
Get luminosity of an RGB image
H&E deconvolution
- class valis.preprocessing.HEDeconvolution(image, src_f, level, series, *args, **kwargs)[source]
Bases:
ImageProcesser
Normalize staining appearence of hematoxylin and eosin (H&E) stained image and get the H or E deconvolution image.
Reference
A method for normalizing histology slides for quantitative analysis. M. Macenko et al., ISBI 2009.
- process_image(stain='hem', Io=240, alpha=1, beta=0.15, *args, **kwargs)[source]
Reference
A method for normalizing histology slides for quantitative analysis. M. Macenko et al., ISBI 2009.
Note
Adaptation of the code from https://github.com/schaugf/HEnorm_python.