Array Manipulation Modules
Functions for manipulating numpy arrays.
pad_bounding_box_dynamically_at_limits(bbox: tuple[int, int, int, int], limits: tuple[int, int, int, int], padding: int) -> tuple[int, int, int, int]
Pad a bounding box within limits. If the padding would exceed the limits bounds, pad in the other direction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bbox
|
tuple[int, int, int, int]
|
The bounding box to pad. |
required |
limits
|
tuple[int, int, int, int]
|
The region to limit the bounding box to in the form (min_row, min_col, max_row, max_col). |
required |
padding
|
int
|
The padding to apply to the bounding box. |
required |
Returns:
| Type | Description |
|---|---|
tuple[int, int, int, int]
|
The new bounding box indices. |
Source code in topostats\array_manipulation.py
re_crop_grain_image_and_mask_to_set_size_nm(filename: str, grain_number: int, grain_bbox: tuple[int, int, int, int], pixel_to_nm_scaling: float, full_image: npt.NDArray[np.float32], full_mask_tensor: npt.NDArray[np.bool_], target_size_nm: float) -> tuple[npt.NDArray[np.float32], npt.NDArray[np.bool_]]
Re-crop a grain image and mask to be a target size in nanometres.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
The name of the file being processed, used for logging. |
required |
grain_number
|
int
|
The number of the grain being processed, used for logging. |
required |
grain_bbox
|
tuple[int, int, int, int]
|
The bounding box of the grain in the form (min_row, min_col, max_row (exclusive), max_col (exclusive)). |
required |
pixel_to_nm_scaling
|
float
|
Pixel to nanometre scaling factor. |
required |
full_image
|
NDArray[float32]
|
The full image from which to crop the grain image. |
required |
full_mask_tensor
|
NDArray[bool_]
|
The full mask tensor from which to crop the mask. |
required |
target_size_nm
|
float
|
The target size in nanometres to crop the grain image and mask to. |
required |
Returns:
| Type | Description |
|---|---|
tuple[NDArray[float32], NDArray[bool_]]
|
The cropped grain image and mask, both as numpy arrays. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the target size in nanometres is larger than the full image or mask dimensions. |
Source code in topostats\array_manipulation.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |