-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocesar_dataset.py
More file actions
67 lines (54 loc) · 2.03 KB
/
procesar_dataset.py
File metadata and controls
67 lines (54 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import os
import glob
from PIL import Image
# --- CONFIGURACIÓN ---
ESTACION_X = 745
ESTACION_Y = 313
CROP_SIZE = 512
HALF_SIZE = CROP_SIZE // 2
# Caja de Recorte
x_start = ESTACION_X - HALF_SIZE
y_start = ESTACION_Y - HALF_SIZE
x_end = ESTACION_X + HALF_SIZE
y_end = ESTACION_Y + HALF_SIZE
crop_box = (x_start, y_start, x_end, y_end)
INPUT_FOLDER = "todas_las_imagenes"
INPUT_PATTERN = os.path.join(INPUT_FOLDER, "*.png")
OUTPUT_FOLDER = "Recortes-satelitales"
os.makedirs(OUTPUT_FOLDER, exist_ok=True)
def formatear_nombre(ruta_completa):
try:
nombre_archivo = os.path.basename(ruta_completa)
partes = nombre_archivo.split('---')
fecha_sucia = partes[-1]
fecha_str = fecha_sucia.replace('.png', '')
if len(fecha_str) != 14 or not fecha_str.isdigit():
return None
year = fecha_str[0:4]
month = fecha_str[4:6]
day = fecha_str[6:8]
hour = fecha_str[8:10]
minute = fecha_str[10:12]
return f"{year}-{month}-{day}-{hour}{minute}_band-13.png"
except:
return None
def procesar():
archivos = glob.glob(INPUT_PATTERN)
print(f"Procesando {len(archivos)} imágenes desde '{INPUT_FOLDER}'...")
procesados = 0
for archivo_ruta in archivos:
nuevo_nombre = formatear_nombre(archivo_ruta)
if nuevo_nombre is None: continue
try:
with Image.open(archivo_ruta) as img:
if img.mode == 'RGBA': img = img.convert('RGB')
recorte = img.crop(crop_box)
ruta_salida = os.path.join(OUTPUT_FOLDER, nuevo_nombre)
recorte.save(ruta_salida)
procesados += 1
if procesados % 500 == 0: print(f" -> {procesados} listos.")
except Exception as e:
print(f"Error en {archivo_ruta}: {e}")
print(f"¡Listo! {procesados} imágenes en '{OUTPUT_FOLDER}'.")
if __name__ == "__main__":
procesar()