Skip to main content

HV Explorer

Python based helper tool developed by qtec for visualizing and manipulating HSI data cubes.

Features

It supports importing and exporting to/from difference datacube file formats (currently PAM, ENVI and TIFF). The data can then be visualized as individual slices of the cube shown as full images (of a single selectable spectral band) with different color maps or by composing false "RGB" image from selected bands.

Moreover, it can also plot the mean spectra of multiple rectangular regions of the images for comparison. The spectra can then, if desired, be normalized using SNV (Standard Normal Variate) and/or smoothed (using Gaussian or Savitzky Golay smoothing methods). Optionally, the spectral derivatives (1st or 2nd orders) can be plotted. The spectra of the selected regions can be exported in the CSV format.

Multiple images can be opened and compared at once due to HV SDK's efficient data loading which minimizes RAM usage (Buteo data cubes are often 1Gbyte in size which can overload normal programs).

The HV Explorer supports several common HSI image transformations, including reflectance calibration (using white/black references), dimensionality reduction (PCA), clustering, noise reduction, dead pixel removal, band math, etc.

The HV Explorer currently requires the datacubes to be have been captured beforehand through the Buteo Hyperspectral Imaging System interface (or by other means), but support for capturing live data directly from the Hypervision cameras will be added in subsequent releases.

Both Linux and Windows versions are available.

HV Explorer

HV Explorer showing spectral curve of meat and fat regions

Under development

The HV Explorer is still under development.

The alpha version has been released in March 2025 and the next release will include some classification tools. Live data capture support is expected by the end of 2025.

Some features such as dead pixel removal and band math are still not fully implemented and will be added in subsequent releases.

Minimum system requirements

Windows11 or Linux (Python 3.10 or higher required)

Minimum RAM: 8Gb (16Gb recommended)

Installation

Windows

Simply download the latest Qtec-HV-Explorer-Setup.exe and follow the instructions.

Linux

installation script

The installation script automatically performs all the steps described below in the uv section.

You can use curl to download the script and execute it with bash:

curl -LsSf https://gitlab.com/api/v4/projects/67863505/packages/generic/qtec-hv-explorer/0.2.3/install.sh | bash

If your system doesn't have curl, you can use wget:

wget -qO- https://gitlab.com/api/v4/projects/67863505/packages/generic/qtec-hv-explorer/0.2.3/install.sh | bash

uv

uv can install/update the package directly from the repository. You need to have the tool installed, then run:

uv tool install qtec-hv-explorer@0.2.3 --index https://gitlab.com/api/v4/projects/67863505/packages/pypi/simple --index-strategy unsafe-best-match --prerelease=allow

To create an application shortcut, copy HV-Explorer.desktop and hv-explorer.svg to the appropriate locations or use the example commands below:

cp <download_path>/HV-Explorer.desktop ~/.local/share/applications/
sudo cp <download_path>/hv-explorer.svg /usr/share/icons/

Tutorial

info

This tutorial was generated based on the HV Explorer version 0.2.3

Start by opening the HV Explorer, the following interface will be appear:

HV Explorer

HV Explorer interface

NumberNameDescription
1Open fileOpens a file containig a datacube
Supported formats: PAM, ENVI (HDR) and TIFF
2Open folderSets the "root folder" for the "File list (11)"
3ExportExports the resulting datacube (after the selected operations have been applied)
Supported formats:PAM, ENVI (HDR) and TIFF
Supported interleave types: BIL, BIP and BSQ
4Spectra chartShows the plot containing all the selected spectra (average spectrum from each ROI)
5PCARuns a PCA based on the ROIs and shows the plot of the result (can select the compenent for each axis)
6MLShows the interface for training ML models based on the ROIs
7Spectra settingsShows the interface for configuring the "Spectra chart (4)": name the ROIs, hide/show ROIs, select ROI color, create/assign properties to data, apply filters, ...
8OperationsShows the interface for appliying operations to the datacube: calibration, crop, binning, band selection, apply ML models, ...
9File infoShows information about the datacube: Interleave type, shape, data type, wavelengths, ...
10Preview settingsShows the interface for configuring the datacube preview options: false RGB (select bands) or specific band with color map
11File listFile explorer interface
Defaults to home, change with "Open folder (2)"
12File menuOperations related to files: "Open file (1)", "Open folder (2)" and "Export"
13View menuOperations related to visualization: "Spectra chart (4), "PCA (5)" and "ML (6)"
14ML menu
15HelpAbout HV Explorer (version and copyright)
License information

Example data

Qtec provides some example datacubes for testing the HV Explorer.

The datacubes where captured using the Buteo Hyperspectral Imaging System.

