microglia_analyzer.utils module
- microglia_analyzer.utils.bindings_as_napari_shapes(bindings, exclude=-1)[source]
From the bindings, creates a list of rectangles and a list of colors following the format expected by Napari. Both lists have the same size. There is the possibility to exclude a class by its index.
- Parameters:
bindings (-) – List of bindings, each containing a class and a bounding-box: (cls, (y1, x1, y2, x2)).
exclude (-) – Class to be excluded.
- Returns:
List of rectangles and list of colors.
- Return type:
(list, list)
- microglia_analyzer.utils.calculate_iou(box1, box2)[source]
Calculate the Intersection over Union (IoU) between two bounding boxes. It is designed to work with the format [x1, y1, x2, y2] (Raw YOLO output).
- Parameters:
box1 (-) – [x1, y1, x2, y2], coordinates of the first box.
box2 (-) – [x1, y1, x2, y2], coordinates of the second box.
- Returns:
Intersection over Union, a value between 0 and 1.
- Return type:
(float)
- microglia_analyzer.utils.download_from_web(url, extract_to, timeout=100)[source]
This function is used to download and extract a ZIP file from the web. In this project, it is used to download the pre-trained models (for both the UNet and the YOLO). To get it working, the files must have been bundled at level-0. It means that when you create your archive, you must do it from inside the folder (Ctrl+A > Compress), not from the parent folder itself.
- Parameters:
url (-) – URL of the ZIP file to download.
extract_to (-) – Parent folder where the ZIP file will be extracted. A new folder will be created inside.
timeout (-) – Maximum time to wait for the download (default=100).
- microglia_analyzer.utils.draw_bounding_boxes(image, bindings, class_names, exclude=-1, thickness=2)[source]
Draw bounding-boxes on an image. There is the possibility to exclude a class by its index. The output image is in BGR format and the modification is not performed in-place.
Parameters: - image (np.array): Canvas on which the bounding-boxes will be drawn. - bindings ([(int, (int, int, int, int))]): List of bindings, each containing a class and a bounding-box: (cls, (y1, x1, y2, x2)). - class_names ([str]): List of class names. - exclude (int): Class to be excluded. - thickness (int): Thickness of the bounding-boxes outlines (default=2).
- microglia_analyzer.utils.get_all_tiff_files(folder_path, no_ext=False)[source]
Probes a folder and filters its content with a regex. All the TIFF are returned, whatever the number of ‘f’ or the case. If the no_ext attribute is True, the name is returned without the extension.