37
37
38
38
39
39
onto_tree_imgannot = common_func .load_onto ()
40
+ class_label_colormap = {
41
+ int (term ["id" ].split (":" )[1 ]): term ["data" ]["hex_color" ]
42
+ for term in onto_tree_imgannot
43
+ if term ["data" ]["image_annotation" ] is True
44
+ }
45
+ class_labels = [
46
+ int (term ["id" ].split (":" )[1 ])
47
+ for term in onto_tree_imgannot
48
+ if term ["data" ]["image_annotation" ] is True
49
+ ]
50
+ button_list = [
51
+ int (i ["id" ].split (":" )[1 ])
52
+ for i in onto_tree_imgannot
53
+ if i ["data" ]["image_annotation" ] is True
54
+ ]
55
+ NUM_LABEL_CLASSES = len (class_label_colormap )
56
+ DEFAULT_LABEL_CLASS = class_labels [0 ]
57
+
58
+ # we can't have less colors than classes
59
+ assert NUM_LABEL_CLASSES <= len (class_label_colormap ) # nosec
40
60
41
61
42
62
def class_to_color (ontology , class_number ):
@@ -51,13 +71,13 @@ def color_to_class(ontology, color_hex):
51
71
return int (term ["id" ].split (":" )[1 ])
52
72
53
73
54
- # def class_to_file(seg_matrix, onto_tree , save_path):
74
+ # def class_to_file(seg_matrix, onto_tree_imgannot , save_path):
55
75
# unique_classes = np.unique(seg_matrix)
56
76
# col_df = {"class": [], "color": [], "onto_id": []}
57
77
# for class_img in unique_classes:
58
78
# col_df["class"].append(class_img)
59
- # col_df["color"].append(onto_tree [class_img - 1]["data"]["hex_color"])
60
- # col_df["onto_id"].append(onto_tree [class_img - 1]["id"])
79
+ # col_df["color"].append(onto_tree_imgannot [class_img - 1]["data"]["hex_color"])
80
+ # col_df["onto_id"].append(onto_tree_imgannot [class_img - 1]["id"])
61
81
# df = pd.DataFrame.from_dict(col_df)
62
82
# df.to_csv(save_path, index=False)
63
83
@@ -100,7 +120,12 @@ def save_img_classifier(clf, label_to_colors_args, segmenter_args):
100
120
101
121
102
122
def show_segmentation (
103
- image_path , mask_shapes , features , segmenter_args , class_label_colormap , onto_tree
123
+ image_path ,
124
+ mask_shapes ,
125
+ features ,
126
+ segmenter_args ,
127
+ class_label_colormap ,
128
+ onto_tree_imgannot ,
104
129
):
105
130
"""adds an image showing segmentations to a figure's layout"""
106
131
# add 1 because classifier takes 0 to mean no mask
@@ -109,7 +134,8 @@ def show_segmentation(
109
134
# for shape in mask_shapes
110
135
# ]
111
136
shape_layers = [
112
- color_to_class (onto_tree , shape ["line" ]["color" ]) for shape in mask_shapes
137
+ color_to_class (onto_tree_imgannot , shape ["line" ]["color" ])
138
+ for shape in mask_shapes
113
139
]
114
140
label_to_colors_args = {
115
141
"colormap" : class_label_colormap ,
@@ -166,30 +192,6 @@ def annotation_react(
166
192
sigma_range_slider_value ,
167
193
masks_data ,
168
194
):
169
- with open (os .path .join ("data/ontology" , "ontology.json" ), "r" ) as fp :
170
- onto_tree = json .load (fp )
171
- class_label_colormap = {
172
- int (term ["id" ].split (":" )[1 ]): term ["data" ]["hex_color" ]
173
- for term in onto_tree_imgannot
174
- if term ["data" ]["image_annotation" ] is True
175
- }
176
- class_labels = [
177
- int (term ["id" ].split (":" )[1 ])
178
- for term in onto_tree
179
- if term ["data" ]["image_annotation" ] is True
180
- ]
181
- button_list = [
182
- int (i ["id" ].split (":" )[1 ])
183
- for i in onto_tree_imgannot
184
- if i ["data" ]["image_annotation" ] is True
185
- ]
186
- NUM_LABEL_CLASSES = len (class_label_colormap )
187
- DEFAULT_LABEL_CLASS = class_labels [0 ]
188
- DEFAULT_STROKE_WIDTH = 3 # gives line width of 2^3 = 8
189
-
190
- # we can't have less colors than classes
191
- assert NUM_LABEL_CLASSES <= len (class_label_colormap ) # nosec
192
-
193
195
classified_image_store_data = dash .no_update
194
196
classifier_store_data = dash .no_update
195
197
alertbox = html .Div ()
@@ -254,7 +256,7 @@ def annotation_react(
254
256
# label_class_value = class_labels[label_class_value]
255
257
fig = make_default_figure (
256
258
images = [image .image_path ],
257
- stroke_color = class_to_color (onto_tree , label_class_value ),
259
+ stroke_color = class_to_color (onto_tree_imgannot , label_class_value ),
258
260
stroke_width = stroke_width ,
259
261
shapes = masks_data ["shapes" ],
260
262
source_img = source ,
@@ -277,7 +279,7 @@ def annotation_react(
277
279
features ,
278
280
feature_opts ,
279
281
class_label_colormap ,
280
- onto_tree ,
282
+ onto_tree_imgannot ,
281
283
)
282
284
if cbcontext == "download-button.n_clicks" :
283
285
classifier_store_data = clf
0 commit comments