Skip to content

Commit

Permalink
Merge pull request #1149 from psavery/brightness-contrast-editor-impr…
Browse files Browse the repository at this point in the history
…ovements

Use current view data for B&C editor histogram and auto button
  • Loading branch information
joelvbernier authored Feb 1, 2022
2 parents 3034c8f + 5ad9882 commit ace5114
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 15 deletions.
4 changes: 2 additions & 2 deletions hexrd/ui/brightness_contrast_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ def data_bounds(self):
return (0, 1)

data = self.data_list
mins = [x.min() for x in data]
maxes = [x.max() for x in data]
mins = [np.nanmin(x) for x in data]
maxes = [np.nanmax(x) for x in data]
return (min(mins), max(maxes))

def reset_data_range(self):
Expand Down
7 changes: 7 additions & 0 deletions hexrd/ui/hexrd_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ class HexrdConfig(QObject, metaclass=QSingleton):
"""Emitted when new plane data is generated for the active material"""
new_plane_data = Signal()

"""Emitted when an image view has finished loading
The dict contains the images. This is used, for instance, to update
the brightness and contrast histogram with the new image data.
"""
image_view_loaded = Signal(dict)

"""Emitted when overlay configuration has changed"""
overlay_config_changed = Signal()

Expand Down
25 changes: 15 additions & 10 deletions hexrd/ui/image_canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ def load_images(self, image_names):

images_dict = HexrdConfig().images_dict

def apply_masks(img, name):
visible_masks = HexrdConfig().visible_masks
for mask_name, data in HexrdConfig().masks.items():
for det, mask in data:
if mask_name in visible_masks and det == name:
img[~mask] = 0

if (self.mode != ViewType.raw or
len(image_names) != len(self.axes_images)):
# Either we weren't in image mode before, we have a different
Expand All @@ -134,11 +141,7 @@ def load_images(self, image_names):
img = images_dict[name]

# Apply any masks
for mask_name, data in HexrdConfig().masks.items():
for det, mask in data:
if (mask_name in HexrdConfig().visible_masks and
det == name):
img[~mask] = 0
apply_masks(img, name)

axis = self.figure.add_subplot(rows, cols, i + 1)
axis.set_title(name)
Expand All @@ -158,11 +161,7 @@ def load_images(self, image_names):
img = images_dict[name]

# Apply any masks
for mask_name, data in HexrdConfig().masks.items():
for det, mask in data:
if (mask_name in HexrdConfig().visible_masks and
det == name):
img[~mask] = 0
apply_masks(img, name)
self.axes_images[i].set_data(img)

# This will call self.draw_idle()
Expand All @@ -173,6 +172,8 @@ def load_images(self, image_names):
self.update_auto_picked_data()
self.update_overlays()

HexrdConfig().image_view_loaded.emit(images_dict)

msg = 'Image view loaded!'
HexrdConfig().emit_update_status_bar(msg)

Expand Down Expand Up @@ -605,6 +606,8 @@ def finish_show_cartesian(self, iviewer):
self.update_overlays()
self.draw_detector_borders()

HexrdConfig().image_view_loaded.emit({'img': img})

msg = 'Cartesian view loaded!'
HexrdConfig().emit_update_status_bar(msg)

Expand Down Expand Up @@ -711,6 +714,8 @@ def finish_show_polar(self, iviewer):
self.update_overlays()
self.draw_detector_borders()

HexrdConfig().image_view_loaded.emit({'img': img})

msg = 'Polar view loaded!'
HexrdConfig().emit_update_status_bar(msg)

Expand Down
6 changes: 6 additions & 0 deletions hexrd/ui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ def setup_connections(self):
self.enforce_view_mode)

HexrdConfig().instrument_config_loaded.connect(self.update_config_gui)
HexrdConfig().image_view_loaded.connect(self.on_image_view_loaded)

def set_icon(self, icon):
self.ui.setWindowIcon(icon)
Expand Down Expand Up @@ -988,3 +989,8 @@ def on_action_llnl_import_tool_triggered(self):

def on_action_image_stack_triggered(self):
self.image_stack_dialog.show()

def on_image_view_loaded(self, images):
# Update the data, but don't reset the bounds
# This will update the histogram in the B&C editor
self.color_map_editor.data = images
4 changes: 1 addition & 3 deletions hexrd/ui/snip_viewer_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ def setup_connections(self):
def setup_color_map(self):
self.color_map_editor = ColorMapEditor(self, self.ui)
self.ui.color_map_editor_layout.addWidget(self.color_map_editor.ui)

no_nans_data = np.nan_to_num(self.data)
self.color_map_editor.update_bounds(no_nans_data)
self.color_map_editor.update_bounds(self.data)

def setup_canvas(self):
canvas = FigureCanvas(Figure(tight_layout=True))
Expand Down

0 comments on commit ace5114

Please sign in to comment.