liom_toolkit.segmentation.vseg.utils module
- liom_toolkit.segmentation.vseg.utils.add_patch_to_empty_array(inference: ndarray, pred_y: ndarray, coords: tuple[int, int], stride: int, overlap: int, size: tuple[int, int]) ndarray
Add a inferred patch to empty array
- Parameters:
inference (np.ndarray) – The empty array to add the patch to
pred_y (np.ndarray) – The predicted patch
coords (tuple[int, int]) – The coordinates of the patch
stride (int) – The stride of the patch
overlap (int) – The overlap of the patch
size (tuple[int, int]) – The size of the patch
- Returns:
The array with the patch added
- Return type:
np.ndarray
- liom_toolkit.segmentation.vseg.utils.calculate_metrics(y_true: ndarray, y_pred: ndarray) list[float]
Calculate metrics between ground truth and prediction. Metrics are F1, Recall, Precision, Accuracy, and Jaccard.
- Parameters:
y_true (np.ndarray) – Ground truth
y_pred (np.ndarray) – Prediction
- Returns:
List of metrics
- Return type:
list[float]
- liom_toolkit.segmentation.vseg.utils.create_dir(path: str) None
Create a directory if it does not exist yet
- Parameters:
path (str) – The path to create
- Returns:
None
- liom_toolkit.segmentation.vseg.utils.create_patches(image_path: str, size: tuple[int, int] = (256, 256), stride: int = 64, norm: bool = False) tuple[list[Any], tuple[int, ...], tuple[int, ...], ndarray[Any, dtype[Any]] | Any]
Create patches from an image
- Parameters:
image_path (str) – The path to the image
size (tuple[int, int]) – The size of the patches
stride (int) – The stride of the patches
norm (bool) – Normalize the patches
- Returns:
The patches, the shape of the image, the shape of the patches, and the image
- Return type:
tuple[np.ndarray, tuple[int, int], tuple[int, int], np.ndarray]
- liom_toolkit.segmentation.vseg.utils.crop_image(image: ndarray, size: tuple[int, int], stride: int) ndarray
Crop an image to a specific size and stride
- Parameters:
image (np.ndarray) – The image to crop
size (tuple[int, int]) – The size to crop to
stride (int) – The stride to crop with
- Returns:
The cropped image
- Return type:
np.ndarray
- liom_toolkit.segmentation.vseg.utils.epoch_time(start_time: float, end_time: float) tuple[int, int]
Calculate the elapsed time between start and end time
- Parameters:
start_time (float) – The start time
end_time (float) – The end time
- Returns:
The elapsed time in minutes and seconds
- Return type:
tuple[int, int]
- liom_toolkit.segmentation.vseg.utils.matplotlib_imshow(img: Tensor, one_channel: bool = False) None
Visualize an image using matplotlib
- Parameters:
img (torch.Tensor) – The image to visualize
one_channel (bool) – Whether the image has one channel
- Returns:
None
- liom_toolkit.segmentation.vseg.utils.numeric_filesort(path: str, folder: str = 'images', extension: str = 'png') list[str]
Sort a list of filenames by numerical order
- Parameters:
path (str) – The path to the folder
folder (str) – The folder to sort
extension (str) – The extension of the files
- Returns:
The sorted list of filenames
- Return type:
list[str]
- liom_toolkit.segmentation.vseg.utils.patch(image_path: str, save_path: str, norm: bool, size: tuple[int, int] = (256, 256), stride: int = 64, augment: bool = True, threshold: int = 5, save_image: bool = True, use_mask: bool = True, remove_background_tiles: bool = False) tuple[tuple[int, ...], tuple[int, ...], Any, Any] | tuple[tuple[int, ...], tuple[int, ...], Any]
Patch an image
- Parameters:
image_path (str) – The path to the image
save_path (str) – The path to save the patches
norm (bool) – Normalize the image
size (tuple[int, int]) – The size of the patches
stride (int) – The stride of the patches
augment (bool) – Augment the patches
threshold (int) – The threshold for removing background tiles
save_image (bool) – Save the image
use_mask (bool) – Use a mask
remove_background_tiles (bool) – Remove background tiles
- Returns:
The shape of the image, the shape of the patches, and the image
- Return type:
tuple[tuple[int, int], tuple[int, int], np.ndarray]
- liom_toolkit.segmentation.vseg.utils.process_image(image: ndarray, device: device) Tensor
Process an image to present to U-net model
- Parameters:
image (np.ndarray) – The image to process
device (torch.device) – The device to use
- Returns:
The processed image
- Return type:
torch.Tensor
- liom_toolkit.segmentation.vseg.utils.seeding(seed: int) None
Set seed for reproducibility
- Parameters:
seed (int) – The seed to set
- Returns:
None