stouputils.data_science.data_processing.image.auto_contrast module#
- auto_contrast_image(image: ndarray[Any, dtype[Any]], ignore_dtype: bool = False) ndarray[Any, dtype[Any]] [source]#
Adjust the contrast of an image.
- Parameters:
image (NDArray[Any]) – Image to adjust contrast
ignore_dtype (bool) – Ignore the dtype check
- Returns:
Image with adjusted contrast
- Return type:
NDArray[Any]
>>> ## Basic tests >>> image = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=np.uint8) >>> adjusted = auto_contrast_image(image) >>> adjusted.tolist() [[0, 36, 73], [109, 146, 182], [219, 255, 255]] >>> adjusted.shape == image.shape True >>> adjusted.dtype == image.dtype True
>>> ## Test invalid inputs >>> auto_contrast_image("not an image") Traceback (most recent call last): ... AssertionError: Image must be a numpy array