1. Introduction
Hyperspectral imaging systems capture fine spectral responses of materials through optical sensing processes by recording hundreds of contiguous spectral bands for each spatial pixel [
1]. Compared with conventional RGB images, hyperspectral images (HSIs) acquire rich and continuous spectral measurements, providing distinctive advantages for fine-grained material identification and quantitative inversion. As a result, HSIs have been widely applied in a variety of fields, including agricultural production [
2], mineral exploration [
3], land resource investigation [
4], environmental monitoring [
5], ocean analysis [
6], agricultural inspection [
7], and military applications [
8,
9,
10]. However, due to limited spatial resolution and mixed-pixel effects inherent in optical imaging systems, each observed pixel often represents a mixture of multiple material signatures (endmembers). Consequently, hyperspectral unmixing (HU) has become a fundamental task that aims to decompose mixed pixels into constituent endmember spectra and their corresponding abundance fractions. The objective of HU is to quantify sub-pixel material proportions or detect sub-pixel targets [
11], and its accuracy directly affects the performance of subsequent fine-grained classification and target detection tasks, thereby facilitating the advancement of sub-pixel applications. In practice, HU remains challenging due to spectral variability caused by illumination changes, atmospheric effects, intrinsic material variations, and sensor-related degradations, as well as endmember uncertainty in real scenes, nonlinear mixing effects, and strong spatial heterogeneity across regions. Spectral variability, in particular, may lead to amplitude scaling and spectral shape distortions of the same material across different spatial locations, thereby increasing the difficulty of reliable similarity estimation and abundance reconstruction. Therefore, improving the modeling of spatial–spectral relationships under realistic imaging conditions is essential for enhancing the accuracy and stability of spectral reconstruction in computational optical imaging.
In general, hyperspectral unmixing models can be categorized into linear mixing models (LMMs), nonlinear models, and bilinear models [
12]. Among them, the LMM has been the most widely adopted model in hyperspectral unmixing research due to its clear physical interpretability, computational efficiency, and strong adaptability. Classical approaches based on geometry, statistics, and sparse regression, such as Vertex Component Analysis (VCA) [
13], Minimum Volume Constrained Nonnegative Matrix Factorization (MVC-NMF) [
14], Nonnegative Matrix Factorization (NMF) [
15], and Multi-Objective Group Sparse Unmixing (MO-GSU) have achieved favorable performances under specific conditions [
16]. However, these methods exhibit inherent limitations when applied to diverse hyperspectral scenarios. For instance, geometric-based methods perform well on images with low noise levels and abundant pure pixels, but their effectiveness degrades significantly in highly mixed scenes. In contrast, statistical error-based and sparse regression-based methods are more capable of handling complex mixtures, yet they usually suffer from high computational costs and strong sensitivity to parameter selection.
To overcome these limitations, the introduction of deep learning techniques has opened up new directions for hyperspectral unmixing. Among them, autoencoder (AE)-based frameworks have attracted considerable attention due to their end-to-end learning capability and powerful feature representation ability, particularly in unsupervised learning, feature extraction, and dimensionality reduction tasks [
17]. Wu et al. [
18] proposed CHCANet, a cascaded hybrid convolutional autoencoder network for nonlinear unmixing, which exploits convolutional structures to deeply mine spatial–spectral information from hyperspectral data while preserving material details through a self-awareness mechanism. Zhao et al. [
19] introduced AE-RED, a hyperspectral unmixing framework that combines deep autoencoders with denoising regularization, achieving strong robustness and accuracy in noisy and complex unsupervised unmixing scenarios. Cao et al. [
20] proposed BU-Net, a hyperspectral unmixing method based on the generalized bilinear mixing model (GBM), which adopts a dual-stream stacked autoencoder architecture and 3D convolutions to extract multiscale spatial–spectral features, thereby effectively addressing nonlinear light scattering effects. Despite their effectiveness, most AE-based methods primarily focus on spectral feature extraction while overlooking the importance of spatial contextual information. To incorporate spatial contextual information, Chen et al. [
21] proposed a Spatial–Spectral Adaptive Nonlinear Unmixing Network (SSANU-Net), which employs a dual-stream encoder to jointly learn spatial and spectral representations, followed by a dual-stream decoder to model linear and nonlinear photon scattering components. Nevertheless, conventional autoencoder architectures struggle to inherently satisfy the non-negativity and sum-to-one constraints of abundance fractions, and their representational capacity remains limited when dealing with complex nonlinear mixtures, spectral variability, and spatial heterogeneity.
Furthermore, advanced AE variants have been proposed to improve physical interpretability and stability. Gao et al. [
22] proposed a cycle-consistency unmixing network (CyCU-Net) by learning cascaded autoencoders, which utilizes a self-perception loss to preserve high-level semantic information. Tao et al. [
23] designed an abundance-guided attention network (A2SAN) that directly extracts endmembers from the network and uses estimated abundances to guide spatial–spectral attention, thereby skipping the traditional initialization step. Similarly, Tao et al. [
24] introduced a dual-feature fusion network (DFFN) that explicitly computes spectral and spatial similarities to enhance the input HSI, followed by separate modules for abundance and endmember estimation, which reduces the inherent randomness of AE training. More recently, to explicitly tackle the critical challenge of endmember variability, Yang et al. [
25] developed a cascaded dual-constrained transformer autoencoder (CDCTA), which incorporates a minimum distance constraint for geometric information and an abundance-weighted spectral angle constraint to determine spectral variations, effectively integrating physical priors into deep representation learning.
With the introduction of convolutional neural networks (CNNs), CNN-based methods have significantly enhanced the capability of spatial feature extraction in hyperspectral images. Early studies extended 1D spectral CNNs to 2D spatial CNNs [
26], and later to 3D CNNs [
27], enabling joint spatial–spectral learning. Chen et al. [
28] introduced a multi-task 3D-CNN-based autoencoder for adaptive feature learning. Nevertheless, using 2D-CNNs alone makes it difficult to capture inter-band relationships unless a more complex network architecture is employed, whilst relying solely on 3D-CNNs often results in high computational complexity and suboptimal unmixing performance when dealing with similar textures across wide spectral bands. To balance these trade-offs, Tao et al. [
29] combined 2D-CNNs and 3D-CNNs and proposed the Cross-Convolutional Unmixing Network (CrossCUN). Furthermore, Tulczyjew et al. [
30] developed a multi-branch convolutional architecture for hyperspectral unmixing, in which the 1D-CNN and 2D-CNN branches are designed to extract spectral and spatial features, respectively, while the 3D-CNN branch performs early fusion of the features learned from the other two branches.
However, the limited receptive field of CNNs inevitably leads to the loss of abundant contextual information in original hyperspectral images, making it difficult to model long-range dependencies. Transformer architecture, which is capable of capturing global contextual dependencies and recovering missing information, provides a promising solution to this limitation. In recent years, various improvements to Transformer-based architectures have been proposed for hyperspectral image analysis. Ghosh et al. [
31] proposed a novel deep neural network-based unmixing model with transformers (DeepTrans). Yang et al. [
32] proposed a shifted-window U-shaped Transformer network (UST-Net), which enhances hierarchical feature modeling while reducing computational overhead. Duan et al. [
33] introduced a novel dual-aware Transformer named UnDAT, which simultaneously exploits regional homogeneity and spectral correlation in hyperspectral images. Jiang et al. [
34] proposed SSLT-Net, a hybrid network that integrates CNNs with Transformers to jointly learn local and global spatial–spectral features. Fazal Hadi et al. [
35] developed a dual-branch spatial–spectral feature fusion Transformer (DSSFT) to enhance feature representation through complementary branch interactions. While pure Transformer architectures are capable of modeling long-range dependencies, they often suffer from high computational cost and patch-induced discontinuity. To combine global contextual modeling with local structural preservation, hybrid CNN–Transformer frameworks have been proposed. Subsequently, Chen et al. [
36] employed a dual-stream collaborative design to jointly learn spatial–spectral global and local representations. Wang et al. [
37] further introduced multiscale spatial aggregation within a Transformer-enhanced framework to adapt to heterogeneous object sizes. Despite their effectiveness, these hybrid methods generally depend on implicit attention fusion and fixed receptive-field designs, which may limit their capability in explicitly preserving spectral similarity and modeling variability under complex mixing conditions. Nevertheless, conventional Vision Transformer (ViT) methods partition images into non-overlapping fixed-size patches, which disrupt pixel-level spatial continuity and weaken local structural relationships. To address this issue, Sun et al. [
38] proposed a self-supervised relation-aware Vision Transformer (SRViT). Although SRViT effectively enhances local relationship modeling, its high model complexity and substantial computational cost limit its efficiency when processing hyperspectral images. To further improve efficiency and representation capability, Xu et al. [
39] proposed a multi-scale convolutional cross Transformer with convolutional cross-attention (MSCC-ViT). This network extracts multi-scale spatial–spectral features and achieves efficient cross-scale fusion by integrating attention mechanisms with convolutional operations, thereby capturing both local contextual information and non-local dependencies.
Although Transformer-based methods enhance global contextual modeling, several limitations remain in hyperspectral unmixing applications. Fixed non-overlapping patch partitioning weakens pixel-level spatial continuity, which is essential for accurate spatial–spectral representation. In addition, the quadratic computational complexity of global self-attention increases the computational burden when processing large-scale hyperspectral images. Furthermore, the absence of explicit similarity modeling within local neighborhoods limits the effective characterization of spatial–spectral consistency under spectral variability. In particular, most existing Transformer-based unmixing methods rely on implicit attention learning, where spatial–spectral relationships are derived solely from feature similarity in the embedding space without incorporating physically interpretable similarity constraints. As a result, the learned attention weights may not fully reflect intrinsic material consistency, especially under spectral variability and noise interference. Moreover, current approaches rarely introduce explicit spatial–spectral similarity priors to guide hierarchical relationship modeling. Therefore, there remains a need for a physically informed mechanism that can constrain both local and global attention computation while maintaining computational efficiency.
To address these issues, this study proposes a TNT-based unmixing framework guided by spatial–spectral similarity, which integrates similarity priors with TNT [
40] for hyperspectral image unmixing. The main contributions of this work are summarized as follows:
- (1)
An improved TNT network is proposed and implemented: Based on the original TNT architecture, the inner Transformer employs a linear self-attention (LSA) mechanism to efficiently compute local pixel similarities within a sliding window, while the outer Transformer maintains global self-attention to integrate contextual information across different image patches. This local–global collaborative mechanism significantly reduces computational complexity while enhancing the modeling capability for local spectral variations and spatial consistency.
- (2)
A spatial–spectral similarity module is introduced: This module explicitly captures the spectral and spatial similarity within a local neighborhood by computing the cosine similarity and Euclidean distance between each pixel and its four neighboring pixels. By concatenating the resulting similarity tensor with the original spectral information, the input features are further enriched, providing the TNT network with spatial–spectral features that incorporate neighborhood structure. This effectively improves the model’s ability to capture local details and maintain spatial consistency, thereby enhancing the accuracy of endmember extraction and abundance estimation.
- (3)
An end-to-end trainable unmixing framework is constructed: The model decodes endmembers through 1 × 1 convolutions and estimates abundances via channel-wise Softmax. During training, the framework simultaneously optimizes reconstruction accuracy and physical interpretability by minimizing loss functions such as MSE and SAD.
3. Proposed Method
This section provides a detailed description of the proposed hyperspectral unmixing framework, termed SSTNT (Spatial–Spectral Similarity guided Transformer-in-Transformer with Linear Self-Attention). As illustrated in
Figure 1, the overall architecture consists of a SCEB module, a TNT encoder, a linear self-attention mechanism, and decoding and constraint modules.
3.1. SCEB Module
Pixels in hyperspectral images often exhibit strong spatial continuity, and adjacent pixels typically share highly similar spectral characteristics. If neighborhood relationships are neglected, the resulting abundance maps are prone to noise artifacts or spatial discontinuities [
43]. Cosine similarity is effective for material discrimination based on spectral shape; however, when different materials exhibit highly similar spectral shapes, cosine similarity alone may not provide sufficient discriminative power [
44]. In such cases, the Euclidean distance between the input spectrum and the endmember spectrum can effectively reflect amplitude variations induced by intrinsic material properties, facilitating the capture of absolute intensity differences and thereby improving unmixing accuracy [
45]. Traditional methods often rely on a single similarity metric, making it difficult to simultaneously account for both spectral shape and intensity information, which limits their ability to distinguish spectrally similar pixels in complex scenes. Therefore, motivated by the two fundamental characteristics of hyperspectral data, spectral shape similarity and amplitude consistency, a similarity module is introduced at the input stage. This module jointly exploits cosine similarity and Euclidean distance to construct a similarity tensor that comprehensively characterizes the spectral relationships among pixels.
Specifically, for a central
pixel in the input hyperspectral image and its neighboring pixel
, both the cosine similarity and the Euclidean distance are computed simultaneously:
where
denotes the Euclidean norm, and
,
represent the spectral values of pixels
and
at the k-th spectral band, respectively. A cosine similarity value closer to 1 indicates higher spectral shape similarity between two pixels, while a smaller Euclidean distance implies a smaller spectral discrepancy. By combining these two complementary similarity measures, a comprehensive spectral similarity between pixels is obtained.
To this end, a weighted formulation is adopted to generate the similarity tensor
, which represents the similarity between pixels
and
, defined as:
Through this similarity tensor, neighborhood information is constructed for each pixel and introduced as a structural prior, enabling the model to adapt to different regional spectral distributions. In regions with higher similarity, abundance distributions tend to be sparser, whereas in regions with lower similarity, abundance distributions become smoother. This adaptive behavior allows the unmixing process to more accurately capture region-specific characteristics.
The similarity tensor generated by this module is concatenated with the original hyperspectral image along the channel dimension and subsequently fed into the improved Transformer-in-Transformer (TNT) network after dimensionality reduction via a 1 × 1 convolution, followed by batch normalization (BN) and ReLU activation. This design facilitates a deep fusion of spectral and spatial information.
3.2. Linear Self-Attention Mechanism
In the proposed framework, Linear Self-Attention (LSA) serves as the core module of the inner Transformer, aiming to efficiently capture local spatial–spectral dependencies. As illustrated in
Figure 2, the input to the LSA module is the fused feature representation
, which is obtained by concatenating the similarity tensor produced by the similarity module with the original hyperspectral image, followed by dimensionality reduction using a 1 × 1 convolution.
First, three 1 × 1 convolutional layers are employed to generate the query, key, and value matrices Q, K, and V, respectively:
where the convolutional operations perform feature projections along the spectral dimension without altering the spatial resolution.
The core computation of LSA is defined as:
where
denotes the Softmax function and d is the scaling factor corresponding to the feature dimensionality. The key idea of this formulation lies in reordering the computation sequence: instead of explicitly computing the full attention matrix,
is calculated first, followed by multiplication with Q. This reformulation effectively reduces the computational complexity of conventional self-attention from
to
.
As shown in
Table 1, when the window size is small (e.g., 4 × 4), the computational cost of LSA is comparable to that of MHSA. However, as the window size increases, the computational burden of MHSA grows rapidly. When the window size reaches 64 × 64 (4096 tokens), MHSA requires 268.42 MFLOPs and 39.80 ms inference time, while LSA requires 67.90 MFLOPs and 0.94 ms. Meanwhile, GPU memory consumption is reduced from 524.38 MB to 278.38 MB. In the proposed SSTNT framework, the window size is set to 5 × 5, which is consistent with the patch size in the inner Transformer.
Finally, the output of the LSA module is reshaped back to the original spatial dimensions:
Through this linear self-attention mechanism, the model not only efficiently captures local spectral similarity and spatial dependencies, but also preserves fine-grained regional details under a computationally tractable cost.
3.3. Modified Transformer-in-Transformer (TNT) Encoder
Transformers exhibit excellent capability in global modeling; however, when applied to high-resolution hyperspectral images (HSIs), they suffer from two major limitations: insufficient capture of local spatial details and high computational complexity of window-based attention. The Transformer-in-Transformer (TNT) framework addresses these issues by introducing a dual-token mechanism, in which interactions between inner tokens and outer tokens enable effective modeling of both local and global information.
In the TNT framework, the input image is first partitioned into a set of patch tokens, and each patch is further subdivided into smaller sub-patches. The outer Transformer operates at the patch level, focusing on global information modeling by capturing long-range dependencies among different patches and integrating global contextual information to maintain overall image coherence. In contrast, the inner Transformer concentrates on fine-grained pixel-level information within each patch, capturing local spectral characteristics and spatial relationships to preserve detailed local structures. Through the interaction between inner and outer tokens, TNT is able to jointly attend to local details and global semantics, thereby achieving multi-scale feature modeling.
Suppose that the input hyperspectral image is uniformly divided into n patches, denoted as:
where
represents the input feature of the i-th patch, n is the number of patches, p denotes the spatial size of each patch, and C is the number of spectral bands.
Each patch is further subdivided into m sub-patches, denoted as:
where
represents the feature of the j-th sub-patch within the i-th patch, and s denotes the spatial size of each sub-patch.
By vectorization and linear projection, the sub-patch features are transformed into a sequence of token embeddings:
where
denotes the token representation of all sub-patches within the i-th patch,
is the token corresponding to the j-th sub-patch, c is the embedding dimension of the sub-patch tokens, FC is a fully connected layer, and
denotes the vectorization operator that reshapes a spatial feature map into a one-dimensional vector by flattening its spatial dimensions.
For the sub-patch token sequences, an inner Transformer is employed to model fine-grained local relationships within each patch. The computation of the inner Transformer is given by:
where
denotes the index of the Transformer layer, L is the total number of inner Transformer layers,
denotes the linear self-attention mechanism,
is layer normalization, and
represents a feed-forward network. This process aggregates detailed intra-patch information and provides high-quality local semantic representations for subsequent global modeling.
To capture global relationships among patches, the patch-level token sequence is defined as:
where
is a learnable class token, and
denotes the initial token of the i-th patch.
At each layer, the features learned by the inner Transformer from the sub-patches are projected via a linear transformation and added to the corresponding patch-level token representation.
where
. Through this additive operation, the patch representation effectively integrates both the original structural information and the locally enhanced semantic features.
Subsequently, the outer Transformer updates the patch-level token sequence as follows:
It is used to capture the long-range dependencies among different patches and achieve global feature modeling.
In summary, a TNT block jointly updates both sub-patch and patch representations, which can be expressed as:
Compared with the conventional Transformer architecture, the TNT framework exhibits significant advantages. First, by employing nested inner and outer Transformers, it enables hierarchical feature extraction, allowing information learning from local to global scales in a more effective manner. Second, TNT reduces computational complexity: compared with the complexity of standard Transformers, the TNT complexity is reduced to , which significantly alleviates the computational burden when processing high-resolution images.
To preserve spatial information, learnable one-dimensional positional embeddings are added to both patch and sub-patch tokens. The patch-level positional encoding is defined as:
and the sub-patch positional encoding is defined as:
This design preserves global spatial consistency while maintaining local relative positional relationships.
In our implementation, the input hyperspectral image is uniformly partitioned into fixed-size patches of 5 × 5, resulting in 25 sub-patch tokens (pixel-level inner tokens) within each patch. The sub-patch size corresponds to a 1 × 1 pixel, meaning that each pixel inside a patch is treated as an individual inner token for fine-grained local modeling. These structural hyperparameters are kept consistent across all datasets and are not tuned per dataset, ensuring architectural consistency and experimental fairness.
3.4. Decoder
The feature representations output by the TNT module denoted as
are first passed through a 3 × 3 convolutional layer to integrate local contextual information and reconstruct the feature maps:
Subsequently, a 1 × 1 convolutional layer is applied to project the channel dimension to the number of endmembers P, thereby generating the abundance maps
:
To satisfy the physical constraints of hyperspectral unmixing, namely non-negativity and the sum-to-one constraint, a Softmax function is applied along the channel dimension to normalize the abundance distribution of each pixel:
After abundance estimation, the model performs linear spectral reconstruction using a trainable endmember matrix
:
where
denotes the reconstructed hyperspectral image and
represents the estimated endmember spectra learned by the network.
The endmember matrix is learned in an end-to-end manner without requiring a predefined spectral library, which not only preserves the physical interpretability of the unmixing process but also enables adaptive spectral representation learning.
3.5. Loss Function
To improve the accuracy of endmember extraction and abundance estimation, a joint loss function is designed in this work, which is defined as:
where λ is a balancing coefficient that controls the trade-off between spectral amplitude differences and spectral shape discrepancies.
The Mean Squared Error (MSE) loss is employed to minimize the discrepancy between the reconstructed spectra and the ground-truth spectra, and is defined as:
where
denote the ground-truth and reconstructed spectra of the i-th pixel, respectively, and N is the total number of pixels.
The Spectral Angle Distance (SAD) loss emphasizes spectral shape similarity and is introduced to enhance endmember purity. It is formulated as: