2D + 3D viewer same size and centered + refactored
Browse files- neukit/gui.py +26 -23
- neukit/inference.py +2 -8
neukit/gui.py
CHANGED
@@ -21,7 +21,8 @@ class WebUI:
|
|
21 |
self.volume_renderer = gr.Model3D(
|
22 |
clear_color=[0.0, 0.0, 0.0, 0.0],
|
23 |
label="3D Model",
|
24 |
-
visible=True
|
|
|
25 |
).style(height=512)
|
26 |
|
27 |
def combine_ct_and_seg(self, img, pred):
|
@@ -30,19 +31,13 @@ class WebUI:
|
|
30 |
def upload_file(self, file):
|
31 |
return file.name
|
32 |
|
33 |
-
def get_file_extension(self, file):
|
34 |
-
filename = file.split("/")[-1]
|
35 |
-
splits = filename.split(".")
|
36 |
-
return ".".join(splits[1:])
|
37 |
-
|
38 |
def load_mesh(self, mesh_file_name):
|
39 |
path = mesh_file_name.name
|
40 |
-
|
41 |
-
|
42 |
-
#nifti_to_glb("prediction." + extension)
|
43 |
|
44 |
self.images = load_ct_to_numpy(path)
|
45 |
-
self.pred_images = load_pred_volume_to_numpy("./prediction."
|
46 |
self.slider = self.slider.update(value=2)
|
47 |
return "./prediction.obj"
|
48 |
|
@@ -53,11 +48,19 @@ class WebUI:
|
|
53 |
return out
|
54 |
|
55 |
def run(self):
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
-
with gr.Row()
|
59 |
file_output = gr.File(
|
60 |
-
#file_types=[".nii", ".nii.gz"],
|
61 |
file_count="single"
|
62 |
).style(full_width=False, size="sm")
|
63 |
file_output.upload(self.upload_file, file_output, file_output)
|
@@ -69,21 +72,21 @@ class WebUI:
|
|
69 |
outputs=self.volume_renderer
|
70 |
)
|
71 |
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
|
81 |
-
with gr.Row()
|
82 |
with gr.Box():
|
83 |
image_boxes = []
|
84 |
for i in range(self.nb_slider_items):
|
85 |
visibility = True if i == 1 else False
|
86 |
-
t = gr.AnnotatedImage(visible=visibility)\
|
87 |
.style(color_map={self.class_name: "#ffae00"}, height=512, width=512)
|
88 |
image_boxes.append(t)
|
89 |
|
|
|
21 |
self.volume_renderer = gr.Model3D(
|
22 |
clear_color=[0.0, 0.0, 0.0, 0.0],
|
23 |
label="3D Model",
|
24 |
+
visible=True,
|
25 |
+
elem_id="model-3d",
|
26 |
).style(height=512)
|
27 |
|
28 |
def combine_ct_and_seg(self, img, pred):
|
|
|
31 |
def upload_file(self, file):
|
32 |
return file.name
|
33 |
|
|
|
|
|
|
|
|
|
|
|
34 |
def load_mesh(self, mesh_file_name):
|
35 |
path = mesh_file_name.name
|
36 |
+
run_model(path, model_path=self.cwd + "resources/models/")
|
37 |
+
nifti_to_glb("prediction.nii.gz")
|
|
|
38 |
|
39 |
self.images = load_ct_to_numpy(path)
|
40 |
+
self.pred_images = load_pred_volume_to_numpy("./prediction.nii.gz")
|
41 |
self.slider = self.slider.update(value=2)
|
42 |
return "./prediction.obj"
|
43 |
|
|
|
48 |
return out
|
49 |
|
50 |
def run(self):
|
51 |
+
css="""
|
52 |
+
#model-3d {
|
53 |
+
height: 512px;
|
54 |
+
}
|
55 |
+
#model-2d {
|
56 |
+
height: 512px;
|
57 |
+
margin: auto;
|
58 |
+
}
|
59 |
+
"""
|
60 |
+
with gr.Blocks(css=css) as demo:
|
61 |
|
62 |
+
with gr.Row():
|
63 |
file_output = gr.File(
|
|
|
64 |
file_count="single"
|
65 |
).style(full_width=False, size="sm")
|
66 |
file_output.upload(self.upload_file, file_output, file_output)
|
|
|
72 |
outputs=self.volume_renderer
|
73 |
)
|
74 |
|
75 |
+
with gr.Row():
|
76 |
+
gr.Examples(
|
77 |
+
examples=[self.cwd + "test-volume.nii"],
|
78 |
+
inputs=file_output,
|
79 |
+
outputs=file_output,
|
80 |
+
fn=self.upload_file,
|
81 |
+
cache_examples=True,
|
82 |
+
)
|
83 |
|
84 |
+
with gr.Row():
|
85 |
with gr.Box():
|
86 |
image_boxes = []
|
87 |
for i in range(self.nb_slider_items):
|
88 |
visibility = True if i == 1 else False
|
89 |
+
t = gr.AnnotatedImage(visible=visibility, elem_id="model-2d")\
|
90 |
.style(color_map={self.class_name: "#ffae00"}, height=512, width=512)
|
91 |
image_boxes.append(t)
|
92 |
|
neukit/inference.py
CHANGED
@@ -24,18 +24,12 @@ def run_model(input_path: str, model_path: str, verbose: str = "info", task: str
|
|
24 |
extension = ".".join(splits[1:])
|
25 |
patient_directory = "./patient/"
|
26 |
os.makedirs(patient_directory + "T0/", exist_ok=True)
|
27 |
-
|
28 |
|
29 |
# define output directory to save results
|
30 |
output_path = "./result/prediction-" + splits[0] + "/"
|
31 |
os.makedirs(output_path, exist_ok=True)
|
32 |
|
33 |
-
print("orig input:", input_path)
|
34 |
-
print("updated input:", patient_directory + "T0/" + splits[0] + "-t1gd." + extension)
|
35 |
-
print("patient_dir:", patient_directory)
|
36 |
-
print("output path:", output_path)
|
37 |
-
print("model path:", model_path)
|
38 |
-
|
39 |
# Setting up the configuration file
|
40 |
rads_config = configparser.ConfigParser()
|
41 |
rads_config.add_section('Default')
|
@@ -64,7 +58,7 @@ def run_model(input_path: str, model_path: str, verbose: str = "info", task: str
|
|
64 |
print(e)
|
65 |
|
66 |
# rename and move final result
|
67 |
-
os.rename("./result/prediction-" + splits[0] + "/T0/" + splits[0] + "-t1gd_annotation-Tumor."
|
68 |
|
69 |
# Clean-up
|
70 |
if os.path.exists(patient_directory):
|
|
|
24 |
extension = ".".join(splits[1:])
|
25 |
patient_directory = "./patient/"
|
26 |
os.makedirs(patient_directory + "T0/", exist_ok=True)
|
27 |
+
shutil.copy(input_path, patient_directory + "T0/" + splits[0] + "-t1gd." + extension)
|
28 |
|
29 |
# define output directory to save results
|
30 |
output_path = "./result/prediction-" + splits[0] + "/"
|
31 |
os.makedirs(output_path, exist_ok=True)
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
# Setting up the configuration file
|
34 |
rads_config = configparser.ConfigParser()
|
35 |
rads_config.add_section('Default')
|
|
|
58 |
print(e)
|
59 |
|
60 |
# rename and move final result
|
61 |
+
os.rename("./result/prediction-" + splits[0] + "/T0/" + splits[0] + "-t1gd_annotation-Tumor.nii.gz", "./prediction.nii.gz")
|
62 |
|
63 |
# Clean-up
|
64 |
if os.path.exists(patient_directory):
|