-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
1244 lines (1151 loc) · 65.8 KB
/
index.html
File metadata and controls
1244 lines (1151 loc) · 65.8 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.5, user-scalable=yes">
<title>🛰️ EspectroLab · Laboratorio de Firmas Espectrales</title>
<!-- Tailwind CSS -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- Chart.js -->
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.min.js"></script>
<!-- Font Awesome -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<!-- Favicons -->
<link rel="apple-touch-icon" sizes="180x180" href="img/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="img/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="img/favicon-16x16.png">
<link rel="manifest" href="img/site.webmanifest">
<link rel="shortcut icon" href="img/favicon.ico">
<meta name="msapplication-TileColor" content="#da532c">
<meta name="theme-color" content="#ffffff">
<style>
.canvas-container { position: relative; display: inline-block; }
.band-canvas, .visible-canvas {
border: 2px solid #334155;
border-radius: 0.5rem;
background-color: #1e293b;
width: 100%;
height: auto;
cursor: crosshair;
touch-action: none; /* prevenir scroll al tocar */
}
.escala-img {
width: 100%;
max-width: 200px;
height: auto;
border-radius: 0.25rem;
margin-top: 0.25rem;
}
.slider-value {
font-family: monospace;
background: #0f172a;
padding: 0.2rem 0.5rem;
border-radius: 0.25rem;
border: 1px solid #f43f5e;
color: #fda4af;
}
.cors-warning {
background-color: #fef9c3;
color: #854d0e;
padding: 0.5rem 1rem;
border-radius: 0.5rem;
border: 1px solid #facc15;
display: none;
}
#videoCam {
border-radius: 0.5rem;
border: 2px solid #f43f5e;
background: #0f172a;
max-width: 100%;
}
.nir-label {
cursor: pointer;
border-bottom: 1px dashed #c084fc;
}
.popup {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: #1f2937;
border: 2px solid #c084fc;
border-radius: 1rem;
padding: 1.5rem;
max-width: 450px;
box-shadow: 0 25px 50px -12px rgba(0,0,0,0.5);
z-index: 1000;
display: none;
}
.popup p { margin-bottom: 1rem; }
.popup button {
background: #c084fc;
color: #0f172a;
padding: 0.5rem 1rem;
border-radius: 0.5rem;
font-weight: bold;
}
.overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0,0,0,0.7);
z-index: 999;
display: none;
}
/* Barra de navegación fija */
.navbar {
position: sticky;
top: 0;
z-index: 50;
backdrop-filter: blur(8px);
background-color: rgba(31, 41, 55, 0.9);
border-bottom: 1px solid #374151;
}
/* Footer */
.footer {
background-color: #1e293b;
border-top: 1px solid #334155;
padding: 2rem 1rem;
margin-top: 2rem;
}
.footer-content {
max-width: 1200px;
margin: 0 auto;
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
gap: 1.5rem;
}
.footer-text {
color: #9ca3af;
font-size: 0.875rem;
flex: 2;
min-width: 250px;
}
.footer-links {
display: flex;
flex-wrap: wrap;
gap: 1.5rem;
align-items: center;
}
.footer-links a {
color: #d1d5db;
text-decoration: none;
font-size: 0.9rem;
transition: color 0.2s;
}
.footer-links a:hover {
color: #f43f5e;
}
.social-icons a {
margin-left: 1rem;
font-size: 1.2rem;
color: #9ca3af;
}
.social-icons a:hover {
color: #f43f5e;
}
/* Texto de presentación GeoWay */
.geoway-intro {
background: linear-gradient(145deg, #1f2937, #111827);
border-left: 4px solid #f43f5e;
padding: 1.5rem;
border-radius: 1rem;
margin-bottom: 2rem;
box-shadow: 0 10px 25px -5px rgba(0,0,0,0.5);
}
.geoway-intro h2 {
color: #fda4af;
font-size: 1.5rem;
font-weight: 300;
margin-bottom: 0.5rem;
}
.geoway-intro p {
color: #d1d5db;
margin-bottom: 0.5rem;
}
.geoway-intro a {
color: #f43f5e;
text-decoration: underline;
}
/* Estilos para el zoom */
.zoom-container {
position: relative;
display: inline-block;
width: 100%;
}
.zoom-lens {
position: absolute;
bottom: 10px;
right: 10px;
width: 150px;
height: 150px;
border: 3px solid #f43f5e;
border-radius: 8px;
background-color: #1e293b;
box-shadow: 0 4px 15px rgba(0,0,0,0.5);
display: none;
pointer-events: none;
z-index: 20;
overflow: hidden;
}
.zoom-lens canvas {
width: 100%;
height: 100%;
display: block;
}
.flash-effect {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: white;
opacity: 0;
pointer-events: none;
z-index: 10;
transition: opacity 0.2s;
}
</style>
</head>
<body class="bg-gray-900 text-gray-200 font-sans antialiased">
<!-- Barra de navegación fija con selector de idioma mejorado -->
<nav class="navbar py-2 px-3 flex items-center justify-between gap-1">
<!-- Lado izquierdo: logo + título -->
<div class="flex items-center gap-2 min-w-0">
<img src="img/LOGO.png" alt="EspectroLab" class="h-7 w-auto flex-shrink-0" onerror="this.style.display='none'">
<span class="text-rose-400 font-mono text-base sm:text-lg font-light truncate">
<span class="hidden sm:inline">🛰️</span> EspectroLab
</span>
</div>
<!-- Lado derecho: enlaces + selector -->
<div class="flex items-center gap-2 flex-nowrap">
<a href="index.html" class="text-rose-300 border-b-2 border-rose-500 pb-0.5 text-xs sm:text-sm whitespace-nowrap" data-i18n="nav.firmas">Firmas</a>
<a href="ndvi.html" class="text-gray-300 hover:text-rose-300 transition text-xs sm:text-sm whitespace-nowrap" data-i18n="nav.ndvi">NDVI</a>
<!-- Selector de idioma compacto con bandera + código -->
<select id="lang-select" class="bg-gray-800 text-white border border-gray-600 rounded-md px-1.5 py-1 text-xs sm:text-sm w-auto min-w-[70px] max-w-[90px]">
<option value="es" selected>🇪🇸 ES</option>
<option value="en">🇬🇧 EN</option>
<option value="de">🇩🇪 DE</option>
</select>
</div>
</nav>
<!-- Popup de información NIR -->
<div class="overlay" id="overlay" onclick="cerrarPopup()"></div>
<div class="popup" id="popupNIR">
<h3 class="text-purple-300 text-xl font-mono mb-3" id="popupNIRTitle">🌿 Banda NIR</h3>
<div id="popupNIRContent"></div>
<div class="text-right"><button onclick="cerrarPopup()" data-i18n="popup.close">Entendido</button></div>
</div>
<main class="max-w-7xl mx-auto px-4 py-6">
<!-- Aviso CORS -->
<div id="corsWarning" class="cors-warning mb-4">
⚠️ Las imágenes no pueden cargarse correctamente porque el archivo se abrió directamente desde el disco.
Para que funcione, <strong>sirve la página con un servidor local</strong> (ej: python -m http.server 8000).
</div>
<!-- Bloque de presentación GeoWay -->
<div class="geoway-intro" id="geowayIntro">
<h2 data-i18n="intro.title">🌍 EspectroLab / PyroLab — Un proyecto de GeoWay</h2>
<p data-i18n="intro.p1">Esta aplicación forma parte del <strong>Laboratorio Geoespacial de GeoWay</strong>, un espacio de innovación dedicado a explorar y construir soluciones educativas con tecnologías geoespaciales. Nuestro objetivo es acercar conceptos complejos —como las firmas espectrales o el índice NDVI— a estudiantes y profesionales mediante herramientas interactivas e intuitivas.</p>
<p data-i18n="intro.p2">A través de la experimentación visual y el aprendizaje práctico, buscamos inspirar nuevas formas de entender y aplicar la teledetección en la gestión del territorio, la respuesta a emergencias y el estudio del medio ambiente.</p>
<p><span data-i18n="intro.tagline">Explorando ideas, construyendo soluciones.</span> <em>Exploring ideas, building solutions.</em> — <a href="https://geo-way.github.io/GeoWay.io/blog.html" target="_blank">GeoWay Geospatial Lab</a></p>
</div>
<!-- Panel de cámara -->
<div class="bg-gray-800/70 p-5 rounded-xl border border-gray-700 mb-8">
<div class="grid md:grid-cols-2 gap-6 items-center">
<div class="space-y-3">
<div class="camera-preview relative">
<video id="videoCam" autoplay playsinline class="w-full bg-gray-950 rounded-lg border border-rose-800"></video>
<div id="flash" class="flash-effect"></div>
</div>
<div class="flex flex-wrap gap-3">
<button id="startCamera" class="bg-rose-800 hover:bg-rose-700 text-white px-4 py-2 rounded-lg text-sm font-mono flex items-center gap-1">
📸 <span data-i18n="camera.start">Activar cámara</span>
</button>
<button id="snapshotBtn" class="bg-gray-700 hover:bg-gray-600 text-white px-4 py-2 rounded-lg text-sm font-mono flex items-center gap-1">
⚡ <span data-i18n="camera.capture">Capturar y generar bandas</span>
</button>
<button id="stopCamera" class="bg-gray-800 hover:bg-gray-700 text-gray-300 px-4 py-2 rounded-lg text-sm border border-gray-600">
⏹️ <span data-i18n="camera.stop">Detener</span>
</button>
</div>
<p class="text-xs text-gray-500 mt-2" data-i18n="camera.orUpload">O sube tu propia imagen:</p>
<input type="file" id="fileInput" accept="image/*" class="block w-full text-sm text-gray-400 file:mr-4 file:py-2 file:px-4 file:rounded-full file:border-0 file:text-sm file:font-semibold file:bg-rose-900 file:text-rose-200 hover:file:bg-rose-800">
<button id="loadExampleBtn" class="mt-3 bg-amber-800/50 hover:bg-amber-700/70 text-amber-200 px-4 py-2 rounded-lg text-sm border border-amber-700 flex items-center gap-2">
🌿 <span data-i18n="camera.loadExample">Volver a imágenes de ejemplo (carpeta img/)</span>
</button>
</div>
<!-- Bloque de flujo de trabajo actualizado -->
<div class="bg-gray-900/70 p-4 rounded-lg border border-gray-700 text-sm text-gray-300 leading-relaxed">
<p class="font-semibold text-rose-300 mb-1" data-i18n="workflow.intro.title">✨ Intro</p>
<p class="mb-2" data-i18n="workflow.intro.text">Esta aplicación permite comprender el concepto de firma espectral a partir de una imagen de laboratorio tomada con una cámara con filtro infrarrojo (ejemplo: una planta). El objetivo es asignar un valor cuantitativo a cada banda en escala de grises, ya sea de forma manual (según la escala de brillo) o automáticamente al tocar la imagen en color.</p>
<p class="font-semibold text-rose-300 mb-1" data-i18n="workflow.steps.title">✨ Flujo de trabajo</p>
<ol class="list-decimal list-inside space-y-1">
<li data-i18n="workflow.step1">Al iniciar, se carga una imagen de muestra descompuesta en 4 bandas: azul, verde y rojo (región visible) y una banda del infrarrojo cercano (NIR).</li>
<li data-i18n="workflow.step2">Puedes usar la cámara o subir una imagen para generar nuevas bandas (NIR simulado).</li>
<li data-i18n="workflow.step3">Toca una banda para cargar sus valores en los controles deslizantes y ajustarlos manualmente.</li>
<li data-i18n="workflow.step4">Toca cualquier punto de la imagen para visualizar en tiempo real los valores espectrales de cada banda.</li>
<li data-i18n="workflow.step5">En la parte inferior se genera automáticamente la curva o gráfica espectral del píxel o región seleccionada.</li>
</ol>
<p class="text-amber-400 text-xs mt-2" data-i18n="workflow.note">🔴 La banda NIR simulada se genera mediante un algoritmo de transformación aplicado a la imagen de entrada. Toca (i) para más información técnica.</p>
</div>
</div>
</div>
<!-- Grid de bandas + visible con zoom -->
<div class="grid grid-cols-1 md:grid-cols-5 gap-4 mb-8">
<!-- Imagen visible con contenedor para zoom -->
<div class="md:col-span-2 flex flex-col items-center bg-gray-800/50 p-3 rounded-xl border border-gray-700">
<label class="text-sm font-medium text-white uppercase tracking-wider mb-2" data-i18n="bands.visible">Imagen visible (color)</label>
<div class="zoom-container relative w-full">
<canvas id="canvasVisible" class="visible-canvas w-full"></canvas>
<div id="zoomLens" class="zoom-lens">
<canvas id="zoomCanvas" width="150" height="150"></canvas>
</div>
</div>
</div>
<!-- Bandas 2x2 -->
<div class="md:col-span-3 grid grid-cols-2 gap-4">
<!-- Azul -->
<div class="flex flex-col items-center bg-gray-800/50 p-2 rounded-xl border border-gray-700">
<label class="text-sm font-medium text-blue-300 uppercase tracking-wider" data-i18n="bands.blue">Azul</label>
<div class="canvas-container relative w-full">
<canvas id="canvasBlue" class="band-canvas w-full"></canvas>
</div>
<img src="img/escala.jpg" alt="escala" class="escala-img" onerror="this.style.display='none'">
<div class="flex items-center gap-2 w-full mt-1">
<input type="range" id="sliderBlue" min="0" max="10" step="0.1" value="0" class="w-full accent-rose-500">
<span id="valBlue" class="slider-value text-sm">0.0</span>
</div>
</div>
<!-- Verde -->
<div class="flex flex-col items-center bg-gray-800/50 p-2 rounded-xl border border-gray-700">
<label class="text-sm font-medium text-green-300 uppercase tracking-wider" data-i18n="bands.green">Verde</label>
<div class="canvas-container relative w-full">
<canvas id="canvasGreen" class="band-canvas w-full"></canvas>
</div>
<img src="img/escala.jpg" alt="escala" class="escala-img" onerror="this.style.display='none'">
<div class="flex items-center gap-2 w-full mt-1">
<input type="range" id="sliderGreen" min="0" max="10" step="0.1" value="0" class="w-full accent-rose-500">
<span id="valGreen" class="slider-value text-sm">0.0</span>
</div>
</div>
<!-- Rojo -->
<div class="flex flex-col items-center bg-gray-800/50 p-2 rounded-xl border border-gray-700">
<label class="text-sm font-medium text-red-300 uppercase tracking-wider" data-i18n="bands.red">Rojo</label>
<div class="canvas-container relative w-full">
<canvas id="canvasRed" class="band-canvas w-full"></canvas>
</div>
<img src="img/escala.jpg" alt="escala" class="escala-img" onerror="this.style.display='none'">
<div class="flex items-center gap-2 w-full mt-1">
<input type="range" id="sliderRed" min="0" max="10" step="0.1" value="0" class="w-full accent-rose-500">
<span id="valRed" class="slider-value text-sm">0.0</span>
</div>
</div>
<!-- NIR -->
<div class="flex flex-col items-center bg-gray-800/50 p-2 rounded-xl border border-gray-700">
<label id="nirTitle" class="text-sm font-medium text-purple-300 uppercase tracking-wider nir-label" onclick="mostrarPopup()">NIR ℹ️</label>
<div class="canvas-container relative w-full">
<canvas id="canvasNir" class="band-canvas w-full"></canvas>
</div>
<img src="img/escala.jpg" alt="escala" class="escala-img" onerror="this.style.display='none'">
<div class="flex items-center gap-2 w-full mt-1">
<input type="range" id="sliderNir" min="0" max="10" step="0.1" value="0" class="w-full accent-rose-500">
<span id="valNir" class="slider-value text-sm">0.0</span>
</div>
</div>
</div>
</div>
<!-- Panel de información del cursor -->
<div class="bg-gray-800 p-4 rounded-xl border border-gray-700 mb-6 grid grid-cols-2 md:grid-cols-5 gap-2 text-sm">
<div class="text-gray-400" data-i18n="cursor.coords">Coordenadas: <span id="cursorCoords" class="text-rose-300">- , -</span></div>
<div class="text-blue-300" data-i18n="cursor.blue">Azul: <span id="cursorBlue" class="text-white">0.0</span></div>
<div class="text-green-300" data-i18n="cursor.green">Verde: <span id="cursorGreen" class="text-white">0.0</span></div>
<div class="text-red-300" data-i18n="cursor.red">Rojo: <span id="cursorRed" class="text-white">0.0</span></div>
<div class="text-purple-300" data-i18n="cursor.nir">NIR: <span id="cursorNir" class="text-white">0.0</span></div>
</div>
<!-- Gráfica -->
<div class="bg-gray-800 p-5 rounded-xl border border-gray-700 shadow-2xl mb-6">
<div class="flex justify-between items-center mb-3">
<h2 class="text-xl font-light text-rose-300 flex items-center gap-2">
<span>📈</span> <span data-i18n="chart.title">Firma espectral</span>
</h2>
<div class="flex gap-2">
<button id="resetBtn" class="bg-gray-700 hover:bg-gray-600 text-white text-sm px-4 py-1.5 rounded-lg border border-gray-600 flex items-center gap-1">
↺ <span data-i18n="chart.reset">Reset</span>
</button>
<button id="idealBtn" class="bg-green-800/50 hover:bg-green-700/70 text-green-200 text-sm px-4 py-1.5 rounded-lg border border-green-700 flex items-center gap-1">
✦ <span data-i18n="chart.ideal">Ideal (verde)</span>
</button>
</div>
</div>
<div class="relative h-64 w-full">
<canvas id="firmaChart"></canvas>
</div>
</div>
</main>
<!-- Footer -->
<footer class="footer">
<div class="footer-content">
<img src="img/Logo5.png" alt="DEULCHALEX Logo" class="h-12 w-auto" onerror="this.style.display='none'">
<div class="footer-text">
<p data-i18n="footer.copyright">© 2024 GEOWAY</p>
<p data-i18n="footer.rights">Todos los derechos de contenido educativo pertenecen a GEOWAY. Plataforma con fines educativos.</p>
</div>
<div class="footer-links">
<a href="#" data-i18n="footer.about"><i class="fas fa-info-circle"></i> Acerca de</a>
<a href="#" data-i18n="footer.tips"><i class="fas fa-lightbulb"></i> Consejos</a>
<a href="#" data-i18n="footer.faq"><i class="fas fa-question-circle"></i> FAQ</a>
<a href="https://calendly.com/alexanderariza/new-meeting" target="_blank" data-i18n="footer.contact"><i class="fas fa-envelope"></i> Contacto</a>
<!-- Redes sociales -->
<div class="social-icons">
<a href="https://www.facebook.com/sharer/sharer.php?u=https://tudominio.github.io/endmember/index.html" target="_blank"><i class="fab fa-facebook"></i></a>
<a href="https://www.linkedin.com/sharing/share-offsite/?url=https://tudominio.github.io/endmember/index.html" target="_blank"><i class="fab fa-linkedin"></i></a>
<a href="https://twitter.com/intent/tweet?url=https://tudominio.github.io/endmember/index.html&text=Explora%20firmas%20espectrales%20con%20EspectroLab" target="_blank"><i class="fab fa-x-twitter"></i></a>
<a href="https://www.instagram.com/" target="_blank"><i class="fab fa-instagram"></i></a>
</div>
</div>
</div>
</footer>
<script>
// Funciones globales para el popup
function mostrarPopup() {
document.getElementById('overlay').style.display = 'block';
document.getElementById('popupNIR').style.display = 'block';
}
function cerrarPopup() {
document.getElementById('overlay').style.display = 'none';
document.getElementById('popupNIR').style.display = 'none';
}
(function() {
// Detectar file://
if (window.location.protocol === 'file:') {
document.getElementById('corsWarning').style.display = 'block';
}
// --- Traducciones ---
const translations = {
es: {
'nav.firmas': 'Firmas',
'nav.ndvi': 'NDVI',
'popup.close': 'Entendido',
'intro.title': '🌍 EspectroLab / PyroLab — Un proyecto de GeoWay',
'intro.p1': 'Esta aplicación forma parte del <strong>Laboratorio Geoespacial de GeoWay</strong>, un espacio de innovación dedicado a explorar y construir soluciones educativas con tecnologías geoespaciales. Nuestro objetivo es acercar conceptos complejos —como las firmas espectrales o el índice NDVI— a estudiantes y profesionales mediante herramientas interactivas e intuitivas.',
'intro.p2': 'A través de la experimentación visual y el aprendizaje práctico, buscamos inspirar nuevas formas de entender y aplicar la teledetección en la gestión del territorio, la respuesta a emergencias y el estudio del medio ambiente.',
'intro.tagline': 'Explorando ideas, construyendo soluciones.',
'camera.start': 'Activar cámara',
'camera.capture': 'Capturar y generar bandas',
'camera.stop': 'Detener',
'camera.orUpload': 'O sube tu propia imagen:',
'camera.loadExample': 'Volver a imágenes de ejemplo (carpeta img/)',
'workflow.intro.title': '✨ Intro',
'workflow.intro.text': 'Esta aplicación permite comprender el concepto de firma espectral a partir de una imagen de laboratorio tomada con una cámara con filtro infrarrojo (ejemplo: una planta). El objetivo es asignar un valor cuantitativo a cada banda en escala de grises, ya sea de forma manual (según la escala de brillo) o automáticamente al tocar la imagen en color.',
'workflow.steps.title': '✨ Flujo de trabajo',
'workflow.step1': 'Al iniciar, se carga una imagen de muestra descompuesta en 4 bandas: azul, verde y rojo (región visible) y una banda del infrarrojo cercano (NIR).',
'workflow.step2': 'Puedes usar la cámara o subir una imagen para generar nuevas bandas (NIR simulado).',
'workflow.step3': 'Toca una banda para cargar sus valores en los controles deslizantes y ajustarlos manualmente.',
'workflow.step4': 'Toca cualquier punto de la imagen para visualizar en tiempo real los valores espectrales de cada banda.',
'workflow.step5': 'En la parte inferior se genera automáticamente la curva o gráfica espectral del píxel o región seleccionada.',
'workflow.note': '🔴 La banda NIR simulada se genera mediante un algoritmo de transformación aplicado a la imagen de entrada. Toca (i) para más información técnica.',
'bands.visible': 'Imagen visible (color)',
'bands.blue': 'Azul',
'bands.green': 'Verde',
'bands.red': 'Rojo',
'bands.nir': 'NIR ℹ️',
'cursor.coords': 'Coordenadas:',
'cursor.blue': 'Azul:',
'cursor.green': 'Verde:',
'cursor.red': 'Rojo:',
'cursor.nir': 'NIR:',
'chart.title': 'Firma espectral',
'chart.reset': 'Reset',
'chart.ideal': 'Ideal (verde)',
'footer.copyright': '© 2024 GEOWAY',
'footer.rights': 'Todos los derechos de contenido educativo pertenecen a GEOWAY. Plataforma con fines educativos.',
'footer.about': 'Acerca de',
'footer.tips': 'Consejos',
'footer.faq': 'FAQ',
'footer.contact': 'Contacto',
},
en: {
'nav.firmas': 'Signatures',
'nav.ndvi': 'NDVI',
'popup.close': 'Got it',
'intro.title': '🌍 EspectroLab / PyroLab — A GeoWay Project',
'intro.p1': 'This application is part of the <strong>GeoWay Geospatial Lab</strong>, an innovation space dedicated to exploring and building educational solutions with geospatial technologies. Our goal is to bring complex concepts—such as spectral signatures or the NDVI index—to students and professionals through interactive and intuitive tools.',
'intro.p2': 'Through visual experimentation and hands-on learning, we aim to inspire new ways of understanding and applying remote sensing in land management, emergency response, and environmental studies.',
'intro.tagline': 'Exploring ideas, building solutions.',
'camera.start': 'Start camera',
'camera.capture': 'Capture and generate bands',
'camera.stop': 'Stop',
'camera.orUpload': 'Or upload your own image:',
'camera.loadExample': 'Back to example images (img folder)',
'workflow.intro.title': '✨ Intro',
'workflow.intro.text': 'This app allows you to understand the concept of spectral signature from a laboratory image taken with an infrared filter camera (e.g., a plant). The goal is to assign a quantitative value to each band in grayscale, either manually (according to the brightness scale) or automatically by tapping the color image.',
'workflow.steps.title': '✨ Workflow',
'workflow.step1': 'Initially, a sample image is loaded and decomposed into 4 bands: blue, green, red (visible region) and a near-infrared band (NIR).',
'workflow.step2': 'You can use the camera or upload an image to generate new bands (simulated NIR).',
'workflow.step3': 'Tap a band to load its values into the sliders and adjust them manually.',
'workflow.step4': 'Tap any point on the image to see the spectral values of each band in real time.',
'workflow.step5': 'At the bottom, the spectral curve or graph of the selected pixel or region is automatically generated.',
'workflow.note': '🔴 The simulated NIR band is generated by a transformation algorithm applied to the input image. Tap (i) for more technical information.',
'bands.visible': 'Visible image (color)',
'bands.blue': 'Blue',
'bands.green': 'Green',
'bands.red': 'Red',
'bands.nir': 'NIR ℹ️',
'cursor.coords': 'Coordinates:',
'cursor.blue': 'Blue:',
'cursor.green': 'Green:',
'cursor.red': 'Red:',
'cursor.nir': 'NIR:',
'chart.title': 'Spectral Signature',
'chart.reset': 'Reset',
'chart.ideal': 'Ideal (green)',
'footer.copyright': '© 2024 GEOWAY',
'footer.rights': 'All educational content rights belong to GEOWAY. Platform for educational purposes.',
'footer.about': 'About',
'footer.tips': 'Tips',
'footer.faq': 'FAQ',
'footer.contact': 'Contact',
},
de: {
'nav.firmas': 'Signaturen',
'nav.ndvi': 'NDVI',
'popup.close': 'Verstanden',
'intro.title': '🌍 EspectroLab / PyroLab — Ein GeoWay-Projekt',
'intro.p1': 'Diese Anwendung ist Teil des <strong>GeoWay Geospatial Lab</strong>, einem Innovationsraum, der sich der Erforschung und Entwicklung von Bildungs-lösungen mit geodätischen Technologien widmet. Unser Ziel ist es, komplexe Konzepte wie spektrale Signaturen oder den NDVI-Index Schülern und Fachleuten durch interaktive und intuitive Werkzeuge näherzubringen.',
'intro.p2': 'Durch visuelle Experimente und praktisches Lernen möchten wir neue Wege inspirieren, Fernerkundung in der Landverwaltung, Notfallhilfe und Umweltstudien zu verstehen und anzuwenden.',
'intro.tagline': 'Ideen erforschen, Lösungen bauen.',
'camera.start': 'Kamera starten',
'camera.capture': 'Aufnehmen und Bänder generieren',
'camera.stop': 'Stopp',
'camera.orUpload': 'Oder eigenes Bild hochladen:',
'camera.loadExample': 'Zurück zu Beispielbildern (img-Ordner)',
'workflow.intro.title': '✨ Einführung',
'workflow.intro.text': 'Diese App ermöglicht es, das Konzept der spektralen Signatur anhand eines Laborbildes zu verstehen, das mit einer Infrarotfilter-Kamera aufgenommen wurde (z.B. eine Pflanze). Ziel ist es, jeder Bande einen quantitativen Wert in Graustufen zuzuweisen, entweder manuell (anhand der Helligkeitsskala) oder automatisch durch Antippen des Farbbildes.',
'workflow.steps.title': '✨ Arbeitsablauf',
'workflow.step1': 'Zu Beginn wird ein Beispielbild geladen und in 4 Bänder zerlegt: Blau, Grün, Rot (sichtbarer Bereich) und ein Nahinfrarot-Band (NIR).',
'workflow.step2': 'Du kannst die Kamera verwenden oder ein Bild hochladen, um neue Bänder zu generieren (simuliertes NIR).',
'workflow.step3': 'Tippe auf ein Band, um seine Werte in die Schieberegler zu laden und manuell anzupassen.',
'workflow.step4': 'Tippe auf einen beliebigen Punkt im Bild, um die Spektralwerte jedes Bandes in Echtzeit anzuzeigen.',
'workflow.step5': 'Unten wird automatisch die Spektralkurve oder Grafik des ausgewählten Pixels oder Bereichs generiert.',
'workflow.note': '🔴 Das simulierte NIR-Band wird durch einen Transformationsalgorithmus erzeugt, der auf das Eingabebild angewendet wird. Tippe auf (i) für weitere technische Informationen.',
'bands.visible': 'Sichtbares Bild (Farbe)',
'bands.blue': 'Blau',
'bands.green': 'Grün',
'bands.red': 'Rot',
'bands.nir': 'NIR ℹ️',
'cursor.coords': 'Koordinaten:',
'cursor.blue': 'Blau:',
'cursor.green': 'Grün:',
'cursor.red': 'Rot:',
'cursor.nir': 'NIR:',
'chart.title': 'Spektrale Signatur',
'chart.reset': 'Zurücksetzen',
'chart.ideal': 'Ideal (grün)',
'footer.copyright': '© 2024 GEOWAY',
'footer.rights': 'Alle Bildungsinhalte gehören GEOWAY. Plattform zu Bildungszwecken.',
'footer.about': 'Über',
'footer.tips': 'Tipps',
'footer.faq': 'FAQ',
'footer.contact': 'Kontakt',
}
};
// Elementos con data-i18n
const i18nElements = document.querySelectorAll('[data-i18n]');
// Función para cambiar idioma
function setLanguage(lang) {
// Actualizar el select
document.getElementById('lang-select').value = lang;
// Traducir elementos
i18nElements.forEach(el => {
const key = el.dataset.i18n;
if (translations[lang] && translations[lang][key]) {
if (el.tagName === 'INPUT' || el.tagName === 'TEXTAREA') {
el.placeholder = translations[lang][key];
} else {
el.innerHTML = translations[lang][key];
}
}
});
// Actualizar popup NIR según el modo actual (real/simulado) y el idioma
actualizarPopupNIRIdioma(lang);
// Cambiar el atributo lang del HTML
document.documentElement.lang = lang;
}
// Función para actualizar el contenido del popup NIR según el idioma y el modo
function actualizarPopupNIRIdioma(lang) {
const modo = nirModo; // variable global definida más abajo
const popupTitle = document.getElementById('popupNIRTitle');
const popupContent = document.getElementById('popupNIRContent');
if (modo === 'real') {
popupTitle.innerHTML = lang === 'es' ? '🌿 Banda NIR (real)' :
lang === 'en' ? '🌿 NIR Band (real)' :
'🌿 NIR-Band (real)';
popupContent.innerHTML = lang === 'es' ? `
<p class="text-gray-300 text-sm">Esta imagen fue obtenida con una <strong>cámara sensible al infrarrojo cercano</strong> en condiciones de laboratorio.</p>
<p class="text-gray-300 text-sm">Refleja la radiación en el espectro de 700-1100 nm, donde la vegetación sana aparece brillante.</p>
<p class="text-gray-400 text-xs mt-2">Fuente: Fotografía multiespectral con filtro NIR.</p>
` : lang === 'en' ? `
<p class="text-gray-300 text-sm">This image was obtained with a <strong>near-infrared sensitive camera</strong> under laboratory conditions.</p>
<p class="text-gray-300 text-sm">It reflects radiation in the 700-1100 nm spectrum, where healthy vegetation appears bright.</p>
<p class="text-gray-400 text-xs mt-2">Source: Multispectral photography with NIR filter.</p>
` : `
<p class="text-gray-300 text-sm">Dieses Bild wurde mit einer <strong>nahen Infrarot-Kamera</strong> unter Laborbedingungen aufgenommen.</p>
<p class="text-gray-300 text-sm">Es reflektiert Strahlung im Spektrum von 700-1100 nm, wo gesunde Vegetation hell erscheint.</p>
<p class="text-gray-400 text-xs mt-2">Quelle: Multispektralfotografie mit NIR-Filter.</p>
`;
} else {
popupTitle.innerHTML = lang === 'es' ? '🌿 Banda NIR (simulada)' :
lang === 'en' ? '🌿 NIR Band (simulated)' :
'🌿 NIR-Band (simuliert)';
popupContent.innerHTML = lang === 'es' ? `
<p class="text-gray-300 text-sm">Esta banda se genera mediante un algoritmo basado en el índice de vegetación simulado:</p>
<div class="bg-gray-800 p-3 rounded-lg font-mono text-sm text-purple-200 my-3">
NIR = 255 · (0.5 + 0.5 · (G - R) / (G + R + ε))
</div>
<p class="text-gray-300 text-sm">Donde ε es una constante pequeña para evitar división por cero. Esta fórmula aproxima el comportamiento espectral de la vegetación: valores altos donde el verde supera al rojo (vegetación sana) y valores bajos en suelos u objetos inertes.</p>
<p class="text-gray-400 text-xs mt-2">Referencia: Adaptado de Tucker, C.J. (1979). "Red and photographic infrared linear combinations for monitoring vegetation". Remote Sensing of Environment.</p>
` : lang === 'en' ? `
<p class="text-gray-300 text-sm">This band is generated by an algorithm based on the simulated vegetation index:</p>
<div class="bg-gray-800 p-3 rounded-lg font-mono text-sm text-purple-200 my-3">
NIR = 255 · (0.5 + 0.5 · (G - R) / (G + R + ε))
</div>
<p class="text-gray-300 text-sm">Where ε is a small constant to avoid division by zero. This formula approximates the spectral behavior of vegetation: high values where green exceeds red (healthy vegetation) and low values in soils or inert objects.</p>
<p class="text-gray-400 text-xs mt-2">Reference: Adapted from Tucker, C.J. (1979). "Red and photographic infrared linear combinations for monitoring vegetation". Remote Sensing of Environment.</p>
` : `
<p class="text-gray-300 text-sm">Dieses Band wird durch einen Algorithmus basierend auf dem simulierten Vegetationsindex generiert:</p>
<div class="bg-gray-800 p-3 rounded-lg font-mono text-sm text-purple-200 my-3">
NIR = 255 · (0.5 + 0.5 · (G - R) / (G + R + ε))
</div>
<p class="text-gray-300 text-sm">Wobei ε eine kleine Konstante ist, um Division durch Null zu vermeiden. Diese Formel nähert das spektrale Verhalten der Vegetation an: hohe Werte, wenn Grün Rot übersteigt (gesunde Vegetation), und niedrige Werte bei Böden oder inerten Objekten.</p>
<p class="text-gray-400 text-xs mt-2">Referenz: Adaptiert von Tucker, C.J. (1979). "Red and photographic infrared linear combinations for monitoring vegetation". Remote Sensing of Environment.</p>
`;
}
}
// Event listener para el select de idioma
document.getElementById('lang-select').addEventListener('change', function(e) {
setLanguage(e.target.value);
});
// Referencias a los canvas
const canvasVisible = document.getElementById('canvasVisible');
const canvasBlue = document.getElementById('canvasBlue');
const canvasGreen = document.getElementById('canvasGreen');
const canvasRed = document.getElementById('canvasRed');
const canvasNir = document.getElementById('canvasNir');
const ctxVisible = canvasVisible.getContext('2d');
const ctxBlue = canvasBlue.getContext('2d');
const ctxGreen = canvasGreen.getContext('2d');
const ctxRed = canvasRed.getContext('2d');
const ctxNir = canvasNir.getContext('2d');
// Sliders y spans
const sliders = {
blue: document.getElementById('sliderBlue'),
green: document.getElementById('sliderGreen'),
red: document.getElementById('sliderRed'),
nir: document.getElementById('sliderNir')
};
const spans = {
blue: document.getElementById('valBlue'),
green: document.getElementById('valGreen'),
red: document.getElementById('valRed'),
nir: document.getElementById('valNir')
};
// Info cursor
const cursorCoords = document.getElementById('cursorCoords');
const cursorBlue = document.getElementById('cursorBlue');
const cursorGreen = document.getElementById('cursorGreen');
const cursorRed = document.getElementById('cursorRed');
const cursorNir = document.getElementById('cursorNir');
// Elementos de cámara
const video = document.getElementById('videoCam');
const startBtn = document.getElementById('startCamera');
const snapshotBtn = document.getElementById('snapshotBtn');
const stopBtn = document.getElementById('stopCamera');
const fileInput = document.getElementById('fileInput');
const loadExampleBtn = document.getElementById('loadExampleBtn');
const flash = document.getElementById('flash');
// Elementos de zoom
const zoomLens = document.getElementById('zoomLens');
const zoomCanvas = document.getElementById('zoomCanvas');
const zoomCtx = zoomCanvas.getContext('2d');
const ZOOM_SIZE = 150; // tamaño del lens
const ZOOM_FACTOR = 2; // factor de aumento
// Variables para ImageData
let imgDataVisible, imgDataBlue, imgDataGreen, imgDataRed, imgDataNir;
let canvasWidth = 0, canvasHeight = 0;
// Variable de modo
let nirModo = 'real'; // por defecto al cargar ejemplo
// Gráfica
const ctxChart = document.getElementById('firmaChart').getContext('2d');
const chart = new Chart(ctxChart, {
type: 'line',
data: {
labels: ['Azul', 'Verde', 'Rojo', 'NIR'],
datasets: [{
label: 'Tu estimación',
data: [0, 0, 0, 0],
borderColor: '#f43f5e',
backgroundColor: 'rgba(244, 63, 94, 0.1)',
tension: 0.2,
pointBackgroundColor: '#f43f5e',
pointBorderColor: '#881337',
borderWidth: 3,
pointRadius: 5
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: { labels: { color: '#d1d5db', font: { family: 'monospace' } } },
tooltip: { backgroundColor: '#1f2937', titleColor: '#9ca3af', bodyColor: '#e5e7eb' }
},
scales: {
y: { min: 0, max: 10, grid: { color: '#374151' }, title: { display: true, text: 'Reflectividad (0-10)', color: '#9ca3af' }, ticks: { stepSize: 1, color: '#d1d5db' } },
x: { grid: { color: '#374151' }, ticks: { color: '#d1d5db' } }
}
}
});
// Sincronizar sliders
for (let key in sliders) {
sliders[key].addEventListener('input', function(e) {
spans[key].textContent = parseFloat(e.target.value).toFixed(1);
actualizarGrafica();
});
spans[key].textContent = sliders[key].value;
}
function actualizarGrafica() {
chart.data.datasets[0].data = [
parseFloat(sliders.blue.value),
parseFloat(sliders.green.value),
parseFloat(sliders.red.value),
parseFloat(sliders.nir.value)
];
chart.update();
}
function actualizarTituloNIR() {
const nirLabel = document.getElementById('nirTitle');
const lang = document.documentElement.lang || 'es';
if (nirModo === 'real') {
nirLabel.innerHTML = lang === 'es' ? 'NIR ℹ️' : lang === 'en' ? 'NIR ℹ️' : 'NIR ℹ️';
} else {
nirLabel.innerHTML = lang === 'es' ? 'NIR (simulado) ℹ️' : lang === 'en' ? 'NIR (simulated) ℹ️' : 'NIR (simuliert) ℹ️';
}
// Actualizar popup según modo e idioma
actualizarPopupNIRIdioma(lang);
}
function calcularNIR(r, g, b) {
const denom = g + r + 1e-5;
const vi = (g - r) / denom;
let nir = 255 * (0.5 + 0.5 * vi);
nir = Math.min(255, Math.max(0, Math.floor(nir)));
return nir;
}
function procesarImagen(img) {
nirModo = 'simulado';
actualizarTituloNIR();
const maxDim = 400;
let w = img.naturalWidth || img.width;
let h = img.naturalHeight || img.height;
let scale = Math.min(maxDim / w, maxDim / h, 1);
w = Math.floor(w * scale);
h = Math.floor(h * scale);
canvasWidth = w;
canvasHeight = h;
[canvasVisible, canvasBlue, canvasGreen, canvasRed, canvasNir].forEach(c => { c.width = w; c.height = h; });
ctxVisible.drawImage(img, 0, 0, w, h);
try {
imgDataVisible = ctxVisible.getImageData(0, 0, w, h);
} catch (e) {
console.warn('CORS error');
document.getElementById('corsWarning').style.display = 'block';
return;
}
const data = imgDataVisible.data;
const dataBlue = new Uint8ClampedArray(data.length);
const dataGreen = new Uint8ClampedArray(data.length);
const dataRed = new Uint8ClampedArray(data.length);
const dataNir = new Uint8ClampedArray(data.length);
for (let i = 0; i < data.length; i += 4) {
const r = data[i];
const g = data[i+1];
const b = data[i+2];
dataBlue[i] = b; dataBlue[i+1] = b; dataBlue[i+2] = b; dataBlue[i+3] = 255;
dataGreen[i] = g; dataGreen[i+1] = g; dataGreen[i+2] = g; dataGreen[i+3] = 255;
dataRed[i] = r; dataRed[i+1] = r; dataRed[i+2] = r; dataRed[i+3] = 255;
const nirVal = calcularNIR(r, g, b);
dataNir[i] = nirVal; dataNir[i+1] = nirVal; dataNir[i+2] = nirVal; dataNir[i+3] = 255;
}
imgDataBlue = new ImageData(dataBlue, w, h);
imgDataGreen = new ImageData(dataGreen, w, h);
imgDataRed = new ImageData(dataRed, w, h);
imgDataNir = new ImageData(dataNir, w, h);
ctxBlue.putImageData(imgDataBlue, 0, 0);
ctxGreen.putImageData(imgDataGreen, 0, 0);
ctxRed.putImageData(imgDataRed, 0, 0);
ctxNir.putImageData(imgDataNir, 0, 0);
sliders.blue.value = 0; sliders.green.value = 0; sliders.red.value = 0; sliders.nir.value = 0;
spans.blue.textContent = '0.0'; spans.green.textContent = '0.0'; spans.red.textContent = '0.0'; spans.nir.textContent = '0.0';
actualizarGrafica();
actualizarCursor(0, 0);
}
function cargarImagenesPredeterminadas() {
nirModo = 'real';
actualizarTituloNIR();
const sources = {
visible: 'img/visible.jpg',
blue: 'img/blue.jpg',
green: 'img/green.jpg',
red: 'img/red.jpg',
nir: 'img/nir.jpg'
};
let loaded = 0;
const imgs = {};
const total = 5;
function checkAll() {
if (++loaded === total) {
const first = imgs.visible;
let w = first.naturalWidth;
let h = first.naturalHeight;
const maxDim = 400;
if (w > maxDim || h > maxDim) {
const scale = maxDim / Math.max(w, h);
w = Math.floor(w * scale);
h = Math.floor(h * scale);
}
canvasWidth = w;
canvasHeight = h;
[canvasVisible, canvasBlue, canvasGreen, canvasRed, canvasNir].forEach(c => { c.width = w; c.height = h; });
ctxVisible.drawImage(imgs.visible, 0, 0, w, h);
ctxBlue.drawImage(imgs.blue, 0, 0, w, h);
ctxGreen.drawImage(imgs.green, 0, 0, w, h);
ctxRed.drawImage(imgs.red, 0, 0, w, h);
ctxNir.drawImage(imgs.nir, 0, 0, w, h);
try {
imgDataVisible = ctxVisible.getImageData(0, 0, w, h);
imgDataBlue = ctxBlue.getImageData(0, 0, w, h);
imgDataGreen = ctxGreen.getImageData(0, 0, w, h);
imgDataRed = ctxRed.getImageData(0, 0, w, h);
imgDataNir = ctxNir.getImageData(0, 0, w, h);
} catch (e) {
console.warn('CORS error');
document.getElementById('corsWarning').style.display = 'block';
}
sliders.blue.value = 0; sliders.green.value = 0; sliders.red.value = 0; sliders.nir.value = 0;
spans.blue.textContent = '0.0'; spans.green.textContent = '0.0'; spans.red.textContent = '0.0'; spans.nir.textContent = '0.0';
actualizarGrafica();
actualizarCursor(0, 0);
}
}
for (let key in sources) {
const img = new Image();
img.crossOrigin = 'Anonymous';
img.onload = () => {
imgs[key] = img;
checkAll();
};
img.onerror = () => {
console.warn(`No se pudo cargar ${sources[key]}. Usando patrón.`);
const canvas = document.createElement('canvas');
canvas.width = 400;
canvas.height = 400;
const ctx = canvas.getContext('2d');
ctx.fillStyle = '#1e293b';
ctx.fillRect(0, 0, 400, 400);
ctx.fillStyle = '#9ca3af';
ctx.font = '20px monospace';
ctx.fillText('no img', 150, 200);
const imgPlaceholder = new Image();
imgPlaceholder.src = canvas.toDataURL();
imgs[key] = imgPlaceholder;
checkAll();
};
img.src = sources[key];
}
}
function getReflectivity(imgData, x, y) {
if (!imgData) return 0;
const idx = (y * imgData.width + x) * 4;
return imgData.data[idx] / 25.5;
}
// Función para dibujar líneas de cursor
function dibujarCrosshairEnCanvas(ctx, x, y) {
ctx.save();
ctx.strokeStyle = 'rgba(255, 255, 255, 0.8)';
ctx.lineWidth = 1;
ctx.beginPath();
ctx.moveTo(0, y + 0.5);
ctx.lineTo(ctx.canvas.width, y + 0.5);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(x + 0.5, 0);
ctx.lineTo(x + 0.5, ctx.canvas.height);
ctx.stroke();
ctx.restore();
}
function redrawAllImages() {
if (!imgDataVisible) return;
ctxVisible.putImageData(imgDataVisible, 0, 0);
ctxBlue.putImageData(imgDataBlue, 0, 0);
ctxGreen.putImageData(imgDataGreen, 0, 0);
ctxRed.putImageData(imgDataRed, 0, 0);
ctxNir.putImageData(imgDataNir, 0, 0);
}
// Actualizar cursor y zoom
function actualizarCursor(x, y) {
if (!imgDataVisible || x < 0 || y < 0 || x >= canvasWidth || y >= canvasHeight) {
zoomLens.style.display = 'none';
return;
}
cursorCoords.textContent = `${x}, ${y}`;
cursorBlue.textContent = getReflectivity(imgDataBlue, x, y).toFixed(1);
cursorGreen.textContent = getReflectivity(imgDataGreen, x, y).toFixed(1);
cursorRed.textContent = getReflectivity(imgDataRed, x, y).toFixed(1);
cursorNir.textContent = getReflectivity(imgDataNir, x, y).toFixed(1);
redrawAllImages();
dibujarCrosshairEnCanvas(ctxVisible, x, y);
dibujarCrosshairEnCanvas(ctxBlue, x, y);
dibujarCrosshairEnCanvas(ctxGreen, x, y);
dibujarCrosshairEnCanvas(ctxRed, x, y);
dibujarCrosshairEnCanvas(ctxNir, x, y);
// Actualizar zoom
actualizarZoom(x, y);
}
// Función para actualizar el zoom
function actualizarZoom(x, y) {
if (!imgDataVisible) return;
const w = canvasWidth;
const h = canvasHeight;
const size = ZOOM_SIZE / ZOOM_FACTOR; // área a capturar en la imagen original
let srcX = x - size/2;
let srcY = y - size/2;
// Ajustar para no salir de la imagen
srcX = Math.max(0, Math.min(srcX, w - size));
srcY = Math.max(0, Math.min(srcY, h - size));
// Dibujar en el canvas de zoom
zoomCtx.clearRect(0, 0, ZOOM_SIZE, ZOOM_SIZE);
zoomCtx.drawImage(
canvasVisible,
srcX, srcY, size, size,
0, 0, ZOOM_SIZE, ZOOM_SIZE
);
// Dibujar un pequeño retículo en el centro del zoom