Spaces:
Runtime error
Runtime error
Update src/io/load_images.py
Browse files- src/io/load_images.py +21 -10
src/io/load_images.py
CHANGED
|
@@ -1,13 +1,24 @@
|
|
| 1 |
-
|
| 2 |
import numpy as np
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
out = []
|
| 7 |
-
if not files: return out
|
| 8 |
-
for f in files:
|
| 9 |
-
if hasattr(f, 'size') and f.size and f.size>max_bytes:
|
| 10 |
-
raise ValueError("PNG/JPG excede limite.")
|
| 11 |
-
img = Image.open(f.name).convert('L')
|
| 12 |
-
out.append(np.array(img))
|
| 13 |
-
return out # lista de arrays 2D
|
|
|
|
| 1 |
+
import io
|
| 2 |
import numpy as np
|
| 3 |
+
from PIL import Image
|
| 4 |
+
|
| 5 |
+
def load_png_group(pngs, max_bytes=400 * 1024 * 1024):
|
| 6 |
+
"""
|
| 7 |
+
Carrega uma lista de imagens PNG/JPG (scaneadas) em numpy arrays normalizados.
|
| 8 |
+
Retorna: list[np.ndarray]
|
| 9 |
+
"""
|
| 10 |
+
out = []
|
| 11 |
+
if not pngs:
|
| 12 |
+
return out
|
| 13 |
+
|
| 14 |
+
for f in pngs:
|
| 15 |
+
# Verifica tamanho
|
| 16 |
+
if hasattr(f, "size") and f.size > max_bytes:
|
| 17 |
+
raise ValueError(f"Arquivo {f.name} excede o limite de {max_bytes / 1024 / 1024:.1f} MB")
|
| 18 |
|
| 19 |
+
# Abre imagem e converte para escala de cinza
|
| 20 |
+
img = Image.open(f.name).convert("L")
|
| 21 |
+
arr = np.array(img, dtype="float32") / 255.0
|
| 22 |
+
out.append(arr)
|
| 23 |
|
| 24 |
+
return out
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|