Skip to content

Commit

Permalink
Autoscale input data with percentiles
Browse files Browse the repository at this point in the history
  • Loading branch information
Wiebke committed Mar 12, 2024
1 parent 3106810 commit 431ddd6
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions callbacks/image_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ def render_image(
if image_idx:
image_idx -= 1 # slider starts at 1, so subtract 1 to get the correct index
tf = tiled_datasets.get_data_sequence_by_name(project_name)[image_idx]
# Auto-scale data
low = np.percentile(tf.ravel(), 1)
high = np.percentile(tf.ravel(), 99)
tf_scaled = np.clip((tf - low) / (high - low), 0, 1)
if toggle_seg_result:
# if toggle is true and overlay exists already (2 images in data) this will
# be handled in hide_show_segmentation_overlay callback
Expand Down Expand Up @@ -142,8 +146,9 @@ def render_image(
else:
result = None
else:
tf = np.zeros((500, 500))
fig = px.imshow(tf, binary_string=True)
tf_scaled = np.zeros((500, 500))

fig = px.imshow(tf_scaled, binary_string=True)
if toggle_seg_result and result is not None:
colorscale, max_class_id = generate_segmentation_colormap(
all_annotation_class_store
Expand Down

0 comments on commit 431ddd6

Please sign in to comment.