@@ -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