From ed050bbf72f324d3c80bae5a939dfd9ae69668a1 Mon Sep 17 00:00:00 2001 From: admin <51248046+danton267@users.noreply.github.com> Date: Fri, 20 Oct 2023 04:46:28 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20hardcoded=20overlay=20colourscale?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- callbacks/image_viewer.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/callbacks/image_viewer.py b/callbacks/image_viewer.py index 696f611..7003212 100644 --- a/callbacks/image_viewer.py +++ b/callbacks/image_viewer.py @@ -119,12 +119,30 @@ def render_image( and ctx.triggered_id == "show-result-overlay-toggle" ): raise PreventUpdate + print(seg_result_selection, image_idx) result = get_data_sequence_by_name(seg_result_selection)[image_idx] else: tf = np.zeros((500, 500)) fig = px.imshow(tf, binary_string=True) if toggle_seg_result: - fig.add_trace(go.Heatmap(z=result, showscale=False, colorscale=None)) + unique_segmentation_values = np.unique(result) + normalized_range = np.linspace( + 0, 1, len(unique_segmentation_values) + ) # heatmap requires a normalized range + color_list = ( + px.colors.qualitative.Plotly + ) # TODO placeholder - replace with user defined classess + colorscale = [ + [normalized_range[i], color_list[i % len(color_list)]] + for i in range(len(unique_segmentation_values)) + ] + fig.add_trace( + go.Heatmap( + z=result, + colorscale=colorscale, + showscale=False, + ) + ) fig["data"][1]["opacity"] = opacity / 100 fig.update_layout(