def make_default_figure( images=[DEFAULT_IMAGE_PATH], stroke_color=class_to_color(DEFAULT_LABEL_CLASS), stroke_width=DEFAULT_STROKE_WIDTH, shapes=[], ): fig = plot_common.dummy_fig() plot_common.add_layout_images_to_fig(fig, images) fig.update_layout({ "dragmode": "drawopenpath", "shapes": shapes, "newshape.line.color": stroke_color, "newshape.line.width": stroke_width, "margin": dict(l=0, r=0, b=0, t=0, pad=4), }) return fig
def make_default_figure( images=[], stroke_color=DEFAULT_STROKE_COLOR, stroke_width=DEFAULT_STROKE_WIDTH, shapes=[], img_args=dict(layer="above"), width_scale=1, height_scale=1, ): fig = plot_common.dummy_fig() plot_common.add_layout_images_to_fig( fig, images, img_args=img_args, width_scale=width_scale, height_scale=height_scale, update_figure_dims="height", ) # add an empty image with the same size as the greatest of the already added # images so that we can add computed masks clientside later mwidth, mheight = [ max([im[sz] for im in fig["layout"]["images"]]) for sz in ["sizex", "sizey"] ] fig.add_layout_image( dict( source="", xref="x", yref="y", x=0, y=0, sizex=mwidth, sizey=mheight, sizing="contain", layer="above", ) ) fig.update_layout( { "dragmode": "drawopenpath", "shapes": shapes, "newshape.line.color": stroke_color, "newshape.line.width": stroke_width, "margin": dict(l=0, r=0, b=0, t=0, pad=4), } ) return fig
def test_image_figure(shape=(300, 500), color="#002EA7"): """ Make a figure containing an image that is just a constant color for testing. """ fig = plot_common.dummy_fig() im = np.ones(shape, dtype="uint8") imc = image_utils.label_to_colors(im, ["#000000", color], alpha=255) imcu = plot_common.img_array_to_uri(imc) fig = plot_common.add_layout_images_to_fig(fig, [imcu]) # and we make it so you can draw for fun fig.update_layout({ "dragmode": "drawopenpath", "shapes": [], "newshape.line.color": "purple", "newshape.line.width": 5, "margin": dict(l=0, r=0, b=0, t=0, pad=4), }) return fig
app=dash.Dash(server=server) app.layout=html.Div(children=[ dcc.Store(id='img_array'), dcc.Upload( id='uploader', children=html.Button('Load Image'), multiple=False), html.Button( 'Rotate Clockwise', id='rotate_cw'), html.Button( 'Rotate Counter-clockwise', id='rotate_ccw'), html.Div(id='dummy'), dcc.Graph(id='graph',figure=plot_common.dummy_fig()), html.Div(id='button1_n_clicks_display'), html.A(id='download',children='Download image',href='/0000.png') ]) @app.callback( [dash.dependencies.Output('download','href')], [dash.dependencies.Input('download','n_clicks')]) def update_image_num(download_n_clicks): """ This is used simply to update the href so that browsers don't just use a cached image. """ return ("/%s.png" % (uuid.uuid4().hex,),) img_array = [None]