research papers\(\def\hfill{\hskip 5em}\def\hfil{\hskip 3em}\def\eqno#1{\hfil {#1}}\)

Journal logoJOURNAL OF
APPLIED
CRYSTALLOGRAPHY
ISSN: 1600-5767

A deep learning approach to gap filling for synchrotron small-angle X-ray scattering and wide-angle X-ray diffraction patterns

crossmark logo

aShanghai Synchrotron Radiation Facility, Shanghai Advanced Research Institute, Chinese Academy of Sciences, Shanghai 201204, People's Republic of China, bThe College of Automation and Electronic Information, Xiangtan University, Xiangtan 411100, People's Republic of China, cShanghai Institute of Applied Physics, Chinese Academy of Sciences, Shanghai 201800, People's Republic of China, and dUniversity of Chinese Academy of Sciences, Beijing 101408, People's Republic of China
*Correspondence e-mail: [email protected], [email protected], [email protected]

Edited by J. Ilavsky, Argonne National Laboratory, USA (Received 9 June 2026; accepted 7 September 2026; online 16 November 2026)

In synchrotron small-angle X-ray scattering (SAXS) and wide-angle X-ray diffraction (WAXD) experiments, detector gaps mean that no scattering signal is collected in gap regions, leading to data loss that breaks the continuity of scattering rings and affects subsequent physical analysis. Unfortunately, the high dynamic range and strong structural correlations inherent in X-ray scattering patterns pose significant challenges for accurate missing-data filling. In this paper, we present a two-stage inpainting network (TSINet) to fill the gaps in SAXS/WAXD patterns through a progressive coarse-to-fine architecture. During the coarse filling phase, a feature correlation refiner extracts physically consistent priors from valid regions to infer missing geometric continuity, thereby establishing a robust structural estimate. In the subsequent refinement stage, a feature pyramid mask-aware fusion module captures both global diffraction geometry and fine-grained local textures. Finally, the entire framework is optimized by structure-guided adaptive loss, promoting stable convergence across broad dynamic intensity ranges. Experimental results on a diverse dataset indicate that TSINet outperforms mainstream models. Ultimately, this method provides a reliable automated solution for high-throughput data preprocessing at synchrotron radiation facilities.

1. Introduction

Synchrotron small-angle X-ray scattering (SAXS) and wide-angle X-ray diffraction (WAXD) serve as essential non-destructive tools for probing multiscale microstructures across materials like alloys, ceramics, polymers, nanomaterials and biological tissues (Wang, Yang et al., 2026View full citation; Lundgren et al., 2026View full citation; Song et al., 2026View full citation). However, due to the physical assembly constraints of silicon sensor modules, multi-panel pixelated X-ray detectors intrinsically contain inactive inter-module regions, commonly known as detector gaps. These gaps result in inherent region data loss in scattering patterns, leading to the loss of critical spatial information. Such incomplete scattering patterns noticeably impede downstream quantitative analysis, including azimuthal integration, particle size distribution modeling and full-pattern structural refinement. Therefore, filling these detector gaps while maintaining physical consistency and structural continuity remains a pivotal task in both the computer vision and synchrotron radiation communities. Recently, deep-learning-based image restoration techniques have progressed rapidly (Ekeberg, 2024View full citation), demonstrating strong generative capabilities for recovering missing semantic regions and realistic textures under severe occlusions (Shi et al., 2026View full citation). In contrast to traditional numerical interpolations, these data-driven approaches can effectively leverage structural priors to reconstruct complex spatial topologies and maintain global structural consistency (Zhang et al., 2026View full citation).

Typically, image inpainting provides a viable approach to restoring these missing pixels in X-ray scattering patterns, evolving from classical numerical techniques to modern generative models. Previous studies have predominantly relied on partial differential equation models (Wang, Gao et al., 2026View full citation) and exemplar-based methods (Criminisi et al., 2004View full citation), which perform effectively on natural images. Traditional interpolation methods, such as biharmonic inpainting, can effectively reconstruct simple textures (Jini & Rajkumar, 2021View full citation). However, these local-patch-based methods largely fail when confronted with the broad dynamic ranges and long-range structural correlations inherent in SAXS/WAXD patterns. Similarly, while Fourier-constraint-based extrapolation attempts to recover global structural continuity, it often struggles to preserve high-frequency diffraction features essential for crystallographic characterization (Ding et al., 2024View full citation). Although these methods achieve reasonable performance on natural imagery, they cannot deal with complex geometric gaps and fail to model the extreme photon intensity distribution characteristic of diffraction intensities.

Recognizing the inadequacies of general numerical methods, researchers turned to domain-specific strategies that incorporate physical priors or employ experimental compensation. For instance, the physics-aware inpainting algorithm reported by Liu et al. (2017View full citation) attempts to reconstruct missing regions by exploiting the intrinsic symmetry and continuity of scattering patterns in reciprocal space, but such methods rely heavily on strong point-symmetry assumptions. In practical experiments, even slight beam-center misalignment or sample orientation variations can distort symmetry axes, rendering rigid mathematical models ineffective. Alternatively, experimental acquisition strategies, such as the dual-acquisition method (Chen et al., 2024View full citation), seek to directly capture missing information by shifting the sample carrier (Mairhöfer et al., 2026View full citation). However, such repeated acquisitions are difficult to apply when the sample state evolves during measurement or cannot be reliably reproduced, as in many time-resolved, in situ and high-throughput experiments (Bellisario et al., 2022View full citation). Under conditions where neither strict symmetry assumptions nor repeated acquisition can provide the missing information, computational gap filling that relies on the available scattering data becomes particularly important.

Concurrently, deep-learning-based methods for natural image inpainting have progressed rapidly. Local methods like partial convolution (Liu et al., 2018View full citation) and contextual attention (Yu et al., 2018View full citation) effectively address irregular missing regions but fail to capture long-range structural consistency. More recently, generative frameworks, including diffusion models (Chen et al., 2026aView full citation) and generative adversarial networks (GANs) (Son et al., 2026View full citation), have demonstrated strong distribution-learning capabilities for synthesizing visually realistic textures. However, specific GAN-based methods often suffer from training instability and may introduce physically inconsistent artefacts. Crucially, while all these models excel at visual restoration, they are primarily optimized for perceptual naturalness, which greatly differs from strong physical constraints like ring continuity and intensity decay laws inherent in diffraction patterns (Zhou et al., 2024View full citation).

Driven by the success of deep learning, specialized architectures have been increasingly utilized to address the restoration of X-ray scattering patterns (Zhou et al., 2023View full citation). Early implementations, such as two-layer convolutional autoencoders, demonstrated the ability to capture overall intensity distributions but remained limited in recovering fine-grained structures and local peaks. Subsequent advancements like the tunable U-Net improved restoration accuracy by optimizing network depth and width (Masto et al., 2024View full citation). However, the performance of such approaches remains heavily dependent on the direct availability of adjacent valid contextual information. To specifically handle irregular gap geometries, the partial convolution U-Net was employed to dynamically mask invalid pixels during convolution, though it remains constrained by the limits of local information propagation. Furthermore, architectures such as the mixed-scale dense network (MSDNet) (Chavez et al., 2022View full citation) were developed to optimize computational efficiency, achieving performance comparable to U-Net with significantly fewer parameters. Despite these architectural evolutions, current methods remain predominantly driven by statistical feature mapping and struggle to robustly fill detector gaps when confronted with completely absent structural guidance and extreme signal variations.

While various strategies have been explored to address this regional data loss, generalizing existing filling approaches to SAXS/WAXD patterns remains a significant challenge due to three intrinsic characteristics:

(1) Blind geometric inference. Unlike standard image corruption, information within detector gaps is completely missing rather than merely corrupted. Consequently, geometric continuity must be inferred solely from non-gap prior information without the aid of local pixel guidance.

(2) Dual dependency on texture and structure. Gap recovery simultaneously depends on fine-grained local textures and global physical structures (e.g. symmetry and ring continuity), requiring a balance between high local fidelity and global coherence.

(3) Broad dynamic range. Scattering intensity typically spans several orders of magnitude, ranging from near saturation to weak signals in high-q regions. This unique distribution imposes noticeable constraints on network stability and the efficacy of feature extraction.

To address these challenges, we propose a two-stage inpainting network (TSINet), a gap-filling framework specifically designed for SAXS/WAXD patterns. Operating as an intelligent gap-filling system, TSINet adopts a hierarchical coarse-to-fine architecture dedicated to preserving physical structural integrity while enhancing fine-grained textures.

TSINet incorporates a feature correlation refiner (FCR) module and a feature pyramid mask-aware fusion (FPMAF) module. These synergistic components explicitly capture structural and contextual prior information to guide the accurate restoration of missing regions. We also introduce structure-guided adaptive loss (SGALoss) to effectively mitigate the gradient instability and optimization bias caused by the broad dynamic range inherent in X-ray scattering data.

The remainder of this paper is organized as follows: Section 2[link] describes the overall framework and core modules of TSINet, Section 3[link] presents the experimental setup and evaluation metrics, Section 4[link] reports the experimental results and analysis, Section 5[link] evaluates generalization performance, and Section 6[link] concludes the paper and outlines future work.

2. Method

2.1. Overview

Drawing inspiration from the success of the U-Net architecture (Ronneberger et al., 2015View full citation) in structured medical imaging, we construct TSINet following that architecture. Moreover, incorporating the strengths of the gated convolutional network (GatedConv) (Yu et al., 2019View full citation), which excels at natural image inpainting, we integrate gated convolutions into TSINet, as illustrated in Fig. 1[link].

[Figure 1]
Figure 1
The overall architecture of the proposed TSINet.

Rather than treating SAXS/WAXD patterns as ordinary RGB images, the proposed TSINet adopts a dual-stage cascaded architecture designed for progressive coarse-to-fine reasoning strategy, inspired by the analytical workflow of a human crystallographer. By explicitly decoupling the restoration process into an initial structural estimation and a subsequent high-frequency texture refinement, this architecture effectively alleviates the optimization burden on the network and prevents the blurring of fine-grained details (Yang et al., 2022View full citation). The first stage, designated as coarse structural restoration, focuses on extracting the global physical constraints and reconstructing primary diffraction features within the missing regions. As a subsequent fine-grained texture refinement phase, the second stage further enhances fine textures and local details, helping to maintain both global coherence and local analytical fidelity in the final output.

Specifically, the first stage employs a symmetrical five-layer encoder–decoder architecture. The encoder extracts deep structural representations through gated convolutions and four successive downsampling operations, while the decoder progressively restores spatial resolution. Within the main backbone, gated convolutions are applied following each downsampling and upsampling operation. Acting as a learnable soft mask, this gating mechanism automatically distinguishes valid structural signals from invalid detector gaps, so that only meaningful physical features are propagated. To incorporate physical priors into the latent space, FCR modules are inserted at all hierarchical levels (except the first layer), enabling the network to infer missing geometric continuity from valid non-gap regions. The output of this stage serves as an initial structurally consistent reconstruction estimate. In the second stage, the input is constructed via a mask-guided strategy. The original image information is preserved in valid regions, while the detector gaps are filled with the coarse predictions from the first stage. This stage adopts a three-layer encoder–decoder structure with two downsampling and upsampling operations, and integrates a FPMAF module at the third layer to capture multi-scale contextual information. Finally, the entire framework is jointly optimized using SGALoss, establishing an end-to-end expert system tailored for high-precision SAXS/WAXD pattern reconstruction (Lv et al., 2026View full citation).

2.2. Feature correlation refiner module

In SAXS/WAXD patterns, detector-gap regions inherently lack the sample's scattering intensity, so the restoration of geometric continuity within these blind spots must rely primarily on structural priors inferred from adjacent valid areas (Yuan et al., 2026View full citation). However, conventional skip connections in standard encoder–decoder frameworks, typically employing linear concatenation or additive fusion, exhibit limited capacity for modeling complex cross-layer feature dependencies. This limitation manifests as insufficient structural constraints, frequently leading to local geometric incoherence. Furthermore, the indiscriminate propagation of features allows both high-frequency noise and valid diffraction structures to be transmitted to the decoder with uniform weights. Related studies indicate that multi-level semantic attention mechanisms can effectively alleviate these issues by enhancing structural inference capabilities (Lu et al., 2023View full citation). Accordingly, we propose the FCR, which is designed to improve the structural restoration quality of deficient regions by constructing a cross-layer feature interaction mechanism constrained by physical priors, as illustrated in Fig. 2[link].

[Figure 2]
Figure 2
Structure of the FCR module.

The FCR module adopts a dual-path feature interaction architecture, whose core consists of an efficient structural attention unit. Given encoder features Mathematical equation and decoder features Mathematical equation, the encoder provides reliable structural priors derived from the uncorrupted regions of the input scattering pattern to guide the inpainting process. The mathematical derivations of the FCR module are provided in Section S1.1 of the supporting information.

2.3. Feature pyramid mask-aware fusion module

In SAXS/WAXD patterns, the accurate recovery of detector-gap regions depends on maintaining both the structural correspondence of local textures and the physical consistency of global scattering geometries (Yuan, Yang et al., 2025View full citation). The spatial coexistence of periodic isotropic rings, anisotropic radial spots and irregular diffuse scattering introduces a noticeable scale disparity between local and global features. In particular, when detector gaps are expansive or critical periodic structures are truncated, this often leads to impaired texture continuity, broken periodic patterns or misaligned global structures.

Here, the FPMAF module is integrated into the proposed TSINet, as illustrated in Fig. 1[link]. As a semantic aggregator, the FPMAF adopts a cascaded architecture composed of two sub-modules: the X-ray-based self-attention module (XBSAM) and the semantic coherence attention module (SCAM). The former enhances the representation of local textures and diffraction features through gradient saliency and physics-informed periodic pattern detection, while the latter establishes cross-region semantic correspondences. Such cross-attention guided feature fusion frameworks play an important role in enhancing local-range feature interaction and multi-scale semantic aggregation (Huang et al., 2026View full citation).

The XBSAM, as illustrated in Fig. 3[link], is designed to explicitly embed crystallographic feature priors into the network's attention mechanisms. It consists of a main feature-extraction path and two auxiliary guidance branches: the gradient detection branch (GDB) and the periodic pattern detection branch (PPDB). The mathematical derivations of the XBSAM are provided in Section S1.2.1.

[Figure 3]
Figure 3
Structure of the XBSAM.

The purpose of SCAM, as illustrated in Fig. 4[link], is to maintain the macroscopic semantic consistency of missing regions from a global perspective. Unlike conventional inpainting methods reliant solely on local context, the SCAM observes the entire feature map from the viewpoint of the detector gap. It performs semantic matching and fusion within a constrained set of similar patches via a mask-aware global search mechanism (Liu et al., 2019View full citation). This design effectively captures long-range structural dependencies across regions, enabling the model to recover more natural and continuous scattering details at the semantic level. The mathematical derivations of the SCAM are provided in Section S1.2.2.

[Figure 4]
Figure 4
Structure of the SCAM.

2.4. Structure-guided adaptive loss

To address the inherent instability and numerical convergence difficulties of gap filling under expansive dynamic intensity ranges, we propose SGALoss, which is integrated into the proposed TSINet as illustrated in Fig. 1[link]. Due to the broad dynamic range and highly non-uniform intensity distribution in SAXS and WAXD patterns, conventional pixel-wise loss functions, such as mean squared error (MSE) and mean absolute error (MAE), suffer from a significant optimization bias toward majority-pixel statistics. Consequently, these standard loss functions fail to simultaneously maintain global structural consistency and local filling accuracy. To address these limitations, SGALoss is designed as a physics-aware objective function. By introducing multi-scale structural weighting and an adaptive optimization strategy, SGALoss effectively balances global morphological reconstruction with fine-grained local gap-filling accuracy. Given the proven robustness of hierarchical constraints against severe image degradation (Wang et al., 2024View full citation), this design ensures stable and high-fidelity reconstruction under complex intensity distributions. The mathematical derivations of SGALoss are provided in Section S1.3.

3. Experiment description

3.1. Dataset

In this study, we employed synchrotron SAXS/WAXD patterns from the Science Data Bank (Yuan, Li et al., 2025View full citation) for model training and evaluation. The data were collected at the BL14B1 and BL16B1 beamlines of the Shanghai Synchrotron Radiation Facility (SSRF) and include both SAXS and WAXD experimental modes.

The dataset is categorized into three subsets: a SAXS subset (1661 images), a WAXD subset (1900 images) and an Mathematical equation subset (896 images). The SAXS and WAXD data were acquired at SSRF BL16B1 using a MarCCD165 detector (2048 × 2048 pixels, 79 µm pixel size), whereas the AgBiO3 data were acquired at BL14B1 using a MarCCD300 detector (4096 × 4096 pixels, 73 µm pixel size). Representative exposure times were 0.2–10, 10–100 and 60 s for the SAXS, WAXD and AgBiO3 data, respectively. To standardize detector resolutions under varying experimental conditions and reduce subsequent computational complexity, all images were uniformly rescaled to a resolution of 512 × 512 pixels using bilinear interpolation. This preprocessing step effectively preserves the spatial continuity of scattering signals while significantly reducing the computational cost. Regular gaps with a width of 10 pixels were introduced into the resized 512 × 512 patterns to simulate inter-module detector gaps. To define the application boundary, images with a detected gap width exceeding 10% of the image dimension or 50 pixels are excluded from model processing and a warning is issued.

Covering a diverse array of material systems and experimental conditions, the dataset exhibits pronounced variations in scattering intensity distributions, radial structural characteristics and local intensity fluctuations, with the AgBiO3 subset containing only partial diffraction rings within the detector field of view. Consequently, it provides a comprehensive representation of the structural diversity in synchrotron SAXS and WAXD patterns, serving as a reliable data foundation for evaluating the generalization capability of the proposed model.

3.2. Pre-processing of SAXS/WAXD patterns

Since SAXS/WAXD patterns typically exhibit a high dynamic range, directly inputting them into the network frequently leads to training instability and convergence difficulties. Here, we designed a multi-stage dynamic range compression strategy. First, a valid-region mask is constructed based on an intensity threshold. Second, sequential linear scaling, logarithmic transformation and value mapping are applied to the intensities of valid pixels, transforming the high-range images into a smoother [0, 1] interval:

Mathematical equation

where Mathematical equation represents the ground truth (GT) data intensity and Mathematical equation is a scaling coefficient used to enhance the intensity of weak scattering signals.

To maintain consistency across the input domain, valid regions within the masked patterns inherit the normalized intensity values of the GT. Meanwhile, the masked regions are uniformly set to zero, establishing a standardized network input format. This processing approach effectively reconciles the high intensity from diffraction spots and beamstop regions with low-intensity background scattering.

The experimental configuration and training details are provided in Section S2.1, while the evaluation metrics are provided in Section S2.2.

4. Results and discussion

In this section, we evaluate the performance of TSINet in reconstructing detector gaps within SAXS and WAXD patterns across diverse materials. A systematic comparative analysis of the reconstruction performance both qualitatively and quantitatively with various gap-filling methods using our experimental data is provided. For a fair comparison, other models were trained with the standard MSE loss, thereby highlighting the contribution of our proposed SGALoss. Furthermore, because the comparative methods were not designed for high-dynamic-range X-ray images, their default preprocessing configurations often perform poorly. Consequently, all evaluated methods were applied to data processed by our proposed preprocessing pipeline (Section 3.2[link]). Additionally, all scattering pattern visualizations and integrations in this study were performed using the Nautilus software, a dedicated X-ray small-angle scattering processing and analysis program (Shanghai Synchrotron Radiation Facility & Xiangtan University, 2024View full citation).

4.1. Qualitative evaluation of visual morphology

Complete visual comparisons are provided in Figs. S1 and S2 of the supporting information, which include both traditional image inpainting methods (Bertalmio et al., 2000View full citation; Keys, 1981View full citation; Mastyło, 2013View full citation; Olivier & Hanqiang, 2012View full citation) and representative deep-learning-based methods (Oktay et al., 2018View full citation; Badrinarayanan et al., 2017View full citation; Zhou et al., 2018View full citation; Ronneberger et al., 2015View full citation; Yu et al., 2019View full citation). The representative SAXS, WAXD and AgBiO3 patterns shown in these comparisons were obtained from a polymer sample, an oxide sample and a battery material, respectively. Given that traditional interpolation methods often induce structural discontinuities, noticeable semantic misalignments and texture blurring when processing detector gaps, they were excluded from the local detail comparison. Instead, the standard U-Net was selected as a representative baseline for encoder–decoder architectures and compared alongside the gated convolution network and our proposed model. As illustrated in Fig. 5[link], in critical information regions, the U-Net introduces noticeable semantic deviations and structural misalignments. Although Gated­Conv successfully fills the majority of the general structural outlines, it is heavily influenced by background features, resulting in texture blurring and unwanted background assimilation (Czyzewski et al., 2021View full citation). In contrast, a comparison between the output generated by our TSINet and the raw detector image (GT) clearly demonstrates that our method accurately fills complex diffraction structures and fine details within the gap regions with high precision.

[Figure 5]
Figure 5
Magnified views of local details corresponding to Figs. S1 and S2 showing the patterns filled by methods with superior visual morphology.

In terms of texture fidelity, TSINet effectively maintains morphological consistency in overlapping ring regions through its contextual attention mechanism. Filling errors are primarily concentrated in high-intensity diffraction regions, while homogeneous background areas are filled with high precision. Specifically, TSINet preserves the topological continuity of inner and outer diffraction rings, significantly mitigating common issues in baseline methods such as ring fragmentation and local diffraction spot loss. In particular, our method demonstrates superior pattern coherence in regions with high ring density. For detector-gap regions adjacent to the beamstop, through the synergistic effect of the gated convolution and structural context refinement modules, TSINet accurately fills the radial texture distribution, avoiding edge distortion and spurious beam-shift artefacts.

4.2. Quantitative evaluation and performance analysis

To evaluate the efficacy of TSINet, we conducted quantitative comparisons using the SAXS, WAXD and Mathematical equation datasets. Representative results are summarized in Tables 1[link], 2[link] and 3[link], respectively, while the complete quantitative comparisons are provided in Tables S1, S2 and S3 of the supporting information. Overall, TSINet consistently outperforms most competing methods across all standard evaluation metrics for every dataset. These results establish the proposed model's superior performance in both numerical reconstruction accuracy and preservation of structural fidelity within diverse X-ray scattering and diffraction patterns.

Table 1
Quantitative comparison of different gap-filling methods on SAXS patterns

Red indicates the best result and blue indicates the second-best result.

No. Methods MSE RMSE MAE GMSD SSIM PSNR (dB)
1 U-Net 3.20 × 10−5 5.40 × 10−3 1.21 × 10−3 7.37 × 10−2 0.98648 46.17
2 GatedConv 1.23 × 10−5 3.44 × 10−3 8.20 × 10−4 9.64 × 10−2 0.99133 49.70
3 TSINet 9.39 × 10−6 2.94 × 10−3 7.01 × 10−4 9.40 × 10−2 0.99193 51.44

Table 2
Quantitative comparison of different gap-filling methods on WAXD patterns

Red indicates the best result and blue indicates the second-best result.

No. Methods MSE RMSE MAE GMSD SSIM PSNR (dB)
1 U-Net 1.63 × 10−5 3.98 × 10−3 4.66 × 10−4 3.94 × 10−2 0.99714 50.19
2 GatedConv 1.50 × 10−5 3.75 × 10−3 3.43 × 10−4 2.76 × 10−2 0.99823 51.75
3 TSINet 1.11 × 10−5 3.17 × 10−3 2.77 × 10−4 2.28 × 10−2 0.99847 54.59

Table 3
Quantitative comparison of different gap-filling methods on WAXD patterns of Mathematical equation crystal

Red indicates the best result and blue indicates the second-best result.

No. Methods MSE RMSE MAE GMSD SSIM PSNR (dB)
1 U-Net 1.89 × 10−6 1.37 × 10−3 2.98 × 10−4 2.32 × 10−2 0.99847 57.29
2 GatedConv 1.46 × 10−6 1.21 × 10−3 2.44 × 10−4 2.28 × 10−2 0.99891 58.43
3 TSINet 6.20 × 10−7 7.84 × 10−4 1.56 × 10−4 1.49 × 10−2 0.99944 62.14

Regarding pixel-wise error metrics [i.e. MSE, root MSE (RMSE) and MAE], TSINet achieves the lowest values across all test scenarios. Taking the Mathematical equation dataset as an example, our method yields an MSE of 6.20 × 10−7, an RMSE of 7.84 × 10−4 and an MAE of 1.56 × 10−4. Compared with the second-best method, GatedConv, TSINet further reduces the MSE by ∼57.5% and the RMSE by 35.2%. Similar substantial reductions in error are also observed in the SAXS and WAXD datasets, indicating significant and stable improvements in both global intensity recovery and local error suppression.

For structural and perceptual metrics, including gradient magnitude similarity deviation (GMSD), structural similarity index measure (SSIM) and peak signal-to-noise ratio (PSNR), TSINet consistently demonstrates state-of-the-art performance. The GMSD metric, which reflects local gradient variations and detail preservation, shows that TSINet obtains competitive values across the board (e.g. 1.49 × 10−2). Furthermore, TSINet achieves the highest PSNR scores of 51.44, 54.59 and 62.14 dB on the SAXS, WAXD and Mathematical equation datasets, respectively. Specifically, on the Mathematical equation data, TSINet exceeds the classical U-Net by 4.85 dB and Gated­Conv by 3.71 dB, further validating its superiority in reconstructing high-dynamic-range scattering patterns.

To further assess the computational characteristics of the proposed method, the model complexity and inference speed were compared under the same input resolution, as summarized in Table 4[link]. TSINet contains 43.450 M parameters and requires 465.095 G FLOPs for a 512 × 512 input. Although its parameter count is higher than those of U-Net and Gated­Conv, its computational complexity is lower than that of U-Net (523.575 G FLOPs) and remains comparable in magnitude to that of GatedConv (367.322 G FLOPs). The inference speed of TSINet is 3.178 FPS (frames per second), in contrast to 11.446 FPS for U-Net and 4.511 FPS for Gated­Conv. These results quantitatively characterize the additional computational cost introduced by the structural correlation and mask-aware feature-fusion mechanisms. Together with the reconstruction results in Tables 1[link], 2[link] and 3[link], this comparison provides a direct assessment of the trade-off between reconstruction performance and computational efficiency.

Table 4
Quantitative comparison of computational complexity, parameter count and inference speed of different gap-filling methods

No. Methods Input size (pixel) FLOPs (G) Parameters (M) FPS
1 U-Net 512 523.575 34.526 11.446
2 GatedConv 512 367.322 15.541 4.511
3 TSINet 512 465.095 43.450 3.178

Overall, the proposed method exhibits comprehensive and stable advantages in error suppression, structural preservation and overall reconstruction quality, confirming its effectiveness and strong potential for SAXS, WAXD and Mathematical equation pattern gap-filling applications.

4.3. Physical methodological accuracy

In X-ray scattering and diffraction analysis, radial integration profiles serve as essential one-dimensional representations that directly encode the critical structural characteristics of the measured materials (Ashiotis et al., 2015View full citation). Therefore, we converted the two-dimensional patterns into one-dimensional integration curves, using these profiles as the primary criterion to determine whether the gap-filling results preserve the underlying physical validity. We conducted a quantitative comparative analysis across the SAXS, WAXD and Mathematical equation datasets. We selected U-Net and GatedConv, both of which demonstrated competitive performance in prior visual and metric assessments, to compare against our proposed TSINet model. This evaluation enables the gap-filled data to remain scientifically actionable for downstream crystallographic analysis.

The selected integration regions are shown in Fig. S3, and the corresponding radial integration results are presented in Fig. 6[link]. The overall diffraction peak profiles indicate that, compared with the GT, the results generated by U-Net still exhibit significant deviations, and GatedConv also shows moderate discrepancies. In contrast, the integration curves produced by TSINet maintain high consistency with the GT. The magnified views of the integration curves further highlight the differences among the three methods at the specific diffraction peaks. Additionally, the difference plots reveal the overall errors of the three methods. While U-Net and Gated­Conv suffer from noticeable fitting deviations in local regions, TSINet accurately fills the diffraction intensity and peak morphology, demonstrating stable and reliable performance. The reconstructed one-dimensional scattering curves are highly consistent with the GT in their overall trends, effectively restoring the intensity distributions and variation patterns of the primary scattering features. In structurally critical regions, the relative deviations between our predictions and the GT remain within a negligible range. This indicates that the proposed method effectively preserves and recovers the structurally and physically meaningful information inherent in the original scattering data.

[Figure 6]
Figure 6
Integration Region shows magnified views of the integration regions corresponding to Fig. S3, also matching the locations of the local details in Fig. 5[link]; Integration Profiles presents the corresponding integration profiles of the GT and selected methods; Enlarged Profiles provides enlarged views of the areas marked by the orange boxes in the Integration Profiles; and Difference Profiles illustrates the differences between the model predictions and the GT.

5. TSINet model generalization

To further validate that TSINet is not limited to scenarios with fixed-gap positions and quantities, we conducted generalization tests under more challenging conditions. Specifically, we constructed three generalization datasets by introducing artificial detector gaps into the pristine SAXS, WAXD and Mathematical equation data. For the SAXS and WAXD datasets, 1–4 gaps with a fixed width of 10 pixels were randomly positioned along both the horizontal and vertical axes. For the Mathematical equation dataset, the number of inserted gaps was increased to between 5 and 10, while maintaining the consistent 10-pixel width. Crucially, for each image in these three datasets, both the positions and the exact number of gaps were randomly generated, making each image's missing pattern independent and unique.

We fed these generalization datasets, which exhibit diversity in gap number, gap position and imaging modality, into TSINet to evaluate its robustness and applicability when confronted with different types of gaps in practical scenarios. This experimental design aims to examine whether TSINet can maintain stable performance under complex gap patterns that are closer to real experimental conditions, rather than relying only on regularized gap structures. The results are given in Table 5[link].

Table 5
The results of each metric on three generalized datasets

No. Datasets MSE RMSE MAE GMSD SSIM PSNR (dB)
1 SAXS 9.89 × 10−6 3.05 × 10−3 5.97 × 10−4 8.91 × 10−2 0.99312 51.41
2 WAXD 4.22 × 10−5 6.46 × 10−3 3.63 × 10−4 2.93 × 10−2 0.99816 45.02
3 Mathematical equation 2.60 × 10−6 1.61 × 10−3 5.23 × 10−4 2.43 × 10−2 0.99806 56.01

Comparing the generalization tests with the fixed-gap baseline highlights the adaptability of TSINet. The model maintains robust gap-filling accuracy when processing unpredictable missing patterns. Quantitative evaluations on the generalization datasets exhibit considerable consistency with the original controlled baselines. Specifically, the PSNR on the generalization SAXS, WAXD and Mathematical equation datasets reaches 51.41, 45.02 and 56.01 dB, respectively, comparable to the original high-performance metrics of 51.44, 54.59 and 62.14 dB. The absolute filling errors remain limited; for example, the MSE for the SAXS patterns shifts negligibly from 9.39 × 10−6 to 9.89 × 10−6. Furthermore, the GMSD remains highly stable, shifting only marginally from 2.28 × 10−2 to 2.93 × 10−2 on the WAXD dataset, which indicates consistent high-frequency detail preservation. Other foundational metrics, including RMSE, MAE and SSIM, demonstrate identical trends of minimal degradation across all unpredictable test scenarios. This near-identical performance proves that the network successfully translates its learned restoration techniques to random gap distributions. Consequently, this model effectively manages the unpredictable data loss frequently encountered in actual X-ray scattering and diffraction experiments.

To visually confirm the structural continuity of the filled areas, these selected integration regions are explicitly marked on the TSINet predictions in Fig. S4. On the basis of these designated regions, as illustrated in Fig. 7[link], detector gaps cause the integration profiles of the raw input images to deviate significantly from the GT. Conversely, the integration curves predicted by TSINet exhibit robust alignment with the GT. The enlarged profiles detail this consistency, demonstrating the model's robust restoration capability across a broad dynamic intensity range. Furthermore, the difference profiles reveal a minimal overall error, with the discrepancy confined to ∼0.5% of the peak intensity.

[Figure 7]
Figure 7
Integration Region shows magnified views of the integration regions corresponding to Fig. S4; Integration Profiles presents the corresponding integration profiles of the GT and TSINet; Enlarged Profiles provides enlarged views of the areas marked by the orange boxes in the Integration Profiles; and Difference Profiles illustrates the differences between the TSINet predictions and the GT.

In contrast to training on a fixed gap layout, using datasets with randomized gap positions reduces the risk that the model overfits to a specific gap location. Since gap locations are randomly generated in each image, the model is compelled to comprehensively learn the structural and intensity distribution patterns of the entire scattering patterns. It cannot rely on memorizing specific positional features, and instead establishes a general mapping from valid contextual information to missing content. This approach enables the model to achieve high inpainting accuracy while learning a more stable and generalizable internal feature representation.

This finding provides an important direction for future research: it points toward the potential development of a self-supervised inpainting model capable of learning physically consistent reconstruction of missing regions directly from gap-containing input data, without relying on a fully supervised GT. Such a method holds significant application promise for practical beamline scenarios, where obtaining complete accurately aligned GT data is often challenging.

6. Conclusions and future work

This study introduces TSINet, a specialized architecture designed to fill the missing data loss caused by detector gaps in SAXS/WAXD measurements. The framework is specifically designed to handle the high-dynamic-range data and complex structural patterns characteristic of X-ray patterns. Through a coarse-to-fine restoration strategy, the network effectively recovers scattering profiles while maintaining the continuity of diffraction rings and their physical intensity distributions. Systematic experimental evaluations demonstrate that TSINet can accomplish high-precision filling of missing regions across both simulated and experimental SAXS/WAXD patterns. It consistently outperforms mainstream existing methods by maintaining superior results in diffraction ring continuity, discrete spot restoration and intensity distribution consistency. Consequently, this framework validates the utility of deep learning for scientific data restoration. It serves as a highly reliable preprocessing pipeline for synchrotron radiation SAXS/WAXD experiments, ultimately minimizing quantitative errors in subsequent structural analyses.

Currently, we are validating self-supervised training strategies on MarCCD165 and MarCCD300 detector datasets to expand the model's generalization across variable experimental conditions. Building upon these ongoing experiments, our immediate next step is to apply TSINet to Pilatus and similar detectors. This upcoming phase will specifically focus on generalizing the model for instruments with real physical gaps. Ultimately, TSINet will be deployed within the automated data-processing pipelines at synchrotron radiation facilities to enable the high-precision filling of various detector gaps, thereby supporting the data integrity required for dynamic in situ investigations.

7. Related literature

The following references are only cited in the supporting information for this article: Chen et al. (2026bView full citation), Kang et al. (2025View full citation), Kingma & Ba (2014View full citation), Xiao et al. (2026View full citation), Yang et al. (2021View full citation).

Supporting information


Conflict of interest

The authors declare that we have no known competing financial interests or personal relationships that could have appeared to influence the work reported in this paper.

Data availability

The dataset used in this study is publicly available on the SciDB platform and can be accessed at https://doi.org/10.57760/sciencedb.34110. The dataset is provided as part of the webpage. If there are any difficulties in accessing or downloading the data, or to obtain updated access information, please contact the author at [email protected] for assistance.

Funding information

This research was funded by the National Key Research and Development Program Young Scientist Project (2023YFA1609900).

References

Return to citationAshiotis, G., Deschildre, A., Nawaz, Z., Wright, J. P., Karkoulis, D., Picca, F. E. & Kieffer, J. (2015). J. Appl. Cryst. 48, 510–519.  Web of Science CrossRef CAS IUCr Journals Google Scholar
Return to citationBadrinarayanan, V., Kendall, A. & Cipolla, R. (2017). IEEE Trans. Pattern Anal. Mach. Intell. 39, 2481–2495.  Web of Science CrossRef PubMed Google Scholar
Return to citationBellisario, A., Maia, F. R. N. C. & Ekeberg, T. (2022). J. Appl. Cryst. 55, 122–132.  Web of Science CrossRef CAS IUCr Journals Google Scholar
Return to citationBertalmio, M., Sapiro, G., Caselles, V. & Ballester, C. (2000). Proceedings of the 27th Annual Conference on Computer Graphics and Interactive Techniques (SIGGRAPH '00), pp. 417–424. ACM Press/Addison–Wesley Publishing Co.  Google Scholar
Return to citationChavez, T., Roberts, E. J., Zwart, P. H. & Hexemer, A. (2022). J. Appl. Cryst. 55, 1277–1288.  Web of Science CrossRef CAS IUCr Journals Google Scholar
Return to citationChen, D., Guo, C., Li, Q., Gu, J., Xie, M. & Zhu, H. (2026a). Neural Netw. 199, 108630.  CrossRef PubMed Google Scholar
Return to citationChen, Z., Xi, X., Han, Y., Tan, S., Li, L., Lu, X. & Yan, B. (2024). Appl. Opt. 63, 2345–2356.  Google Scholar
Return to citationChen, Y., Yin, A., Qiao, Z., Wei, Y. & Chen, C. (2026b). Neurocomputing 670, 132569.   Google Scholar
Return to citationCriminisi, A., Pérez, P. & Toyama, K. (2004). IEEE Trans. Image Process. 13, 1200–1212.  Web of Science CrossRef PubMed Google Scholar
Return to citationCzyzewski, A., Krawiec, F., Brzezinski, D., Porebski, P. J. & Minor, W. (2021). Expert Syst. Appl. 174, 114740.  Web of Science CrossRef PubMed Google Scholar
Return to citationDing, H., Huang, Y., Chen, N., Lu, J. & Li, S. (2024). Appl. Soft Comput. 167, 112410.  CrossRef Google Scholar
Return to citationEkeberg, T. (2024). J. Appl. Cryst. 57, 1–2.  Web of Science CrossRef CAS IUCr Journals Google Scholar
Return to citationHuang, W., Mei, J., Yan, T., Wang, Y. & Chang, X. (2026). Neural Netw. 201, 108936.  CrossRef PubMed Google Scholar
Return to citationJini, P. & Rajkumar, K. K. (2021). Rev. Gestão Inovação Tecnol. 11, 1906–1920.  Google Scholar
Return to citationKang, Q., Liu, F. & Cai, C. (2025). Front. Neurorobot. 19, 1705970.   Google Scholar
Return to citationKeys, R. (1981). IEEE Trans. Acoust. Speech Signal Process. 29, 1153–1160.  CrossRef Google Scholar
Return to citationKingma, D. P. & Ba, J. (2014). arXiv, 1412.6980.  Google Scholar
Return to citationLiu, G., Reda, F. A., Shih, K. J., Wang, T.-C., Tao, A. & Catanzaro, B. (2018). Computer Vision – ECCV 2018, edited by V. Ferrari, M. Hebert, C. Sminchisescu & Y. Weiss, pp. 85–100. Cham: Springer International Publishing.  Google Scholar
Return to citationLiu, H., Jiang, B., Xiao, Y. & Yang, C. (2019). 2019 IEEE/CVF International Conference on Computer Vision (ICCV), 27 October–2 November 2019, Seoul, Republic of Korea, pp. 4169–4178. IEEE.  Google Scholar
Return to citationLiu, J., Lhermitte, J., Tian, Y., Zhang, Z., Yu, D. & Yager, K. G. (2017). IUCrJ 4, 455–465.  CrossRef CAS PubMed IUCr Journals Google Scholar
Return to citationLu, Q., Lin, H., Xing, W., Zhao, L. & Chen, J. (2023). Concurrency Computat. Pract. Exper. 36, e7960.  CrossRef Google Scholar
Return to citationLundgren, K. J. M., Sun, X., Pacoste, L., Kumar, R., Hofer, G., Xu, H., Zou, X., Högbom, M., Oksanen, E. & Ryde, U. (2026). J. Appl. Cryst. 59, 277–290.  CrossRef CAS IUCr Journals Google Scholar
Return to citationLv, Y., Zhang, S., Chen, J., Gao, C. & Lin, Y. (2026). Neural Netw. 201, 108955.  CrossRef PubMed Google Scholar
Return to citationMairhöfer, D., Laufer, M., Berkel, L., Sieren, M., Bischof, A., Barth, E., Barkhausen, J. & Martinetz, T. (2026). Neurocomputing 661, 131881.  Google Scholar
Return to citationMasto, M., Favre-Nicolin, V., Leake, S., Schülli, T., Richard, M.-I. & Bellec, E. (2024). J. Appl. Cryst. 57, 966–974.   CrossRef CAS IUCr Journals Google Scholar
Return to citationMastyło, M. (2013). J. Funct. Anal. 265, 185–207.  Google Scholar
Return to citationOktay, O., Schlemper, J., Folgoc, L., Lee, M., Heinrich, M., Misawa, K., Mori, K., McDonagh, S., Hammerla, N., Kainz, B., Glocker, B. & Rueckert, D. (2018). arXiv, 1804.03999v3 [cs.CV].  Google Scholar
Return to citationOlivier, R. & Hanqiang, C. (2012). Int. J. Adv. Comput. Sci. Appl. 3, 25–30.  Google Scholar
Return to citationRonneberger, O., Fischer, P. & Brox, T. (2015). Medical Image Computing and Computer-Assisted Intervention – MICCAI 2015, 5–9 October 2015, Munich, Germany, pp. 234–241. Springer.  Google Scholar
Return to citationShanghai Synchrotron Radiation Facility & Xiangtan University (2024). Nautilus, https://bdsc.ssrf.ac.cn/zh/ssrf/index.html.  Google Scholar
Return to citationShi, Y., Huang, D., Liu, J., Qu, J. & Tang, W. (2026). Pattern Recognit. 179, 113670.  CrossRef Google Scholar
Return to citationSon, G., Lee, J. R. & Hwang, D. (2026). Neural Netw. 199, 108666.  CrossRef PubMed Google Scholar
Return to citationSong, H., Wei, L., Liu, X., Xu, Y., Liu, H. & Jiang, H. (2026). J. Appl. Cryst. 59, 462–471.  CrossRef CAS IUCr Journals Google Scholar
Return to citationWang, B., Gao, Y. & Guo, S. (2026). Neural Netw. 196, 108387.  CrossRef PubMed Google Scholar
Return to citationWang, T., Tao, G., Lu, W., Zhang, K., Luo, W., Zhang, X. & Lu, T. (2024). Pattern Recognit. 145, 109956.  CrossRef Google Scholar
Return to citationWang, Y.-K., Yang, Y.-M., Li, R.-G., Yu, D.-H., Wang, S.-S., Wang, Z.-J., Liu, P. & Wang, Y.-D. (2026). J. Appl. Cryst. 59, 923–931.  CrossRef CAS IUCr Journals Google Scholar
Return to citationXiao, L., Li, H., Yao, S. & Hou, C. (2026). Pattern Recognit. 179, 113621.   Google Scholar
Return to citationYang, S., Wang, Y., Cai, H. & Chen, X. (2022). Neurocomputing 510, 149–158.  CrossRef Google Scholar
Return to citationYang, L., Zhang, R. Y., Li, L. & Xie, X. (2021). Proceedings of the 38th International Conference on Machine Learning, edited by M. Meila & T. Zhang, pp. 11863–11874. Proceedings of Machine Learning Research.  Google Scholar
Return to citationYu, J., Lin, Z., Yang, J., Shen, X., Lu, X. & Huang, T. S. (2018). 2018 IEEE/CVF Conference on Computer Vision and Pattern Recognition, 18–22 June 2018, Salt Lake City, Utah, USA, pp. 5505–5514. IEEE.  Google Scholar
Return to citationYu, J., Lin, Z., Yang, J., Shen, X., Lu, X. & Huang, T. S. (2019). 2019 IEEE/CVF International Conference on Computer Vision (ICCV), 27 October–2 November 2019, Seoul, Republic of Korea, pp. 4470–4479. IEEE.  Google Scholar
Return to citationYuan, J., Li, X., Cao, H., Jing, Y., Xiaoyun, L., Haojun, C., Wen, W., Chunpeng, W. & Sepe, A. (2025). Synchrotron Small-Angle X-ray Scattering and Wide-Angle X-ray Diffraction Dataset, Vol. V3, Science Data Bank, https://doi.org/10.57760/sciencedb.34110.  Google Scholar
Return to citationYuan, W., Meng, C. & Bai, X. (2026). Neural Netw. 194, 108138.  CrossRef PubMed Google Scholar
Return to citationYuan, X., Yang, C., Chen, Y., Zhang, Y., Zhong, A. & Zheng, Q. (2025). IEEE Trans. Geosci. Remote Sensing 63, 5623615.  Google Scholar
Return to citationZhang, J., Liu, J., Zhang, H., Zhang, J. & Lian, J. (2026). Pattern Recognit. 172, 112432.  CrossRef Google Scholar
Return to citationZhou, Z., Li, C., Bi, X., Zhang, C., Huang, Y., Zhuang, J., Hua, W., Dong, Z., Zhao, L., Zhang, Y. & Dong, Y. (2023). npj Comput. Mater. 9, 58.  Web of Science CrossRef Google Scholar
Return to citationZhou, Z., Li, C., Fan, L., Dong, Z., Wang, W., Liu, C., Zhang, B., Liu, X., Zhang, K., Wang, L., Zhang, Y. & Dong, Y. (2024). J. Appl. Cryst. 57, 741–754.  Web of Science CrossRef CAS IUCr Journals Google Scholar
Return to citationZhou, Z., Rahman Siddiquee, M. M., Tajbakhsh, N. & Liang, J. (2018). Deep Learning in Medical Image Analysis and Multimodal Learning for Clinical Decision Support, edited by D. Stoyanov, Z. Taylor, G. Carneiro, T. Syeda-Mahmood, A. Martel, L. Maier-Hein, J. M. R. S. Tavares, A. Bradley, J. P. Papa, V. Belagiannis, J. C. Nascimento, Z. Lu, S. Conjeti, M. Moradi, H. Greenspan & A. Madabhushi, pp. 3–11. Cham: Springer International Publishing.  Google Scholar

This is an open-access article distributed under the terms of the Creative Commons Attribution (CC-BY) Licence, which permits unrestricted use, distribution, and reproduction in any medium, provided the original authors and source are cited.

Journal logoJOURNAL OF
APPLIED
CRYSTALLOGRAPHY
ISSN: 1600-5767