Loading datacubes

Click on the File list (11) icon on the left side, and navigate to the folder containing the datacube to be loaded. By default the File list starts in the home directory, but this can be changed using the Open folder (2) dialog.

In this example we have used the mixed nuts example data: mix1_1296x1000x900_imageCube.pam, containing almonds, walnuts and hasselnuts.

Alternatively use the Open (1) button on the tool bar at the top to get a "file dialog".

HV Explorer

HV Explorer: file explorer interface

The datacube will be loaded. By default an image of the "middle" band of the cube will be shown (in this case the cube has 900 bands so band 450 is shown). An inferno color map is used by default (color maps help enhance contrast in order to aid the visualization of grey scale data).

It is possible to move the image around and zoom in/out by using the mouse.

HV Explorer

HV Explorer: image loaded

tip

The File list can be minimized by clicking on the "minimize" button (on the top right corner).

Demo

HV Explorer: loading datacubes

PAM interleave

Note that HV SDK (the HV Explorer backend) supports all three types of interleave for the PAM file format. However, in order to determine the interleave and properly load the files, it expects the interleave type to be specified in the TUPLTYPE part of the header.

File View

HV Explorer

HV Explorer: file view interface

NumberNameDescription
1File nameName of the datacube
2SliceShow a slice of the datacube
The slice position can be selected
3Rectangular ROICreate a rectangular ROI for averaging the spectra
(which will be displayed in the Spectra chart)
Size and position can be adjusted
4Elliptical ROICreate an elliptical ROI for averaging the spectra
(which will be displayed in the Spectra chart)
Size, position and angle can be adjusted
5Polygonal ROICreate a polygon based ROI for averaging the spectra
(which will be displayed in the Spectra chart)
Created by selecting multiple points
6ML model selectionChoose ML model to generate the overlay
7OverlayEnable/disable overlay of result from ML model
8Channel/band selectionSelect which channel/band is being shown
9List all tabs
10Dettach groupMake the current interface "float", so that it can be moved around and attached to a new position
11Pin active tab
12Close groupCloses the image. Note that the ROIs persist and aren't removed
If the file is opened again the original ROIs will be automatically shown

Preview Inspector

Click on the Preview Inspector (10) icon on the right side in order to change the preview settings: select a different color map or change the band/channel shown.

It is also possible to change bewteen visualizing the Gray bands/channels or creating a "false RGB" Color image representation composed of the specified bands/channels.

HV Explorer

HV Explorer: image preview settings

There are also in-build presets which select the appropriate bands/channels in order to generate a proper RGB visualization of the datacube, however this requires setting up information about the wavelengths covered by the datacube (otherwise the preset option is disabled in the interface).

This can be done by opening the Operation Inspector (8) icon on the right side. Then click the "plus" icon in order to add a new operation and choose the WavelengthSpec operation. Now type in the start and end wavelengths for the datacube, in this example the data was captured using a Hypervision 1700 camera with all bands present, so the minimum wavelength is 430nm and the maximum wavelength is 1700nm.

HV Explorer

HV Explorer: wavelength information

This information is now available in the File info / Metadata inspector (9), along with image dimensions (lines, samples and bands), interleave type and data type ((un)signed integer/float with 8, 16, 32 or 64 bits).

The image dimensions are defined as:

  • lines: number of raw images, corresponding to "image height"
  • samples: spatial width
  • bands: number of channels/wavelengths

HV Explorer

HV Explorer: metadata information

Now a False RGB color preset can be choosen in the Preview Inspector (10).

The bands used for the red, green and blue channels can be changed, if desired, in order to generate a different visual representation of the data.

Note that the generated image doesn't seem to be a good representation of the expected color image, it is too redish, this is due to missing "white balancing", which will be performed in the next step by doing "Reflectance calibration".

HV Explorer

HV Explorer: false RGB color image (missing white balancing)

Alternatively, by choosing Normalize the HV explorer will perform a simple "white balance" by normalizing the channels, which might improve the false RGB image without reflectance calibration.

Note however that a lot of noise becomes visible and therefore it is a much better choice (strongly reccomended) to perform the "Reflectance calibration" instead.

HV Explorer

HV Explorer: normalized false RGB color image

Demo

HV Explorer: Preview inspector

Reflectance calibration

As mentioned above, the color balance of the False RGB image is not correct. This can be adjusted by converting the data into a reflectance model using both a white and a black reference image. The white reference image will adjust the color balance between the different wavelengths as well as correct for differences in illumination through the FOV (field of view). The black reference image will adjust the black level. See the Reflectance model section for in-depth information about the process.

