Spaces:
Runtime error

Tdanyim commited on
Commit
b88802a
·
verified ·
1 Parent(s): 1e77882

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +604 -598
src/streamlit_app.py CHANGED
@@ -230,601 +230,607 @@
230
 
231
 
232
 
233
- # # (02) Data Preprocessing
234
- from pathlib import Path
235
- import numpy as np
236
- import pandas as pd
237
- import matplotlib.pyplot as plt
238
- import streamlit as st
239
- import torch
240
- import torch.nn.functional as F
241
- from scipy.io import loadmat
242
-
243
- # ---------------------------------------------------
244
- # Page config
245
- # ---------------------------------------------------
246
- st.set_page_config(
247
- page_title="MRI Reconstruction - EDA + Preprocessing",
248
- layout="wide"
249
- )
250
-
251
- # ---------------------------------------------------
252
- # Intro text
253
- # ---------------------------------------------------
254
- st.title("MRI Reconstruction App")
255
- st.subheader("Interactive Exploratory Data Analysis (EDA) + Preprocessing")
256
- st.write(
257
- "Use the sidebar to explore HF/LF sample pairs, inspect their properties, "
258
- "and apply preprocessing to visualise full and undersampled k-space/image domains."
259
- )
260
-
261
- # ---------------------------------------------------
262
- # Resolve project paths
263
- # ---------------------------------------------------
264
- ROOT_DIR = Path(__file__).resolve().parent.parent
265
- HF_DIR = ROOT_DIR / "data" / "HF"
266
- LF_DIR = ROOT_DIR / "data" / "LF"
267
- MASK_FILE = ROOT_DIR / "mask" / "prs" / "mask_30.mat"
268
-
269
- # ---------------------------------------------------
270
- # Helper functions for EDA
271
- # ---------------------------------------------------
272
- @st.cache_data
273
- def get_paired_files(hf_dir: Path, lf_dir: Path) -> pd.DataFrame:
274
- hf_files = sorted([f for f in hf_dir.glob("*.npy")])
275
- lf_files = sorted([f for f in lf_dir.glob("*.npy")])
276
-
277
- hf_map = {f.name: f for f in hf_files}
278
- lf_map = {f.name: f for f in lf_files}
279
-
280
- common_names = sorted(set(hf_map.keys()) & set(lf_map.keys()))
281
-
282
- return pd.DataFrame({
283
- "sample_name": common_names,
284
- "gdtFiles": [str(hf_map[name]) for name in common_names], # HF
285
- "imgFiles": [str(lf_map[name]) for name in common_names], # LF
286
- })
287
-
288
-
289
- @st.cache_data
290
- def load_npy_file(file_path: str) -> np.ndarray:
291
- return np.load(file_path)
292
-
293
-
294
- def array_summary(arr: np.ndarray) -> dict:
295
- return {
296
- "shape": arr.shape,
297
- "ndim": arr.ndim,
298
- "dtype": str(arr.dtype),
299
- "min": float(np.min(arr)),
300
- "max": float(np.max(arr)),
301
- "mean": float(np.mean(arr)),
302
- }
303
-
304
-
305
- def get_display_slice(arr: np.ndarray, slice_idx: int | None = None) -> np.ndarray:
306
- if arr.ndim == 2:
307
- return arr
308
- if arr.ndim == 3:
309
- return arr[slice_idx if slice_idx is not None else 0]
310
- raise ValueError(f"Unsupported array shape for display: {arr.shape}")
311
-
312
-
313
- def plot_side_by_side(lf_img: np.ndarray, hf_img: np.ndarray, lf_title="LF Image", hf_title="HF Image"):
314
- fig, axes = plt.subplots(1, 2, figsize=(12, 5))
315
-
316
- axes[0].imshow(lf_img, cmap="gray")
317
- axes[0].set_title(lf_title)
318
- axes[0].axis("off")
319
-
320
- axes[1].imshow(hf_img, cmap="gray")
321
- axes[1].set_title(hf_title)
322
- axes[1].axis("off")
323
-
324
- plt.tight_layout()
325
- return fig
326
-
327
-
328
- # ---------------------------------------------------
329
- # Preprocessing functions
330
- # ---------------------------------------------------
331
- def resizeImage(
332
- img_np: np.ndarray,
333
- target_size=(256, 256),
334
- mode="bicubic",
335
- antialias=True,
336
- device="cpu"
337
- ):
338
- """
339
- Resize a 2D NumPy image to the target size using torch interpolation.
340
- """
341
- # Early return if already correct size
342
- if img_np.shape[-2:] == target_size:
343
- return img_np.astype(np.float32)
344
-
345
- # Convert NumPy -> Torch tensor
346
- tensor = torch.from_numpy(img_np.astype(np.float32)).to(device)
347
-
348
- # Add batch and channel dimensions: (H, W) -> (1, 1, H, W)
349
- tensor = tensor.unsqueeze(0).unsqueeze(0)
350
-
351
- # Resize
352
- tensor = F.interpolate(
353
- tensor,
354
- size=target_size,
355
- mode=mode,
356
- align_corners=False if mode in ["bilinear", "bicubic"] else None,
357
- antialias=antialias
358
- )
359
-
360
- # Remove batch and channel dimensions: (1, 1, H, W) -> (H, W)
361
- tensor = tensor.squeeze(0).squeeze(0)
362
-
363
- return tensor.cpu().numpy()
364
-
365
-
366
- def fft2c(image):
367
- """
368
- Convert image -> centered 2D k-space.
369
- """
370
- return np.fft.fftshift(
371
- np.fft.fft2(np.fft.ifftshift(image, axes=(-2, -1))),
372
- axes=(-2, -1)
373
- )
374
-
375
-
376
- def ifft2c(kspace):
377
- """
378
- Convert centered 2D k-space -> image magnitude.
379
- """
380
- return np.abs(
381
- np.fft.ifftshift(
382
- np.fft.ifft2(np.fft.fftshift(kspace, axes=(-2, -1))),
383
- axes=(-2, -1)
384
- )
385
- )
386
-
387
-
388
- @st.cache_data
389
- def load_mask(mask_file: str) -> np.ndarray:
390
- """
391
- Load the undersampling mask once and cache it.
392
- """
393
- mask_data = loadmat(mask_file)
394
- mask_matrix = mask_data["mask_matrix"]
395
- mask_matrix = np.fft.ifftshift(mask_matrix).astype(np.float32)
396
- return mask_matrix
397
-
398
-
399
- def und2DMask(slice_kspace, maskFile):
400
- """
401
- Apply undersampling mask to one 2D k-space slice.
402
- """
403
- undersamplingMask = load_mask(str(maskFile))
404
- udkspace = undersamplingMask * slice_kspace
405
- return udkspace, undersamplingMask
406
-
407
-
408
- def ch2ksp(c):
409
- """
410
- Convert 2-channel representation to complex k-space.
411
- Not yet used in preprocessing visualisation, but kept for later stages.
412
- """
413
- return c[0, :, :] + 1j * c[1, :, :]
414
-
415
-
416
- def preprocess_single_pair(hr_array: np.ndarray, lr_array: np.ndarray, mask_file: Path, target_size=(256, 256)):
417
- """
418
- Preprocess one selected HF/LF pair.
419
-
420
- Handles:
421
- - 2D arrays: process single image
422
- - 3D arrays: process slice-by-slice
423
-
424
- Returns a dictionary of processed lists ready for visualisation.
425
- """
426
- HR_images = []
427
- full_HR_kspace = []
428
- ud_HR_kspace = []
429
- mag_HR_images = []
430
-
431
- LR_images = []
432
- full_LR_kspace = []
433
- ud_LR_kspace = []
434
- mag_LR_images = []
435
-
436
- # If 2D, wrap into a list so we can reuse the same processing loop
437
- if hr_array.ndim == 2 and lr_array.ndim == 2:
438
- hr_slices = [hr_array]
439
- lr_slices = [lr_array]
440
-
441
- # If 3D, process slice-by-slice
442
- elif hr_array.ndim == 3 and lr_array.ndim == 3:
443
- num_slices = min(hr_array.shape[0], lr_array.shape[0])
444
- hr_slices = [hr_array[i] for i in range(num_slices)]
445
- lr_slices = [lr_array[i] for i in range(num_slices)]
446
-
447
- else:
448
- raise ValueError("HF and LF arrays must both be 2D or both be 3D with matching slice structure.")
449
-
450
- # Process each slice
451
- for HRimage, LRimage in zip(hr_slices, lr_slices):
452
- # Resize both HF and LF images
453
- HRimage = resizeImage(HRimage, target_size=target_size)
454
- LRimage = resizeImage(LRimage, target_size=target_size)
455
-
456
- # Full k-space
457
- full_HRkspace = fft2c(HRimage)
458
- full_LRkspace = fft2c(LRimage)
459
-
460
- # Undersampled k-space
461
- ud_HRkspace, _ = und2DMask(full_HRkspace, mask_file)
462
- ud_LRkspace, _ = und2DMask(full_LRkspace, mask_file)
463
-
464
- # Reconstructed image magnitude from undersampled k-space
465
- recon_HRimage = ifft2c(ud_HRkspace)
466
- recon_LRimage = ifft2c(ud_LRkspace)
467
-
468
- mag_HRimage = np.abs(recon_HRimage)
469
- mag_LRimage = np.abs(recon_LRimage)
470
-
471
- # Store outputs
472
- HR_images.append(HRimage)
473
- full_HR_kspace.append(full_HRkspace)
474
- ud_HR_kspace.append(ud_HRkspace)
475
- mag_HR_images.append(mag_HRimage)
476
-
477
- LR_images.append(LRimage)
478
- full_LR_kspace.append(full_LRkspace)
479
- ud_LR_kspace.append(ud_LRkspace)
480
- mag_LR_images.append(mag_LRimage)
481
-
482
- return {
483
- "HR_images": HR_images,
484
- "full_HR_kspace": full_HR_kspace,
485
- "ud_HR_kspace": ud_HR_kspace,
486
- "mag_HR_images": mag_HR_images,
487
- "LR_images": LR_images,
488
- "full_LR_kspace": full_LR_kspace,
489
- "ud_LR_kspace": ud_LR_kspace,
490
- "mag_LR_images": mag_LR_images,
491
- "num_samples": len(HR_images),
492
- "target_size": target_size,
493
- }
494
-
495
-
496
- def plot_preprocessing_hr(sample_idx: int, processed: dict):
497
- """
498
- Plot full and undersampled k-space/image for HR sample.
499
- """
500
- sample_fsHRkspace = processed["full_HR_kspace"][sample_idx]
501
- sample_udHRkspace = processed["ud_HR_kspace"][sample_idx]
502
- sample_fsHRimg = processed["HR_images"][sample_idx]
503
- sample_udHRimg = processed["mag_HR_images"][sample_idx]
504
-
505
- fig, axes = plt.subplots(1, 4, figsize=(16, 4))
506
-
507
- axes[0].imshow(np.log(np.abs(sample_fsHRkspace) + 1e-9), cmap="gray")
508
- axes[0].set_title("fsHR k-space")
509
- axes[0].axis("off")
510
-
511
- axes[1].imshow(sample_fsHRimg, cmap="gray")
512
- axes[1].set_title("fsHR Image")
513
- axes[1].axis("off")
514
-
515
- axes[2].imshow(np.log(np.abs(sample_udHRkspace) + 1e-9), cmap="gray")
516
- axes[2].set_title("udHR k-space")
517
- axes[2].axis("off")
518
-
519
- axes[3].imshow(sample_udHRimg, cmap="gray")
520
- axes[3].set_title("udHR Image")
521
- axes[3].axis("off")
522
-
523
- plt.tight_layout()
524
- return fig
525
-
526
-
527
- def plot_preprocessing_lr(sample_idx: int, processed: dict):
528
- """
529
- Plot full and undersampled k-space/image for LR sample.
530
- """
531
- sample_fsLRkspace = processed["full_LR_kspace"][sample_idx]
532
- sample_udLRkspace = processed["ud_LR_kspace"][sample_idx]
533
- sample_fsLRimg = processed["LR_images"][sample_idx]
534
- sample_udLRimg = processed["mag_LR_images"][sample_idx]
535
-
536
- fig, axes = plt.subplots(1, 4, figsize=(16, 4))
537
-
538
- axes[0].imshow(np.log(np.abs(sample_fsLRkspace) + 1e-9), cmap="gray")
539
- axes[0].set_title("fsLR k-space")
540
- axes[0].axis("off")
541
-
542
- axes[1].imshow(sample_fsLRimg, cmap="gray")
543
- axes[1].set_title("fsLR Image")
544
- axes[1].axis("off")
545
-
546
- axes[2].imshow(np.log(np.abs(sample_udLRkspace) + 1e-9), cmap="gray")
547
- axes[2].set_title("udLR k-space")
548
- axes[2].axis("off")
549
-
550
- axes[3].imshow(sample_udLRimg, cmap="gray")
551
- axes[3].set_title("udLR Image")
552
- axes[3].axis("off")
553
-
554
- plt.tight_layout()
555
- return fig
556
-
557
-
558
- # ---------------------------------------------------
559
- # Validate folders
560
- # ---------------------------------------------------
561
- if not HF_DIR.exists():
562
- st.error(f"HF directory not found: {HF_DIR}")
563
- st.stop()
564
-
565
- if not LF_DIR.exists():
566
- st.error(f"LF directory not found: {LF_DIR}")
567
- st.stop()
568
-
569
- if not MASK_FILE.exists():
570
- st.error(f"Mask file not found: {MASK_FILE}")
571
- st.stop()
572
-
573
- # ---------------------------------------------------
574
- # Load paired dataset
575
- # ---------------------------------------------------
576
- ts_df = get_paired_files(HF_DIR, LF_DIR)
577
-
578
- if ts_df.empty:
579
- st.warning("No matching .npy file pairs found in data/HF and data/LF.")
580
- st.stop()
581
-
582
- # ---------------------------------------------------
583
- # Sidebar controls - EDA
584
- # ---------------------------------------------------
585
- with st.sidebar.expander("EDA Controls", expanded=False):
586
- selected_name = st.selectbox(
587
- "Choose sample file",
588
- ts_df["sample_name"].tolist(),
589
- index=0
590
- )
591
-
592
- show_stats = st.checkbox("Show array statistics", value=False)
593
- show_visualisation = st.checkbox("Display EDA visualisation", value=False)
594
-
595
- show_dataframe = st.sidebar.checkbox("Show dataframe", value=False)
596
-
597
- # ---------------------------------------------------
598
- # Sidebar controls - Preprocessing
599
- # ---------------------------------------------------
600
- with st.sidebar.expander("Preprocessing Controls", expanded=False):
601
- st.markdown("Apply preprocessing to the currently selected HF/LF pair.")
602
-
603
- target_height = st.number_input("Target height", min_value=32, max_value=1024, value=256, step=32)
604
- target_width = st.number_input("Target width", min_value=32, max_value=1024, value=256, step=32)
605
-
606
- apply_preprocessing = st.button("Apply preprocessing")
607
- show_preprocessing_viz = st.checkbox("Display preprocessing visualisation", value=False)
608
-
609
- # ---------------------------------------------------
610
- # Load selected sample from EDA
611
- # ---------------------------------------------------
612
- selected_row = ts_df[ts_df["sample_name"] == selected_name].iloc[0]
613
- img_path = selected_row["imgFiles"] # LF
614
- gdt_path = selected_row["gdtFiles"] # HF
615
-
616
- imgTs = load_npy_file(img_path)
617
- gdtTs = load_npy_file(gdt_path)
618
-
619
- # ---------------------------------------------------
620
- # Initialise session state keys
621
- # ---------------------------------------------------
622
- if "preprocessed_data" not in st.session_state:
623
- st.session_state["preprocessed_data"] = None
624
-
625
- if "preprocessed_sample_name" not in st.session_state:
626
- st.session_state["preprocessed_sample_name"] = None
627
-
628
- # ---------------------------------------------------
629
- # Run preprocessing only when the button is clicked
630
- # ---------------------------------------------------
631
- if apply_preprocessing:
632
- try:
633
- with st.spinner("Applying preprocessing..."):
634
- processed = preprocess_single_pair(
635
- hr_array=gdtTs, # HF
636
- lr_array=imgTs, # LF
637
- mask_file=MASK_FILE,
638
- target_size=(int(target_height), int(target_width))
639
- )
640
-
641
- st.session_state["preprocessed_data"] = processed
642
- st.session_state["preprocessed_sample_name"] = selected_name
643
-
644
- st.success(f"Preprocessing completed for sample: {selected_name}")
645
-
646
- except Exception as e:
647
- st.error(f"Preprocessing failed: {e}")
648
-
649
- # ---------------------------------------------------
650
- # Build visible sections dynamically
651
- # ---------------------------------------------------
652
- tab_names = []
653
- tab_keys = []
654
-
655
- if show_dataframe:
656
- tab_names.append("Dataset")
657
- tab_keys.append("dataframe")
658
-
659
- if show_stats:
660
- tab_names.append("Statistics")
661
- tab_keys.append("stats")
662
-
663
- if show_visualisation:
664
- tab_names.append("EDA Visualisation")
665
- tab_keys.append("eda_viz")
666
-
667
- if show_preprocessing_viz:
668
- tab_names.append("Preprocessing Visualisation")
669
- tab_keys.append("prep_viz")
670
-
671
- # ---------------------------------------------------
672
- # If nothing is checked, keep the main panel empty
673
- # ---------------------------------------------------
674
- if not tab_names:
675
- st.empty()
676
- else:
677
- tabs = st.tabs(tab_names)
678
-
679
- for tab, key in zip(tabs, tab_keys):
680
- with tab:
681
- # ---------------------------------------
682
- # Dataset tab
683
- # ---------------------------------------
684
- if key == "dataframe":
685
- st.markdown("### Available Dataset")
686
- st.dataframe(ts_df, use_container_width=True)
687
-
688
- # ---------------------------------------
689
- # Statistics tab
690
- # ---------------------------------------
691
- elif key == "stats":
692
- st.markdown("### Selected Sample Statistics")
693
-
694
- col1, col2 = st.columns(2)
695
-
696
- img_stats = array_summary(imgTs)
697
- gdt_stats = array_summary(gdtTs)
698
-
699
- with col1:
700
- st.markdown("#### LF Image")
701
- st.write(f"**File:** `{selected_name}`")
702
- st.write(f"**Shape:** {img_stats['shape']}")
703
- st.write(f"**Dimensions:** {img_stats['ndim']}D")
704
- st.write(f"**Dtype:** {img_stats['dtype']}")
705
- st.write(f"**Min:** {img_stats['min']:.6f}")
706
- st.write(f"**Max:** {img_stats['max']:.6f}")
707
- st.write(f"**Mean:** {img_stats['mean']:.6f}")
708
-
709
- with col2:
710
- st.markdown("#### HF Ground Truth")
711
- st.write(f"**File:** `{selected_name}`")
712
- st.write(f"**Shape:** {gdt_stats['shape']}")
713
- st.write(f"**Dimensions:** {gdt_stats['ndim']}D")
714
- st.write(f"**Dtype:** {gdt_stats['dtype']}")
715
- st.write(f"**Min:** {gdt_stats['min']:.6f}")
716
- st.write(f"**Max:** {gdt_stats['max']:.6f}")
717
- st.write(f"**Mean:** {gdt_stats['mean']:.6f}")
718
-
719
- # ---------------------------------------
720
- # EDA Visualisation tab
721
- # ---------------------------------------
722
- elif key == "eda_viz":
723
- st.markdown("### EDA Image Visualisation")
724
-
725
- if imgTs.ndim == 2 and gdtTs.ndim == 2:
726
- img_show = imgTs
727
- gdt_show = gdtTs
728
-
729
- elif imgTs.ndim == 3 and gdtTs.ndim == 3:
730
- max_slice = min(imgTs.shape[0], gdtTs.shape[0]) - 1
731
- slice_idx = st.slider(
732
- "Choose slice index",
733
- min_value=0,
734
- max_value=max_slice,
735
- value=0,
736
- key="eda_slice_slider"
737
- )
738
-
739
- img_show = get_display_slice(imgTs, slice_idx)
740
- gdt_show = get_display_slice(gdtTs, slice_idx)
741
-
742
- st.info(f"Displaying EDA slice index: {slice_idx}")
743
-
744
- else:
745
- st.error("LF and HF arrays do not have compatible dimensions for joint display.")
746
- st.stop()
747
-
748
- fig = plot_side_by_side(
749
- img_show,
750
- gdt_show,
751
- lf_title=f"LF: {selected_name}",
752
- hf_title=f"HF: {selected_name}"
753
- )
754
- st.pyplot(fig)
755
-
756
- # ---------------------------------------
757
- # Preprocessing Visualisation tab
758
- # ---------------------------------------
759
- elif key == "prep_viz":
760
- st.markdown("### Preprocessing Visualisation")
761
-
762
- processed = st.session_state.get("preprocessed_data")
763
- processed_sample_name = st.session_state.get("preprocessed_sample_name")
764
-
765
- # Guard: user requested preprocessing visualisation but has not run preprocessing yet
766
- if processed is None:
767
- st.warning("Please click 'Apply preprocessing' in the sidebar first.")
768
- st.stop()
769
-
770
- # Guard: selected sample changed after preprocessing
771
- if processed_sample_name != selected_name:
772
- st.warning(
773
- "The currently displayed preprocessing result belongs to a different selected file. "
774
- "Please click 'Apply preprocessing' again for the newly selected sample."
775
- )
776
- st.stop()
777
-
778
- num_samples = processed["num_samples"]
779
-
780
- # For 2D data there is only one processed sample
781
- if num_samples == 1:
782
- sample_idx = 0
783
- st.info("This sample is 2D, so only one processed image is available.")
784
-
785
- # For 3D data let the user choose the slice/sample index
786
- else:
787
- sample_idx = st.slider(
788
- "Choose preprocessing sample index",
789
- min_value=0,
790
- max_value=num_samples - 1,
791
- value=0,
792
- key="prep_sample_slider"
793
- )
794
- st.info(f"Displaying preprocessing sample index: {sample_idx}")
795
-
796
- # Show dimensions of current processed outputs
797
- sample_udHRkspace = processed["ud_HR_kspace"][sample_idx]
798
- sample_fsHRkspace = processed["full_HR_kspace"][sample_idx]
799
- sample_udLRkspace = processed["ud_LR_kspace"][sample_idx]
800
- sample_fsLRkspace = processed["full_LR_kspace"][sample_idx]
801
-
802
- sample_udHRimg = processed["mag_HR_images"][sample_idx]
803
- sample_fsHRimg = processed["HR_images"][sample_idx]
804
- sample_udLRimg = processed["mag_LR_images"][sample_idx]
805
- sample_fsLRimg = processed["LR_images"][sample_idx]
806
-
807
- st.markdown("#### Processed Sample Shapes")
808
- col1, col2 = st.columns(2)
809
-
810
- # with col1:
811
- # st.write(f"**udHRkspace:** {sample_udHRkspace.shape}")
812
- # st.write(f"**fsHRkspace:** {sample_fsHRkspace.shape}")
813
- # st.write(f"**udHRimg:** {sample_udHRimg.shape}")
814
- # st.write(f"**fsHRimg:** {sample_fsHRimg.shape}")
815
-
816
- # with col2:
817
- # st.write(f"**udLRkspace:** {sample_udLRkspace.shape}")
818
- # st.write(f"**fsLRkspace:** {sample_fsLRkspace.shape}")
819
- # st.write(f"**udLRimg:** {sample_udLRimg.shape}")
820
- # st.write(f"**fsLRimg:** {sample_fsLRimg.shape}")
821
-
822
- # Plot HR row
823
- st.markdown("#### HR Domain Visualisation")
824
- fig_hr = plot_preprocessing_hr(sample_idx, processed)
825
- st.pyplot(fig_hr)
826
-
827
- # Plot LR row
828
- st.markdown("#### LR Domain Visualisation")
829
- fig_lr = plot_preprocessing_lr(sample_idx, processed)
830
- st.pyplot(fig_lr)
 
 
 
 
 
 
 
