Welcome to viewmask’s documentation!¶
Command Line Interface¶
viewmask¶
viewmask [OPTIONS] COMMAND [ARGS]...
Options

version
¶
Show the version and exit.
Package¶

viewmask.utils.
centers_of_contours
(contours)¶ Return the centers of a list of OpenCV contours.
 Parameters
contours (list of numpy.ndarray) – A list of cv2 contours; each contour’s center will be calculated. Each contour is a list with 1 element, which is a list with 2 elements, representing the X and Y coordinates as integers, respectively.
 Returns
centers – A list of coordinates, where each coordinate is a tuple with exactly 2 ints, representing the X and Y coordinates, respectively. Each coordinate represents the center of the corresponding contour in contours. In this method, the center is defined as the centroid of the contour. If the centroid cannot be calculated, the circumcenter of the center is used.
 Return type
list of tuple of int

viewmask.utils.
centers_to_image
(centers, radius=4, write_color=[255, 0, 0], shape=None)¶ Draw coordinates of centers to a static image.
 Parameters
centers (list of tuple of int) – A list of coordinates, where each coordinate is a tuple with exactly 2 ints, representing the X and Y coordinates, respectively. Each coordinate represents the center of the corresponding contour in contours.
radius (int, optional) – The radius of each center, defaults to 4.
write_color (array_like of int, optional) – The RGB color that should be used to draw the centers, defaults to [255, 0, 0], which is red. write_color have a length of 3; each integer represents red, green, and blue, respectively.
shape (tuple of int, optional) – The shape of the output image. Defaults to (x_max, y_max, 3), where x_max are the maximum xcoordinate and ycoordinate, respectively, of the centers.
 Returns
rendered_annotations – An Ndimensional NumPy array representing the RGB output image with the shape defined as shape.
 Return type
numpy.ndarray

viewmask.utils.
file_to_dask_array
(path, tile_size=1000, overlap=0, remove_last=True, allow_unknown_chunksizes=False)¶ Load an image to a dask array.
 Parameters
path (str) – The path to the image file as a string.
tile_size (int, optional) – Size of chunk to be read in.
overlap (int, optional) – Do not modify, overlap between neighboring tiles.
remove_last (bool, optional) – Remove last tile because it has a custom size.
allow_unknown_chunksizes (bool, optional) – Allow different chunk sizes, more flexible, but slowdown.
 Returns
arr – A Dask Array representing the contents of the image file.
 Return type
dask.array.Array
Examples
>>> da_img = file_to_dask_array(path) >>> npa_img = arr.compute() # convert the dask array to a numpy array >>> pil_img = Image.fromarray(cv2.resize( ... npa_img, ... dsize=(1440, 700), ... interpolation=cv2.INTER_CUBIC ... )) >>> pil_img.save(test_image_name)

viewmask.utils.
fit_spline_to_points
(points)¶ Fits a Bspline through a sequence of points.
 Parameters
points (numpy.ndarray) – A list of sample vector arrays representing the curve.
 Returns
spline_points – An Ndimensional NumPy array representing the RGB output image with the shape defined as shape.
 Return type
numpy.ndarray

viewmask.utils.
get_hematoxylin
(rgb)¶ Extract the hematoxylin layer from an RGB image.
 Parameters
rgb ((.., 3) array_like) – The RGB input image to process.
 Returns
arr_hema – A 2dimensional array representing the hematoxylin intensity.
 Return type
ndarray
 Raises
ValueError – If rgb is not at least 2D with shape (…, 3).
References
 1
A. C. Ruifrok and D. A. Johnston, “Quantification of histochemical staining by color deconvolution.,” Analytical and quantitative cytology and histology / the International Academy of Cytology [and] American Society of Cytology, vol. 23, no. 4, pp. 2919, Aug. 2001.
Examples
>>> from skimage import data >>> from viewmask.utils import get_hematoxylin >>> rgb = data.immunohistochemistry() >>> he_layer = get_hematoxylin(rgb)

viewmask.utils.
get_stroke_color
(xml_tree)¶ Determine the line color for annotations from a TCGA annotations file.
 Parameters
xml_tree (xml.etree.ElementTree) – The XML tree of the TCGA annotations file.
 Returns
line_color – A string representing the proper hex code to use for the stroke color. The output is always 6 characters and does not include the hashtag.
 Return type
str

viewmask.utils.
mask_to_contours
(mask)¶ Determine the line color for annotations from a TCGA annotations file.
 Parameters
mask (numpy.ndarray) – A NumPy Ndimensional array representing the image. If mask has 3 dimensions, the image is assumed to be RGB, and will be converted to grayscale. If mask only has 2 dimensions, the image is assumed to be grayscale. The values in the input should be in the range [0, 255].
 Returns
contours – A list of contours, where each contour is a list of coordinates, where each coordinate is a list of a list of X and Y integers.
 Return type
list of numpy.ndarray