Hyperexplorer Module

Hyperspectral Imaging Explorers and GUI Tools

This module provides several interactive classes for exploring hyperspectral or volumetric image data, particularly for chemical imaging datasets. It includes mouse-interactive tools for visualizing spectra, image slices, and intensity profiles. F

Classes:
  • HyperSliceExplorer: Explore hyperspectral imaging data

  • ImageSpectrumGUI: Explore hyperspectral imaging data

  • InteractiveProfileExtraction: Extract 1D intensity profiles along a line in a 2D image

  • InteractiveHyperProfileExtraction: Extract 1D and spectral profiles along a line in a hyperspectral volume

  • ImageSpectrumFitGUI: Compare raw and fitted spectra from voxel data interactively

  • chemimexplorer: A version of ImageSpectrumGUI which is used as embedded in jupyter notebooks

@author: Antony Vamvakeros

class nDTomo.methods.hyperexpl.HyperSliceExplorer(data, xaxis=None, xaxislabel='Channels')[source]

Bases: object

Interactive explorer for hyperspectral or volumetric imaging data.

Allows the user to click and move the mouse over a mean image view to inspect voxel-level spectra and update an associated spectrum plot. Users can visualize individual channel images and view spectral changes dynamically. Particularly useful for visual inspection of 3D chemical imaging datasets.

explore(cmap='jet')[source]

Launch interactive exploration of hyperspectral data.

This method creates two interactive Matplotlib figures: - A mean image view that supports mouse hovering and clicking to inspect voxel-level spectra. - A spectrum plot that updates dynamically based on cursor position over the image or spectrum.

Users can click: - On the image (left-click) to fix and label a specific voxel’s spectrum. - On the spectrum (right-click) to re-enable hover-based channel selection.

Parameters:

cmap (str, optional) – Colormap used for image display. Default is ‘jet’.

Notes

  • A vertical line (vCurve) indicates the current spectral channel under inspection.

  • Uses Matplotlib event callbacks to manage interactive behavior.

  • Updates self.dproi, self.histogramCurve, and self.activeCurve for spectrum display.

onMapClick(event)[source]

Handle mouse click events on the image panel.

Left-click:
  • Captures the coordinates of the clicked voxel (row, col).

  • Extracts and displays the corresponding spectrum in the spectral plot.

  • Updates the label to show voxel location.

Right-click:
  • Hides the fixed spectrum curve.

  • Rescales the y-axis to fit the last selected voxel spectrum.

Parameters:

event (matplotlib.backend_bases.MouseEvent) – The mouse click event containing button info and coordinates.

Notes

  • Left-click outside the axes resets the spectrum plot to the mean spectrum.

  • This function updates self.dproi, self.histogramCurve, and plot limits.

onMapMoveEvent(event)[source]

Handle mouse movement over the image panel.

When the cursor is over the image axes:
  • Displays the spectrum corresponding to the hovered voxel (row, col).

  • Updates the red “activeCurve” line in the spectrum plot.

  • Updates the legend to show voxel coordinates.

  • Dynamically adjusts the y-axis limits based on the hovered spectrum.

When the cursor leaves the image axes:
  • Hides the red “activeCurve”.

  • Resets y-axis to fit the last clicked spectrum (self.dproi).

Parameters:

event (matplotlib.backend_bases.MouseEvent) – The mouse motion event with axis and coordinate info.

Notes

This function provides real-time spectral feedback for hyperspectral data exploration.

onPlotClick(event)[source]

Handle mouse click events on the spectral plot.

Left-click (button 1) disables channel hover updates by disconnecting the motion event that controls image updates.

Right-click (button 3) re-enables channel hover updates by reconnecting the motion event handler to update the image view based on cursor position.

Parameters:

event (matplotlib.backend_bases.MouseEvent) – The mouse click event.

onPlotMoveEvent(event)[source]

Handle mouse movement over the spectral plot panel.

Updates the left-hand image panel in real-time to show the spatial image corresponding to the spectral channel under the cursor.

Actions performed: - Determines the nearest spectral channel (index nx) based on x-coordinate. - Updates the image (imoi) to show the spatial slice at nx. - Updates the title with channel and axis label (e.g., energy, 2θ). - Replaces the colorbar and redraws the figure. - Moves the vertical guide line (vCurve) on the spectrum plot to follow the cursor.

Parameters:

event (matplotlib.backend_bases.MouseEvent) – The mouse motion event with axis and coordinate information.

update()[source]

Refresh the left-hand image display based on the currently selected channels.

If no specific channels are selected, displays the mean image across all channels. If a single channel is selected, displays that channel. If multiple channels are selected, displays the mean across those channels.

