Skip to content
Snippets Groups Projects

Load common formats

1 file
+ 14
2
Compare changes
  • Side-by-side
  • Inline
+ 14
2
@@ -11,7 +11,7 @@ import qim3d
@@ -11,7 +11,7 @@ import qim3d
from qim3d.io.logger import log
from qim3d.io.logger import log
from qim3d.utils.internal_tools import sizeof, stringify_path
from qim3d.utils.internal_tools import sizeof, stringify_path
from qim3d.utils.system import Memory
from qim3d.utils.system import Memory
from PIL import Image
from PIL import Image, UnidentifiedImageError
class DataLoader:
class DataLoader:
@@ -273,6 +273,17 @@ class DataLoader:
@@ -273,6 +273,17 @@ class DataLoader:
return vol, metadata
return vol, metadata
else:
else:
return vol
return vol
 
 
def load_pil(self, path):
 
"""Load a PIL image from the specified path
 
 
Args:
 
path (str): The path to the image supported by PIL.
 
 
Returns:
 
numpy.ndarray: The loaded image/volume as a NumPy array.
 
"""
 
return np.array(Image.open(path))
def load(self, path):
def load(self, path):
"""
"""
@@ -293,6 +304,7 @@ class DataLoader:
@@ -293,6 +304,7 @@ class DataLoader:
data = loader.load("image.tif")
data = loader.load("image.tif")
"""
"""
 
# Stringify path in case it is not already a string
path = stringify_path(path)
path = stringify_path(path)
# Load a file
# Load a file
@@ -308,7 +320,7 @@ class DataLoader:
@@ -308,7 +320,7 @@ class DataLoader:
return self.load_nifti(path)
return self.load_nifti(path)
else:
else:
try:
try:
return np.array(Image.open(path))
return self.load_pil(path)
except UnidentifiedImageError:
except UnidentifiedImageError:
raise ValueError("Unsupported file format")
raise ValueError("Unsupported file format")
Loading