The reflectance calibration can be performed by opening the Operation Inspector (8) and adding a Calibration operation. Then selecting the White reference and Dark reference files. For this example we have used:

tip

Note that is it also possible to use a White Reference which is embedded in the original datacube by selecting Inline instead of File and then adjusting the start and end positions of the white target in the image.

The false RGB color image now looks like a more real color representation of the data.

HV Explorer

HV Explorer: reflectance calibration (correct false RGB color)

info

Although it is clearly best to use both a white and a black reference it is possible to apply only one of them to the datacube. Applying the white reference will generally result in a "white balanced" image. While applying the dark reference will help with decreasing noise (specially the vertical lines seen in the Normalized false RGB image).

Scaling

Note that doing a reflectance calibration will transform the data type from the original unsigned 8-bit integer into a 32-bit float (clipped between 0 and 1). This can be verified through the Metadata Inspector.

HV Explorer

HV Explorer: 32-bit float datatype

Therefore if the new datacube (reflectance calibrated) is to be exported into, for example PAM, it has to be first converted back into an unsigned integer type of either 8 or 16-bit (since this is what PAM supports).

This can be done using a Scaling operation. Just selected the desired datatype, in this case 8 or 16-bit unsigned, and then adjust the Scale to an appropriate value (255 for 8-bit and 65535 for 16-bit).

HV Explorer

HV Explorer: reflectance calibration (after scaling)

tip

The individual operations can be enabled/disabled by clicking on the checkbox to their right.

Alternatively, they can also be completely removed by clicking on the Remove operation button (red minus at the top bar).

Demo

HV Explorer: Reflectance calibration

Operation Inspector

HV Explorer img500

HV Explorer: Operation Inspector interface

NumberNameDescription
1Add operationAdd a new operation to the bottom of the list
2Remove operationRemove the selected operation
3Move operation upMove selected operation up (will be applied earlier in the "pipeline")
4Move operation downMove selected operation down (will be applied later in the "pipeline")
5Operation listList of operations with order of execution
6Enable/disable operationEnable/disable specific operation
7Operation optionsOptions related to the specific operation
8Pin panelPin the panel to graphical interface (so that it is not on top of the image but next to it)
9Minimize panelHide the Operation Inspector
tip

The order of the individual operations can be changed by using the up/down arrows in the Operation Inspector. However, the Calibration operation should generally be one of the first ones.

Spectral plot

Now we will move into showning how to plot spectral information.

Choose one of the ROI options from the File View (rectangular, elliptical or polygonal). For example, click on the elliptical spectrum icon on the top of the image. This will add an elliptical selection box to the middle of the image.

Move, resize and angle the ellipse as desired in order to select the region from which spectral data is desired (the data inside the ROI will be averaged). Add as many selection areas as desired.

HV Explorer

HV Explorer: ROI selection placement

Polygonal ROI

When using the polygonal ROI tool, click to create consecutive point segments. Close the selection area (polygon) by either pressing the ENTER key on the keyboard or clicking on the first point of the segment.

Note that points can be later added/removed from the polygon, as well as moved around. To add new points click on a line segment of the polygon. To remove points right click on a point and select remove handle.

HV Explorer img250

Now open the Spectral settings (7) panel on the left. A list of the created selection areas is displayed, each with a color and a name.

HV Explorer

HV Explorer: Spectral analysis panel

Change the names and colors as necessary by double clicking.

HV Explorer

HV Explorer: spectra color picker

Now click on the Spectral chart (4) icon on the tool bar at the top. This will open a plot view for the spectral data contained in the selection areas.

Clicking on the different spectra inside the Spectral analysis panel will "highlight" both the selected spectra in the Spectral chart plot as well as the corresponding selection area in the image.

removing ROIs

It is possible to remove a selection box from the image (and therefore removing the corresponding data from the plot) by selecting it in the Spectral analysis panel and then clicking on the red minus icon.

HV Explorer

HV Explorer: Spectral chart

tip

Plotting the spectra of the point under the mouse cursor can be toggled by clicking on the "red crosshair" symbol.

info

Since we have inputed Wavelength information as an operation the plot displays the wavelengths (in nm) in the Y-axis, otherwise the band/channel number would be displayed.

Demo

HV Explorer: Spectra chart

Spectra settings

The Spectral analysis panel contains several options that can modify the plots.

HV Explorer

HV Explorer: Spectral settings interface

