mzbsuite module
Here we detail the main classes and functions in mzbsuite.
mzb_classification_dataloader
- class mzbsuite.classification.mzb_classification_dataloader.Denormalize(mean, std)[source]
De-normalizes an image given its mean and standard deviation.
- class mzbsuite.classification.mzb_classification_dataloader.MZBLoader(dir_dict, ls_inds=[], learning_set='all', transforms=None, glob_pattern='*_rgb.*')[source]
Class definition for the dataloader for the macrozoobenthos dataset.
- Parameters:
dir_dict (dict) – dictionary containing the paths to the folders of the dataset
ls_inds (list) – indices of images to be used for the learning set, optional
learning_set (str) – type of learning set to be used, optional, default: ‘all’
transforms (torchvision.transforms) – list of transformations to apply to blobs. Optional, default: None
glob_pattern (str) – glob pattern to use for finding images. Optional, default: ‘_rgb.’
- static prepare_data(dir_dict: dict, ls_inds: list = [], glob_pattern: str = '*_rgb.*') tuple[source]
Prepare data for training and testing, returns image paths, labels and indices
- Parameters:
dir_dict (dict) – dictionary with keys as class names and values as paths to images
ls_inds (list) – list of indices to be used for training or testing
glob_pattern (str) – glob pattern to use for finding images
- Returns:
img_paths – list of paths to images
- Return type:
list
mzb_classification_pilmodel
mzb_skeletons_dataloader
- class mzbsuite.skeletons.mzb_skeletons_dataloader.MZBLoader_skels(im_folder, bo_folder, he_folder, ls_inds=[], learning_set='all', transforms=None)[source]
Class definition for the dataloader for the macrozoobenthos skeletons dataset.
- Parameters:
im_folder (Path) – folder path of input images
bo_folder (Path) – folder path of body length skeleton masks
he_folder (Path) – folder path of head length skeleton masks
ls_inds (list) – indices of images to be used for the learning set, optional
learning_set (str) – type of learning set to be used, optional, default: ‘all’
transforms (torchvision.transforms) – optional, default: None
mzb_skeletons_pilmodel
mzb_skeletons_helpers
- class mzbsuite.skeletons.mzb_skeletons_helpers.Denormalize(mean, std)[source]
Denormalize a tensor image with mean and standard deviation, for plotting purposes.
- mzbsuite.skeletons.mzb_skeletons_helpers.get_endpoints(skeleton: ndarray) List[Tuple[int, int]][source]
Given a skeletonised image, it will give the coordinates of the endpoints of the skeleton.
- Parameters:
skeleton (numpy.ndarray) – The skeletonised image to detect the endpoints of
- Returns:
endpoints – List of 2-tuples (x,y) containing the intersection coordinates
- Return type:
list
- mzbsuite.skeletons.mzb_skeletons_helpers.get_intersections(skeleton: ndarray) List[Tuple[int, int]][source]
Given a skeletonised image, it will give the coordinates of the intersections of the skeleton.
- Parameters:
skeleton (np.ndarray) – Binary image of the skeleton
- Returns:
intersections – List of 2-tuples (x,y) containing the intersection coordinates
- Return type:
list
- mzbsuite.skeletons.mzb_skeletons_helpers.neighbours(x, y, image)[source]
Return 8-neighbours of image point P1(x,y), in a clockwise order
- Parameters:
x (int) – x-coordinate of the point
y (int) – y-coordinate of the point
image (numpy.ndarray) – The image to find the neighbours of
- Returns:
_ – List of 8-neighbours of the point in the image
- Return type:
list
- mzbsuite.skeletons.mzb_skeletons_helpers.paint_image(image: ndarray, mask: array, color: List[float]) ndarray[source]
Given an input image, a binary mask indicating where to paint, and a color to use, returns a new image where the pixels within the mask are colored with the specified color.
- Parameters:
(np.ndarray) (image) –
(np.array) (mask) –
(List[float]) (color) –
- Returns:
rgb_fi (np.ndarray)
- Return type:
New image with painted-in mask.
- mzbsuite.skeletons.mzb_skeletons_helpers.paint_image_tensor(image: Tensor, masks: Tensor, color: List[float]) Tensor[source]
Given an input image, a binary mask indicating where to paint, and a color to use, returns a new image where the pixels within the mask are colored with the specified color.
- Parameters:
image (torch.Tensor) – Input image to paint.
mask (torch.Tensor) – Binary mask indicating where to paint.
color (List[float]) – List of 3 floats representing the RGB color to use.
- Returns:
rgb_body – New image with painted pixels.
- Return type:
torch.Tensor
- mzbsuite.skeletons.mzb_skeletons_helpers.segment_skel(skeleton, inter, conn=1)[source]
Custom function to segment a skeletonised image into individual branches. Each branch gets a unique ID.
- Parameters:
skeleton (numpy.ndarray) – The skeletonised image to segment
inter (list) – List of 2-tuples (x,y) containing the intersection coordinates, as returned by the function find_intersections
conn (int) – Connectivity of the skeleton. 1 for 4-connectivity, 2 for 8-connectivity
- Returns:
skel_labels (numpy.ndarray) – The labelled skeleton image
edge_attributes (dict) – Dictionary containing the attributes of each edge (branch) (for now, its size in pixels)
skprops (dict) – Dictionary containing the skimage.regionprops of each branch
- mzbsuite.skeletons.mzb_skeletons_helpers.traverse_graph(graph: dict, init: int, end_nodes: List[int], debug: bool = False) List[List[int]][source]
Function to traverse a graph from a starting node to a list of end nodes, and return all possible paths as a list of lists.
- Parameters:
graph (dict) – The graph to traverse
init (int) – The starting node ID
end_nodes (list) – List of end nodes
debug (bool) – Whether to print debug information
- Returns:
all_paths (list) – List of lists containing all possible paths from init to end_nodes
TODO
Maybe.
* Make it work for graphs with multiple paths between nodes and ensure that a subset of paths can be visited multiple times
* Make a test for it