Journal of Fuzzy Systems and Control, Vol. 4, No 3, 2026 |
A Hybrid Approach Using MAE‑ViT Enhancement and Inpainting for the Detection and Reconstruction of Damaged QR Codes
Ari Setiawan 1 , Hadi Santoso 2 , Bambang Jokonowo 3
1, 2, 3 Faculty of Computer Science, Universitas Mercu Buana, Jakarta, Indonesia
Email: 1 56225110001@student.mercubuana.ac.id, 2 hadi.santoso@mercubuana.ac.id,
3 bambang.jokonowo@mercubuana.ac.id
*Corresponding Author
Abstract—The use of Quick Response codes has become a standard in various digital applications, yet they remain highly susceptible to physical degradation. Standard decoding libraries generally perform well under ideal conditions but experience reduced accuracy when processing damaged codes. This study proposes a hybrid preprocessing approach that combines Masked Autoencoder–Vision Transformer (MAE–ViT) enhancement and mask-guided inpainting to improve the detection and reconstruction of damaged QR codes. Although light, medium, and heavy degradations are examined, the primary target regime is moderate damage near the decoder failure boundary. The enhancement stage refines global and local visual structure to improve contrast, edge sharpness, and module visibility, while the inpainting stage reconstructs missing or corrupted regions that still disrupt scanability. By applying this hybrid pipeline before standard decoding with ZXing, ZBar, and OpenCV, the method functions as a decoder-assistance module rather than replacing conventional decoders. Experimental results show that the proposed approach improves decoding success on damaged QR codes relative to direct baseline decoding, with the strongest gains under moderate degradation, while restoration quality and processing time are reported as supporting metrics. A supplementary real-world hold-out evaluation is also discussed to clarify generalization limits. The hybrid MAE–ViT framework therefore provides a practical solution for enhancing QR scanability under recoverable damage conditions.
Keywords—Decoder Assistance; Image Enhancement; Image Inpainting; Masked Autoencoder; Quick Response Code; Vision Transformer
QR codes have become a widely adopted two-dimensional encoding technology in payment systems, product traceability, authentication, logistics, and public information access because they provide fast machine-readable access to digital information through compact visual patterns [1]-[3]. Despite their robustness through built-in error correction, QR codes in practical environments frequently suffer from degradation caused by scratches, stains, fading, blur, low contrast, geometric distortion, and partial occlusion, which can reduce scan reliability and eventually prevent successful decoding when the damage exceeds the tolerance of standard readers [2], [4], [5].
Recent studies have shown that deep learning can improve QR code readability by enhancing degraded visual structure before decoding [4], [6]. Super-resolution approaches such as EDSR, VDSR, ESPCN, and SRCNN have been reported to recover unreadable low-resolution QR codes effectively, with EDSR and VDSR generally achieving higher restoration quality while lighter models such as ESPCN offer faster inference suitable for real-time settings [6], [11]-[13]. In parallel, restoration methods based on generative adversarial networks (GANs) have demonstrated strong ability to reconstruct damaged code regions and preserve structural similarity, including edge-enhanced GAN architectures and GAN models with spectral normalization specifically designed for damaged QR code reconstruction [5], [7], [8]. More broadly, image inpainting literature also indicates that reconstruction is especially beneficial when missing regions are relatively large, because it can restore semantically and structurally plausible content beyond simple pixel interpolation [14]-[16].
In recent years, Vision Transformers (ViT) and Masked Autoencoders (MAE) have emerged as strong alternatives for learning visual structure from incomplete inputs by reconstructing masked image patches and capturing long-range context. This property is attractive for QR restoration, because scanability depends on the global arrangement of finder patterns, timing patterns, and data modules. A detailed discussion of MAE–ViT foundations and related restoration/inpainting models is provided in Section II.
Prior work tends to emphasize either visual enhancement, restoration of severely damaged codes, or lightweight deployment, while fewer studies focus specifically on moderately damaged QR codes, where important structural patterns are still partially present and can benefit from targeted enhancement before reconstruction [5]-[7]. This damage regime is practically important because moderate degradation is common in everyday use and often lies near the boundary where conventional decoders begin to fail, yet full reconstruction may still be achievable with lower computational cost than methods designed for extreme damage.
Based on this gap, this study proposes a hybrid approach that combines MAE–ViT–based enhancement and image inpainting for the detection and reconstruction of damaged QR codes, with particular emphasis on the moderate-damage regime. In the proposed framework, the MAE–ViT enhancement stage is employed to refine global and local visual representations, improving contrast, edge sharpness, and module visibility so that the QR structure becomes easier to localize and interpret, while the inpainting stage reconstructs damaged regions that still disrupt decoding [6], [14]. This combination is motivated by the complementary strengths of transformer-based MAE–ViT enhancement for learning context-aware representations of degraded inputs and inpainting-based restoration for recovering missing or corrupted structural elements [5], [7], [15].
The proposed approach is expected to provide a practical balance between restoration quality, scanability, and computational efficiency, particularly for deployment in resource-constrained environments such as mobile devices or embedded scanners [5], [6], [8]. In contrast to methods aimed mainly at severe destruction or highly specialized restoration settings, the focus on moderate damage supports a more application-oriented solution for real-world QR code usage, where readable structure often remains but requires enhancement and selective reconstruction to restore successful decoding [5], [7], [8].
The main contributions of this study are fourfold. First, we formulate QR restoration as a decoder-assistance problem for moderately damaged codes, where success is measured by decode rate rather than visual similarity alone. Second, we propose a task-specific two-stage pipeline in which MAE–ViT enhancement is followed by mask-guided inpainting using a four-channel input (enhanced RGB plus binary damage mask), rather than a generic single-stage restoration model. Third, we evaluate the proposed pipeline under a standardized multi-decoder protocol (ZXing, ZBar, and OpenCV) with ablation analysis and comparison against a CNN–U-Net backend on a held-out test set. Fourth, we provide a lightweight MAE–ViT configuration tailored to structured QR imagery, together with MAE-style warm-start on clean QR samples prior to supervised training on damaged pairs.
QR Code (Quick Response Code) is a two-dimensional barcode developed by Denso Wave in 1994 to enable fast machine-readable data storage. Information is encoded as black and white modules in a square grid, which allows higher capacity and more flexible applications than one-dimensional barcodes, including payments, logistics, and authentication. The basic structure of a QR code consists of finder patterns, alignment patterns, timing patterns, data modules, and error correction codewords. Finder and alignment patterns support detection and geometric correction, timing patterns define module spacing, while data and error correction regions store the encoded information and provide redundancy against partial damage. In restoration tasks, these structural regions are critical targets because scan ability depends not only on global image quality but on whether these components remain recognizable or can be reconstructed in moderately damaged QR codes.
In practical applications, QR code images are subject to various degradation factors that reduce scan ability even when the symbol remains partially intact. These factors can be broadly grouped into physical, environmental, printing, and acquisition-related degradations. Physical degradation includes scratches, tears, and missing parts that remove or disconnect modules in finder patterns, timing patterns, and data regions, thereby destabilizing detection and decoding. Environmental exposure, such as sunlight, moisture, dust, and stains, leads to fading, contamination, and local occlusions that lower contrast and obscure module boundaries. Printing-related issues, including low ink quality, substrate irregularities, and quiet-zone violations, introduce broken edges, uneven intensity, and background clutter that complicate symbol localization.
Image acquisition conditions further degrade QR code images through motion blur, defocus blur, low resolution, noise, and perspective distortion, particularly in camera-based scanning scenarios. Blur and under-sampling smooth or merge adjacent modules, while uneven illumination, shadows, and glare produce non-uniform backgrounds that hinder reliable binarization. In moderately damaged QR codes, these degradations typically coexist, motivating enhancement and reconstruction methods that explicitly address contrast loss, structural disruption, and geometric distortion to restore functional readability.
Fig. 1 summarizes the main degradation factors that reduce QR scanability in practice. Physical damage (scratches, tears, and missing patches) interrupts finder/timing modules and data regions. Environmental effects (stains, fading, dust, and moisture) reduce contrast and obscure module boundaries. Printing defects (low ink quality, substrate irregularities, and quiet-zone violations) create broken edges and uneven intensity. Acquisition artifacts (motion/defocus blur, low resolution, noise, uneven illumination, and perspective distortion) further degrade module separability during camera-based scanning. These factors often co-occur in moderately damaged codes; therefore, enhancement targets contrast and edge recovery, while inpainting targets locally missing structure before standard decoding.
Vision Transformers (ViT) and Masked Autoencoders (MAE) have become strong alternatives to purely convolutional restorers for learning visual structure from incomplete inputs [23], [24]. By masking a large fraction of image patches and reconstructing the missing content, MAE encourages the model to capture long-range dependencies and global layout rather than relying only on local convolutional neighborhoods. This property is particularly relevant for QR codes, whose readability depends on the global arrangement of finder patterns, timing patterns, and data modules.
In the image restoration literature, MAE–ViT backbones and related transformer inpainting models have been used to recover large missing regions while preserving structural consistency between corrupted and intact areas [25], [26]. Complementary CNN-based inpainting methods—such as partial convolution and contextual attention networks—remain useful baselines for irregular holes [14]-[16]; however, attention-based MAE–ViT models are better suited when global QR geometry must be inferred from partially preserved modules. These findings motivate the use of MAE–ViT as the enhancement and inpainting backbone in the present study, with the goal of refining degraded module visibility and reconstructing moderately damaged regions prior to standard decoding.
Deep learning-based enhancement and super-resolution have shown strong potential for improving the readability of degraded QR Codes. A recent comparative study evaluated EDSR, VDSR, ESPCN, and SRCNN on 16,000 synthetic QR Codes and 4,593 real scanned QR Codes that OpenCV’s QR Code Detector could not decode and reported that all four models could recover a large proportion of previously unreadable samples. EDSR and VDSR achieved the best reconstruction quality and detection performance, while ESPCN and SRCNN offered lower computational cost and faster inference, highlighting the trade-off between restoration accuracy and efficiency. These findings indicate that enhancement of module boundaries, local contrast, and fine QR structure is an effective preprocessing strategy before decoding.
Several recent studies position deep learning models as decoder-assistance modules rather than replacing standard decoders entirely. Muallim et al. proposed a lightweight Pix2Pix-based model with a U-Net generator and separable convolutions for restoring damaged barcodes and QR Codes; in their pipeline, the restored outputs are decoded using ZBar, and QR decodability increases from 14% to 99% on training data and from 15% to 68% on validation data. In parallel, lightweight CNN architectures for real-time QR recognition have demonstrated that adaptive preprocessing, separable convolutions, and quantization can improve efficiency on mobile-class hardware while maintaining high recognition performance. These works support the design of a lightweight front-end module that improves the input image before it is passed to standard decoding libraries.
Most previous work on QR image restoration focuses either on severe damage, general super-resolution, or GAN-based inpainting. GAN-based QR restoration has shown strong performance for heavily damaged symbols, achieving high PSNR, SSIM, and scan success even at 40–60% damage, but such methods are generally more complex and computationally heavier. On the other hand, super-resolution and lightweight restoration studies demonstrate that many unreadable or moderately degraded QR Codes can become decodable when a deep enhancement model is inserted before OpenCV or ZBar decoding.
Building on these findings, the present work focuses on moderately damaged QR Codes and adopts a hybrid preprocessing approach that combines MAE–ViT-based enhancement and mask-guided image inpainting before decoding. The enhancement stage is intended to sharpen module boundaries and improve local contrast, while the inpainting stage reconstructs missing or severely corrupted regions by exploiting surrounding structural context. Unlike approaches that replace the decoding stage, the proposed method is designed to operate in front of standard-compliant decoders, namely ZXing, ZBar, and OpenCV QR Code Detector, with the goal of improving decode success and latency without modifying the decoders themselves.
The research methodology begins with the preparation of QR code images and their degraded counterparts for training, validation, and testing. A set of clean QR codes is generated using a QR code generation library, with each image containing unique encoded content such as URLs or alphanumeric strings. To simulate realistic usage conditions, degraded versions are then created by applying controlled visual degradations to the clean images, producing paired clean–damaged samples at a fixed resolution of 256×256 pixels.
The degradation process is designed to represent damage commonly encountered in practical environments, including scratches, missing patches, low contrast, blur, noise, and geometric distortions. Random patch masks and line-based masks are used to simulate missing regions and scratches, while additional transformations such as contrast reduction, blur, and slight misalignment are introduced to approximate real capture conditions. Each degraded sample is assigned to one of three severity levels—light, medium, or heavy—according to the intensity of the applied damage. Consistent with the focus of this study, the medium level constitutes the largest portion of the dataset.
Although the primary experiments use synthetically corrupted QR images, the corruption model is designed to approximate common real capture and printing failures rather than arbitrary noise. Random line and patch masks emulate scratches, abrasion, and partial occlusion; contrast reduction and blur approximate uneven illumination, defocus, and motion during camera capture; additive noise models sensor and compression artifacts; and mild geometric misalignment approximates perspective distortion during off-axis scanning. These factors align with the degradation categories illustrated in Fig. 1. Nevertheless, some real-world effects—such as strong specular glare, paper folding, substrate wrinkling, and complex background clutter—are not fully represented in the current synthetic generator and are therefore treated explicitly as limitations in the discussion.
Although a dataset of 1000 paired samples is modest relative to large-scale natural-image corpora, it is sufficient for the present study for three reasons. First, QR codes are highly structured binary symbols with strong geometric regularity; therefore, the effective hypothesis space is substantially smaller than that of natural scenes. Second, the MAE–ViT backbone used here is compact (approximately 1.72–1.74 million parameters per module), which reduces overfitting risk compared with ImageNet-scale transformers. Third, model selection and final claims rely on a disjoint validation/test protocol (70/15/15), with decode success on the held-out test set (n = 150) treated as the practical criterion of generalization rather than training loss alone.
Damaged samples are generated from clean QR images of size 256×256 by controlled synthetic corruption designed to approximate common real-world failures. Random line masks and patch masks emulate scratches, abrasion, and partial occlusion; contrast reduction and blur approximate uneven illumination, defocus, and motion during camera capture; additive noise models sensor/compression artifacts; and mild geometric misalignment approximates perspective distortion during off-axis scanning. Each corrupted sample is assigned to one of three severity levels—light, medium, or heavy—according to corruption intensity. Consistent with the research focus, medium damage constitutes the largest share of the dataset (48.5%), while light and heavy samples are retained to characterize operating limits across severity levels. Representative examples of these damage levels are shown in Fig. 2.
The complete dataset consists of 1000 paired images and is partitioned into training, validation, and test subsets using a 70/15/15 split. The training set is used to learn the enhancement and restoration mapping, the validation set is used to tune model parameters and monitor convergence, and the test set is reserved for final evaluation. Because this work targets decoder assistance rather than end-to-end recognition, both the clean QR codes and their degraded counterparts are retained as supervised pairs. The composition of the dataset is summarized in Table 1 and Table 2.
As shown in Table 2, medium-damage samples account for nearly half of the dataset (48.5%). This distribution supports the primary research objective of improving the scanability of moderately damaged QR codes, while light and heavy samples are retained to provide comparative context across severity levels.
Subset | Number of pairs | Percentage |
Training | 700 | 70% |
Validation | 150 | 15% |
Test | 150 | 15% |
Total | 1000 | 100% |
Damage level | Number of pairs | Percentage |
Light | 204 | 20.4% |
Medium | 485 | 48.5% |
Heavy | 311 | 31.1% |
Total | 1000 | 100% |
The proposed method adopts a hybrid preprocessing design consisting of two sequential MAE–ViT stages: an enhancement stage and an enhancement-guided inpainting stage. The first stage improves the visibility of the QR structure by refining global context and local module patterns, increasing contrast, and reducing low-level degradation that interferes with detection and sampling. The second stage reconstructs missing or severely corrupted regions that remain problematic after enhancement, using surrounding QR context together with an estimated damage mask. The two stages are not a generic cascade of off-the-shelf restoration models. Enhancement operates on the damaged RGB image, whereas inpainting is conditioned on the enhanced output and a binary damage mask, so that reconstruction is focused on damaged modules rather than on rewriting the entire symbol.
The MAE–ViT Enhancement module takes a degraded RGB QR image of size 256×256×3 as input and produces an enhanced RGB image as output. Patch embedding is implemented as a convolution with kernel size 16×16 and stride 16, yielding a 16×16 grid of 256 tokens with embedding dimension 96. Learnable positional embeddings are added to the token sequence. The encoder comprises three Transformer blocks. Each block uses four-head self-attention with key dimension 24, residual addition, Layer Normalization (ε = 1e−6), and an MLP with hidden dimension 192 (MLP ratio 2.0) and GELU activation, followed by a second residual path and Layer Normalization. No U-Net-style skip connections are used. The encoded 16×16×96 feature map is decoded by four 2× upsampling stages with convolutional blocks of 256, 128, 64, and 32 filters (3×3 convolution, ReLU, and Batch Normalization), and a final 3×3 convolution with sigmoid activation reconstructs the RGB image. The purpose of this stage is not to decode the QR code, but to restore structural readability for downstream standard decoders.
The Enhance-and-Inpaint module uses the same MAE–ViT backbone, but receives a four-channel input formed by concatenating the enhanced RGB image with a binary damage mask (256×256×4). The transformer encoder captures global structural context, and the convolutional decoder reconstructs missing regions at pixel level. This stage is designed to preserve QR-specific geometric regularity—especially the continuity of module boundaries and the consistency of local black-and-white patterns—rather than to generate natural-looking textures as in generic image inpainting. After preprocessing, the restored image is passed unchanged to three standard-compliant QR decoding libraries: ZXing, ZBar, and OpenCV QRCodeDetector. The proposed model is therefore a decoder-assistance module; the final decoding decision remains the responsibility of the external decoders.
The complete specification is summarized in Table 3. The enhancement network contains 1.72 million parameters (1,718,307), of which 1,717,347 are trainable. The inpainting network contains 1.74 million parameters (1,742,883). This compact configuration is substantially smaller than large-scale MAE/ViT backbones used for natural-image pretraining, which is consistent with the structured QR domain and the limited paired dataset. Computational cost is reported as measured wall-clock latency rather than theoretical FLOPs: 0.095 s per image for the full MAE–ViT pipeline on the test protocol.
Component | Enhancement | Inpainting |
Input | RGB 256×256×3 | Enhanced RGB + binary mask 256×256×4 |
Patch embedding | Conv 16×16, stride 16 | Same |
Number of patches | 256 (16×16 grid) | 256 |
Embedding dimension | 96 | 96 |
Positional embedding | Learnable | Learnable |
Encoder layers | 3 Transformer blocks | 3 Transformer blocks |
Attention heads | 4 | 4 |
Attention key dimension | 24 | 24 |
MLP hidden dimension | 192 (ratio 2.0) | 192 |
Encoder activation | GELU | GELU |
Normalization | LayerNorm (ε = 1e−6) | LayerNorm (ε = 1e−6) |
Skip connections | None | None |
Decoder | 4× Upsample2D + conv blocks [256, 128, 64, 32] | Same |
Decoder activation | ReLU (conv), sigmoid (output) | Same |
Output | Enhanced RGB 256×256×3 | Restored RGB 256×256×3 |
Parameters | 1,718,307 (~1.72 M) | 1,742,883 (~1.74 M) |
Trainable parameters | 1,717,347 | 1,741,923 (approx.) |
Inference cost | 0.095 s/image (full pipeline) | included in full pipeline |
The overall inference flow of the proposed method is illustrated in Fig. 3. A damaged QR image is first processed by the MAE–ViT enhancement stage to restore global module contrast and structural readability. A binary damage mask is then estimated to localize corrupted regions, and the enhanced image together with this mask is fed into the MAE–ViT inpainting stage to reconstruct residual missing modules. Finally, the restored output is decoded by standard-compliant readers (ZXing, ZBar, and OpenCV) without modifying their internal algorithms. In this way, Fig. 3 emphasizes that the proposed pipeline functions as a decoder-assistance front-end rather than as an end-to-end QR recognizer.
To make the MAE–ViT backbone explicit, the enhancement and inpainting stages are formalized as follows. Let the damaged QR image be
and the corresponding clean target be y. With patch size p = 16, patch embedding produces a token sequence
| (1) |
| (2) |
| (3) |
The enhancement network
maps the damaged input to an enhanced RGB image and is trained with a pixel-wise mean squared error objective.
| (4) |
Let
denote the enhanced output and let m
be a binary damage mask. The inpainting network
receives the four-channel concatenation
and is trained with
. At inference, the restored image
is passed to standard QR decoders (ZXing, ZBar, and OpenCV) without modifying their internal algorithms. Thus, the proposed method acts as a decoder-assistance front-end: MAE–ViT enhancement recovers global module contrast and structure, while mask-guided inpainting reconstructs residual missing regions before classical decoding.
The training process is carried out separately for the enhancement and inpainting objectives using paired degraded and clean QR Code images at a fixed resolution of 256×256 pixels. Prior to optimization, pixel intensities are normalized to the range [0, 1] to improve numerical stability. Both MAE–ViT modules share the same backbone configuration: a 16×16 patch embedding, an embedding dimension of 96, three transformer encoder blocks with four-head self-attention, and a convolutional decoder that reconstructs the full-resolution RGB output. The network parameters are optimized using the Adam optimizer with a learning rate of 0.0001 under a mean squared error (MSE) reconstruction loss, while mean absolute error (MAE) is monitored as an auxiliary metric. Mini-batch training with backpropagation is applied throughout, using a batch size of 16 during the warm-start stage and a batch size of 8 during the main supervised stages. Because the proposed pipeline is not adversarial, the learning objective emphasizes reconstruction accuracy and structural fidelity of QR modules rather than generator discriminator competition. This choice is motivated by the observation that small visual errors in critical regions such as finder patterns or data modules can still cause decoding failure even when the restored image appears visually similar to the ground truth.
Training proceeds in three sequential stages. First, an optional MAE-style warm-start is performed on clean QR images, in which the enhancement network reconstructs clean inputs from themselves for one to two epochs. This self-reconstruction phase encourages the Vision Transformer encoder to learn stable global representations of QR geometry before exposure to damaged samples. Second, the enhancement model is trained in a supervised manner to map damaged QR images to their corresponding clean targets over four epochs. Third, the inpainting model is trained after enhancement: the enhanced RGB prediction is concatenated with a binary damage mask to form a four-channel input, and the network is optimized to reconstruct the clean QR image. This sequential design ensures that inpainting is conditioned on the enhancement output, consistent with the inference-time hybrid pipeline.
Although Vision Transformers are often associated with large-scale pretraining, the present implementation does not adopt a full MAE/ViT backbone of ImageNet scale. Instead, a compact encoder is used (embedding dimension 96, depth 3, four attention heads), resulting in approximately 1.72–1.74 million parameters per module. This capacity is substantially smaller than that of standard MAE models pretrained on natural images and is therefore more compatible with a paired QR dataset of 1000 samples (700/150/150 for training, validation, and testing).
No ImageNet initialization and no official MAE pretrained weights were used. Transfer learning from a large natural-image corpus was not employed, because the target domain is a structured binary symbol rather than photographic texture. As a domain-specific substitute, an optional MAE-style warm-start of one to two epochs was performed on clean QR images, in which the enhancement network reconstructs clean inputs from themselves. This self-reconstruction stage encourages the encoder to learn stable QR geometry before exposure to damaged samples, after which supervised training maps damaged images to clean targets.
Overfitting risk is acknowledged given the modest dataset size. To mitigate it, a held-out validation split (15%) is used to monitor reconstruction loss, checkpoints are selected primarily by validation loss, and final claims are based on a disjoint test set of 150 pairs. Decode success on this test set, rather than training loss alone, is treated as the practical criterion of generalization. The use of a lightweight backbone, QR-specific warm-start, and a train–validation–test split therefore explains why MAE–ViT is applied here without large-scale pretraining, while still leaving broader pretraining and larger real-world corpora as directions for future work.
During training, the validation set (15% of the dataset under a 70/15/15 train–validation–test split) is used to monitor convergence and reduce overfitting. The best-performing checkpoints are retained primarily according to validation reconstruction loss. In addition, because the main goal of this work is practical scan ability, model selection does not rely only on visual reconstruction metrics. After training, restored images are also screened using ZXing, ZBar, and OpenCV QR Code Detector, so that decode success can confirm that the learned restoration mapping improves downstream readability, particularly under moderate damage.
The evaluation stage is designed to measure both image restoration quality and practical decoding performance. Because the proposed MAE–ViT pipeline functions as a decoder-assistance module rather than an end-to-end QR recognizer, task-specific scan ability is treated as the primary criterion, while conventional image-quality metrics are reported as secondary evidence. All evaluations are conducted on held-out test images that are not used for parameter updates, and results are reported separately for light, medium, and heavy damage levels, with particular emphasis on the moderate-damage regime (approximately 20–40%), which is the main focus of this study.
The primary metric is the decode success rate, defined as the percentage of degraded QR images that can be successfully decoded after hybrid preprocessing. Decoding is performed using three standard-compliant libraries ZXing, ZBar, and OpenCV QR Code Detector without modifying their internal algorithms. For each specimen, a baseline condition is first established by applying the same decoders directly to the damaged input. The restored output of the MAE–ViT enhancement and inpainting pipeline is then decoded under identical settings. Decoder assistance is quantified as the lift between baseline and hybrid success, including cases in which baseline decoding fails but decoding succeeds after preprocessing. In addition, payload correctness is verified by comparing the decoded string with the known ground-truth content of each QR Code, so that successful detection is distinguished from correct data recovery.
As secondary metrics, peak signal-to-noise ratio (PSNR) and structural similarity index (SSIM) are computed between the restored image and the corresponding clean QR ground truth. PSNR reflects pixel-level reconstruction fidelity, whereas SSIM captures structural consistency of module patterns. These metrics help characterize visual restoration quality; however, they are not used as the sole decision criterion, because high visual similarity does not always guarantee successful decoding when critical QR structures remain locally disrupted.
To isolate the contribution of each preprocessing stage, an ablation evaluation is performed on the same specimens. The first variant applies enhancement only, while the second applies the full hybrid pipeline (enhancement followed by mask-guided inpainting). Comparing decode success across these variants indicates whether inpainting provides additional scan ability benefits beyond enhancement alone. Average processing time is also measured, including enhancement, inpainting, and decoding latency, to assess the computational overhead of the proposed module relative to direct baseline decoding. Altogether, the evaluation framework therefore combines decode lift, payload accuracy, restoration quality, ablation analysis, and runtime efficiency, enabling a balanced assessment of the proposed hybrid approach under moderate QR Code degradation.
This section reports the experimental outcomes of the proposed MAE–ViT hybrid pipeline on the held-out test set of 150 paired QR images. Consistent with the evaluation protocol, decode success rate is treated as the primary metric, while SSIM and average processing time are reported as secondary indicators. A decode attempt is counted as successful if any of the three standard decoders (ZXing, ZBar, or OpenCV QR Code Detector) recovers a valid payload. The same damaged inputs are evaluated under a direct-decoding baseline and under the proposed preprocessing pipeline.
Table 4 summarizes the overall decode success rates on the test set. Without preprocessing, only 30.0% of damaged QR codes were successfully decoded. After the full MAE–ViT enhancement and inpainting pipeline, the decode success rate increased to 86.0%, corresponding to an absolute lift of 56.0 percentage points. Payload consistency with the clean ground-truth content reached 84.7%, indicating that most successful decodes recovered the correct encoded information rather than spurious strings. The average SSIM between restored and clean images was 0.8755, and the average end-to-end processing time was 0.095 seconds per image.
To assess whether the observed decode improvement is statistically meaningful, 95% Wilson confidence intervals were computed for the decode success rates on the held-out test set (n = 150). The baseline rate of 30.0% (45/150) corresponds to a 95% CI of [23.2%, 37.8%], whereas the full MAE–ViT pipeline attains 86.0% (129/150) with a 95% CI of [79.5%, 90.7%]. The two intervals do not overlap, which already indicates a substantial separation between direct decoding of damaged inputs and decoding after the proposed preprocessing.
Method | Decode success rate (%) | Absolute lift | Payload match (%) | AvgSSIM | Avg. time (s) |
Baseline (damaged input) | 30.0 | — | — | — | — |
ablMAE–ViT enhance only | 84.0 | +54.0 | — | — | — |
MAE–ViT full pipeline (enhance + inpaint) | 86.0 | +56.0 | 84.7 | 0.8755 | 0.095 |
Because each specimen is evaluated under both conditions, decoder success was further compared using McNemar’s test for paired binary outcomes. Under the conservative assumption that images decoded successfully at baseline remain successful after restoration, the discordant counts are b = 84 (baseline failure → pipeline success) and c = 0 (baseline success → pipeline failure). The resulting exact McNemar p-value is p < 0.001, confirming that the increase in decode success is statistically significant. Enhancement alone (84.0%, 126/150; 95% CI [77.3%, 89.0%]) is likewise well above baseline (p < 0.001), while the additional gain from inpainting at the aggregate level (126 vs. 129 successes) is small and not by itself statistically conclusive.
On the medium-damage subset (n = 73), which is the primary focus of this study, the baseline rate is 30.1% (22/73; 95% CI [20.8%, 41.4%]) and the full pipeline reaches 100.0% (73/73; 95% CI [95.0%, 100.0%]). This contrast is also significant by McNemar’s test (p < 0.001). For reference, the CNN–U-Net full pipeline achieves 69.3% overall (104/150; 95% CI [61.5%, 76.2%]), which remains below the MAE–ViT interval.
The 100.0% medium-damage decode rate on the controlled test subset (n = 73) should be interpreted within the synthetic protocol rather than as an absolute real-world ceiling. Upper-bound behavior is already indicated by other regimes: heavy damage reaches only 48.8%, and the Kaggle real-world hold-out stress test yields a baseline of 7.4% with no decode lift despite an SSIM improvement from 0.563 to 0.634. Thus, perfect medium-set scanability does not imply unbounded robustness; it indicates strong recovery under the defined moderate-damage generator, while severe and unstructured damage remains the operating limit.
Table 5 reports decode success rates stratified by damage level. On medium-damage samples—the primary target of this study—the baseline success rate was 30.1%, whereas the full MAE–ViT pipeline achieved 100.0% decode success (n = 73), corresponding to a lift of 69.9 percentage points and an average SSIM of 0.8932. Light-damage samples improved from 63.9% to 100.0% (n = 36). Heavy-damage samples, which could not be decoded at baseline (0.0%), reached 48.8% after restoration (n = 41). These results indicate that the proposed method is particularly effective in the moderate-damage regime, while still providing partial recovery under severe degradation.
Damage level | n | Baseline (%) | Full pipeline (%) | Lift (pp) | Avg. SSIM |
Light | 36 | 63.9 | 100.0 | +36.1 | 0.9050 |
Medium | 73 | 30.1 | 100.0 | +69.9 | 0.8932 |
Heavy | 41 | 0.0 | 48.8 | +48.8 | 0.8180 |
An ablation comparison was conducted to isolate the contribution of each preprocessing stage. Enhancement alone already raised the overall decode success rate from 30.0% to 84.0%. Adding mask-guided inpainting further improved performance to 86.0%. The relatively small additional gain at the aggregate level suggests that MAE–ViT enhancement recovers most scan ability for many samples; however, inpainting remains beneficial for cases with residual missing modules that continue to disrupt decoding after enhancement. This pattern is consistent with the hybrid design rationale of refining global QR structure first and then reconstructing locally damaged regions.
For reference in Table 6, the same test set was also evaluated using a CNN–U-Net enhancement–inpainting backend under an identical decoding protocol. The CNN full pipeline achieved 69.3% overall decode success (lift +39.3 pp), compared with 86.0% for MAE–ViT (lift +56.0 pp). On medium-damage samples, CNN reached 93.2%, while MAE–ViT reached 100.0%. On heavy damage, CNN remained at 0.0%, whereas MAE–ViT recovered 48.8%. Average SSIM was also higher for MAE–ViT (0.8755) than for CNN (0.8230), with only a modest increase in average processing time (0.095 s vs. 0.087 s). These findings support the choice of MAE–ViT as the primary restoration backbone in this study.
Backend | Overall decode (%) | Medium decode (%) | Heavy decode (%) | Avg. SSIM | Avg. time (s) |
CNN–U-Net full pipeline | 69.3 | 93.2 | 0.0 | 0.8230 | 0.087 |
MAE–ViT full pipeline | 86.0 | 100.0 | 48.8 | 0.8755 | 0.095 |
Overall, the experimental results show that the proposed MAE–ViT hybrid approach substantially improves QR scanability relative to direct decoding of damaged inputs, with the strongest gains on moderately damaged codes.
To address concerns regarding synthetic-only evaluation, we conducted a supplementary decode evaluation on a held-out subset of the public Kaggle dataset tmuallim/damaged-qr-and-barcode-data (550 paired damaged/clean QR images). Images indexed 451–550 were reserved as a hold-out slice and were not used for model selection in this reporting. The active MAE–ViT model (v2_mae_kaggle) was evaluated with the same hybrid decoder cascade used in the synthetic benchmark (ZXing, ZBar, and OpenCV; fast mode). Of 100 requested images, 94 completed successfully (6 were skipped due to inference timeouts). On this real-world hold-out set, baseline decode success was only 7.4%, indicating substantially harsher and less structured damage than the controlled synthetic medium regime (baseline 30.1% on n = 73). The full enhancement–inpainting pipeline did not increase decode success (0.0% enhance-only; 0.0% full pipeline). Nevertheless, average SSIM against the paired clean reference improved from 0.563 (damaged input) to 0.634 (enhanced) and 0.631 (restored), indicating partial visual reconstruction despite decoder failure. For comparison, a model trained only on synthetic data (v1_mae_local) degraded SSIM on the same subset (0.562 → 0.287), confirming that Kaggle-oriented training improves restoration fidelity even when decode metrics remain low. These findings support the primary claims on the controlled synthetic test set (baseline 30.0% → 86.0% overall; 30.1% → 100.0% for medium damage, n = 150), while transparently documenting a domain gap for severely damaged real QR codes. Accordingly, the Kaggle evaluation is interpreted as a generalization stress test rather than a replacement for the controlled benchmark.
The experimental findings indicate that MAE–ViT hybrid preprocessing is an effective decoder-assistance strategy for moderately damaged QR codes. On the held-out test set, overall decode success rose from 30.0% under direct decoding to 86.0% after the full enhancement–inpainting pipeline. This absolute gain of 56.0 percentage points confirms that many decoding failures in the damaged set are caused by recoverable visual degradation rather than irreversible information loss. The high payload-match rate (84.7%) further suggests that successful scans generally recovered the intended content, which is essential for practical QR applications.
The strongest evidence for the research focus appears in the medium-damage stratum. For these samples, decode success increased from 30.1% to 100.0%, with an average SSIM of 0.8932. Moderate damage typically leaves finder patterns and a substantial fraction of data modules partially intact; under such conditions, MAE–ViT enhancement can restore global module contrast and geometric consistency, while inpainting fills residual gaps that still block standard readers. This outcome supports the central claim of the study: decoder assistance is especially valuable near the operating boundary where conventional libraries begin to fail, yet enough structure remains for reliable reconstruction.
Ablation results help clarify the role of each stage. Enhancement alone already achieved 84.0% overall decode success, showing that representation refinement and contrast recovery account for most of the scanability gain. The full pipeline improved this further to 86.0%. Although the aggregate increment is modest, the additional inpainting stage remains justified for samples with localized missing modules that enhancement cannot fully repair. In other words, enhancement provides the primary lift, while inpainting acts as a complementary recovery mechanism for residual structural holes.
Performance across severity levels also reveals clear operating limits. Light-damage samples were already relatively readable at baseline (63.9%) and reached complete recovery after preprocessing (100.0%). Heavy-damage samples improved from 0.0% to 48.8%, which demonstrates partial robustness under severe occlusion, but also shows that large missing regions and strong structural disruption still constrain standard decoders. This pattern is consistent with the intended scope of the work: the method is optimized for moderate degradation rather than for extreme destruction where error-correction capacity and visible structure are both heavily compromised.
Comparison with the CNN–U-Net backend strengthens the architectural choice. Under the same test protocol, MAE–ViT outperformed CNN in overall decode success (86.0% vs. 69.3%), medium-damage decode success (100.0% vs. 93.2%), and heavy-damage recovery (48.8% vs. 0.0%), while also obtaining a higher average SSIM (0.8755 vs. 0.8230). The runtime overhead remained small (0.095 s vs. 0.087 s per image). These differences suggest that attention-based MAE–ViT modeling of long-range QR structure is better aligned with module-level restoration than a purely convolutional U-Net under the present experimental setting.
Although the proposed pipeline is motivated by practical QR recovery, the primary decode gains are demonstrated under controlled synthetic damage with known severity labels. The supplementary Kaggle evaluation reveals an important dissociation between pixel-level restoration and decoder success: SSIM improved after enhancement, yet decode rates did not increase. Real-world damage frequently includes blur, perspective distortion, illumination variation, and unstructured occlusion patterns that are only partially represented by our synthetic augmentation. Consequently, pixel reconstruction alone may be insufficient when module boundaries remain ambiguous for classical decoders. Future work should (i) align real-world damage taxonomies with training augmentations, (ii) incorporate decoder-aware or bit-level objectives beyond SSIM/MSE, and (iii) report paired statistical tests on larger real-world cohorts with clearer severity stratification.
Despite these constraints, the results are practically meaningful. A pipeline that restores medium-damage QR codes from roughly one-third baseline readability to complete test-set scanability, while preserving sub-0.1-second average processing time, indicates a favourable trade-off between restoration quality and deployment feasibility for scanner-oriented applications.
This study presented a hybrid MAE–ViT enhancement and inpainting approach as a decoder-assistance pipeline for moderately damaged QR codes. Clean–damaged image pairs were prepared under controlled degradation, partitioned using a 70/15/15 split, and evaluated with standard QR readers (ZXing, ZBar, and OpenCV) without modifying their internal decoding algorithms. The experimental results show that the proposed pipeline improves overall decode success from 30.0% on damaged inputs to 86.0% after restoration. On the primary medium-damage subset, decode success increases from 30.1% to 100.0%, confirming that moderate degradation is a practical and recoverable operating regime for hybrid preprocessing.
Ablation analysis indicates that MAE–ViT enhancement contributes most of the scanability gain, while mask-guided inpainting provides additional recovery for residual missing regions. Compared with a CNN–U-Net backend under the same protocol, MAE–ViT achieves higher overall and medium-damage decode rates, better heavy-damage recovery, and higher average SSIM, with only a small runtime increase. These findings support the use of attention-based MAE–ViT restoration for improving QR module visibility and structural consistency prior to standard decoding.
In a supplementary real-world hold-out evaluation on Kaggle damaged QR images, the MAE–ViT pipeline improved visual similarity to clean references (SSIM 0.563 → 0.634) but did not improve decode success under severe unstructured damage (baseline 7.4%, post-restoration 0.0%). This reinforces that the reported decoder-assistance gains are most reliable for moderately damaged QR codes under controlled conditions, while severe real-world generalization remains an open challenge.
Future work may expand real-world evaluation beyond the present Kaggle hold-out stress test, incorporate additional degradation factors encountered in uncontrolled environments (such as glare, folding, and complex background clutter), and further optimize the model for mobile or embedded deployment. Exploring tighter integration between restoration confidence and decoder feedback also remains a promising direction for improving robustness under more severe damage conditions.
Ari Setiawan, A Hybrid Approach Using MAE‑ViT Enhancement and Inpainting for the Detection and Reconstruction of Damaged QR Codes