230
 
231
 
232
 
233
+ # # # (02) Data Preprocessing
234
+ # from pathlib import Path
235
+ # import numpy as np
236
+ # import pandas as pd
237
+ # import matplotlib.pyplot as plt
238
+ # import streamlit as st
239
+ # import torch
240
+ # import torch.nn.functional as F
241
+ # from scipy.io import loadmat
242
+
243
+ # # ---------------------------------------------------
244
+ # # Page config
245
+ # # ---------------------------------------------------
246
+ # st.set_page_config(
247
+ # page_title="MRI Reconstruction - EDA + Preprocessing",
248
+ # layout="wide"
249
+ # )
250
+
251
+ # # ---------------------------------------------------
252
+ # # Intro text
253
+ # # ---------------------------------------------------
254
+ # st.title("MRI Reconstruction App")
255
+ # st.subheader("Interactive Exploratory Data Analysis (EDA) + Preprocessing")
256
+ # st.write(
257
+ # "Use the sidebar to explore HF/LF sample pairs, inspect their properties, "
258
+ # "and apply preprocessing to visualise full and undersampled k-space/image domains."
259
+ # )
260
+
261
+ # # ---------------------------------------------------
262
+ # # Resolve project paths
263
+ # # ---------------------------------------------------
264
+ # ROOT_DIR = Path(__file__).resolve().parent.parent
265
+ # HF_DIR = ROOT_DIR / "data" / "HF"
266
+ # LF_DIR = ROOT_DIR / "data" / "LF"
267
+ # MASK_FILE = ROOT_DIR / "mask" / "prs" / "mask_30.mat"
268
+
269
+ # # ---------------------------------------------------
270
+ # # Helper functions for EDA
271
+ # # ---------------------------------------------------
272
+ # @st.cache_data
273
+ # def get_paired_files(hf_dir: Path, lf_dir: Path) -> pd.DataFrame:
274
+ # hf_files = sorted([f for f in hf_dir.glob("*.npy")])
275
+ # lf_files = sorted([f for f in lf_dir.glob("*.npy")])
276
+
277
+ # hf_map = {f.name: f for f in hf_files}
278
+ # lf_map = {f.name: f for f in lf_files}
279
+
280
+ # common_names = sorted(set(hf_map.keys()) & set(lf_map.keys()))
281
+
282
+ # return pd.DataFrame({
283
+ # "sample_name": common_names,
284
+ # "gdtFiles": [str(hf_map[name]) for name in common_names], # HF
285
+ # "imgFiles": [str(lf_map[name]) for name in common_names], # LF
286
+ # })
287
+
288
+
289
+ # @st.cache_data
290
+ # def load_npy_file(file_path: str) -> np.ndarray:
291
+ # return np.load(file_path)
292
+
293
+
294
+ # def array_summary(arr: np.ndarray) -> dict:
295
+ # return {
296
+ # "shape": arr.shape,
297
+ # "ndim": arr.ndim,
298
+ # "dtype": str(arr.dtype),
299
+ # "min": float(np.min(arr)),
300
+ # "max": float(np.max(arr)),
301
+ # "mean": float(np.mean(arr)),
302
+ # }
303
+
304
+
305
+ # def get_display_slice(arr: np.ndarray, slice_idx: int | None = None) -> np.ndarray:
306
+ # if arr.ndim == 2:
307
+ # return arr
308
+ # if arr.ndim == 3:
309
+ # return arr[slice_idx if slice_idx is not None else 0]
310
+ # raise ValueError(f"Unsupported array shape for display: {arr.shape}")
311
+
312
+
313
+ # def plot_side_by_side(lf_img: np.ndarray, hf_img: np.ndarray, lf_title="LF Image", hf_title="HF Image"):
314
+ # fig, axes = plt.subplots(1, 2, figsize=(12, 5))
315
+
316
+ # axes[0].imshow(lf_img, cmap="gray")
317
+ # axes[0].set_title(lf_title)
318
+ # axes[0].axis("off")
319
+
320
+ # axes[1].imshow(hf_img, cmap="gray")
321
+ # axes[1].set_title(hf_title)
322
+ # axes[1].axis("off")
323
+
324
+ # plt.tight_layout()
325
+ # return fig
326
+
327
+
328
+ # # ---------------------------------------------------
329
+ # # Preprocessing functions
330
+ # # ---------------------------------------------------
331
+ # def resizeImage(
332
+ # img_np: np.ndarray,
333
+ # target_size=(256, 256),
334
+ # mode="bicubic",
335
+ # antialias=True,
336
+ # device="cpu"
337
+ # ):
338
+ # """
339
+ # Resize a 2D NumPy image to the target size using torch interpolation.
340
+ # """
341
+ # # Early return if already correct size
342
+ # if img_np.shape[-2:] == target_size:
343
+ # return img_np.astype(np.float32)
344
+
345
+ # # Convert NumPy -> Torch tensor
346
+ # tensor = torch.from_numpy(img_np.astype(np.float32)).to(device)
347
+
348
+ # # Add batch and channel dimensions: (H, W) -> (1, 1, H, W)
349
+ # tensor = tensor.unsqueeze(0).unsqueeze(0)
350
+
351
+ # # Resize
352
+ # tensor = F.interpolate(
353
+ # tensor,
354
+ # size=target_size,
355
+ # mode=mode,
356
+ # align_corners=False if mode in ["bilinear", "bicubic"] else None,
357
+ # antialias=antialias
358
+ # )
359
+
360
+ # # Remove batch and channel dimensions: (1, 1, H, W) -> (H, W)
361
+ # tensor = tensor.squeeze(0).squeeze(0)
362
+
363
+ # return tensor.cpu().numpy()
364
+
365
+
366
+ # def fft2c(image):
367
+ # """
368
+ # Convert image -> centered 2D k-space.
369
+ # """
370
+ # return np.fft.fftshift(
371
+ # np.fft.fft2(np.fft.ifftshift(image, axes=(-2, -1))),
372
+ # axes=(-2, -1)
373
+ # )
374
+
375
+
376
+ # def ifft2c(kspace):
377
+ # """
378
+ # Convert centered 2D k-space -> image magnitude.
379
+ # """
380
+ # return np.abs(
381
+ # np.fft.ifftshift(
382
+ # np.fft.ifft2(np.fft.fftshift(kspace, axes=(-2, -1))),
383
+ # axes=(-2, -1)
384
+ # )
385
+ # )
386
+
387
+
388
+ # @st.cache_data
389
+ # def load_mask(mask_file: str) -> np.ndarray:
390
+ # """
391
+ # Load the undersampling mask once and cache it.
392
+ # """
393
+ # mask_data = loadmat(mask_file)
394
+ # mask_matrix = mask_data["mask_matrix"]
395
+ # mask_matrix = np.fft.ifftshift(mask_matrix).astype(np.float32)
396
+ # return mask_matrix
397
+
398
+
399
+ # def und2DMask(slice_kspace, maskFile):
400
+ # """
401
+ # Apply undersampling mask to one 2D k-space slice.
402
+ # """
403
+ # undersamplingMask = load_mask(str(maskFile))
404
+ # udkspace = undersamplingMask * slice_kspace
405
+ # return udkspace, undersamplingMask
406
+
407
+
408
+ # def ch2ksp(c):
409
+ # """
410
+ # Convert 2-channel representation to complex k-space.
411
+ # Not yet used in preprocessing visualisation, but kept for later stages.
412
+ # """
413
+ # return c[0, :, :] + 1j * c[1, :, :]
414
+
415
+
416
+ # def preprocess_single_pair(hr_array: np.ndarray, lr_array: np.ndarray, mask_file: Path, target_size=(256, 256)):
417
+ # """
418
+ # Preprocess one selected HF/LF pair.
419
+
420
+ # Handles:
421
+ # - 2D arrays: process single image
422
+ # - 3D arrays: process slice-by-slice
423
+
424
+ # Returns a dictionary of processed lists ready for visualisation.
425
+ # """
426
+ # HR_images = []
427
+ # full_HR_kspace = []
428
+ # ud_HR_kspace = []
429
+ # mag_HR_images = []
430
+
431
+ # LR_images = []
432
+ # full_LR_kspace = []
433
+ # ud_LR_kspace = []
434
+ # mag_LR_images = []
435
+
436
+ # # If 2D, wrap into a list so we can reuse the same processing loop
437
+ # if hr_array.ndim == 2 and lr_array.ndim == 2:
438
+ # hr_slices = [hr_array]
439
+ # lr_slices = [lr_array]
440
+
441
+ # # If 3D, process slice-by-slice
442
+ # elif hr_array.ndim == 3 and lr_array.ndim == 3:
443
+ # num_slices = min(hr_array.shape[0], lr_array.shape[0])
444
+ # hr_slices = [hr_array[i] for i in range(num_slices)]
445
+ # lr_slices = [lr_array[i] for i in range(num_slices)]
446
+
447
+ # else:
448
+ # raise ValueError("HF and LF arrays must both be 2D or both be 3D with matching slice structure.")
449
+
450
+ # # Process each slice
451
+ # for HRimage, LRimage in zip(hr_slices, lr_slices):
452
+ # # Resize both HF and LF images
453
+ # HRimage = resizeImage(HRimage, target_size=target_size)
454
+ # LRimage = resizeImage(LRimage, target_size=target_size)
455
+
456
+ # # Full k-space
457
+ # full_HRkspace = fft2c(HRimage)
458
+ # full_LRkspace = fft2c(LRimage)
459
+
460
+ # # Undersampled k-space
461
+ # ud_HRkspace, _ = und2DMask(full_HRkspace, mask_file)
462
+ # ud_LRkspace, _ = und2DMask(full_LRkspace, mask_file)
463
+
464
+ # # Reconstructed image magnitude from undersampled k-space
465
+ # recon_HRimage = ifft2c(ud_HRkspace)
466
+ # recon_LRimage = ifft2c(ud_LRkspace)
467
+
468
+ # mag_HRimage = np.abs(recon_HRimage)
469
+ # mag_LRimage = np.abs(recon_LRimage)
470
+
471
+ # # Store outputs
472
+ # HR_images.append(HRimage)
473
+ # full_HR_kspace.append(full_HRkspace)
474
+ # ud_HR_kspace.append(ud_HRkspace)
475
+ # mag_HR_images.append(mag_HRimage)
476
+
477
+ # LR_images.append(LRimage)
478
+ # full_LR_kspace.append(full_LRkspace)
479
+ # ud_LR_kspace.append(ud_LRkspace)
480
+ # mag_LR_images.append(mag_LRimage)
481
+
482
+ # return {
483
+ # "HR_images": HR_images,
484
+ # "full_HR_kspace": full_HR_kspace,
485
+ # "ud_HR_kspace": ud_HR_kspace,
486
+ # "mag_HR_images": mag_HR_images,
487
+ # "LR_images": LR_images,
488
+ # "full_LR_kspace": full_LR_kspace,
489
+ # "ud_LR_kspace": ud_LR_kspace,
490
+ # "mag_LR_images": mag_LR_images,
491
+ # "num_samples": len(HR_images),
492
+ # "target_size": target_size,
493
+ # }
494
+
495
+
496
+ # def plot_preprocessing_hr(sample_idx: int, processed: dict):
497
+ # """
498
+ # Plot full and undersampled k-space/image for HR sample.
499
+ # """
500
+ # sample_fsHRkspace = processed["full_HR_kspace"][sample_idx]
501
+ # sample_udHRkspace = processed["ud_HR_kspace"][sample_idx]
502
+ # sample_fsHRimg = processed["HR_images"][sample_idx]
503
+ # sample_udHRimg = processed["mag_HR_images"][sample_idx]
504
+
505
+ # fig, axes = plt.subplots(1, 4, figsize=(16, 4))
506
+
507
+ # axes[0].imshow(np.log(np.abs(sample_fsHRkspace) + 1e-9), cmap="gray")
508
+ # axes[0].set_title("fsHR k-space")
509
+ # axes[0].axis("off")
510
+
511
+ # axes[1].imshow(sample_fsHRimg, cmap="gray")
512
+ # axes[1].set_title("fsHR Image")
513
+ # axes[1].axis("off")
514
+
515
+ # axes[2].imshow(np.log(np.abs(sample_udHRkspace) + 1e-9), cmap="gray")
516
+ # axes[2].set_title("udHR k-space")
517
+ # axes[2].axis("off")
518
+
519
+ # axes[3].imshow(sample_udHRimg, cmap="gray")
520
+ # axes[3].set_title("udHR Image")
521
+ # axes[3].axis("off")
522
+
523
+ # plt.tight_layout()
524
+ # return fig
525
+
526
+
527
+ # def plot_preprocessing_lr(sample_idx: int, processed: dict):
528
+ # """
529
+ # Plot full and undersampled k-space/image for LR sample.
530
+ # """
531
+ # sample_fsLRkspace = processed["full_LR_kspace"][sample_idx]
532
+ # sample_udLRkspace = processed["ud_LR_kspace"][sample_idx]
533
+ # sample_fsLRimg = processed["LR_images"][sample_idx]
534
+ # sample_udLRimg = processed["mag_LR_images"][sample_idx]
535
+
536
+ # fig, axes = plt.subplots(1, 4, figsize=(16, 4))
537
+
538
+ # axes[0].imshow(np.log(np.abs(sample_fsLRkspace) + 1e-9), cmap="gray")
539
+ # axes[0].set_title("fsLR k-space")
540
+ # axes[0].axis("off")
541
+
542
+ # axes[1].imshow(sample_fsLRimg, cmap="gray")
543
+ # axes[1].set_title("fsLR Image")
544
+ # axes[1].axis("off")
545
+
546
+ # axes[2].imshow(np.log(np.abs(sample_udLRkspace) + 1e-9), cmap="gray")
547
+ # axes[2].set_title("udLR k-space")
548
+ # axes[2].axis("off")
549
+
550
+ # axes[3].imshow(sample_udLRimg, cmap="gray")
551
+ # axes[3].set_title("udLR Image")
552
+ # axes[3].axis("off")
553
+
554
+ # plt.tight_layout()
555
+ # return fig
556
+
557
+
558
+ # # ---------------------------------------------------
559
+ # # Validate folders
560
+ # # ---------------------------------------------------
561
+ # if not HF_DIR.exists():
562
+ # st.error(f"HF directory not found: {HF_DIR}")
563
+ # st.stop()
564
+
565
+ # if not LF_DIR.exists():
566
+ # st.error(f"LF directory not found: {LF_DIR}")
567
+ # st.stop()
568
+
569
+ # if not MASK_FILE.exists():
570
+ # st.error(f"Mask file not found: {MASK_FILE}")
571
+ # st.stop()
572
+
573
+ # # ---------------------------------------------------
574
+ # # Load paired dataset
575
+ # # ---------------------------------------------------
576
+ # ts_df = get_paired_files(HF_DIR, LF_DIR)
577
+
578
+ # if ts_df.empty:
579
+ # st.warning("No matching .npy file pairs found in data/HF and data/LF.")
580
+ # st.stop()
581
+
582
+ # # ---------------------------------------------------
583
+ # # Sidebar controls - EDA
584
+ # # ---------------------------------------------------
585
+ # with st.sidebar.expander("EDA Controls", expanded=False):
586
+ # selected_name = st.selectbox(
587
+ # "Choose sample file",
588
+ # ts_df["sample_name"].tolist(),
589
+ # index=0
590
+ # )
591
+
592
+ # show_stats = st.checkbox("Show array statistics", value=False)
593
+ # show_visualisation = st.checkbox("Display EDA visualisation", value=False)
594
+
595
+ # show_dataframe = st.sidebar.checkbox("Show dataframe", value=False)
596
+
597
+ # # ---------------------------------------------------
598
+ # # Sidebar controls - Preprocessing
599
+ # # ---------------------------------------------------
600
+ # with st.sidebar.expander("Preprocessing Controls", expanded=False):
601
+ # st.markdown("Apply preprocessing to the currently selected HF/LF pair.")
602
+
603
+ # target_height = st.number_input("Target height", min_value=32, max_value=1024, value=256, step=32)
604
+ # target_width = st.number_input("Target width", min_value=32, max_value=1024, value=256, step=32)
605
+
606
+ # apply_preprocessing = st.button("Apply preprocessing")
607
+ # show_preprocessing_viz = st.checkbox("Display preprocessing visualisation", value=False)
608
+
609
+ # # ---------------------------------------------------
610
+ # # Load selected sample from EDA
611
+ # # ---------------------------------------------------
612
+ # selected_row = ts_df[ts_df["sample_name"] == selected_name].iloc[0]
613
+ # img_path = selected_row["imgFiles"] # LF
614
+ # gdt_path = selected_row["gdtFiles"] # HF
615
+
616
+ # imgTs = load_npy_file(img_path)
617
+ # gdtTs = load_npy_file(gdt_path)
618
+
619
+ # # ---------------------------------------------------
620
+ # # Initialise session state keys
621
+ # # ---------------------------------------------------
622
+ # if "preprocessed_data" not in st.session_state:
623
+ # st.session_state["preprocessed_data"] = None
624
+
625
+ # if "preprocessed_sample_name" not in st.session_state:
626
+ # st.session_state["preprocessed_sample_name"] = None
627
+
628
+ # # ---------------------------------------------------
629
+ # # Run preprocessing only when the button is clicked
630
+ # # ---------------------------------------------------
631
+ # if apply_preprocessing:
632
+ # try:
633
+ # with st.spinner("Applying preprocessing..."):
634
+ # processed = preprocess_single_pair(
635
+ # hr_array=gdtTs, # HF
636
+ # lr_array=imgTs, # LF
637
+ # mask_file=MASK_FILE,
638
+ # target_size=(int(target_height), int(target_width))
639
+ # )
640
+
641
+ # st.session_state["preprocessed_data"] = processed
642
+ # st.session_state["preprocessed_sample_name"] = selected_name
643
+
644
+ # st.success(f"Preprocessing completed for sample: {selected_name}")
645
+
646
+ # except Exception as e:
647
+ # st.error(f"Preprocessing failed: {e}")
648
+
649
+ # # ---------------------------------------------------
650
+ # # Build visible sections dynamically
651
+ # # ---------------------------------------------------
652
+ # tab_names = []
653
+ # tab_keys = []
654
+
655
+ # if show_dataframe:
656
+ # tab_names.append("Dataset")
657
+ # tab_keys.append("dataframe")
658
+
659
+ # if show_stats:
660
+ # tab_names.append("Statistics")
661
+ # tab_keys.append("stats")
662
+
663
+ # if show_visualisation:
664
+ # tab_names.append("EDA Visualisation")
665
+ # tab_keys.append("eda_viz")
666
+
667
+ # if show_preprocessing_viz:
668
+ # tab_names.append("Preprocessing Visualisation")
669
+ # tab_keys.append("prep_viz")
670
+
671
+ # # ---------------------------------------------------
672
+ # # If nothing is checked, keep the main panel empty
673
+ # # ---------------------------------------------------
674
+ # if not tab_names:
675
+ # st.empty()
676
+ # else:
677
+ # tabs = st.tabs(tab_names)
678
+
679
+ # for tab, key in zip(tabs, tab_keys):
680
+ # with tab:
681
+ # # ---------------------------------------
682
+ # # Dataset tab
683
+ # # ---------------------------------------
684
+ # if key == "dataframe":
685
+ # st.markdown("### Available Dataset")
686
+ # st.dataframe(ts_df, use_container_width=True)
687
+
688
+ # # ---------------------------------------
689
+ # # Statistics tab
690
+ # # ---------------------------------------
691
+ # elif key == "stats":
692
+ # st.markdown("### Selected Sample Statistics")
693
+
694
+ # col1, col2 = st.columns(2)
695
+
696
+ # img_stats = array_summary(imgTs)
697
+ # gdt_stats = array_summary(gdtTs)
698
+
699
+ # with col1:
700
+ # st.markdown("#### LF Image")
701
+ # st.write(f"**File:** `{selected_name}`")
702
+ # st.write(f"**Shape:** {img_stats['shape']}")
703
+ # st.write(f"**Dimensions:** {img_stats['ndim']}D")
704
+ # st.write(f"**Dtype:** {img_stats['dtype']}")
705
+ # st.write(f"**Min:** {img_stats['min']:.6f}")
706
+ # st.write(f"**Max:** {img_stats['max']:.6f}")
707
+ # st.write(f"**Mean:** {img_stats['mean']:.6f}")
708
+
709
+ # with col2:
710
+ # st.markdown("#### HF Ground Truth")
711
+ # st.write(f"**File:** `{selected_name}`")
712
+ # st.write(f"**Shape:** {gdt_stats['shape']}")
713
+ # st.write(f"**Dimensions:** {gdt_stats['ndim']}D")
714
+ # st.write(f"**Dtype:** {gdt_stats['dtype']}")
715
+ # st.write(f"**Min:** {gdt_stats['min']:.6f}")
716
+ # st.write(f"**Max:** {gdt_stats['max']:.6f}")
717
+ # st.write(f"**Mean:** {gdt_stats['mean']:.6f}")
718
+
719
+ # # ---------------------------------------
720
+ # # EDA Visualisation tab
721
+ # # ---------------------------------------
722
+ # elif key == "eda_viz":
723
+ # st.markdown("### EDA Image Visualisation")
724
+
725
+ # if imgTs.ndim == 2 and gdtTs.ndim == 2:
726
+ # img_show = imgTs
727
+ # gdt_show = gdtTs
728
+
729
+ # elif imgTs.ndim == 3 and gdtTs.ndim == 3:
730
+ # max_slice = min(imgTs.shape[0], gdtTs.shape[0]) - 1
731
+ # slice_idx = st.slider(
732
+ # "Choose slice index",
733
+ # min_value=0,
734
+ # max_value=max_slice,
735
+ # value=0,
736
+ # key="eda_slice_slider"
737
+ # )
738
+
739
+ # img_show = get_display_slice(imgTs, slice_idx)
740
+ # gdt_show = get_display_slice(gdtTs, slice_idx)
741
+
742
+ # st.info(f"Displaying EDA slice index: {slice_idx}")
743
+
744
+ # else:
745
+ # st.error("LF and HF arrays do not have compatible dimensions for joint display.")
746
+ # st.stop()
747
+
748
+ # fig = plot_side_by_side(
749
+ # img_show,
750
+ # gdt_show,
751
+ # lf_title=f"LF: {selected_name}",
752
+ # hf_title=f"HF: {selected_name}"
753
+ # )
754
+ # st.pyplot(fig)
755
+
756
+ # # ---------------------------------------
757
+ # # Preprocessing Visualisation tab
758
+ # # ---------------------------------------
759
+ # elif key == "prep_viz":
760
+ # st.markdown("### Preprocessing Visualisation")
761
+
762
+ # processed = st.session_state.get("preprocessed_data")
763
+ # processed_sample_name = st.session_state.get("preprocessed_sample_name")
764
+
765
+ # # Guard: user requested preprocessing visualisation but has not run preprocessing yet
766
+ # if processed is None:
767
+ # st.warning("Please click 'Apply preprocessing' in the sidebar first.")
768
+ # st.stop()
769
+
770
+ # # Guard: selected sample changed after preprocessing
771
+ # if processed_sample_name != selected_name:
772
+ # st.warning(
773
+ # "The currently displayed preprocessing result belongs to a different selected file. "
774
+ # "Please click 'Apply preprocessing' again for the newly selected sample."
775
+ # )
776
+ # st.stop()
777
+
778
+ # num_samples = processed["num_samples"]
779
+
780
+ # # For 2D data there is only one processed sample
781
+ # if num_samples == 1:
782
+ # sample_idx = 0
783
+ # st.info("This sample is 2D, so only one processed image is available.")
784
+
785
+ # # For 3D data let the user choose the slice/sample index
786
+ # else:
787
+ # sample_idx = st.slider(
788
+ # "Choose preprocessing sample index",
789
+ # min_value=0,
790
+ # max_value=num_samples - 1,
791
+ # value=0,
792
+ # key="prep_sample_slider"
793
+ # )
794
+ # st.info(f"Displaying preprocessing sample index: {sample_idx}")
795
+
796
+ # # Show dimensions of current processed outputs
797
+ # sample_udHRkspace = processed["ud_HR_kspace"][sample_idx]
798
+ # sample_fsHRkspace = processed["full_HR_kspace"][sample_idx]
799
+ # sample_udLRkspace = processed["ud_LR_kspace"][sample_idx]
800
+ # sample_fsLRkspace = processed["full_LR_kspace"][sample_idx]
801
+
802
+ # sample_udHRimg = processed["mag_HR_images"][sample_idx]
803
+ # sample_fsHRimg = processed["HR_images"][sample_idx]
804
+ # sample_udLRimg = processed["mag_LR_images"][sample_idx]
805
+ # sample_fsLRimg = processed["LR_images"][sample_idx]
806
+
807
+ # st.markdown("#### Processed Sample Shapes")
808
+ # col1, col2 = st.columns(2)
809
+
810
+ # # with col1:
811
+ # # st.write(f"**udHRkspace:** {sample_udHRkspace.shape}")
812
+ # # st.write(f"**fsHRkspace:** {sample_fsHRkspace.shape}")
813
+ # # st.write(f"**udHRimg:** {sample_udHRimg.shape}")
814
+ # # st.write(f"**fsHRimg:** {sample_fsHRimg.shape}")
815
+
816
+ # # with col2:
817
+ # # st.write(f"**udLRkspace:** {sample_udLRkspace.shape}")
818
+ # # st.write(f"**fsLRkspace:** {sample_fsLRkspace.shape}")
819
+ # # st.write(f"**udLRimg:** {sample_udLRimg.shape}")
820
+ # # st.write(f"**fsLRimg:** {sample_fsLRimg.shape}")
821
+
822
+ # # Plot HR row
823
+ # st.markdown("#### HR Domain Visualisation")
824
+ # fig_hr = plot_preprocessing_hr(sample_idx, processed)
825
+ # st.pyplot(fig_hr)
826
+
827
+ # # Plot LR row
828
+ # st.markdown("#### LR Domain Visualisation")
829
+ # fig_lr = plot_preprocessing_lr(sample_idx, processed)
830
+ # st.pyplot(fig_lr)
831
+
832
+
833
+
834
+
835
+
836
+ # # # (03) Model Prediction