Hyper Spectral Hierarchical Clustering Analysis (HSHCA) provides hierarchical clustering analysis (HCA) specialized for hyperspectral images that can be measured by techniques such as Raman microscopy.
Generally, when applying HCA to hyperspectral images, the numerous spectra composing the image are treated independently as vectors in multidimensional spaces. Therefore, information about spatial coordinates (example of unit: μm) at each measurement point of the spectra is lost.
HSHCA efficiently clusters spectra originating from physically adjacent measurement points by using both the distances between spectra (
To see an overview of HSHCA, please refer to this file.
In HSHCA, the distance between cluster A and cluster B (
Since
where
Install Hyper Spectral HCA with:
$ python -m pip install git+https://github.com/MiLL4U/hshca.git-
download a wheel package (*.whl) from Releases
-
Install Hyper Spectral HCA with pip:
$ python -m pip install hshca-x.y.z-py3-none-any.whl(replace x.y.z with the version of HSHCA which you downloaded)
- Clone this repository
$ git clone https://github.com/MiLL4U/hshca.git- Go into the repository
$ cd hshca- Install Hyper Spectral HCA with setup.py
$ python setup.py installPlease refer to this script for an example of execution (need to install matplotlib).
from hshca import HyperSpectralHCA
from hshca.linkmethod import Ward
from hshca.metric import Euclideanimport numpy as np
image = np.load("./test/test_cell.npy")hshca = HyperSpectralHCA(
data=image, # hyperspectral image to analyze
method=Ward, # linkage method
spectral_metric=Euclidean, # metric
spatial_dist_factor=1e-5, # factor for spatial distance (lambda)
spatial_scale=(1.0, 1.0), # scale for each spatial axis (x, y, ...)
show_progress=True # set True here if you want to see progress bar
)
hshca.compute()cluster_map = hshca.get_cluster_map(5) # number of clusters
average_spectra = hshca.get_average_vectors(5)import matplotlib.pyplot as plt
fig, ax = plt.subplots(1, 2, layout='constrained')
cluster_map = ax[0].imshow(cluster_map, cmap='Paired')
for cluster_idx, spectra in enumerate(average_spectra):
ax[1].plot(spectra, label=f"Cluster {cluster_idx}")
ax[1].legend()
fig.colorbar(cluster_map, ax=ax[0], orientation='horizontal',
label="Cluster index")
plt.show()This script yields:
