Skip to content

Commit

Permalink
Display normalized values in spectrum viewer image view
Browse files Browse the repository at this point in the history
  • Loading branch information
ashmeigh committed Jan 28, 2025
1 parent c3be194 commit 3f2ecf9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
12 changes: 12 additions & 0 deletions mantidimaging/gui/windows/spectrum_viewer/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,18 @@ def set_stack(self, stack: ImageStack | None) -> None:
def set_normalise_stack(self, normalise_stack: ImageStack | None) -> None:
self._normalise_stack = normalise_stack

def get_normalized_averaged_image(self) -> np.ndarray | None:
"""
Get the normalized averaged image if both sample and normalization stacks are available.
"""
if self._stack is None or self._normalise_stack is None:
return None

tof_slice = slice(self.tof_range[0], self.tof_range[1] + 1)
sample_data = self._stack.data[tof_slice].mean(axis=0)
norm_data = self._normalise_stack.data[tof_slice].mean(axis=0)
return np.divide(sample_data, norm_data, out=np.zeros_like(sample_data), where=norm_data != 0)

def get_averaged_image(self) -> np.ndarray | None:
"""
Get the averaged image from the stack in the model returning as a numpy array
Expand Down
7 changes: 5 additions & 2 deletions mantidimaging/gui/windows/spectrum_viewer/presenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,12 @@ def show_new_sample(self) -> None:
Show the new sample in the view and update the spectrum and
image view accordingly. Resets the ROIs.
"""

averaged_image = self.model.get_averaged_image()
if self.view.normalisation_enabled():
averaged_image = self.model.get_normalized_averaged_image()
else:
averaged_image = self.model.get_averaged_image()
assert averaged_image is not None

self.view.set_image(averaged_image)
self.view.spectrum_widget.spectrum_plot_widget.add_range(*self.model.tof_plot_range)
self.view.spectrum_widget.spectrum_plot_widget.set_image_index_range_label(*self.model.tof_range)
Expand Down

0 comments on commit 3f2ecf9

Please sign in to comment.