Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

remove PIL dependency (#512)

Edgar Riba49f4e372bc26
diff --git a/kornia/utils/image.py b/kornia/utils/image.py
index 382360a74..62716e724 100644
--- a/kornia/utils/image.py
+++ b/kornia/utils/image.py
@@ -1,15 +1,12 @@
-from typing import Union
-from PIL import Image
-
import numpy as np
import torch
-def image_to_tensor(image: Union[np.ndarray, Image.Image], keepdim: bool = True) -> torch.Tensor:
- """Converts a numpy or PIL image to a PyTorch 4d tensor image.
+def image_to_tensor(image: np.ndarray, keepdim: bool = True) -> torch.Tensor:
+ """Converts a numpy image to a PyTorch 4d tensor image.
Args:
- image (numpy.ndarray or PIL Image): image of the form :math:`(H, W, C)`, :math:`(H, W)` or
+ image (numpy.ndarray): image of the form :math:`(H, W, C)`, :math:`(H, W)` or
:math:`(B, H, W, C)`.
keepdim (bool): If ``False`` unsqueeze the input image to match the shape
:math:`(B, H, W, C)`. Default: ``True``
@@ -19,13 +16,10 @@ def image_to_tensor(image: Union[np.ndarray, Image.Image], keepdim: bool = True)
:math:`(C, H, W)` otherwise.
"""
- if not isinstance(image, (np.ndarray, Image.Image)):
- raise TypeError("Input type must be a numpy.ndarray or PIL Image. Got {}".format(
+ if not isinstance(image, (np.ndarray,)):
+ raise TypeError("Input type must be a numpy.ndarray. Got {}".format(
type(image)))
- if isinstance(image, Image.Image):
- image = np.array(image)
-
if len(image.shape) > 4 or len(image.shape) < 2:
raise ValueError(
"Input size must be a two, three or four dimensional array")