diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cee6309717..bffb8601a1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file. - Update ModelAPI configuration() - Add Anomaly modelAPI changes () +- Update Image numpy access () ### Bug fixes diff --git a/src/otx/api/entities/image.py b/src/otx/api/entities/image.py index a241a9511bb..e841820c92d 100644 --- a/src/otx/api/entities/image.py +++ b/src/otx/api/entities/image.py @@ -10,6 +10,7 @@ import cv2 import imagesize import numpy as np +from PIL import Image as PILImage from otx.api.entities.annotation import Annotation from otx.api.entities.media import IMedia2DEntity @@ -91,7 +92,12 @@ def numpy(self) -> np.ndarray: np.ndarray: NumPy representation of the image. """ if self.__data is None: - return cv2.cvtColor(cv2.imread(self.__file_path), cv2.COLOR_BGR2RGB) + try: + image = PILImage.open(self.__file_path) + image = np.asarray(image.convert("RGB")) + except ValueError: + image = cv2.cvtColor(cv2.imread(self.__file_path), cv2.COLOR_BGR2RGB) + return image if callable(self.__data): return self.__data() return self.__data