r""" Checks if the input is a valid image. A valid image can be: - A `PIL.Image.Image`. - A 2D or 3D `np.ndarray` or `torch.Tensor` (grayscale or color image). Args: image (`PIL.Image.Image | np.ndarray | torch.Tensor`): The image to validate. It can be a PI
(image)
| 33 | |
| 34 | |
| 35 | def is_valid_image(image) -> bool: |
| 36 | r""" |
| 37 | Checks if the input is a valid image. |
| 38 | |
| 39 | A valid image can be: |
| 40 | - A `PIL.Image.Image`. |
| 41 | - A 2D or 3D `np.ndarray` or `torch.Tensor` (grayscale or color image). |
| 42 | |
| 43 | Args: |
| 44 | image (`PIL.Image.Image | np.ndarray | torch.Tensor`): |
| 45 | The image to validate. It can be a PIL image, a NumPy array, or a torch tensor. |
| 46 | |
| 47 | Returns: |
| 48 | `bool`: |
| 49 | `True` if the input is a valid image, `False` otherwise. |
| 50 | """ |
| 51 | return isinstance(image, PIL.Image.Image) or isinstance(image, (np.ndarray, torch.Tensor)) and image.ndim in (2, 3) |
| 52 | |
| 53 | |
| 54 | def is_valid_image_imagelist(images): |
no outgoing calls
no test coverage detected
searching dependent graphs…