Rydhi commited on
Commit
0ffb846
·
1 Parent(s): 6da3f9c

Improve visualization colors and layout

Browse files
Files changed (2) hide show
  1. app.py +20 -15
  2. inference.py +15 -5
app.py CHANGED
@@ -37,20 +37,25 @@ def run(t1_file, t1ce_file, t2_file, flair_file):
37
  return fig_path, pdf_path
38
 
39
 
40
- demo = gr.Interface(
41
- fn=run,
42
- inputs=[
43
- gr.File(label="T1"),
44
- gr.File(label="T1ce"),
45
- gr.File(label="T2"),
46
- gr.File(label="FLAIR"),
47
- ],
48
- outputs=[
49
- gr.Image(label="Segmentation Preview"),
50
- gr.File(label="Download PDF Report"),
51
- ],
52
- title="MedSegNet — Brain Tumor Segmentation",
53
- description="Upload T1, T1ce, T2, and FLAIR NIfTI volumes (.nii or .nii.gz) to get automated tumor segmentation.",
54
- )
 
 
 
 
 
55
 
56
  demo.launch()
 
37
  return fig_path, pdf_path
38
 
39
 
40
+ with gr.Blocks(title="MedSegNet — Brain Tumor Segmentation") as demo:
41
+ gr.Markdown("## MedSegNet — Brain Tumor Segmentation")
42
+ gr.Markdown("Upload T1, T1ce, T2, and FLAIR NIfTI volumes (.nii or .nii.gz) to get automated tumor segmentation.")
43
+
44
+ with gr.Row():
45
+ t1 = gr.File(label="T1")
46
+ t1ce = gr.File(label="T1ce")
47
+ t2 = gr.File(label="T2")
48
+ flair = gr.File(label="FLAIR")
49
+
50
+ submit_btn = gr.Button("Run Segmentation", variant="primary")
51
+
52
+ output_image = gr.Image(label="Segmentation Result")
53
+ pdf_output = gr.File(label="📄 Download PDF Report", visible=True)
54
+
55
+ submit_btn.click(
56
+ fn=run,
57
+ inputs=[t1, t1ce, t2, flair],
58
+ outputs=[output_image, pdf_output],
59
+ )
60
 
61
  demo.launch()
inference.py CHANGED
@@ -61,17 +61,27 @@ def make_slice_figure(volume, pred, save_path="preview.png"):
61
  flair_slice = volume[3][mid]
62
  pred_combined = combine_regions(pred)[mid]
63
 
64
- fig, axes = plt.subplots(1, 2, figsize=(10, 5))
 
65
  axes[0].imshow(flair_slice, cmap="gray")
66
- axes[0].set_title("Input (FLAIR)")
67
  axes[0].axis("off")
68
 
69
  axes[1].imshow(flair_slice, cmap="gray")
70
- axes[1].imshow(pred_combined, cmap=region_cmap, alpha=0.5, vmin=0, vmax=3)
71
- axes[1].set_title("Predicted Segmentation")
72
  axes[1].axis("off")
73
 
 
 
 
 
 
 
 
 
 
74
  plt.tight_layout()
75
- plt.savefig(save_path, dpi=150, bbox_inches="tight")
76
  plt.close(fig)
77
  return save_path
 
61
  flair_slice = volume[3][mid]
62
  pred_combined = combine_regions(pred)[mid]
63
 
64
+ fig, axes = plt.subplots(1, 2, figsize=(12, 6))
65
+
66
  axes[0].imshow(flair_slice, cmap="gray")
67
+ axes[0].set_title("Input (FLAIR)", fontsize=14)
68
  axes[0].axis("off")
69
 
70
  axes[1].imshow(flair_slice, cmap="gray")
71
+ im = axes[1].imshow(pred_combined, cmap=region_cmap, alpha=0.6, vmin=0, vmax=3)
72
+ axes[1].set_title("Predicted Segmentation", fontsize=14)
73
  axes[1].axis("off")
74
 
75
+ # legend instead of faint colorbar
76
+ from matplotlib.patches import Patch
77
+ legend_elements = [
78
+ Patch(facecolor="yellow", label="Whole Tumor (WT)"),
79
+ Patch(facecolor="green", label="Tumor Core (TC)"),
80
+ Patch(facecolor="red", label="Enhancing Tumor (ET)"),
81
+ ]
82
+ axes[1].legend(handles=legend_elements, loc="lower right", fontsize=9, framealpha=0.8)
83
+
84
  plt.tight_layout()
85
+ plt.savefig(save_path, dpi=150, bbox_inches="tight", facecolor="white")
86
  plt.close(fig)
87
  return save_path