Utils¶
Visualization Utils¶
Visualization utilities.
-
staintools.utils.visual.build_stack(images)[source]¶ Build a stack of images from a tuple/list of images.
Parameters: images – A tuple/list of images. Returns:
-
staintools.utils.visual.patch_grid(ims, width=5, sub_sample=False, rand=False, save_name=None)[source]¶ Display a grid of patches.
Parameters: - ims – A patch ‘stack’
- width – Images per row.
- sub_sample – Should we take a subsample?
- rand – Randomize subsample?
Returns:
-
staintools.utils.visual.read_image(path)[source]¶ Read an image to RGB uint8. Read with opencv (cv) and covert from BGR colorspace to RGB.
Parameters: path – The path to the image. Returns: RGB uint8 image.
Misc Utils¶
Other utilities.
-
staintools.utils.misc.OD_to_RGB(OD)[source]¶ Convert from optical density (OD_RGB) to RGB RGB = 255 * exp(-1*OD_RGB)
Parameters: OD – Optical denisty RGB image. Returns: Image RGB uint8.
-
staintools.utils.misc.RGB_to_OD(I)[source]¶ Convert from RGB to optical density (OD_RGB) space. RGB = 255 * exp(-1*OD_RGB).
Parameters: I – Image RGB uint8. Returns: Optical denisty RGB image.
-
staintools.utils.misc.array_equal(A, B, eps=1e-09)[source]¶ Are arrays A and B equal?
Parameters: - A – Array.
- B – Array.
- eps – Tolerance.
Returns: True/False.
-
staintools.utils.misc.check_image(x)[source]¶ Check if is an image. If gray make sure it is ‘squeezed’ correctly.
Parameters: x – Input. Returns: True/False.
-
staintools.utils.misc.is_gray_image(x)[source]¶ Is x a gray image?
Parameters: x – Input. Returns: True/False.
-
staintools.utils.misc.is_image(x)[source]¶ Is x an image? i.e. numpy array of 2 or 3 dimensions.
Parameters: x – Input. Returns: True/False.
-
staintools.utils.misc.is_uint8_image(x)[source]¶ Is x a uint8 image?
Parameters: x – Input. Returns: True/False.
-
staintools.utils.misc.normalize_rows(A)[source]¶ Normalize the rows of an array.
Parameters: A – An array. Returns: Array with rows normalized.
-
staintools.utils.misc.notwhite_mask(I, thresh=0.8)[source]¶ Get a binary mask where true denotes ‘not white’. Specifically, a pixel is not white if its luminance (in LAB color space) is less than the specified threshold.
Parameters: - I – RGB uint 8 image.
- thresh – Luminosity threshold.
Returns: Binary mask where true denotes ‘not white’.
-
staintools.utils.misc.remove_zeros(I)[source]¶ Remove zeros in an image, replace with 1’s.
Parameters: I – An Array. Returns: New array where 0’s have been replaced with 1’s.