stouputils.data_science.data_processing.image.axis_flip module#
- flip_image(image: ndarray[Any, dtype[Any]], axis: Literal['horizontal', 'vertical', 'both'], ignore_dtype: bool = True) ndarray[Any, dtype[Any]] [source]#
Flip an image along specified axis
- Parameters:
image (NDArray[Any]) – Image to flip
axis (str) – Axis along which to flip (“horizontal” or “vertical” or “both”)
ignore_dtype (bool) – Ignore the dtype check
- Returns:
Flipped image
- Return type:
NDArray[Any]
>>> ## Basic tests >>> image = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) >>> flip_image(image, "horizontal").tolist() [[3, 2, 1], [6, 5, 4], [9, 8, 7]]
>>> flip_image(image, "vertical").tolist() [[7, 8, 9], [4, 5, 6], [1, 2, 3]]
>>> flip_image(image, "both").tolist() [[9, 8, 7], [6, 5, 4], [3, 2, 1]]
>>> ## Test invalid inputs >>> flip_image(image, "diagonal") Traceback (most recent call last): AssertionError: axis must be either 'horizontal' or 'vertical' or 'both', got 'diagonal'
>>> flip_image("not an image", "horizontal") Traceback (most recent call last): ... AssertionError: Image must be a numpy array