stain_augment
absorbance_to_image(absorbance, source_intensity=255, dtype=torch.uint8)
Convert an absorbance (optical density) image back to a standard image. Parameters
ndarray
The absorbance image to convert back to a linear intensity range.
float, optional
Reference intensity for image. This should match what was used with
rgb_to_absorbance when creating absorbance.
numpy.dtype, optional
The datatype to cast the output image to.
Returns
ndarray
An image computed from the absorbance
image_to_absorbance(image, source_intensity=255.0, dtype=torch.float32)
Convert an image to units of absorbance (optical density). Parameters
ndarray
The image to convert to absorbance. Can be single or multichannel.
float, optional
Reference intensity for image.
numpy.dtype, optional
The floating point precision at which to compute the absorbance.
Returns
ndarray
The absorbance computed from image.
Notes
If image has an integer dtype it will be clipped to range
[1, source_intensity], while float image inputs are clipped to range
``[source_intensity/255, source_intensity]. The minimum is to avoid log(0).
Absorbance is then given by
.. math::
absorbance = \log{\frac{image}{source_intensity}}.
stain_extraction_pca(image, source_intensity=240, alpha=1, beta=0.345, ref_stain_coeff=((0.5626, 0.2159), (0.7201, 0.8012), (0.4062, 0.5581)), channel_axis=0, image_type='intensity')
Extract the matrix of H & E stain coefficient from an image. Uses a method that selects stain vectors based on the angle distribution within a best-fit plane determined by principle component analysis (PCA) [1]_. Parameters
cp.ndarray
RGB image to perform stain extraction on. Intensities should typically
be within unsigned 8-bit integer intensity range ([0, 255]) when
image_type == "intensity".
float, optional
Transmitted light intensity. The algorithm will clip image intensities
above the specified source_intensity and then normalize by
source_intensity so that image intensities are <= 1.0. Only used
when image_type=="intensity".
float, optional
Algorithm parameter controlling the [alpha, 100 - alpha]
percentile range used as a robust [min, max] estimate.
float, optional
Absorbance (optical density) threshold below which to consider pixels as transparent. Transparent pixels are excluded from the estimation.
Additional Parameters
int, optional
The axis corresponding to color channels (default is the last axis).
{"intensity", "absorbance"}, optional
With the default image_type of "intensity", the image will be
transformed to absorbance units via image_to_absorbance. If
the input image is already an absorbance image, then image_type
should be set to "absorbance" instead.
Returns
cp.ndarray
Stain attenuation coefficient matrix derived from the image, where the first column corresponds to H, the second column is E and the rows are RGB values.
Notes
The default beta of 0.345 is equivalent to the use of 0.15 in [1]_. The
difference is due to our use of the natural log instead of a decadic log
(log10) when computing the absorbance.
References
.. [1] M. Macenko et al., "A method for normalizing histology slides for quantitative analysis," 2009 IEEE International Symposium on Biomedical Imaging: From Nano to Macro, 2009, pp. 1107-1110, doi: 10.1109/ISBI.2009.5193250. http://wwwx.cs.unc.edu/~mn/sites/default/files/macenko2009.pdf