NumberNameDescription
1Add propertyCreate a new property (label or value)
Create classes for ML training, PCA visualiztion, ...
Properties will appear as new columns alongside "Name" and "Color"
2Remove propertyRemove a property
3Remove spectrumRemove selected spectrum/ROI
4Export spectra dataExport spectra data as CSV, XLSX or JSON
5Save annotationsSave ROIs to JSON file
Allows using ROIs in python script with HV SDK
6Load annotationsLoad ROIs from JSON file
7Show/hide spectraToggle the visualization of the selected spectra on the graph
8Spectrum nameName of the spectrum
Double click to edit
9Spectrum colorColor of the spectrum
Double click to change with a color picker
10Filter typeSmooth the spectra
The available filters are Gaussian or Savitzky Golay
11Enable/disable SNVPerform normalization of the spectra to facilitate the comparison of different spectra
12Enable/disable Continuum removalNormalize reflectance spectra in order to compare individual absorption features from a common baseline
13Show/hide Standart DeviationStandart deviation of the spectra inside the ROI
14DerivativeFirst or second order derivatives can be shown instead of the pure spectra
Useful for comparing different spectra

Comparing spectra

Now we add more selection areas in order to try and compare the spectra of the different nuts.

Note that even though SNV is enabled is not very easy to spot the differences between the spectra as their general shape is quite similar. With the buggest differences being in the area around 1150nm and 1400nm.

HV Explorer

HV Explorer: spectra of almonds, walnuts and hasselnuts

plot grid

Right click the plot area and select "Plot options->Grid" to enable/disable the X or Y grids in the plot.

These differences can be visualized easier if we use the 1st derivative. There are big difference around 1150nm, 1200nm and 1350nm.

HV Explorer

HV Explorer: spectra of almonds versus walnuts (1st derivative)

Demo

HV Explorer: Spectra settings

Datacube slice view

It is also possible to show a slice of the datacube so that all the wavelengths/bands/channels of a single image line are shown as a grey scale image. This corresponds to the original image captured by the camera which has been "stacked" in order to generate the datacube from the scanned lines.

This is done by clicking on the slice icon on the top of the image. A line, which can be dragged left/right will be shown, demonstrating where the slice is being made.

HV Explorer

HV Explorer: datacube slice view

Exporting datacubes

Datacubes can be exported by clicking on the Export icon on the top toolbar. This is useful for for example converting between datacube file formats (PAM, TIFF and ENVI currently supported) or changing the interleave type. It can also be used to export a processed datacube (which has, for example, been calibrated for reflectance, cropped or had other operations performed on it).

After clicking on Export, the desired interleave type must be selected (BIL, BSQ or BIP) as well as the file type (PAM, TIFF or HDR (ENVI)). Then a file name must be specified, along with the desired save location.

Note that HV SDK supports all three types of interleave for the three supported file formats, however external applications might expect a specific interleave type depending on the file extension. Therefore, when exporting, it is quite important to choose a proper interleave type for the desired file type: ENVI supports all 3 types of interleave while TIFF is natively BSQ and PAM is natively BIP.

A final consideration before exporting a datacube is the current Data type (which can be inspected using the Metadata Inspector). As described in the Reflectance calibration section the data type of the cube might have been transformed by the Operations applied to it (for example the Reflectance calibration generates 32-bit floating point data in the [0-1] range) and some of the file formats support only specific data types.

PAM, for example, only supports either 8 or 16-bit integer data. The Data type can be modified using a Scaling operation. Just selected the desired datatype, in this case 8 or 16-bit unsigned, and then adjust the Scale to an appropriate value (255 for 8-bit and 65535 for 16-bit).

Besides file format support, changing the Data type is also highly revelant when considering storage efficiency versus loss of detail in the data: a 32-bit float contains pottentially 4x more detailed data but takes 4x the storage space (which might already be quite high for 1Gb datacubes containing 8-bit data).

HV Explorer

HV Explorer: exporting datacubes

ML models

The HV explorer also supports training ML models for classification.

Start by creating ROIs, at least one for each class that should be indentified. If there is more than one ROI per class it is necessary to group the ROIs under a label property (which can be created under Spectra settings). Create names and assign colors for the labels, then assign the labels to the ROIs.

HV Explorer

HV Explorer: Add property

HV Explorer

HV Explorer: ROIs with properties

tip

It is also possible to use ROIs from multiple images.

Now open the ML interface (6) and add a model (by clicking on the green icon on the top).

Select the Target property as the label property created above, or use None if there is only one ROI per class. Adjust sample size and model type as desired, as well as the specific model related parameters. Then click on Train and wait for the progress bar to show 100%.

ML model types

The currently supported ML model types are:

  • Linear SVC
  • SVR
  • Least squares
  • Regularized least squares
  • KMeans
  • PLS-DA

HV Explorer

HV Explorer: ML interface

