Update app.py
Browse files
app.py
CHANGED
@@ -5,9 +5,9 @@ import matplotlib.pyplot as plt
|
|
5 |
from prediction import predict_mask
|
6 |
|
7 |
# Placeholder for your 3D model
|
8 |
-
def process_3d_image(image):
|
9 |
# Dummy model implementation: Replace with your actual model logic
|
10 |
-
binary_mask = predict_mask(image)
|
11 |
return binary_mask
|
12 |
|
13 |
def auximread(filepath):
|
@@ -28,7 +28,7 @@ def auximread(filepath):
|
|
28 |
return image
|
29 |
|
30 |
# Function to handle file input and processing
|
31 |
-
def process_file(file):
|
32 |
"""
|
33 |
Process the uploaded file and return the binary mask.
|
34 |
"""
|
@@ -43,7 +43,7 @@ def process_file(file):
|
|
43 |
raise ValueError("Input image is not 3D.")
|
44 |
|
45 |
# Process image through the model
|
46 |
-
binary_mask = process_3d_image(image)
|
47 |
|
48 |
# Save binary mask to a .tif file to return
|
49 |
output_path = "output_mask.tif"
|
@@ -81,9 +81,9 @@ def visualize_slice(image, mask, slice_index):
|
|
81 |
processed_image = None
|
82 |
processed_mask = None
|
83 |
|
84 |
-
def segment_button_click(file):
|
85 |
global processed_image, processed_mask
|
86 |
-
processed_image, processed_mask, output_path = process_file(file)
|
87 |
num_slices = processed_image.shape[2]
|
88 |
return "Segmentation completed! Use the slider to explore slices.", output_path, gr.update(visible=True, maximum=num_slices - 1)
|
89 |
|
@@ -99,6 +99,12 @@ with gr.Blocks() as iface:
|
|
99 |
Use the slider to navigate through the 2D slices. This is the official implementation of 3DVascNet, described in this paper: https://www.ahajournals.org/doi/10.1161/ATVBAHA.124.320672.
|
100 |
The raw code is available at https://github.com/HemaxiN/3DVascNet.
|
101 |
""")
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
|
103 |
with gr.Row():
|
104 |
file_input = gr.File(label="Upload 3D Image (.tif)")
|
@@ -112,7 +118,9 @@ with gr.Blocks() as iface:
|
|
112 |
visualization_output = gr.Plot(label="2D Slice Visualization")
|
113 |
|
114 |
# Button click triggers segmentation
|
115 |
-
segment_button.click(segment_button_click,
|
|
|
|
|
116 |
|
117 |
# Slider changes trigger visualization updates
|
118 |
slice_slider.change(update_visualization, inputs=slice_slider, outputs=visualization_output)
|
|
|
5 |
from prediction import predict_mask
|
6 |
|
7 |
# Placeholder for your 3D model
|
8 |
+
def process_3d_image(image, resx, resy, resz):
|
9 |
# Dummy model implementation: Replace with your actual model logic
|
10 |
+
binary_mask = predict_mask(image, resx, resy, resz)
|
11 |
return binary_mask
|
12 |
|
13 |
def auximread(filepath):
|
|
|
28 |
return image
|
29 |
|
30 |
# Function to handle file input and processing
|
31 |
+
def process_file(file, resx, resy, resz):
|
32 |
"""
|
33 |
Process the uploaded file and return the binary mask.
|
34 |
"""
|
|
|
43 |
raise ValueError("Input image is not 3D.")
|
44 |
|
45 |
# Process image through the model
|
46 |
+
binary_mask = process_3d_image(image, resx, resy, resz)
|
47 |
|
48 |
# Save binary mask to a .tif file to return
|
49 |
output_path = "output_mask.tif"
|
|
|
81 |
processed_image = None
|
82 |
processed_mask = None
|
83 |
|
84 |
+
def segment_button_click(file, resx, resy, resz):
|
85 |
global processed_image, processed_mask
|
86 |
+
processed_image, processed_mask, output_path = process_file(file, resx, resy, resz)
|
87 |
num_slices = processed_image.shape[2]
|
88 |
return "Segmentation completed! Use the slider to explore slices.", output_path, gr.update(visible=True, maximum=num_slices - 1)
|
89 |
|
|
|
99 |
Use the slider to navigate through the 2D slices. This is the official implementation of 3DVascNet, described in this paper: https://www.ahajournals.org/doi/10.1161/ATVBAHA.124.320672.
|
100 |
The raw code is available at https://github.com/HemaxiN/3DVascNet.
|
101 |
""")
|
102 |
+
|
103 |
+
# Input fields for resolution in micrometers
|
104 |
+
with gr.Row():
|
105 |
+
resx_input = gr.Number(value=0.333, label="Resolution in X (µm)", precision=3)
|
106 |
+
resy_input = gr.Number(value=0.333, label="Resolution in Y (µm)", precision=3)
|
107 |
+
resz_input = gr.Number(value=0.5, label="Resolution in Z (µm)", precision=3)
|
108 |
|
109 |
with gr.Row():
|
110 |
file_input = gr.File(label="Upload 3D Image (.tif)")
|
|
|
118 |
visualization_output = gr.Plot(label="2D Slice Visualization")
|
119 |
|
120 |
# Button click triggers segmentation
|
121 |
+
segment_button.click(segment_button_click,
|
122 |
+
inputs=[file_input, resx_input, resy_input, resz_input],
|
123 |
+
outputs=[status_output, download_output, slice_slider])
|
124 |
|
125 |
# Slider changes trigger visualization updates
|
126 |
slice_slider.change(update_visualization, inputs=slice_slider, outputs=visualization_output)
|