stouputils.data_science.data_processing.image.shearing module#
- shear_image(image: ndarray[Any, dtype[Any]], x: float, y: float, ignore_dtype: bool = False) ndarray[Any, dtype[Any]] [source]#
Shear an image
- Parameters:
image (NDArray[Any]) – Image to shear
x (float) – Shearing along the x axis (between -180 and 180)
y (float) – Shearing along the y axis (between -180 and 180)
ignore_dtype (bool) – Ignore the dtype check
- Returns:
Sheared image
- Return type:
NDArray[Any]
>>> ## Basic tests >>> image = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) >>> shear_image(image.astype(np.uint8), 15, 0).tolist() [[1, 2, 3], [3, 5, 6], [3, 7, 8]]
>>> shear_image(image.astype(np.float32), 0, 15).tolist() [[1.0, 1.4375, 1.40625], [4.0, 4.15625, 4.40625], [7.0, 7.15625, 7.40625]]
>>> ## Test invalid inputs >>> shear_image(image.astype(np.uint8), 200, 0) Traceback (most recent call last): ... AssertionError: x must be between -180 and 180, got 200
>>> shear_image(image.astype(np.uint8), 0, -200) Traceback (most recent call last): ... AssertionError: y must be between -180 and 180, got -200
>>> shear_image("not an image", 0, 0) Traceback (most recent call last): ... AssertionError: Image must be a numpy array