15
15
from dash_canvas .utils .io_utils import image_string_to_PILImage , array_to_data_url
16
16
from dash_canvas .utils .image_processing_utils import modify_segmentation
17
17
18
+ from app import app
19
+
18
20
# Image to segment and shape parameters
19
21
filename = 'https://upload.wikimedia.org/wikipedia/commons/1/1b/HumanChromosomesChromomycinA3.jpg'
20
22
img = io .imread (filename , as_gray = True )
29
31
canvas_width = 500
30
32
canvas_height = round (height * canvas_width / width )
31
33
scale = canvas_width / width
32
- print (scale , canvas_height )
33
34
34
35
# ------------------ App definition ---------------------
35
36
36
- app = dash .Dash (__name__ )
37
-
38
- server = app .server
39
-
40
- app .css .append_css ({
41
- 'external_url' : 'https://codepen.io/chriddyp/pen/bWLwgP.css'
42
- })
43
-
44
37
45
38
46
- app . layout = html .Div ([
39
+ layout = html .Div ([
47
40
html .Div ([
48
41
html .H3 (children = 'Manual correction of automatic segmentation' ),
49
42
dcc .Markdown ('''
92
85
], className = "four columns" ),
93
86
html .Div ([
94
87
dash_canvas .DashCanvas (
95
- id = 'canvas ' ,
88
+ id = 'canvas_ ' ,
96
89
label = 'my-label' ,
97
90
width = canvas_width ,
98
91
height = canvas_height ,
106
99
107
100
# ----------------------- Callbacks -----------------------------
108
101
@app .callback (Output ('cache' , 'data' ),
109
- [Input ('canvas ' , 'trigger' ),],
110
- [State ('canvas ' , 'json_data' ),
111
- State ('canvas ' , 'scale' ),
112
- State ('canvas ' , 'height' ),
113
- State ('canvas ' , 'width' ),
102
+ [Input ('canvas_ ' , 'trigger' ),],
103
+ [State ('canvas_ ' , 'json_data' ),
104
+ State ('canvas_ ' , 'scale' ),
105
+ State ('canvas_ ' , 'height' ),
106
+ State ('canvas_ ' , 'width' ),
114
107
State ('cache' , 'data' ),
115
108
State ('mode' , 'value' )])
116
109
def update_segmentation (toggle , string , s , h , w , children , mode ):
@@ -125,7 +118,7 @@ def update_segmentation(toggle, string, s, h, w, children, mode):
125
118
return new_labels
126
119
127
120
128
- @app .callback (Output ('canvas ' , 'image_content' ),
121
+ @app .callback (Output ('canvas_ ' , 'image_content' ),
129
122
[Input ('cache' , 'data' )])
130
123
def update_figure (labs ):
131
124
new_labels = np .array (labs )
@@ -154,7 +147,7 @@ def save_segmentation(labs, save_mode):
154
147
uri = array_to_data_url (new_labels , dtype = np .uint8 )
155
148
return uri
156
149
157
- @app .callback (Output ('canvas ' , 'tool' ),
150
+ @app .callback (Output ('canvas_ ' , 'tool' ),
158
151
[Input ('tool' , 'value' )])
159
152
def change_tool (tool_value ):
160
153
return tool_value
0 commit comments