fusion_tools package

fusion_tools.handler module

class fusion_tools.handler.DSATool

Bases: Tool

A sub-class of Tool specific to DSA components. The only difference is that these components always update relative to the session data.

Parameters:

Tool (None) – General class for components that perform visualization and analysis of data.

class fusion_tools.handler.Handler

Bases: object

fusion_tools.tileserver module

Tile server components

class fusion_tools.tileserver.CustomTileServer(tiles_url: str, regions_url: str, image_metadata: dict, annotations_url: str | None = None, name: str = None)

Bases: TileServer

CustomTileServer component if using some other tiles endpoint (must pass tileSize and levels in dictionary)

class fusion_tools.tileserver.DSATileServer(api_url: str, item_id: str, user_token: str | None = None)

Bases: TileServer

Use for linking visualization with remote tiles API (DSA server)

class fusion_tools.tileserver.LocalTileServer(local_image_path: str | list | None = [], local_image_annotations: str | list = [], tile_server_port: int = 8050, host: str = 'localhost')

Bases: TileServer

Tile server from image saved locally. Uses large-image to read and parse image formats (default: [common])

add_new_image(new_image_path: str, new_annotations: str | list | dict | None, new_metadata: dict | None = None)
get_annotations(image: int)
get_metadata(image: int)

Getting large-image metadata for image

Returns:

Dictionary containing metadata for local image

Return type:

Response

get_name_annotations_url(name)
get_name_metadata_url(name)
get_name_regions_url(name)
get_name_tiles_url(name)
get_names()
get_region(image: int, top: int, left: int, bottom: int, right: int, style: str = '')

Grabbing a specific region in the image based on bounding box coordinates

get_thumbnail(image: int)

Grabbing an image thumbnail

Parameters:

image (int) – _description_

get_tile(image: int, z: int, x: int, y: int, style: str = '')

Tiles endpoint, returns an image tyle based on provided coordinates

Parameters:
  • z (int) – Zoom level for tile

  • x (int) – X tile coordinate

  • y (int) – Y tile coordinate

  • style (dict, optional) – Additional style arguments to pass to large-image, defaults to {}

Returns:

Image tile containing bytes encoded pixel information

Return type:

Response

load_annotations()
root()
start()

Starting tile server instance on a provided port

Parameters:

port (str, optional) – Tile server port from which tiles are accessed, defaults to ‘8050’

class fusion_tools.tileserver.TileServer

Bases: object

Components which pull information from a slide(s)

fusion_tools.dataset module

Dataset sub-module for fusion-tools

class fusion_tools.dataset.ClassificationDataset(slides: list = [], annotations: list | dict | None = None, label_property: list | str | None = None, transforms: None | Callable = None, label_transforms: None | Callable = None, patch_size: list = [256, 256], patch_mode: str = 'bbox', patch_region: str | list | dict = 'all', spatial_filters: list | None = None, property_filters: list | None = None, use_structures: str | list = 'all', use_cache: bool = True, shuffle: bool = True, seed_val: int = 1701, verbose: bool = False, use_parallel: bool = True, n_jobs: int = 1)

Bases: object

export_configs(save_path: str)
gen_slide_patches()
get_next_image(idx: int)
make_image_and_label(bbox: list, slide_idx: int, features: list)
make_patch(bbox: list, slide_idx: int, annotations: GeoDataFrame)
plant_seed(seed_val)
process_annotations()
class fusion_tools.dataset.FUSIONDataset(slides: list = [], annotations: list | dict | None = None, image_transforms: Callable | None = None, target_transforms: Callable | None = None, patch_size: list = [256, 256], patch_mode: str = 'bbox', patch_region: str | list | dict = 'all', overlap: float | None = None, spatial_filters: list | None = None, property_filters: list | None = None, use_cache: bool = False, shuffle: bool = True, seed_val: int = 1701, verbose: bool = False, use_parallel: bool = True, n_jobs: int = 1)

Bases: object

find_tissue()
gen_slide_patches()
plant_seed(seed_val)
process_annotations()
class fusion_tools.dataset.SegmentationDataset(slides: list = [], annotations: list | dict | None = None, transforms: None | Callable = None, target_transforms: None | Callable = None, mask_key: dict | None = None, patch_size: list = [256, 256], patch_mode: str = 'bbox', patch_region: str | list | dict = 'all', spatial_filters: list | None = None, property_filters: list | None = None, use_structures: str | list = 'all', use_cache: bool = True, shuffle: bool = True, seed_val: int = 1701, verbose: bool = False, use_parallel: bool = True, n_jobs: int = 1)