Also updates the image title and redraws the figure with the current colormap.

class nDTomo.methods.hyperexpl.ImageSpectrumFitGUI(volume, volfit)[source]

Bases: object

GUI for visual comparison between raw and fitted hyperspectral data.

Displays original and fitted spectra from a 3D volume on a voxel-by-voxel basis. Supports dynamic inspection by mouse interaction. Useful for verifying the quality of spectral fitting or peak decomposition across a sample.

toggle_real_time(event)[source]

Toggle real-time updates for spectrum and image panels on right-click.

Right-clicking over the image panel enables/disables updates triggered by mouse motion over it. Same applies for the spectrum panel.

Parameters:

event (matplotlib.backend_bases.MouseEvent) – The mouse button press event.

update_plots(event)[source]

Update the displayed spectrum and image based on mouse hover.

When the cursor hovers over the image panel, updates the spectrum panel to show the corresponding raw and fitted spectra at that voxel.

When hovering over the spectrum panel, switches the image display to show the spatial distribution at the selected spectral bin.

Parameters:

event (matplotlib.backend_bases.MouseEvent) – The mouse event object containing position and axes info.

class nDTomo.methods.hyperexpl.ImageSpectrumGUI(volume, cmap='jet', mask=None)[source]

Bases: object

Interactive viewer for 2D hyperspectral images (rows x cols x channels).

The left pane shows an image for a chosen spectral band; the right pane shows the spectrum at the current mouse position. Hovering over the image updates the spectrum to the voxel (x, y) under the cursor. Hovering over the spectrum updates the image to the spectral band under the cursor (i.e., quick band scrubbing).

Right-click toggles “live” updates independently for each pane so you can freeze either the image or the spectrum while inspecting the other.

If an optional boolean mask is provided, it is overlaid in color on the image view to help assess segmentation quality (uses a semi-transparent overlay). This is useful for QA of thresholding/segmentation against the raw grayscale signal.

Notes

  • Expected input shape is (rows, cols, channels). Displayed images are normalized for visualization only; underlying data are unchanged.

  • The overlay mask should match volume.shape[:2] or volume.shape (if channel-wise masks); when 3D it uses the slice mask[:, :, band].

  • Designed for quick exploratory analysis without precomputations; large volumes are fine as only the needed slices/vectors are drawn on demand.

toggle_real_time(event)[source]

Toggle real-time interactivity for image or spectrum on right-click.

Disables/enables automatic updates depending on the axis clicked.

Parameters:

event (matplotlib.backend_bases.MouseEvent) – Mouse button press event. Right-click toggles interactivity.

update_plots(event)[source]

Handle mouse movement over the figure to update image or spectrum.

If hovering over the image panel and image updates are enabled, it displays the spectrum of the voxel under the cursor.

If hovering over the spectrum panel and spectrum updates are enabled, it displays the image corresponding to the spectral bin under the cursor.

Parameters:

event (matplotlib.backend_bases.MouseEvent) – Event object containing cursor position and axis context.

class nDTomo.methods.hyperexpl.InteractiveHyperProfileExtraction(vol)[source]

Bases: object

Interactive profile extraction tool for 2D hyperspectral imaging data.

Enables users to draw a line on a 2D projection of the volume and extract both spatial intensity profiles and corresponding spectral information along the line. Useful for linking spatial and spectral variations in hyperspectral datasets.

clear_profile()[source]

Clear the currently drawn line and reset the tool state.

extract_intensity_profile()[source]

Extract the spatial intensity profile from the 2D mean image along the selected line using the Bresenham algorithm.

get_line_coordinates(y1, x1, y2, x2)[source]

Generate pixel coordinates along a line between two points using linear interpolation.

Parameters:
  • y1 (float) – Start point of the line.

  • x1 (float) – Start point of the line.

  • y2 (float) – End point of the line.

  • x2 (float) – End point of the line.

Returns:

  • y (ndarray) – Array of row indices.

  • x (ndarray) – Array of column indices.

on_motion(event)[source]

Update the end point of the line dynamically during mouse movement.

Parameters:

event (matplotlib.backend_bases.MouseEvent) – Mouse event captured during movement across the figure.

on_press(event)[source]

Handle mouse click to initiate or complete a line selection.

Left click defines the start and end points of the line. Once the line is completed, intensity and spectral profiles are computed.

Parameters:

event (matplotlib.backend_bases.MouseEvent) – Mouse event captured from the figure canvas.

plot_intensity_profile(xx, yy, intensity_profile)[source]

Overlay the extracted profile line on the image and replot it.

Parameters:
  • xx (ndarray) – Arrays of x and y pixel coordinates along the profile.

  • yy (ndarray) – Arrays of x and y pixel coordinates along the profile.

  • intensity_profile (ndarray) – Intensity values along the drawn line.

show_intensity_profile()[source]

Plot the interpolated 1D intensity profile along the drawn line.

Uses linear interpolation via scipy.ndimage.map_coordinates to extract smooth values along subpixel positions.

show_spectral_profile()[source]

Extract and plot spectra from each pixel along the drawn line.

Displays stacked spectra with slight vertical offsets to highlight spectral variation along the spatial profile.

class nDTomo.methods.hyperexpl.InteractiveProfileExtraction(image)[source]

Bases: object

Interactive tool for extracting 1D intensity profiles from 2D grayscale images.

Enables users to draw a line on an image, then extracts and visualizes the intensity values along that path. Useful for analyzing gradients, edges, and intensity distributions across features in microscopy or tomography images.

Features

  • Interactive line drawing on the image canvas.

  • Real-time line preview during mouse motion.

  • Profile extracted using Bresenham’s algorithm and interpolated coordinates.

  • Three-panel display: image, path overlay, and profile plot.

clear_profile()[source]

Clear the currently drawn line and reset the profile extraction state.

Removes the line overlay from the image, resets internal flags, and clears stored profile information.

extract_intensity_profile()[source]

Extract intensity values from the image along the defined line.

Uses Bresenham’s algorithm to identify discrete pixel coordinates along the user-drawn line. Passes results to the plotting routine.

get_line_coordinates(y1, x1, y2, x2)[source]

Generate integer coordinates along a straight line between two points using linear interpolation.

Parameters:
  • y1 (float) – Row and column of the starting point.

  • x1 (float) – Row and column of the starting point.

  • y2 (float) – Row and column of the ending point.

  • x2 (float) – Row and column of the ending point.

Returns:

  • y (ndarray) – Row indices along the line.

  • x (ndarray) – Column indices along the line.

on_motion(event)[source]

Update the profile line dynamically during mouse movement.

Parameters:

event (matplotlib.backend_bases.MouseEvent) – Mouse movement event over the image axis.

on_press(event)[source]

Handle mouse click events for defining the profile line.

Parameters:

event (matplotlib.backend_bases.MouseEvent) – Mouse event used to place or complete the line.

plot_intensity_profile(xx, yy, intensity_profile)[source]

Display the image with the intensity profile line overlayed.

Parameters:
  • xx (array-like) – X (column) coordinates of the profile path.

  • yy (array-like) – Y (row) coordinates of the profile path.

  • intensity_profile (array-like) – Intensity values along the drawn line.

show_intensity_profile()[source]

Interpolate and plot the 1D intensity profile along the drawn line.

Uses scipy.ndimage.map_coordinates for subpixel interpolation.

nDTomo.methods.hyperexpl.bresenham(y0, x0, y1, x1)[source]

Generate pixel coordinates of a line between two points using Bresenham’s algorithm.

This discrete algorithm is efficient for rasterizing lines in 2D arrays. It ensures that only valid integer pixel coordinates are returned, which is useful for fast profile extraction from images.

Parameters:
  • y0 (int) – Row and column of the starting point.

  • x0 (int) – Row and column of the starting point.

  • y1 (int) – Row and column of the ending point.

  • x1 (int) – Row and column of the ending point.

Returns:

coords – Array of (x, y) coordinates along the line as two 1D arrays stacked vertically. These can be used directly to index into 2D arrays: e.g., image[coords[1], coords[0]]

Return type:

ndarray, shape (2, N)

class nDTomo.methods.hyperexpl.chemimexplorer(volume, fitted=None)[source]

Bases: object

Lightweight GUI for Jupyter-based exploration of chemical imaging volumes.

Provides linked spatial and spectral views for both raw and optionally fitted datasets. Supports mouse-based interaction to inspect individual spectra. Optimized for use within notebook environments.

toggle_real_time(event)[source]

Toggle real-time updates for image and spectrum panels on right-click.

Right-click over the image disables/enables updates from hovering on it. Same applies for the spectrum panel.

Parameters:

event (matplotlib.backend_bases.MouseEvent) – Mouse click event used to toggle interactivity.

update_plots(event)[source]

Update the displayed spectrum and image based on mouse hover.

  • Hovering over the image updates the spectrum view for the selected voxel.

  • Hovering over the spectrum panel updates the image view for the selected channel.

Parameters:

event (matplotlib.backend_bases.MouseEvent) – The mouse event object containing position and axes info.