Now the result of the model can be overlayed on the image. Click on the "purple brain" icon on the top bar of the image and select the newly generated model. The image will turn gray and after a short while the overlay will be displayed on the image (using the same colors as the input classes).

tip

Enable/disable the overlay by clicking on the "eye" icon (on the top bar of the image).

HV Explorer

HV Explorer: ML overlay

It is also possible to apply the ML model as an operation on the datacube. Start by disabling the ML overlay, then add a new operation of the type "ML->Apply ML model" in the Operation Inspector. Choose the newly generated model under the options and click Apply model. An RGB image containing the classification result will be generated.

HV Explorer

HV Explorer: ML overlay

tip

By using the "Apply ML model" it is possible to generate a model from one or more datacubes and then test the result on another datacube.

Demo

HV Explorer: ML models

PCA view

Open the PCA Viewer by clicking on the PCA (5) button on the top bar.

A PCA will be run on the datacube and sample points of the ROIs will be displayed using the ROI colors (from the Spectra settings panel). This tool is useful for evaluating the separation of the data based on the ROI content. The point under the mouse cursor is plottet as a blue cross.

The PCA component for each axis can be chosen by adjusting the selector on the top PCA bar. If data properties (from the Spectra settings panel) have been created it is possible to select them in the drop down menu to the right, so that their colors are used instead of the ROI colors.

HV Explorer

HV Explorer: PCA view

In this example it can be seen that the diffent ROIs don't present enough separation. The background is quite distinct, but the walnuts and hasselnuts are unfortunately quite mixed. And the separation doesn't get much better by changing the PCA components used.

One method that can improve the separation is applying SNV from the Operations (8) panel in order to normalize the data. And indeed we can see below that the separation is improved, specially when inspecting higher PCA components. This indicates that PCA could be a suitable classification method for this data.

HV Explorer

HV Explorer: PCA view with SNV

Demo

HV Explorer: PCA view

PCA operation

For this example we will use the bruised apples example data: cube_reflectance_0_min.pam. For this dataset some apples were dropped and then scanned in order to detect the brown spots hidden under the apple skin. This dataset has already been reflectance calibrated and the spectral channels have been compressed from 900 down to 300 (covering the range from 430 to 1700 nm).

HV Explorer

HV Explorer: Bruised apples with false RGB

Note how the bruised stops are almost invisible to the eye on the false RGB image. But by appliying a PCA operation to the datacube the bruises because easily indentifiable in the PCA component number 5. Other PCA components show for example separtion between the apples and the background, as well as other features (see the PCA chapter under the HSI introduction).

HV Explorer

HV Explorer: Bruised apples with PCA

Demo

HV Explorer: PCA operation

Binning

Binning basically means summing a certain amount of pixels together.

Applying a binning operation can be useful for several reasons. It can, for example, help with reducing noise in situations where the input datacube is too dark (scanning of dark objects, limitations in terms of exposure time because of desired high framerate, etc). Another reason to use binning is to reduce the amount of data in order to speed up the training of ML models. Note that in the case of model training, binning should be applied to both the cube used for training as well as the cube where the model should be applied to.

Binning can be applied to the 3 different cube axis (bands, lines and samples) separately and the amount of pixels to be summed is controlled by the Bin Size parameter. Depending on the situation (which axis require higher or lower resolution) it can be better to apply binning to just some specific cube axis or to all of them.

tip
  • lines: number of raw images, corresponding to "image height"
  • samples: spatial width
  • bands: number of channels/wavelengths

Note that binning in the spacial direction (lines or samples) will alter the aspect ratio of the image.

HV Explorer

HV Explorer: Binning operation

DATA TYPE

Since binning is basically a sum it is necessary to check that the data type of the cube is suitable. For example a 8-bit integer is not recommended since it will have a high risk of saturating and clamping. A 16-bit integer or float type is recommened instead.

The data type can be verified in the File Info (Metadata Inspector). Modify the data type using either a Scaling or DType change operation, depending if scaling is also necessary or just the type change itself.

Band Selection

The general limiting factor for scaning speeds using the Hypersvision cameras is the system framerate (which is directly proportional to the amount of bands selected). For example, the maximum framerate for the Hypervison1700, with all 900 bands, is 153fps. If a higher scanning speed (belt speed) is desired it is necessary to reduce the amount of selected bands.

It is possible to simulate a scan with a reduced amount of bands by using the Band selection operation.

HV Explorer

HV Explorer: Band selection operation

tip

Increasing the camera framerate will reduce the maximum possible exposure time, which can cause the image to become darker if there is not enough light available. In this case the Binning operation can be used in order to reduce noise.

Support

Report bugs by writing an email to: hv-explorer-support