Welcome to viewmask’s documentation!¶
Command Line Interface¶
viewmask¶
viewmask [OPTIONS] COMMAND [ARGS]...
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.
 Return type
list of tuple of int

viewmask.utils.
centers_to_image
(centers, shape=1000, 1000, 3, radius=4)¶ Determine the line color for annotations from a TCGA annotations file.
 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.
shape (tuple of int, optional) – The shape of the mask. shape defaults to (1000, 1000, 3), since most images in the TCGA dataset have a height and width of 1000 pixels and have 3 channels (red, green, and blue). If shape provides a 3rd value with value 3, the centers will be drawn in red; otherwise, if shape has only 2 values, the centers will be drawn in white.
radius (int, optional) – The radius of each center, defaults to 4.
 Returns
rendered_annotations – An Ndimensional NumPy array representing the RGB output image with the shape defined as shape.async
 Return type
numpy.ndarray

viewmask.utils.
file_to_dask_array
(path, tile_size=1000, overlap=0, remove_last=True, allow_unknown_chunksizes=False)¶ Convert SVS, TIF or TIFF to dask array.
 Parameters
svs_file (str) – Image file.
tile_size (int) – Size of chunk to be read in.
overlap (int) – Do not modify, overlap between neighboring tiles.
remove_last (bool) – Remove last tile because it has a custom size.
allow_unknown_chunksizes (bool) – 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
>>> arr = svs2dask_array( ... path, ... tile_size=1000, ... overlap=0, ... remove_last=True, ... allow_unknown_chunksizes=False ... ) >>> arr2 = arr.compute() >>> arr3 = to_pil(cv2.resize( ... arr2, ... dsize=(1440, 700), ... interpolation=cv2.INTER_CUBIC ... )) >>> arr3.save(test_image_name)

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

viewmask.utils.
xml_to_contours
(xml_tree, contour_drawer)¶ Extract contours from a TCGA XML annotations file.
 Parameters
xml_tree (xml.etree.ElementTree) – The XML tree of the TCGA annotations file.
contour_drawer ({'napari', 'cv2'}) – If contour_drawer is ‘napari’ then the contours will be transposed over its main diagonal. When contour_drawer is ‘cv2’, no changes will be made to the returned contours.
 Returns
contours – A list of contours, where each contour is a list of coordinates, where each coordinate is a list with exactly 2 integers, representing the X and Y coordinates, respectively.
 Return type
list of numpy.ndarray
Notes
The main diagonal is defined as the line that connects the topleft corner and the bottom right corner.

viewmask.utils.
xml_to_image
(xml_tree, shape=1000, 1000, 3)¶ Convert a TCGA annotations file to a binary mask.
 Parameters
xml_tree (xml.etree.ElementTree) – The XML tree of the TCGA annotations file.
shape (tuple of int, optional) – The shape of the mask. shape defaults to (1000, 1000, 3), since most images in the TCGA dataset have a height and width of 1000 pixels and have 3 channels (red, green, and blue).
 Returns
rendered_annotations – An Ndimensional NumPy array representing the RGB output image with the shape defined as shape.
 Return type
numpy.ndarray