Skip to content
Snippets Groups Projects
Commit accd26fa authored by Amir MOHAMMADI's avatar Amir MOHAMMADI
Browse files

Merge branch 'JPG' into 'master'

Tests extensions against lower case versions

See merge request !43
parents 740fbd21 11a70614
No related branches found
No related tags found
1 merge request!43Tests extensions against lower case versions
Pipeline #61735 passed
......@@ -81,8 +81,8 @@ def open_file(filename):
img = img[:, :, 0]
return img
extension = os.path.splitext(filename)[1] # get the extension
# logger.error(filename)
# get the extension
extension = os.path.splitext(filename)[1].lower()
if extension in hdf5_extensions:
with h5py.File(filename, "r") as f:
......@@ -101,6 +101,7 @@ def open_file(filename):
if string_dtype is not None:
dataset = dataset.asstr()
return dataset[()]
elif extension in image_extensions:
from ..image import to_bob
......
......@@ -64,8 +64,10 @@ def bob_to_pillow(img):
img = to_matplotlib(img)
# if img is floating point, convert to uint8
if isinstance(img, np.floating):
# we expect float images to be between 0 and 1
img = np.clip(img, 0, 1) * 255
# In Bob, we expect float images to be between 0 and 255
# see https://gitlab.idiap.ch/bob/bob.bio.face/-/issues/48
img = np.round(img)
img = np.clip(img, 0, 255)
img = img.astype(np.uint8)
return Image.fromarray(img)
......@@ -108,7 +110,7 @@ def opencvbgr_to_bob(img):
If the image dimension is less than 3.
"""
if img.ndim < 3:
raise ValueError("You need to provide at least a 3 dimensional image")
return img
img = img[..., ::-1]
return to_bob(img)
......@@ -134,7 +136,7 @@ def bob_to_opencvbgr(img):
If the image dimension is less than 3.
"""
if img.ndim < 3:
raise ValueError("You need to provide at least a 3 dimensional image")
return img
img = img[..., ::-1, :, :]
return to_matplotlib(img)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment