-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
2843 lines (2590 loc) · 144 KB
/
index.html
File metadata and controls
2843 lines (2590 loc) · 144 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="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>QSMbly | Quantitative Susceptibility Mapping</title>
<link rel="icon" href="favicon.ico" type="image/x-icon">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap" rel="stylesheet">
<!-- Tagify (load before our CSS so we can override) -->
<link rel="stylesheet" href="https://unpkg.com/@yaireo/tagify/dist/tagify.css">
<script src="https://unpkg.com/@yaireo/tagify"></script>
<!-- Our styles last to override -->
<link rel="stylesheet" href="css/modern-styles.css">
<!-- NiiVue -->
<script type="module">
import { Niivue, NVImage } from "https://unpkg.com/@niivue/niivue@0.57.0/dist/index.js";
window.Niivue = Niivue;
window.NVImage = NVImage;
</script>
</head>
<body>
<div class="app-container">
<!-- Header -->
<header class="app-header">
<div class="logo">
<div class="logo-icon">
<img src="QSMbly.png" alt="QSMbly" width="20" height="20">
</div>
<h1>QSMbly <span>Quantitative Susceptibility Mapping</span> <span class="version" id="appVersion"></span></h1>
</div>
<div class="header-links">
<button class="header-link" id="openAbout" title="About">
<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="12" r="10"/>
<line x1="12" y1="16" x2="12" y2="12"/>
<line x1="12" y1="8" x2="12.01" y2="8"/>
</svg>
<span>About</span>
</button>
<button class="header-link" id="openCitations" title="Citations">
<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M4 19.5A2.5 2.5 0 0 1 6.5 17H20"/>
<path d="M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"/>
</svg>
<span>Citations</span>
</button>
<button class="header-link" id="openPrivacy" title="Privacy">
<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/>
</svg>
<span>Privacy</span>
</button>
<a href="https://github.com/astewartau/qsmbly" target="_blank" rel="noopener noreferrer" class="header-link" title="View on GitHub">
<svg viewBox="0 0 16 16" width="20" height="20" fill="white">
<path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"/>
</svg>
<span>GitHub</span>
</a>
</div>
</header>
<!-- Sidebar -->
<aside class="app-sidebar" id="sidebar">
<div class="sidebar-scroll">
<!-- File Upload Section -->
<section class="sidebar-section" id="inputSection">
<h2 class="section-title" onclick="toggleSection(this.parentElement)">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/>
<polyline points="17 8 12 3 7 8"/>
<line x1="12" y1="3" x2="12" y2="15"/>
</svg>
Input Files
</h2>
<div class="section-content">
<!-- Input Mode Tabs -->
<div class="input-mode-tabs" id="inputModeTabs">
<button class="input-mode-tab active" data-mode="dicom">DICOM</button>
<button class="input-mode-tab" data-mode="nifti">NIfTI</button>
</div>
<!-- NIfTI Sub-type Tabs (only visible when NIfTI is selected) -->
<div class="input-subtype-tabs" id="inputSubtypeTabs" style="display: none;">
<button class="input-subtype-tab active" data-mode="raw">Mag+Phase</button>
<button class="input-subtype-tab" data-mode="totalField">Total Field</button>
<button class="input-subtype-tab" data-mode="localField">Local Field</button>
</div>
<!-- Raw Images Mode -->
<div class="input-mode-content" id="inputModeRaw" data-mode="raw">
<!-- Magnitude Files -->
<div class="file-upload-group">
<div class="file-upload-header">
<label class="file-upload-label">
Magnitude <span class="count" id="magCount"></span>
</label>
<button class="btn-icon btn-preview" id="vis_magnitude" title="Preview magnitude" disabled>
<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2">
<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/>
<circle cx="12" cy="12" r="3"/>
</svg>
</button>
</div>
<div class="upload-group">
<div class="file-upload-zone file-drop" id="magnitudeDrop">
<input type="file" id="magnitudeFiles" accept=".nii,.nii.gz" multiple>
<svg class="upload-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/>
<polyline points="17 8 12 3 7 8"/>
<line x1="12" y1="3" x2="12" y2="15"/>
</svg>
<p class="upload-text file-drop-label"><span>Drop or click</span></p>
</div>
<div class="file-list" id="magnitudeList"></div>
</div>
</div>
<!-- Phase Files -->
<div class="file-upload-group">
<div class="file-upload-header">
<label class="file-upload-label">
Phase <span class="count" id="phaseCount"></span>
</label>
<button class="btn-icon btn-preview" id="vis_phase" title="Preview phase" disabled>
<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2">
<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/>
<circle cx="12" cy="12" r="3"/>
</svg>
</button>
</div>
<div class="upload-group">
<div class="file-upload-zone file-drop" id="phaseDrop">
<input type="file" id="phaseFiles" accept=".nii,.nii.gz" multiple>
<svg class="upload-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/>
<polyline points="17 8 12 3 7 8"/>
<line x1="12" y1="3" x2="12" y2="15"/>
</svg>
<p class="upload-text file-drop-label"><span>Drop or click</span></p>
</div>
<div class="file-list" id="phaseList"></div>
</div>
</div>
</div>
<!-- DICOM Mode -->
<div class="input-mode-content active" id="inputModeDicom" data-mode="dicom">
<div class="file-upload-group">
<div class="upload-group">
<div class="file-upload-zone file-drop" id="dicomDrop">
<input type="file" id="dicomFiles" webkitdirectory multiple>
<svg class="upload-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/>
<polyline points="17 8 12 3 7 8"/>
<line x1="12" y1="3" x2="12" y2="15"/>
</svg>
<p class="upload-text file-drop-label"><span>Drop DICOM folder or click</span></p>
</div>
</div>
</div>
<!-- Conversion status -->
<div class="dicom-status" id="dicomStatus" style="display: none;">
<div class="dicom-spinner"></div>
<span class="dicom-status-text" id="dicomStatusText">Converting...</span>
</div>
<!-- Triage area: populated dynamically after DICOM conversion -->
<div id="dicomTriage" style="display: none;"></div>
<!-- dicompare validation button -->
<button class="btn btn-secondary btn-dicompare" id="dicompareReportBtn" disabled>
<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2">
<path d="M9 11l3 3L22 4"/>
<path d="M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"/>
</svg>
dicompare Report
</button>
</div>
<!-- Total Field Map Mode -->
<div class="input-mode-content" id="inputModeTotalField" data-mode="totalField">
<div class="file-upload-group">
<div class="file-upload-header">
<label class="file-upload-label">Total Field Map</label>
<button class="btn-icon btn-preview" id="vis_totalField" title="Preview total field map" disabled>
<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2">
<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/>
<circle cx="12" cy="12" r="3"/>
</svg>
</button>
</div>
<div class="upload-group">
<div class="file-upload-zone file-drop" id="totalFieldDrop">
<input type="file" id="totalFieldFiles" accept=".nii,.nii.gz">
<svg class="upload-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/>
<polyline points="17 8 12 3 7 8"/>
<line x1="12" y1="3" x2="12" y2="15"/>
</svg>
<p class="upload-text file-drop-label"><span>Drop or click</span></p>
</div>
<div class="file-list" id="totalFieldList"></div>
</div>
</div>
<div class="file-upload-group">
<div class="file-upload-header">
<label class="file-upload-label">Magnitude <span class="optional-label">(optional)</span></label>
<button class="btn-icon btn-preview" id="vis_magnitudeTF" title="Preview magnitude" disabled>
<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2">
<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/>
<circle cx="12" cy="12" r="3"/>
</svg>
</button>
</div>
<div class="upload-group">
<div class="file-upload-zone file-drop" id="magnitudeTFDrop">
<input type="file" id="magnitudeTFFiles" accept=".nii,.nii.gz" multiple>
<svg class="upload-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/>
<polyline points="17 8 12 3 7 8"/>
<line x1="12" y1="3" x2="12" y2="15"/>
</svg>
<p class="upload-text file-drop-label"><span>Drop or click</span></p>
</div>
<div class="file-list" id="magnitudeTFList"></div>
</div>
</div>
</div>
<!-- Local Field Map Mode -->
<div class="input-mode-content" id="inputModeLocalField" data-mode="localField">
<div class="file-upload-group">
<div class="file-upload-header">
<label class="file-upload-label">Local Field Map</label>
<button class="btn-icon btn-preview" id="vis_localField" title="Preview local field map" disabled>
<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2">
<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/>
<circle cx="12" cy="12" r="3"/>
</svg>
</button>
</div>
<div class="upload-group">
<div class="file-upload-zone file-drop" id="localFieldDrop">
<input type="file" id="localFieldFiles" accept=".nii,.nii.gz">
<svg class="upload-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/>
<polyline points="17 8 12 3 7 8"/>
<line x1="12" y1="3" x2="12" y2="15"/>
</svg>
<p class="upload-text file-drop-label"><span>Drop or click</span></p>
</div>
<div class="file-list" id="localFieldList"></div>
</div>
</div>
<div class="file-upload-group">
<div class="file-upload-header">
<label class="file-upload-label">Magnitude <span class="optional-label">(optional)</span></label>
<button class="btn-icon btn-preview" id="vis_magnitudeLF" title="Preview magnitude" disabled>
<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2">
<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/>
<circle cx="12" cy="12" r="3"/>
</svg>
</button>
</div>
<div class="upload-group">
<div class="file-upload-zone file-drop" id="magnitudeLFDrop">
<input type="file" id="magnitudeLFFiles" accept=".nii,.nii.gz" multiple>
<svg class="upload-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/>
<polyline points="17 8 12 3 7 8"/>
<line x1="12" y1="3" x2="12" y2="15"/>
</svg>
<p class="upload-text file-drop-label"><span>Drop or click</span></p>
</div>
<div class="file-list" id="magnitudeLFList"></div>
</div>
</div>
</div>
</div>
</section>
<!-- Input Parameters Section -->
<section class="sidebar-section collapsed" id="paramsSection">
<h2 class="section-title" onclick="toggleSection(this.parentElement)">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="12" r="3"/>
<path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"/>
</svg>
Input Parameters
</h2>
<div class="section-content">
<!-- Field Map Units (shown for totalField and localField modes) -->
<div class="param-group input-param-fieldmap" id="fieldMapUnitsGroup" style="display: none;">
<label class="param-label" for="fieldMapUnits">Field Map Units</label>
<select id="fieldMapUnits">
<option value="hz">Hz</option>
<option value="rad_s">rad/s</option>
<option value="ppm">ppm</option>
</select>
</div>
<!-- JSON Metadata Upload (NIfTI mode only) -->
<div class="param-group input-param-raw" id="jsonMetadataGroup" style="display: none;">
<label class="param-label">
JSON Metadata <span class="count" id="jsonCount"></span>
</label>
<div class="upload-group compact">
<div class="file-upload-zone file-drop compact" id="jsonDrop">
<input type="file" id="jsonFiles" accept=".json" multiple>
<svg class="upload-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/>
<polyline points="17 8 12 3 7 8"/>
<line x1="12" y1="3" x2="12" y2="15"/>
</svg>
<p class="upload-text file-drop-label"><span>Drop files or click</span></p>
</div>
<div class="file-list" id="jsonList"></div>
</div>
</div>
<!-- Field Strength (hidden when units are ppm) -->
<div class="param-group" id="fieldStrengthGroup">
<label class="param-label" for="magField">Field Strength</label>
<div class="param-inline">
<input type="number" id="magField" value="3.0" step="0.1" min="0.1">
<span class="unit">Tesla</span>
</div>
</div>
<!-- Echo Times (raw mode only) -->
<div class="param-group input-param-raw" id="echoTimesGroup">
<label class="param-label">Echo Times <span class="unit-inline">(ms)</span></label>
<input type="text" id="echoTimesTagify" placeholder="Type values...">
</div>
</div>
</section>
<!-- Magnitude Preparation Section -->
<section class="sidebar-section collapsed" id="magnitudePrepSection">
<h2 class="section-title" onclick="toggleSection(this.parentElement)">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M12 2v4m0 12v4M4.93 4.93l2.83 2.83m8.48 8.48l2.83 2.83M2 12h4m12 0h4M4.93 19.07l2.83-2.83m8.48-8.48l2.83-2.83"/>
</svg>
Magnitude Preparation
</h2>
<div class="section-content">
<div class="param-group">
<label class="param-label" for="maskInputSource">Magnitude Source</label>
<select id="maskInputSource">
<option value="first_echo">First-echo magnitude</option>
<option value="combined" selected>Combined magnitude (RSS)</option>
</select>
</div>
<div class="param-group">
<label class="checkbox-label">
<input type="checkbox" id="applyBiasCorrection" checked>
<span>Apply bias correction</span>
</label>
</div>
<button class="btn btn-secondary btn-sm" id="prepareMaskInput" style="width: 100%; margin-bottom: 0;" disabled>
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M12 2v4m0 12v4M4.93 4.93l2.83 2.83m8.48 8.48l2.83 2.83M2 12h4m12 0h4M4.93 19.07l2.83-2.83m8.48-8.48l2.83-2.83"/>
</svg>
Prepare
</button>
</div>
</section>
<!-- Masking Section -->
<section class="sidebar-section collapsed" id="maskSection">
<h2 class="section-title" onclick="toggleSection(this.parentElement)">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"/>
</svg>
Masking
</h2>
<div class="section-content">
<!-- Direct mask file upload -->
<div class="param-group" id="maskUploadGroup">
<div class="file-upload-header">
<label class="param-label">Upload Mask <span class="optional-label">(optional)</span></label>
<button class="btn-icon btn-preview" id="vis_mask" title="Preview mask" disabled>
<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2">
<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/>
<circle cx="12" cy="12" r="3"/>
</svg>
</button>
</div>
<div class="upload-group compact">
<div class="file-upload-zone file-drop compact" id="maskDrop">
<input type="file" id="maskFiles" accept=".nii,.nii.gz">
<svg class="upload-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/>
<polyline points="17 8 12 3 7 8"/>
<line x1="12" y1="3" x2="12" y2="15"/>
</svg>
<p class="upload-text file-drop-label"><span>Drop or click</span></p>
</div>
<div class="file-list" id="maskList"></div>
</div>
</div>
<!-- Divider shown when magnitude is prepared -->
<div class="mask-divider" id="maskDivider" style="display: none;">
<span>or generate from magnitude</span>
</div>
<div class="mask-preview-buttons" id="maskGenerateButtons">
<button class="btn btn-secondary btn-sm" id="previewMask" title="Generate mask from threshold" disabled>
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/>
<circle cx="12" cy="12" r="3"/>
</svg>
Threshold
</button>
<button class="btn btn-secondary btn-sm" id="runBET" title="BET brain extraction (slower but more accurate)" disabled>
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="12" cy="12" r="10"/>
<path d="M12 8c-2.2 0-4 1.8-4 4s1.8 4 4 4 4-1.8 4-4"/>
</svg>
BET
</button>
</div>
<!-- Threshold Slider (enabled only after Threshold button is pressed) -->
<div class="param-group" id="thresholdSliderGroup" style="margin-top: var(--space-sm);">
<div class="threshold-header">
<label class="param-label" for="maskThreshold" id="thresholdLabel">Threshold</label>
<button class="btn-icon" id="autoThreshold" title="Reset to Otsu threshold" disabled>
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M23 4v6h-6"/>
<path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"/>
</svg>
</button>
</div>
<input type="range" id="maskThreshold" min="1" max="100" value="15" class="threshold-slider" disabled>
</div>
<!-- Morphological Operations (collapsible subsection) -->
<div class="mask-operations subsection collapsed" id="maskOperations" style="display: none;">
<div class="subsection-title" onclick="this.parentElement.classList.toggle('collapsed')">Refine Mask</div>
<div class="subsection-content">
<div class="mask-op-buttons">
<button class="btn btn-secondary btn-sm" id="fillHoles" title="Fill holes inside the mask">
Fill Holes
</button>
<button class="btn btn-secondary btn-sm" id="erodeMask" title="Shrink mask boundaries">
Erode
</button>
<button class="btn btn-secondary btn-sm" id="dilateMask" title="Expand mask boundaries">
Dilate
</button>
<button class="btn btn-secondary btn-sm" id="resetMask" title="Reset to threshold-based mask">
Reset
</button>
</div>
<!-- Drawing/Painting Tools -->
<label class="param-label" style="margin-top: var(--space-sm); margin-bottom: var(--space-xs);">Paint Mask</label>
<div class="drawing-controls">
<div class="brush-mode-buttons">
<button class="btn btn-secondary btn-sm" id="enableDrawing" title="Enable brush painting">
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M12 19l7-7 3 3-7 7-3-3z"/>
<path d="M18 13l-1.5-7.5L2 2l3.5 14.5L13 18l5-5z"/>
<path d="M2 2l7.586 7.586"/>
</svg>
Draw
</button>
<button class="btn btn-secondary btn-sm" id="brushAdd" title="Add to mask" disabled>
+ Add
</button>
<button class="btn btn-secondary btn-sm" id="brushRemove" title="Remove from mask" disabled>
- Remove
</button>
</div>
<div class="brush-size-control" id="brushSizeControl" style="display: none;">
<label class="param-label" style="font-size: 0.7rem;">Brush Size: <span id="brushSizeValue">2</span></label>
<input type="range" id="brushSize" min="1" max="10" value="2" class="threshold-slider">
</div>
<div class="drawing-actions" id="drawingActions" style="display: none;">
<button class="btn btn-secondary btn-sm" id="undoDraw" title="Undo last stroke">
Undo
</button>
<button class="btn btn-primary btn-sm" id="applyDrawing" title="Apply drawing to mask">
Apply
</button>
</div>
</div>
</div>
</div>
</div>
</section>
<!-- SWI Section -->
<section class="sidebar-section collapsed" id="swiSection">
<h2 class="section-title" onclick="toggleSection(this.parentElement)">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7z"/>
<circle cx="12" cy="12" r="3"/>
</svg>
SWI
</h2>
<div class="section-content">
<button class="btn btn-primary" id="runSWI" style="width: 100%;">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<polygon points="5 3 19 12 5 21 5 3"/>
</svg>
<span>Start SWI</span>
</button>
</div>
</section>
<!-- Pipeline Section -->
<section class="sidebar-section collapsed" id="pipelineSection">
<h2 class="section-title" onclick="toggleSection(this.parentElement)">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="12" r="3"/>
<path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"/>
</svg>
QSM Pipeline
</h2>
<div class="section-content">
<div id="sidebarPipelineDropdowns">
<div class="param-group" id="sidebarMethodGroup">
<label class="param-label">Pipeline</label>
<select id="sidebarCombinedMethod">
<option value="none" selected>Standard</option>
<option value="tgv">TGV</option>
<option value="qsmart">QSMART</option>
</select>
</div>
<div class="param-group" id="sidebarUnwrapGroup">
<label class="param-label">Phase Unwrapping</label>
<select id="sidebarUnwrapMethod">
<option value="romeo" selected>ROMEO</option>
<option value="laplacian">Laplacian</option>
</select>
</div>
<div class="param-group" id="sidebarBgRemovalGroup">
<label class="param-label">Background Removal</label>
<select id="sidebarBgRemovalMethod">
<option value="vsharp" selected>V-SHARP</option>
<option value="sharp">SHARP</option>
<option value="ismv">iSMV</option>
<option value="pdf">PDF</option>
<option value="lbv">LBV</option>
</select>
</div>
<div class="param-group" id="sidebarDipoleGroup">
<label class="param-label">Dipole Inversion</label>
<select id="sidebarDipoleMethod">
<option value="tkd">TKD</option>
<option value="tsvd">TSVD</option>
<option value="tikhonov">Tikhonov</option>
<option value="tv" selected>TV-ADMM</option>
<option value="rts">RTS</option>
<option value="nltv">NLTV</option>
<option value="medi">MEDI</option>
<option value="ilsqr">iLSQR</option>
</select>
</div>
</div>
<div style="display: flex; gap: 8px;">
<button class="btn btn-secondary" id="openPipelineSettings" style="flex: 1;">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="12" cy="12" r="3"/>
<path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"/>
</svg>
Advanced
</button>
<button class="btn btn-primary" id="runPipelineSidebar" style="flex: 3;">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<polygon points="5 3 19 12 5 21 5 3"/>
</svg>
<span>Start QSM</span>
</button>
</div>
</div>
</section>
<!-- Results Section - dynamically populated -->
<section class="sidebar-section hidden collapsed" id="stage-buttons">
<h2 class="section-title" onclick="toggleSection(this.parentElement)">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/>
<polyline points="22 4 12 14.01 9 11.01"/>
</svg>
Results
</h2>
<div class="section-content">
<!-- Stage buttons are dynamically added here -->
<div class="stage-buttons-grid" id="dynamicStageButtons"></div>
<button class="btn btn-secondary btn-sm" id="clearAllResults" style="width: 100%; margin-top: var(--space-sm);">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<polyline points="3 6 5 6 21 6"/>
<path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/>
</svg>
Clear All
</button>
</div>
</section>
</div>
<!-- Status Bar (fixed at bottom) -->
<div class="sidebar-status" id="statusBar">
<div class="status-header">
<span class="status-label">Status</span>
<div class="status-right">
<span class="status-value" id="progressText">Ready</span>
<button class="btn-status-cancel" id="cancelPipeline" title="Cancel pipeline" disabled>
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<line x1="18" y1="6" x2="6" y2="18"/>
<line x1="6" y1="6" x2="18" y2="18"/>
</svg>
</button>
</div>
</div>
<div class="progress-bar">
<div class="progress-fill" id="progressFill" style="width: 0%"></div>
</div>
</div>
</aside>
<!-- Main Content -->
<main class="app-main">
<!-- Viewer Toolbar -->
<div class="viewer-toolbar">
<div class="view-tabs">
<button class="view-tab active" data-view="multiplanar">3-Plane</button>
<button class="view-tab" data-view="axial">Axial</button>
<button class="view-tab" data-view="coronal">Coronal</button>
<button class="view-tab" data-view="sagittal">Sagittal</button>
<button class="view-tab" data-view="render">3D</button>
</div>
<!-- Echo Navigation (hidden when not multi-echo) -->
<div class="echo-nav" id="echoNav" style="display: none;">
<button class="btn btn-sm btn-icon" id="echoPrev" title="Previous echo">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="16" height="16">
<polyline points="15 18 9 12 15 6"/>
</svg>
</button>
<span class="echo-label" id="echoLabel">Echo 1/1</span>
<button class="btn btn-sm btn-icon" id="echoNext" title="Next echo">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="16" height="16">
<polyline points="9 18 15 12 9 6"/>
</svg>
</button>
</div>
<div class="viewer-actions">
<div class="window-controls">
<input type="number" id="windowMin" class="window-input" placeholder="min" step="any" title="Window minimum">
<div class="range-slider-container">
<input type="range" id="rangeMin" class="range-slider range-min" min="0" max="100" value="0">
<input type="range" id="rangeMax" class="range-slider range-max" min="0" max="100" value="100">
<div class="range-track"></div>
<div class="range-selected" id="rangeSelected"></div>
</div>
<input type="number" id="windowMax" class="window-input" placeholder="max" step="any" title="Window maximum">
<button class="btn btn-sm" id="resetWindow" title="Reset to full range">Auto</button>
</div>
<label class="interp-checkbox">
<input type="checkbox" id="interpolation">
<span>Interp</span>
</label>
<span class="data-units" id="dataUnits"></span>
<label class="opacity-control" id="overlayOpacityControl" style="display: none;">
<span>Overlay</span>
<input type="range" id="overlayOpacity" min="0" max="100" value="50">
<span id="overlayOpacityValue">50%</span>
</label>
<select class="colormap-select" id="colormapSelect">
<option value="gray">Gray</option>
<option value="hot">Hot</option>
<option value="cool">Cool</option>
<option value="viridis">Viridis</option>
<option value="plasma">Plasma</option>
</select>
<label class="interp-checkbox">
<input type="checkbox" id="colorbarToggle">
<span>Colorbar</span>
</label>
<label class="interp-checkbox">
<input type="checkbox" id="crosshairToggle" checked>
<span>Crosshair</span>
</label>
<button class="btn btn-sm btn-icon" id="downloadCurrentVolume" title="Download current image as NIfTI" disabled>
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/>
<polyline points="7 10 12 15 17 10"/>
<line x1="12" y1="15" x2="12" y2="3"/>
</svg>
</button>
<button class="btn btn-sm btn-icon" id="screenshotViewer" title="Save screenshot as PNG">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<rect x="3" y="3" width="18" height="18" rx="2" ry="2"/>
<circle cx="8.5" cy="8.5" r="1.5"/>
<polyline points="21 15 16 10 5 21"/>
</svg>
</button>
</div>
</div>
<!-- NiiVue Canvas -->
<div class="viewer-canvas-wrapper">
<canvas id="gl1"></canvas>
</div>
<!-- Viewer Info Bar -->
<div class="viewer-info">
<span id="intensity">Upload an image to begin</span>
</div>
<!-- Console -->
<div class="console-container" id="console">
<div class="console-header">
<span class="console-title">Console</span>
<button class="console-clear" id="clearConsole">Clear</button>
</div>
<div class="console-output" id="consoleOutput">
</div>
</div>
</main>
<!-- Footer -->
<footer class="app-footer">
<span>QSMbly | Browser-based Quantitative Susceptibility Mapping</span>
<span>Powered by Rust, WebAssembly & NiiVue</span>
</footer>
</div>
<!-- Modals (outside app-container for proper z-index stacking) -->
<!-- Pipeline Settings Modal -->
<div class="modal-overlay" id="pipelineSettingsModal">
<div class="modal">
<div class="modal-header">
<h3>Pipeline Settings</h3>
<button class="modal-close" id="closePipelineSettings">×</button>
</div>
<div class="modal-body">
<!-- QSM Pipeline Method Section -->
<div class="settings-section">
<h4>QSM Pipeline</h4>
<div class="param-group">
<label class="param-label" for="combinedMethod">Method</label>
<select id="combinedMethod">
<option value="none" selected>Standard Pipeline</option>
<option value="tgv">TGV (Total Generalized Variation)</option>
<option value="qsmart">QSMART (QSM Artifact Reduction Technique)</option>
</select>
</div>
<!-- TGV Settings -->
<div id="tgvSettings" class="method-settings" style="display: none;">
<div class="method-links">
<a href="https://doi.org/10.1016/j.neuroimage.2015.02.041" target="_blank" rel="noopener" title="DOI: 10.1016/j.neuroimage.2015.02.041"><svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/></svg>Paper</a>
<a href="https://doi.org/10.1002/nbm.3570" target="_blank" rel="noopener" title="DOI: 10.1002/nbm.3570"><svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/></svg>Paper</a>
<a href="https://github.com/korbinian90/QuantitativeSusceptibilityMappingTGV.jl" target="_blank" rel="noopener" title="Code: QuantitativeSusceptibilityMappingTGV.jl"><svg viewBox="0 0 16 16" width="14" height="14" fill="currentColor"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"/></svg>Code</a>
</div>
<div class="param-group">
<label class="param-label" for="tgvRegularization">Regularization Level</label>
<select id="tgvRegularization">
<option value="1">1 - Low (sharper, more noise)</option>
<option value="2" selected>2 - Default</option>
<option value="3">3 - High (smoother)</option>
<option value="4">4 - Very High (very smooth)</option>
</select>
</div>
<div class="param-group">
<label class="param-label" for="tgvIterations">Iterations</label>
<input type="number" id="tgvIterations" value="1000" min="100" max="5000" step="100">
</div>
<div class="param-group">
<label class="param-label" for="tgvErosions">Mask Erosions</label>
<input type="number" id="tgvErosions" value="3" min="0" max="10" step="1">
</div>
</div>
<!-- QSMART Settings -->
<div id="qsmartSettings" class="method-settings" style="display: none;">
<div class="method-links">
<a href="https://doi.org/10.1016/j.neuroimage.2021.117701" target="_blank" rel="noopener" title="DOI: 10.1016/j.neuroimage.2021.117701"><svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/></svg>Paper</a>
<a href="https://github.com/wtsyeda/QSMART" target="_blank" rel="noopener" title="Code: QSMART"><svg viewBox="0 0 16 16" width="14" height="14" fill="currentColor"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"/></svg>Code</a>
</div>
<h5 style="margin: var(--space-sm) 0 var(--space-xs); font-size: 0.8rem; color: var(--color-text-muted);">Stage 1: Whole ROI</h5>
<div class="param-group">
<label class="param-label" for="qsmartSdfSigma1Stage1">SDF Sigma 1 (voxels)</label>
<input type="number" id="qsmartSdfSigma1Stage1" value="10" min="1" max="30" step="1">
</div>
<div class="param-group">
<label class="param-label" for="qsmartSdfSigma2Stage1">SDF Sigma 2 (voxels)</label>
<input type="number" id="qsmartSdfSigma2Stage1" value="0" min="0" max="30" step="1">
</div>
<h5 style="margin: var(--space-sm) 0 var(--space-xs); font-size: 0.8rem; color: var(--color-text-muted);">Stage 2: Tissue Only</h5>
<div class="param-group">
<label class="param-label" for="qsmartSdfSigma1Stage2">SDF Sigma 1 (voxels)</label>
<input type="number" id="qsmartSdfSigma1Stage2" value="8" min="1" max="30" step="1">
</div>
<div class="param-group">
<label class="param-label" for="qsmartSdfSigma2Stage2">SDF Sigma 2 (voxels)</label>
<input type="number" id="qsmartSdfSigma2Stage2" value="2" min="0" max="30" step="1">
</div>
<h5 style="margin: var(--space-sm) 0 var(--space-xs); font-size: 0.8rem; color: var(--color-text-muted);">SDF Parameters</h5>
<div class="param-group">
<label class="param-label" for="qsmartSdfSpatialRadius">Spatial Radius (voxels)</label>
<input type="number" id="qsmartSdfSpatialRadius" value="8" min="1" max="20" step="1">
</div>
<div class="param-group">
<label class="param-label" for="qsmartSdfLowerLim">Lower Limit (proximity)</label>
<input type="number" id="qsmartSdfLowerLim" value="0.6" min="0.1" max="1.0" step="0.1">
</div>
<div class="param-group">
<label class="param-label" for="qsmartSdfCurvConstant">Curvature Constant</label>
<input type="number" id="qsmartSdfCurvConstant" value="500" min="100" max="2000" step="50">
</div>
<h5 style="margin: var(--space-sm) 0 var(--space-xs); font-size: 0.8rem; color: var(--color-text-muted);">Vasculature Detection (Frangi)</h5>
<p style="font-size: 0.7rem; color: var(--color-text-muted); margin: 0 0 var(--space-xs);">Parameters in mm - auto-scaled to voxels</p>
<div class="param-group">
<label class="param-label" for="qsmartVascSphereRadius">Bottom-hat Radius (mm)</label>
<input type="number" id="qsmartVascSphereRadius" value="8" min="2" max="20" step="1">
</div>
<div class="param-group">
<label class="param-label" for="qsmartFrangiScaleMin">Min Vessel Radius (mm)</label>
<input type="number" id="qsmartFrangiScaleMin" value="1.0" min="0.5" max="5.0" step="0.5">
</div>
<div class="param-group">
<label class="param-label" for="qsmartFrangiScaleMax">Max Vessel Radius (mm)</label>
<input type="number" id="qsmartFrangiScaleMax" value="10.0" min="1.0" max="20.0" step="1.0">
</div>
<div class="param-group">
<label class="param-label" for="qsmartFrangiScaleRatio">Scale Step (mm)</label>
<input type="number" id="qsmartFrangiScaleRatio" value="2.0" min="0.5" max="5.0" step="0.5">
</div>
<div class="param-group">
<label class="param-label" for="qsmartFrangiC">Frangi C (noise threshold)</label>
<input type="number" id="qsmartFrangiC" value="500" min="100" max="2000" step="50">
</div>
<h5 style="margin: var(--space-sm) 0 var(--space-xs); font-size: 0.8rem; color: var(--color-text-muted);">iLSQR Inversion</h5>
<div class="param-group">
<label class="param-label" for="qsmartIlsqrTol">Tolerance</label>
<input type="number" id="qsmartIlsqrTol" value="0.01" min="0.001" max="0.1" step="0.001">
</div>
<div class="param-group">
<label class="param-label" for="qsmartIlsqrMaxIter">Max Iterations</label>
<input type="number" id="qsmartIlsqrMaxIter" value="50" min="10" max="200" step="10">
</div>
</div>
</div>
<!-- ============================================================ -->
<!-- SWI (Susceptibility Weighted Imaging) Section -->
<!-- ============================================================ -->
<div class="settings-section">
<h4>SWI (Susceptibility Weighted Imaging)</h4>
<div class="method-links">
<a href="https://github.com/korbinian90/CLEARSWI.jl" target="_blank" rel="noopener" title="Code: CLEARSWI.jl"><svg viewBox="0 0 16 16" width="14" height="14" fill="currentColor"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"/></svg>Code</a>
</div>
<div id="swiSettingsGroup">
<div class="param-group">
<label class="param-label" for="swiScaling">Phase Scaling</label>
<select id="swiScaling">
<option value="tanh" selected>Tanh (default)</option>
<option value="negative_tanh">Negative Tanh</option>
<option value="positive">Positive</option>
<option value="negative">Negative</option>
<option value="triangular">Triangular</option>
</select>
</div>
<div class="param-group">
<label class="param-label" for="swiStrength">Strength</label>
<input type="number" id="swiStrength" value="4" min="0.1" max="10" step="0.5">
</div>
<h5 style="margin: var(--space-sm) 0 var(--space-xs); font-size: 0.8rem; color: var(--color-text-muted);">High-Pass Filter Sigma (voxels)</h5>
<div class="param-group">
<label class="param-label" for="swiHpSigmaX">Sigma X</label>
<input type="number" id="swiHpSigmaX" value="4" min="0" max="20" step="1">
</div>
<div class="param-group">
<label class="param-label" for="swiHpSigmaY">Sigma Y</label>
<input type="number" id="swiHpSigmaY" value="4" min="0" max="20" step="1">
</div>
<div class="param-group">
<label class="param-label" for="swiHpSigmaZ">Sigma Z</label>
<input type="number" id="swiHpSigmaZ" value="0" min="0" max="20" step="1">
</div>
<h5 style="margin: var(--space-sm) 0 var(--space-xs); font-size: 0.8rem; color: var(--color-text-muted);">Minimum Intensity Projection</h5>
<div class="param-group">
<label class="param-label" for="swiMipWindow">MIP Window (slices)</label>
<input type="number" id="swiMipWindow" value="7" min="0" max="30" step="1">
</div>
</div>
</div>
<!-- ============================================================ -->
<!-- Phase Processing Section (Multi-Echo) -->
<!-- ============================================================ -->
<div class="settings-section" id="multiEchoSection">
<h4>Phase Processing</h4>
<!-- Step 1: Phase Offset Removal -->
<div class="param-group">
<label class="param-label" for="phaseOffsetMethod">Phase Offset Removal</label>
<select id="phaseOffsetMethod">
<option value="mcpc3ds" selected>MCPC-3D-S (Multi-Channel Phase Combination 3D-Simplified)</option>
<option value="none">None (skip)</option>
</select>
</div>
<!-- MCPC-3D-S Settings -->
<div id="mcpc3dsSettings" class="method-settings" style="margin-left: var(--space-md); padding-left: var(--space-md); border-left: 2px solid var(--color-border);">
<div class="method-links">
<a href="https://doi.org/10.1002/mrm.27277" target="_blank" rel="noopener" title="DOI: 10.1002/mrm.27277"><svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/></svg>Paper</a>
<a href="https://github.com/korbinian90/MriResearchTools.jl" target="_blank" rel="noopener" title="Code: MriResearchTools.jl"><svg viewBox="0 0 16 16" width="14" height="14" fill="currentColor"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"/></svg>Code</a>
</div>
<div class="param-group">
<label class="param-label" for="mcpc3dsSigmaX">Smoothing Sigma X (voxels)</label>
<input type="number" id="mcpc3dsSigmaX" value="10" min="1" max="30" step="1">
</div>
<div class="param-group">
<label class="param-label" for="mcpc3dsSigmaY">Smoothing Sigma Y (voxels)</label>
<input type="number" id="mcpc3dsSigmaY" value="10" min="1" max="30" step="1">
</div>
<div class="param-group">
<label class="param-label" for="mcpc3dsSigmaZ">Smoothing Sigma Z (voxels)</label>
<input type="number" id="mcpc3dsSigmaZ" value="5" min="1" max="30" step="1">
</div>
</div>
<!-- Step 2: Phase Unwrapping -->
<div class="param-group" style="margin-top: var(--space-md);">
<label class="param-label" for="unwrapMethod">Phase Unwrapping</label>
<select id="unwrapMethod">
<option value="romeo" selected>ROMEO (Rapid Opensource Minimum Spanning TreE AlgOrithm)</option>
<option value="laplacian">Laplacian</option>
</select>
<div id="unwrapLockedHint" class="validation-message error inline-warning" style="display: none;">
<span>Requires ROMEO unwrapping</span>
</div>
</div>
<!-- ROMEO Settings -->
<div id="romeoSettings" class="method-settings" style="margin-left: var(--space-md); padding-left: var(--space-md); border-left: 2px solid var(--color-border);">
<div class="method-links">
<a href="https://doi.org/10.1002/mrm.28563" target="_blank" rel="noopener" title="DOI: 10.1002/mrm.28563"><svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/></svg>Paper</a>
<a href="https://github.com/korbinian90/MriResearchTools.jl" target="_blank" rel="noopener" title="Code: MriResearchTools.jl"><svg viewBox="0 0 16 16" width="14" height="14" fill="currentColor"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"/></svg>Code</a>
</div>
<div class="param-group" style="display: flex; flex-direction: column; gap: var(--space-xs); font-size: 0.8rem;">
<label style="display: flex; align-items: center; gap: var(--space-xs);">
<input type="checkbox" id="romeoPhaseCoherence" checked disabled>
Phase Coherence
</label>
<label style="display: flex; align-items: center; gap: var(--space-xs);">
<input type="checkbox" id="romeoPhaseGradientCoherence" checked>
Phase Gradient Coherence
</label>
<label style="display: flex; align-items: center; gap: var(--space-xs);">
<input type="checkbox" id="romeoMagCoherence" checked>
Magnitude Coherence
</label>
<label style="display: flex; align-items: center; gap: var(--space-xs);">
<input type="checkbox" id="romeoMagWeight" checked>
Magnitude Weight
</label>
</div>
</div>
<!-- Laplacian Settings -->
<div id="laplacianSettings" class="method-settings" style="display: none; margin-left: var(--space-md); padding-left: var(--space-md); border-left: 2px solid var(--color-border);">
<div class="method-links">
<a href="https://doi.org/10.1364/OL.28.001194" target="_blank" rel="noopener" title="DOI: 10.1364/OL.28.001194"><svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/></svg>Paper</a>
<a href="https://github.com/kamesy/QSM.jl" target="_blank" rel="noopener" title="Code: QSM.jl"><svg viewBox="0 0 16 16" width="14" height="14" fill="currentColor"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"/></svg>Code</a>
</div>
</div>
<!-- Step 3: Multi-Echo Fitting -->
<div class="param-group" style="margin-top: var(--space-md);">
<label class="param-label" for="fieldCalculationMethod">Multi-Echo Fitting</label>
<select id="fieldCalculationMethod">
<option value="weighted_avg" selected>Weighted Averaging</option>
<option value="linear_fit">Linear Fit</option>
</select>
</div>
<!-- Weighted Averaging Settings -->
<div id="weightedAvgSettings" class="method-settings" style="margin-left: var(--space-md); padding-left: var(--space-md); border-left: 2px solid var(--color-border);">
<div class="param-group">
<label class="param-label" for="b0WeightType">Weight Type</label>