topostats.array_manipulation#
Functions for manipulating numpy arrays.
Attributes#
Functions#
Re-crop a grain image and mask to be a target size in nanometres. |
|
|
Pad a bounding box within limits. If the padding would exceed the limits bounds, pad in the other direction. |
Module Contents#
- topostats.array_manipulation.LOGGER#
- topostats.array_manipulation.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: numpy.typing.NDArray[numpy.float32], full_mask_tensor: numpy.typing.NDArray[numpy.bool_], target_size_nm: float) tuple[numpy.typing.NDArray[numpy.float32], numpy.typing.NDArray[numpy.bool_]] [source]#
Re-crop a grain image and mask to be a target size in nanometres.
- Parameters:
filename (str) – The name of the file being processed, used for logging.
grain_number (int) – The number of the grain being processed, used for logging.
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)).
pixel_to_nm_scaling (float) – Pixel to nanometre scaling factor.
full_image (npt.NDArray[np.float32]) – The full image from which to crop the grain image.
full_mask_tensor (npt.NDArray[np.bool_]) – The full mask tensor from which to crop the mask.
target_size_nm (float) – The target size in nanometres to crop the grain image and mask to.
- Returns:
The cropped grain image and mask, both as numpy arrays.
- Return type:
tuple[npt.NDArray[np.float32], npt.NDArray[np.bool_]]
- Raises:
ValueError – If the target size in nanometres is larger than the full image or mask dimensions.
- topostats.array_manipulation.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] [source]#
Pad a bounding box within limits. If the padding would exceed the limits bounds, pad in the other direction.
- Parameters:
bbox (tuple[int, int, int, int]) – The bounding box to pad.
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).
padding (int) – The padding to apply to the bounding box.
- Returns:
The new bounding box indices.
- Return type:
tuple[int, int, int, int]