Skip to content

Commit bdc93eb

Browse files
Merge pull request #154 from haesleinhuepf/hist2
Bugfix: show correct min/max intensity above histogram
2 parents 6529b3f + fb11883 commit bdc93eb

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="stackview",
8-
version="0.15.0",
8+
version="0.15.1",
99
author="Robert Haase",
1010
author_email="robert.haase@uni-leipzig.de",
1111
description="Interactive image stack viewing in jupyter notebooks",

stackview/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.15.0"
1+
__version__ = "0.15.1"
22

33
from ._static_view import jupyter_displayable_output, insight
44
from ._utilities import merge_rgb

stackview/_histogram.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ def create_histogram_plot(image, x, y, width, height):
8282
#return np.random.normal(50, y, (100, 100))
8383
cropped_image = image[..., y:y+height, x:x+width]
8484

85+
min_val = np.min(cropped_image)
86+
max_val = np.min(cropped_image)
87+
8588
#histogram = np.histogram(cropped_image, bins=256, range=(0, 255))
8689
# plot histogram and store histogram as numpy RGB array
8790
plt.figure(figsize=(1.8, 1.4))
@@ -105,18 +108,18 @@ def create_histogram_plot(image, x, y, width, height):
105108
histogram_image = Image.open(file_obj)
106109

107110
# Convert the PIL image to a numpy array
108-
return np.array(histogram_image)[...,:3]
111+
return np.array(histogram_image)[...,:3], min_val, max_val
109112

110-
histogram_image = create_histogram_plot(image, 0, 0, image.shape[-2], image.shape[-1])
113+
histogram_image, min_val, max_val = create_histogram_plot(image, 0, 0, image.shape[-2], image.shape[-1])
111114
histogram_viewer = _SliceViewer(histogram_image)
112115

113116
width = image.shape[-1]
114117
height = image.shape[-2]
115118
layout = layout=ipywidgets.Layout(display="flex", max_height="25px")
116119
slice_lbl = ipywidgets.Label(f"(..., 0:{height}, 0:{width}", layout=layout)
117120
dtype_lbl = ipywidgets.Label(str(image.dtype), layout=layout)
118-
min_intensity_lbl = ipywidgets.Label("", layout=layout)
119-
max_intensity_lbl = ipywidgets.Label("", layout=layout)
121+
min_intensity_lbl = ipywidgets.Label(str(min_val), layout=layout)
122+
max_intensity_lbl = ipywidgets.Label(str(max_val), layout=layout)
120123

121124
layout = ipywidgets.Layout(display="flex", justify_content="flex-end", min_width="50px", max_height="25px")
122125

@@ -147,11 +150,11 @@ def update_display(event=None):
147150
annotated_image = rgb_image1
148151

149152
if former_drawn_position['state'] == "mouse-up" and bb is not None:
150-
h_image = create_histogram_plot(slice_image1, bb['x'], bb['y'], bb['width'], bb['height'])
153+
h_image, min_val, max_val = create_histogram_plot(slice_image1, bb['x'], bb['y'], bb['width'], bb['height'])
151154
histogram_viewer.view.data = h_image
152155
former_drawn_position['state'] = None
153-
min_intensity_lbl.value = str(np.min(slice_image1))
154-
max_intensity_lbl.value = str(np.max(slice_image1))
156+
min_intensity_lbl.value = str(min_val)
157+
max_intensity_lbl.value = str(max_val)
155158

156159
view.data = annotated_image
157160

0 commit comments

Comments
 (0)