Merge pull request #38 from andreped/gui
Browse filesFixed Model3D camera position; Added inference info to UI; Minor refactoring
- demo/src/gui.py +14 -3
- demo/src/utils.py +7 -0
demo/src/gui.py
CHANGED
|
@@ -55,8 +55,10 @@ class WebUI:
|
|
| 55 |
self.volume_renderer = gr.Model3D(
|
| 56 |
clear_color=[0.0, 0.0, 0.0, 0.0],
|
| 57 |
label="3D Model",
|
|
|
|
| 58 |
visible=True,
|
| 59 |
elem_id="model-3d",
|
|
|
|
| 60 |
).style(height=512)
|
| 61 |
|
| 62 |
def set_class_name(self, value):
|
|
@@ -79,7 +81,7 @@ class WebUI:
|
|
| 79 |
task=self.class_names[self.class_name],
|
| 80 |
name=self.result_names[self.class_name],
|
| 81 |
)
|
| 82 |
-
LOGGER.info("Converting prediction NIfTI to
|
| 83 |
nifti_to_glb("prediction.nii.gz")
|
| 84 |
|
| 85 |
LOGGER.info("Loading CT to numpy...")
|
|
@@ -123,6 +125,7 @@ class WebUI:
|
|
| 123 |
show_copy_button=True,
|
| 124 |
scroll_to_output=False,
|
| 125 |
container=True,
|
|
|
|
| 126 |
)
|
| 127 |
demo.load(read_logs, None, logs, every=1)
|
| 128 |
|
|
@@ -132,7 +135,8 @@ class WebUI:
|
|
| 132 |
sidebar_state = gr.State(True)
|
| 133 |
|
| 134 |
btn_toggle_sidebar = gr.Button(
|
| 135 |
-
"Toggle Sidebar",
|
|
|
|
| 136 |
)
|
| 137 |
btn_toggle_sidebar.click(
|
| 138 |
self.toggle_sidebar,
|
|
@@ -155,7 +159,7 @@ class WebUI:
|
|
| 155 |
model_selector = gr.Dropdown(
|
| 156 |
list(self.class_names.keys()),
|
| 157 |
label="Task",
|
| 158 |
-
info="Which
|
| 159 |
multiselect=False,
|
| 160 |
size="sm",
|
| 161 |
)
|
|
@@ -191,6 +195,13 @@ class WebUI:
|
|
| 191 |
cache_examples=True,
|
| 192 |
)
|
| 193 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
with gr.Row():
|
| 195 |
with gr.Box():
|
| 196 |
with gr.Column():
|
|
|
|
| 55 |
self.volume_renderer = gr.Model3D(
|
| 56 |
clear_color=[0.0, 0.0, 0.0, 0.0],
|
| 57 |
label="3D Model",
|
| 58 |
+
show_label=True,
|
| 59 |
visible=True,
|
| 60 |
elem_id="model-3d",
|
| 61 |
+
camera_position=[90, 180, 768],
|
| 62 |
).style(height=512)
|
| 63 |
|
| 64 |
def set_class_name(self, value):
|
|
|
|
| 81 |
task=self.class_names[self.class_name],
|
| 82 |
name=self.result_names[self.class_name],
|
| 83 |
)
|
| 84 |
+
LOGGER.info("Converting prediction NIfTI to OBJ...")
|
| 85 |
nifti_to_glb("prediction.nii.gz")
|
| 86 |
|
| 87 |
LOGGER.info("Loading CT to numpy...")
|
|
|
|
| 125 |
show_copy_button=True,
|
| 126 |
scroll_to_output=False,
|
| 127 |
container=True,
|
| 128 |
+
line_breaks=True,
|
| 129 |
)
|
| 130 |
demo.load(read_logs, None, logs, every=1)
|
| 131 |
|
|
|
|
| 135 |
sidebar_state = gr.State(True)
|
| 136 |
|
| 137 |
btn_toggle_sidebar = gr.Button(
|
| 138 |
+
"Toggle Sidebar",
|
| 139 |
+
elem_id="toggle-button",
|
| 140 |
)
|
| 141 |
btn_toggle_sidebar.click(
|
| 142 |
self.toggle_sidebar,
|
|
|
|
| 159 |
model_selector = gr.Dropdown(
|
| 160 |
list(self.class_names.keys()),
|
| 161 |
label="Task",
|
| 162 |
+
info="Which structure to segment.",
|
| 163 |
multiselect=False,
|
| 164 |
size="sm",
|
| 165 |
)
|
|
|
|
| 195 |
cache_examples=True,
|
| 196 |
)
|
| 197 |
|
| 198 |
+
gr.Markdown(
|
| 199 |
+
"""
|
| 200 |
+
**NOTE:** Inference might take several minutes (Airways: ~8 minutes), see logs to the left. \\
|
| 201 |
+
The segmentation will be available in the 2D and 3D viewers below when finished.
|
| 202 |
+
"""
|
| 203 |
+
)
|
| 204 |
+
|
| 205 |
with gr.Row():
|
| 206 |
with gr.Box():
|
| 207 |
with gr.Column():
|
demo/src/utils.py
CHANGED
|
@@ -46,12 +46,19 @@ def nifti_to_glb(path, output="prediction.obj"):
|
|
| 46 |
resampled = resample_to_output(image, [1, 1, 1], order=1)
|
| 47 |
data = resampled.get_fdata().astype("uint8")
|
| 48 |
|
|
|
|
|
|
|
|
|
|
| 49 |
# extract surface
|
| 50 |
verts, faces, normals, values = marching_cubes(data, 0)
|
| 51 |
faces += 1
|
| 52 |
|
| 53 |
with open(output, "w") as thefile:
|
|
|
|
|
|
|
|
|
|
| 54 |
for item in verts:
|
|
|
|
| 55 |
thefile.write("v {0} {1} {2}\n".format(item[0], item[1], item[2]))
|
| 56 |
|
| 57 |
for item in normals:
|
|
|
|
| 46 |
resampled = resample_to_output(image, [1, 1, 1], order=1)
|
| 47 |
data = resampled.get_fdata().astype("uint8")
|
| 48 |
|
| 49 |
+
# Create a material with a red diffuse color (RGB value)
|
| 50 |
+
red_material = "newmtl RedMaterial\nKd 1 0 0" # Red diffuse color (RGB)
|
| 51 |
+
|
| 52 |
# extract surface
|
| 53 |
verts, faces, normals, values = marching_cubes(data, 0)
|
| 54 |
faces += 1
|
| 55 |
|
| 56 |
with open(output, "w") as thefile:
|
| 57 |
+
# Write the material definition to the OBJ file
|
| 58 |
+
thefile.write(red_material + "\n")
|
| 59 |
+
|
| 60 |
for item in verts:
|
| 61 |
+
# thefile.write('usemtl RedMaterial\n')
|
| 62 |
thefile.write("v {0} {1} {2}\n".format(item[0], item[1], item[2]))
|
| 63 |
|
| 64 |
for item in normals:
|