HyperEvalSR is an open-source project that facilitates the reading of hyperspectral images and the quality assessment of various indices for unmixing, denoising, and super-resolution. Additionally, it provides algorithms related to the fusion of hyperspectral and multispectral images. In the future, it will also offer algorithms for unmixing, material identification, classification, segmentation, denoising, change detection, and target detection in remote sensing (hyperspectral) images.
pip install HyperEvalSR
The data loading module supports direct reading of TIFF and MAT files. Support for other file formats is currently being added gradually.
from HyperEvalSR import data
img = data.load(file_path)
file_path (str): The path to the image file. Support files ending in tiff and mat.
show(HSI, band_set = None, show = True, save = False, path = None)
The sr module supports the fusion of high spatial resolution multispectral images and high spectral resolution hyperspectral images to reconstruct images with both high spatial and spectral resolutions simultaneously. Currently, it supports the CNMF algorithm based on coupled non-negative matrix factorization.HSI (ndarray): Hyperspectral image to display.
band_set (list or None): List of 3 band indices to compose the pseudo-color image. Defaults to None.
show (bool): Whether to display the image immediately. Defaults to True.
save (bool): Whether to save the image. Defaults to False.
path (str): Path to save the image if save is True.
Reference:
[1] N. Yokoya, T. Yairi, and A. Iwasaki, "Coupled nonnegative matrix factorization unmixing for hyperspectral and multispectral data fusion," IEEE Trans. Geosci. Remote Sens., vol. 50, no. 2, pp. 528-537, 2012.
[2] N. Yokoya, N. Mayumi, and A. Iwasaki, "Cross-calibration for data fusion of EO-1/Hyperion and Terra/ASTER," IEEE J. Sel. Topics Appl. Earth Observ.Remote Sens., vol. 6, no. 2, pp. 419-426, 2013.
[3] N. Yokoya, T. Yairi, and A. Iwasaki, "Hyperspectral, multispectral, and panchromatic data fusion based on non-negative matrix factorization," Proc. WHISPERS, Lisbon, Portugal, Jun. 6-9, 2011.
usage:
from HyperEvalSR import algorithms as algo
out = algo.CNMF(MSI, HSI, mask=0, verbose='off',MEMs=0)
MSI (numpy.ndarray): Multispectral (MS) image data, shape (rows1, cols1, bands1).
HSI (numpy.ndarray): Low-spatial-resolution hyperspectral (HS) image data, shape (rows2, cols2, bands2).
mask (int or numpy.ndarray, optional): Binary mask for processing (rows2, cols2) (0: mask, 1: image). Defaults to 0. verbose (str, optional): Verbosity mode ('on' or 'off'). Defaults to 'off'. MEMs (int or numpy.ndarray, optional): Manually defined endmembers (bands2, num. of endmembers). Defaults to 0.
from HyperEvalSR import metrics
-
Peak Signal to Noise Ratio (PSNR): Measures the ratio between the maximum possible power of a signal and the power of corrupting noise.
metrics.PSNR(ref_img, rec_img)
ref_img (numpy.ndarray): The reference image.
rec_img (numpy.ndarray): The reconstructed image.
-
Reconstruction Signal-to-Noise Ratio (RSNR): Evaluates the signal-to-noise ratio of the reconstructed image.
metrics.RSNR(ref_img, rec_img, mask=None)
ref_img (numpy.ndarray): The reference image.
rec_image (numpy.ndarray): The reconstructed image.
mask (numpy.ndarray, optional): A mask to apply to the images. Defaults to None.
-
Degree of Distortion (DD): Represents the level of distortion in the image.
metrics.DD(ref_img, rec_img)
-
Spectral Angle Mapper (SAM): Measures the spectral similarity between two images using the angle between their spectral vectors.
metrics.SAM(ref_img, rec_img)
-
Root Mean Squared Error (RMSE): Computes the square root of the average squared differences between the reference and reconstructed images.
metrics.RMSE(ref_img, rec_img)
-
Erreur Relative Globale Adimensionnelle de Synthèse (ERGAS): Calculates the relative global dimensionless synthesis error.
metrics.ERGAS(ref_img, rec_img, downsampling_scale):
downsampling_scale (int): The downsampling scale factor.
-
Structural Similarity Index (SSIM): Assesses the structural similarity between the reference and reconstructed images.
metrics.SSIM(ref_img, rec_img, k1=0.01, k2=0.03, L=255)
k1 (float, optional): Constant for stability. Defaults to 0.01.
k2 (float, optional): Constant for stability. Defaults to 0.03.
L (int, optional): Dynamic range of the images. Defaults to 255.
-
Cross-Correlation(CC): Measures the similarity between two images using the correlation coefficient between their pixels.
metrics.CC(ref_img, rec_img, mask=None)
mask (numpy.ndarray, optional): A mask to apply to the images. Defaults to None.
-
Universal Image Quality Index (UIQI):Calculate the Universal Image Quality Index (UIQI) between two images.
metrics.UIQI(ref_img, rec_img)
In this context, we assume that the reference image and the reconstructed image obtained from the algorithm are denoted as
In addition, this also includes operations for loading TIFF data and MAT data as ndarrays.
Peak Signal-to-Noise Ratio (PSNR) is commonly used to measure the similarity between a reconstructed image and an original image. It is expressed in decibels (dB), and a higher value indicates a higher similarity between the reconstructed and original images. The calculation formula for PSNR is as follows:
where
In this formula,
The RMSE is a commonly used indicator to describe the degree of difference between the reconstructed image and the reference image. Smaller errors result in smaller RMSE values. When the reconstructed image and the reference image are exactly the same, the RMSE equals 0. The RMSE is defined as:
The definition of
The RSNR is commonly used to measure the spatial quality of the reconstructed image. Higher RSNR values indicate smaller differences between the reconstructed and original images, and thus better image quality. The RSNR is calculated as:
$$ \mathrm{RSNR}=10\log {10}\left( \frac{||\mathbf{X}||{F}^{2}}{||\widehat{\mathbf{X}}-\mathbf{X}||_{F}^{2}} \right)\tag{4} $$
The Degree of Distortion (DD) is an indicator used to describe the degree of signal distortion, typically used to evaluate the distortion during signal transmission or storage. Smaller distortions result in smaller DD values, with the optimal value being 0. The DD is defined as:
In this formula,
The Spectral Angle Mapper (SAM) compares the similarity between the reconstructed and reference images by measuring the spectral angle of each pixel. The higher the similarity, the smaller the SAM value. The SAM is calculated as:
$$ \mathrm{SAM}=\frac{1}{M} \sum_{n=1}^{M} \text{arccos} (\frac{(\widehat{\mathbf{x}}[n])^{\mathrm{T}} \mathbf{x}[n]}{|\widehat{\mathbf{x}}[n]|{2} \cdot | \mathbf{x}[n]|{2}})\tag{6} $$
In this formula,
ERGAS is a relative error indicator that can be used to compare the quality of reconstructed remote sensing images with different resolutions and sizes, as well as to evaluate image quality at different compression ratios. Smaller ERGAS values indicate higher spatial and spectral similarity between the reconstructed and reference images. The ERGAS is calculated as:
In this formula,
The Structural Similarity Index (SSIM) is an indicator used to evaluate the similarity between two images and to quantitatively assess the degree of image distortion. The SSIM value ranges between
In this formula,
In these formulas,