Bases: object

export_configs(save_path: str)
find_tissue(slide_tile_source, slide_metadata)
gen_slide_patches()
get_next_image(idx: int)
make_image_and_mask(bbox: list, slide_idx: int, features: list)
make_patch(bbox: list, slide_idx: int, annotations: GeoDataFrame)
plant_seed(seed_val)
process_annotations()

fusion_tools.feature_extraction module

Feature extraction functions

class fusion_tools.feature_extraction.ParallelFeatureExtractor(image_source: str | TileServer = None, feature_list: list = [], preprocess: Callable | None = None, sub_mask: Callable | None = None, mask_names: list | None = None, channel_names: list | None = None, n_jobs: None = None, verbose: bool = False)

Bases: object

This class is for extracting multiple types of features at the same time using joblib

extract_features(region: dict) dict
get_bbox(coords: list) list
make_mask(coords: list) ndarray
merge_dict(a: dict, b: dict, path=[])
read_image_region(coords: list) ndarray
start(region_list: list) DataFrame
update_dict_keys(input_dict: dict)
fusion_tools.feature_extraction.color_features(image: ndarray, mask: ndarray, coords: list) dict

Calculate “color” features for each label in mask within image (color defined as channel statistics)

Parameters:
  • image (np.ndarray) – Input image region

  • mask (np.ndarray) – Mask of regions to include in the feature calculation (0=background)

  • coords (list) – Coordinates of this specific image (not used)

Returns:

Dictionary containing key/value pairs for each feature extracted (Mean, Median, Maximum, Std)

Return type:

dict

fusion_tools.feature_extraction.distance_transform_features(image: ndarray, mask: ndarray, coords: list) dict

Function to calculate distance transform features for each label in “mask”

Parameters:
  • image (np.ndarray) – Input image region (not used)

  • mask (np.ndarray) – Mask of regions to include in the feature calculation (0=background)

  • coords (list) – Coordinates of this specific image (not used)

Returns:

Dictionary containing key/value pairs for each feature extracted (Mean, Median, Maximum, Sum)

Return type:

dict

fusion_tools.feature_extraction.morphological_features(image: ndarray, mask: ndarray, coords: list) dict

Calculate morphological features for each label in mask within image.

Parameters:
  • image (np.ndarray) – Input image region (not used)

  • mask (np.ndarray) – Mask of regions to include in the feature calculation (0=background)

  • coords (list) – Coordinates of this specific image (not used)

Returns:

Dictionary containing key/value pairs for each feature extracted (Contrast, Homogeneity, Correlation, Energy)

Return type:

dict

fusion_tools.feature_extraction.relative_distance(input_shapes: dict, other_shapes: dict | list) list

Calculate relative distance statistics between each Feature in “input_shapes” (GeoJSON FeatureCollection) and each Feature in each FeatureCollection in “other_shapes”

Parameters:
  • input_shapes (dict) – FeatureCollection containing Features to calculate relative distance statistics for each FeatureCollection in other_shapes

  • other_shapes (Union[dict,list]) – List of multiple FeatureCollections or single FeatureCollection where relative distance statistics are calculated off of for input_shapes

fusion_tools.feature_extraction.texture_features(image: ndarray, mask: ndarray, coords: list) dict

Calculate texture features for each label in mask within image.

Parameters:
  • image (np.ndarray) – Input image region

  • mask (np.ndarray) – Mask of regions to include in the feature calculation (0=background)

  • coords (list) – Coordinates of this specific image (not used)

Returns:

Dictionary containing key/value pairs for each feature extracted (Contrast, Homogeneity, Correlation, Energy)

Return type:

dict

fusion_tools.feature_extraction.threshold_channels(input_image: ndarray, threshold_method: str | None = None) ndarray

Example preprocessing function that thresholds each channel in the input image according to some method

Parameters:
  • input_image (np.ndarray) – Input image region (Y,X,C)

  • threshold_method (Union[str,None], optional) – Method to use for thresholding (None is set to Otsu’s), defaults to None

Returns:

Returns image with each channel thresholded independently

Return type:

np.ndarray