stouputils.data_science.data_processing.image.zoom module#
- zoom_image(image: ndarray[Any, dtype[Any]], zoom_factor: float, ignore_dtype: bool = False) ndarray[Any, dtype[Any]] [source]#
Zoom into an image.
- Parameters:
image (NDArray[Any]) – Image to zoom
zoom_factor (float) – Zoom factor (greater than 1 for zoom in, less than 1 for zoom out)
ignore_dtype (bool) – Ignore the dtype check
- Returns:
Zoomed image
- Return type:
NDArray[Any]
>>> ## Basic tests >>> image = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) >>> zoomed = zoom_image(image.astype(np.uint8), 1.5) >>> zoomed.shape == image.shape True
>>> img = np.eye(4, dtype=np.uint8) * 255 >>> zoomed_in = zoom_image(img, 2.0) >>> zoomed_in.shape == img.shape # Should preserve size True
>>> zoomed_out = zoom_image(img, 0.5) >>> zoomed_out.shape == img.shape # Should preserve size True
>>> rgb = np.full((4,4,3), 128, dtype=np.uint8) >>> zoomed_rgb = zoom_image(rgb, 1.5) >>> zoomed_rgb.shape == (4,4,3) True
>>> ## Test invalid inputs >>> zoom_image("not an image", 1.5) Traceback (most recent call last): ... AssertionError: Image must be a numpy array
>>> zoom_image(image.astype(np.uint8), "1.5") Traceback (most recent call last): ... AssertionError: zoom_factor must be a number, got <class 'str'>
>>> zoom_image(image.astype(np.uint8), -1) Traceback (most recent call last): ... AssertionError: zoom_factor must be greater than 0, got -1