A Texture-Hidden Anti-Counterfeiting QR Code and Authentication Method

This paper designs a texture-hidden QR code to prevent the illegal copying of a QR code due to its lack of anti-counterfeiting ability. Combining random texture patterns and a refined QR code, the code is not only capable of regular coding but also has a strong anti-copying capability. Based on the proposed code, a quality assessment algorithm (MAF) and a dual feature detection algorithm (DFDA) are also proposed. The MAF is compared with several current algorithms without reference and achieves a 95% and 96% accuracy for blur type and blur degree, respectively. The DFDA is compared with various texture and corner methods and achieves an accuracy, precision, and recall of up to 100%, and also performs well on attacked datasets with reduction and cut. Experiments on self-built datasets show that the code designed in this paper has excellent feasibility and anti-counterfeiting performance.


Introduction
Anti-counterfeiting techniques can prevent or identify counterfeits to a certain extent, and traditional techniques can be classified into the following categories: visual anti-counterfeiting, electronic identification anti-counterfeiting, electronic code anti-counterfeiting, and texture anti-counterfeiting. Visual anti-counterfeiting mainly uses laser holography [1][2][3][4], special inks [5][6][7][8], temperature changes [9,10], security lines [11], chemical substances [12], and so on. They have special materials or unique formulations that not only cost a lot but also lose security once their information is leaked. Electronic identification anti-counterfeiting [13] commonly includes radio frequency, magnetic recording, integrated circuit cards, etc. These techniques work in conjunction with data management systems but they are not as generalizable as relying on specialized devices and are limited in application scenarios and scope. Based on the uniqueness of texture, all digital images of texture anti-counterfeiting marks [14,15] are obtained by high-definition photography, and then a database is established to upload, number, and save them. Consumers take photos with their mobile phones and retrieve the corresponding images saved in a database for human-eye comparison, but there is a lack of objective and intelligent means of identification. Traditional techniques suffer from various problems, such as excessive cost, poor user experience, and poor objectivity.
Different degrees of random toner adsorption occur in a digital graphic during printing, ensuring its physical non-replicability. The special design of the graphic can further amplify the distortion phenomenon, which can be identified by the algorithm. QR codes are widely used due to their strong coding ability and large information capacity. As QR codes are composed of a large number of black and white blocks, they are insensitive to the noise and distortion generated during printing. Therefore, the fusion of anti-counterfeiting graphics with QR codes is gaining increasing attention. At present, the fusion can be summarized as physical unclonable function (PUF) [16][17][18][19], watermark [20][21][22][23], copy detection pattern (CDP) [24][25][26][27][28], and halftone [29][30][31][32]. Although the above methods can achieve certain anti-counterfeiting effects, there are still some aspects that can be improved.
For example, [16] utilizes natural texture features and printing micro-features, then calculates the feature similarity between the code to be tested and the sample code through the feature extraction algorithm; however, this requires high-precision printing and capturing equipment. The authors in [20] adopt the improved discrete wavelet transform and singular value decomposition algorithm to hide the digital watermark in the 2D code. In [21], the researchers embed specific random micro-textures into a 2D code and then convert them into a security layer. Any degradation process due to counterfeiting will change the statistics of the micro-textures and thus achieve anti-counterfeiting. However, watermarking algorithms can show some robustness to relatively low-intensity attacks, while for high-intensity attacks, the watermarking information is altered or significantly lost. A new 2LQR code is proposed in [24] to replace the black block of the QR code with a black and white module of the same size with anti-copy ability. This system includes public and private storage levels; the public level ensures that the decoding program can decode, and the private level uses the sensitivity of the module to the print capture process to distinguish real from fake codes. However, this code would attract visual errors, where it is easy for the naked eye to find the specific structure of the module, while also requiring precision in the capture device, which is not conducive to commercial generalization. The authors in [29] propose a two-dimensional code anti-replication scheme based on the spectral and spatial bar code channel model. Two sets of spectral and spatial features are extracted from the channel model and identified in a cascaded combination. However, the feature extraction process of this method is relatively complicated. In [30], the researchers add a double security authentication to the position of embedded information and then reduce the interval distance through fourth-order modulation. In this way, it is easier to create differences after printing and capturing, thus achieving the anti-replication effect. Figure 1 shows some representative anti-counterfeiting patterns.
Sensors 2023, 23, x FOR PEER REVIEW 2 of 24 the noise and distortion generated during printing. Therefore, the fusion of anti-counterfeiting graphics with QR codes is gaining increasing attention. At present, the fusion can be summarized as physical unclonable function (PUF) [16][17][18][19], watermark [20][21][22][23], copy detection pattern (CDP) [24][25][26][27][28], and halftone [29][30][31][32]. Although the above methods can achieve certain anti-counterfeiting effects, there are still some aspects that can be improved. For example, [16] utilizes natural texture features and printing micro-features, then calculates the feature similarity between the code to be tested and the sample code through the feature extraction algorithm; however, this requires high-precision printing and capturing equipment. The authors in [20] adopt the improved discrete wavelet transform and singular value decomposition algorithm to hide the digital watermark in the 2D code. In [21], the researchers embed specific random micro-textures into a 2D code and then convert them into a security layer. Any degradation process due to counterfeiting will change the statistics of the micro-textures and thus achieve anti-counterfeiting. However, watermarking algorithms can show some robustness to relatively low-intensity attacks, while for high-intensity attacks, the watermarking information is altered or significantly lost. A new 2LQR code is proposed in [24] to replace the black block of the QR code with a black and white module of the same size with anti-copy ability. This system includes public and private storage levels; the public level ensures that the decoding program can decode, and the private level uses the sensitivity of the module to the print capture process to distinguish real from fake codes. However, this code would attract visual errors, where it is easy for the naked eye to find the specific structure of the module, while also requiring precision in the capture device, which is not conducive to commercial generalization. The authors in [29] propose a two-dimensional code anti-replication scheme based on the spectral and spatial bar code channel model. Two sets of spectral and spatial features are extracted from the channel model and identified in a cascaded combination. However, the feature extraction process of this method is relatively complicated. In [30], the researchers add a double security authentication to the position of embedded information and then reduce the interval distance through fourth-order modulation. In this way, it is easier to create differences after printing and capturing, thus achieving the antireplication effect. Figure 1 shows some representative anti-counterfeiting patterns. To address the above issues, this paper designs a texture-hidden QR code, based on the codec mechanism of QR codes, using Gaussian distribution and information-hiding technology. The licensee generates a digital image of the code and then uses an officially authorized printer to legally print the authentic product and paste it on the goods or documents for circulation. The forger does not have access to the original code digital image, so the process involves scanning, reprinting, and pasting the fake product or document on top of the original. Users upload codes by taking photos on their mobile phones, which can be used to verify authenticity. The code has abundant texture details and specific frequency characteristics which improve the anti-replication capability while maintaining the generality of the QR codes. An efficient quality assessment algorithm is also proposed to address possible blur in the authentication processing. The proposed method describes To address the above issues, this paper designs a texture-hidden QR code, based on the codec mechanism of QR codes, using Gaussian distribution and information-hiding technology. The licensee generates a digital image of the code and then uses an officially authorized printer to legally print the authentic product and paste it on the goods or documents for circulation. The forger does not have access to the original code digital image, so the process involves scanning, reprinting, and pasting the fake product or document on top of the original. Users upload codes by taking photos on their mobile phones, which can be used to verify authenticity. The code has abundant texture details and specific frequency characteristics which improve the anti-replication capability while maintaining the generality of the QR codes. An efficient quality assessment algorithm is also proposed to address possible blur in the authentication processing. The proposed method describes the DFT low-frequency region of a code and computes and compares its magnitude and azimuthal features to determine the presence and degree of blur. Finally, this paper proposes a dual feature detection algorithm that includes both a decodability analysis and DFT spectral features. Specially designed anti-counterfeiting textures will show different diffusion patterns after printing. The details of fake codes will be glued together in large quantities, the code points will be destroyed, and the decoding will fail. To ensure accuracy, this paper calculates the spectral similarity between the tested code and the sample code and further compares the eigenvalues in four feature regions. The contributions of this paper are as follows.
(1) This paper designs a texture-hidden anti-counterfeiting QR code to solve the problem of the easily illegally copied QR code. (2) An effective quality assessment algorithm is proposed to judge the type and degree of blur. (3) The proposed dual-feature detection algorithm is shown to cope with different forgery means, capture devices, and attack scenarios.
The paper is structured as follows: Section 2 introduces the design process of anticounterfeiting QR codes, Section 3 describes the quality assessment algorithm and the dual feature detection algorithm for the code, Section 4 presents the experimental effects in detail, and Section 5 concludes the paper.

The Design of Anti-Counterfeiting QR Codes
During the printing process of a digital pattern, the toner will be scattered randomly. Genuine codes only need to be printed once, while forged codes need to be printed at least twice, which can cause severe distortion. Realizing the above mechanism, this paper designs a texture-hidden QR code based on Gaussian distribution and information hiding to achieve an anti-copying effect. The code generation process is shown in Figure 2 and consists of three stages. The first stage is the generation process of an anti-counterfeiting texture. Random patterns generated from the Gaussian distribution function exhibit strong texture properties. Bilinear interpolation is used so that its gray level variation is moderately continuous, with more irregular gray level differences. Halftone operations are then performed by using error diffusion to bring the frequency of the digital code closer to the frequency sampled from the scanning and printing devices, and to improve signal aliasing during replication. The second stage is the refined process of the QR code. The semantic decoding process of QR codes first detects the position detection region and then detects the black and white code blocks. In this paper, the code points outside the position detection region and the calibration region are reduced, which does not affect the decoding. The third stage is the fusion of the above specially designed texture and the refined QR code at the code points. The anti-counterfeit code visually implements the information hiding of code points and has specific frequency characteristics, thus improving the anti-copy capability while maintaining the commonality of the QR code.
Step 1: Generate Gaussian random textures A random matrix is built from a Gaussian random generation function and visualized as a fine random texture pattern. The pattern and its enlarged detail are shown in Figure 3. Random patterns have the characteristics of a strong texture, and at the same time, have differences in each part, which increase the difficulty of counterfeiting. If the random variable g t follows a Gaussian distribution with expected value µ and standard deviation σ, its probability density function is: where µ determines the location of the distribution; σ determines the magnitude of the distribution; and g t is reconstructed into the matrix G (x,y) .  Step 1: Generate Gaussian random textures A random matrix is built from a Gaussian random generation function and visualized as a fine random texture pattern. The pattern and its enlarged detail are shown in Figure 3. Random patterns have the characteristics of a strong texture, and at the same time, have differences in each part, which increase the difficulty of counterfeiting. If the random variable follows a Gaussian distribution with expected value and standard deviation , its probability density function is: where determines the location of the distribution; determines the magnitude of the distribution; and is reconstructed into the matrix ( , ) . Step 2: Use bilinear interpolation operation Bilinear interpolation is to perform linear interpolation in both directions separately. Interpolation has the effect of low-pass filtering which can be anti-aliasing and effectively reduce some of the visual distortions caused by image scaling. Figure 4 shows the bilinear interpolated texture pattern and its enlarged detail. It can be seen that continuously varying grayscale levels are formed between pixels in the image details, with smooth patterns and increased low-frequency information. Bilinear interpolation takes the distance to the last four pixels as a reference weight and computes the integrated score by linearly interpolating it twice to obtain the pixel value of the current point. It can be expressed as follows:  Step 1: Generate Gaussian random textures A random matrix is built from a Gaussian random generat ized as a fine random texture pattern. The pattern and its enlar Figure 3. Random patterns have the characteristics of a strong time, have differences in each part, which increase the difficulty random variable follows a Gaussian distribution with expecte deviation , its probability density function is: where determines the location of the distribution; determin distribution; and is reconstructed into the matrix ( , ) . Step 2: Use bilinear interpolation operation Bilinear interpolation is to perform linear interpolation in bo Interpolation has the effect of low-pass filtering which can be ant reduce some of the visual distortions caused by image scaling. Fig interpolated texture pattern and its enlarged detail. It can be seen ing grayscale levels are formed between pixels in the image deta and increased low-frequency information. Bilinear interpolation last four pixels as a reference weight and computes the integrate polating it twice to obtain the pixel value of the current point. It lows: Step 2: Use bilinear interpolation operation Bilinear interpolation is to perform linear interpolation in both directions separately. Interpolation has the effect of low-pass filtering which can be anti-aliasing and effectively reduce some of the visual distortions caused by image scaling. Figure 4 shows the bilinear interpolated texture pattern and its enlarged detail. It can be seen that continuously varying grayscale levels are formed between pixels in the image details, with smooth patterns and increased low-frequency information. Bilinear interpolation takes the distance to the last four pixels as a reference weight and computes the integrated score by linearly interpolating it twice to obtain the pixel value of the current point. It can be expressed as follows: where G (x 1 ,y 1 ) , G (x 2 ,y 1 ) , G (x 1 ,y 2 ) , and G (x 2 ,y 2 ) are the known points, and P G (x 1 ,y 1 ) , P G (x 2 ,y 1 ) , P G (x 1 ,y 2 ) , and P G (x 2 ,y 2 ) are values of proportion; the closer points are more important.  Step 3: Adopt halftone treatment Since the printing device can only print black and white, th image must be processed into a binary halftone image in the print coverage area of small black and white dots that human eyes ca to simulate the gray level change of the image so that the binary possible to the original image. In this paper, the error diffusion m is adopted for the halftone processing of texture images, that is, and its neighboring pixels are processed, and the error (the differ output and the original image) generated on a pixel is dispersed t in a certain proportion. After the above operation, ( , ) is obtai texture pattern and its enlarged detail after the halftone treatmen Step 4: Refine QR code Step 3: Adopt halftone treatment Since the printing device can only print black and white, the continuous gray tone image must be processed into a binary halftone image in the printing process, and the unit coverage area of small black and white dots that human eyes cannot distinguish is used to simulate the gray level change of the image so that the binary image looks as close as possible to the original image. In this paper, the error diffusion method proposed by [33] is adopted for the halftone processing of texture images, that is, every pixel in the image and its neighboring pixels are processed, and the error (the difference between the actual output and the original image) generated on a pixel is dispersed to the surrounding pixels in a certain proportion. After the above operation, H (x,y) is obtained. Figure 5 shows the texture pattern and its enlarged detail after the halftone treatment.  Step 3: Adopt halftone treatment Since the printing device can only print black and white, th image must be processed into a binary halftone image in the print coverage area of small black and white dots that human eyes ca to simulate the gray level change of the image so that the binary possible to the original image. In this paper, the error diffusion m is adopted for the halftone processing of texture images, that is, and its neighboring pixels are processed, and the error (the differ output and the original image) generated on a pixel is dispersed t in a certain proportion. After the above operation, ( , ) is obtai texture pattern and its enlarged detail after the halftone treatmen Step 4: Refine QR code Figure 6 shows the QR code generated based on the ZXing o refined code. First, the horizontal pixel values of the location detec are calculated and divided by the corresponding ratio (1:1:3:1:1) component module size. Then, the position and size of the calib lated according to the ratio characteristics of 1:1:1:1:1. Finally, the Step 4: Refine QR code Figure 6 shows the QR code generated based on the Zxing open-source code and its refined code. First, the horizontal pixel values of the location detection area of the QR code are calculated and divided by the corresponding ratio (1:1:3:1:1) to obtain the minimum component module size. Then, the position and size of the calibration pattern are calculated according to the ratio characteristics of 1:1:1:1:1. Finally, the areas of the QR code are refined, except for the location detection area and calibration pattern, as follows: R(QR (x,y) ) = QR (x−a:x+a,y−a:y+a) , QR is the local center area 255, Others where QR (x,y) represents the value of the original QR code and a + 1 is the reduced local pixel size.
where ( , ) represents the value of the original QR code and + 1 is the reduced local pixel size. Step 5: Combine texture patterns and refined QR code Figure 7 shows the combined anti-counterfeiting texture code and its details. The code points in the code data region are minor and nearly integrated into the anti-counterfeiting background. Since the position detection area is complete and the original QR code has a maximum error correction capability of 30%, the semantics of the anti-counterfeiting code can still be decoded by the code scanning device. The position detection area, calibration area, and black and white code points of the refined QR code are unchanged, while the rest of the code is replaced with Gaussian random texture patterns. The formula for this is as follows: ( , ) , ℎ (7) Figure 7. Anti-counterfeiting QR code and its local enlarged detail. Figure 8 shows the capturing process of anti-counterfeiting codes. Anti-counterfeiting codes are generated, printed, and attached to product packages by manufacturers. Counterfeiters do not have access to the original digital image and can only scan a highquality printed code, which is then printed a second time after a series of image treatments. Consumers scan anti-counterfeiting codes through their mobile phones and other devices which then authenticates them. Step 5: Combine texture patterns and refined QR code Figure 7 shows the combined anti-counterfeiting texture code and its details. The code points in the code data region are minor and nearly integrated into the anti-counterfeiting background. Since the position detection area is complete and the original QR code has a maximum error correction capability of 30%, the semantics of the anti-counterfeiting code can still be decoded by the code scanning device. The position detection area, calibration area, and black and white code points of the refined QR code are unchanged, while the rest of the code is replaced with Gaussian random texture patterns. The formula for this is as follows:

The Capturing Process of Anti-Counterfeiting Codes
Sensors 2023, 23, x FOR PEER REVIEW 6 of 24 where ( , ) represents the value of the original QR code and + 1 is the reduced local pixel size. Step 5: Combine texture patterns and refined QR code Figure 7 shows the combined anti-counterfeiting texture code and its details. The code points in the code data region are minor and nearly integrated into the anti-counterfeiting background. Since the position detection area is complete and the original QR code has a maximum error correction capability of 30%, the semantics of the anti-counterfeiting code can still be decoded by the code scanning device. The position detection area, calibration area, and black and white code points of the refined QR code are unchanged, while the rest of the code is replaced with Gaussian random texture patterns. The formula for this is as follows: ( , ) , ℎ (7) Figure 7. Anti-counterfeiting QR code and its local enlarged detail. Figure 8 shows the capturing process of anti-counterfeiting codes. Anti-counterfeiting codes are generated, printed, and attached to product packages by manufacturers. Counterfeiters do not have access to the original digital image and can only scan a highquality printed code, which is then printed a second time after a series of image treatments. Consumers scan anti-counterfeiting codes through their mobile phones and other devices which then authenticates them.  Figure 8 shows the capturing process of anti-counterfeiting codes. Anti-counterfeiting codes are generated, printed, and attached to product packages by manufacturers. Counterfeiters do not have access to the original digital image and can only scan a high-quality printed code, which is then printed a second time after a series of image treatments. Consumers scan anti-counterfeiting codes through their mobile phones and other devices which then authenticates them. As shown in Figure 9, the authentication process of the proposed anti-counterfeiting code consists of a quality assessment and dual-feature authentication. In the first stage, the image quality of the anti-counterfeiting code needs to be evaluated. Only anti-counterfeiting codes that meet the sharpness criteria will be tested. If they do not meet the criteria, the consumer is prompted to re-shoot. The second stage consists of a decodability analysis and DFT spectral feature detection. The former identifies whether the anti-counterfeiting code to be tested can be deciphered. If it cannot be decoded, it is directly judged as a fake. If it can be decoded, it is sent to the latter, which uses the decoded QR code semantic as an index to find the corresponding sample code in the sample database and compares it to compute the DFT spectral properties. If the similarity is greater than a threshold, it is judged as a fake, otherwise, it is judged as a genuine product. The combination of decodability and spectral features will improve detection efficiency while ensuring accuracy.  As shown in Figure 9, the authentication process of the proposed anti-counterfeiting code consists of a quality assessment and dual-feature authentication. In the first stage, the image quality of the anti-counterfeiting code needs to be evaluated. Only anti-counterfeiting codes that meet the sharpness criteria will be tested. If they do not meet the criteria, the consumer is prompted to re-shoot. The second stage consists of a decodability analysis and DFT spectral feature detection. The former identifies whether the anti-counterfeiting code to be tested can be deciphered. If it cannot be decoded, it is directly judged as a fake. If it can be decoded, it is sent to the latter, which uses the decoded QR code semantic as an index to find the corresponding sample code in the sample database and compares it to compute the DFT spectral properties. If the similarity is greater than a threshold, it is judged as a fake, otherwise, it is judged as a genuine product. The combination of decodability and spectral features will improve detection efficiency while ensuring accuracy. As shown in Figure 9, the authentication process of the proposed anti-counterfeitin code consists of a quality assessment and dual-feature authentication. In the first stage the image quality of the anti-counterfeiting code needs to be evaluated. Only anti-coun terfeiting codes that meet the sharpness criteria will be tested. If they do not meet th criteria, the consumer is prompted to re-shoot. The second stage consists of a decodabilit analysis and DFT spectral feature detection. The former identifies whether the anti-coun terfeiting code to be tested can be deciphered. If it cannot be decoded, it is directly judge as a fake. If it can be decoded, it is sent to the latter, which uses the decoded QR cod semantic as an index to find the corresponding sample code in the sample database an compares it to compute the DFT spectral properties. If the similarity is greater than threshold, it is judged as a fake, otherwise, it is judged as a genuine product. The comb nation of decodability and spectral features will improve detection efficiency while ensur ing accuracy.

Quality Assessment Algorithm
The captured anti-counterfeiting codes may be blurred due to various factors such as environment, equipment, habit, etc. which typically manifest as defocus blur and motion blur. A clear code is particularly crucial for subsequent authentication. This paper transforms the code in the DFT frequency domain and calculates the magnitude and azimuthal characteristics of the low-frequency region to determine the type and degree of blur. The defocus blur is due to the incomplete coincidence of the image plane with the detector's receptive plane, resulting in the lens not being clustered. Motion blur is caused by the relative motion between the image and the camera that captured it. The texture and edges of the image will become blurred, and its general expression is: where q(x, y) is the output image; p(x, y) is the input image; h(x, y) is the point spread function; n(x, y) is the noise; and ⊗ is the convolution operation. The main difference between the two blurs is h(x, y), in defocus blur, h(x, y) is symmetrically distributed about the center of the circle, and in motion blur, h(x, y) is asymmetric and related to both the angle and the length of the motion.
For defocus blur, h(x, y) can be expressed as: where r is the radius of the blur spot. For motion blur, h(x, y) can be expressed as: where R(θ) is a rotation matrix, which represents the rotation angle, and D is the displacement of the movement. The proposed anti-counterfeiting code is characterized by slow and continuous grayscale variations between pixels, as well as rich low-frequency information. Therefore, it is used to evaluate the quality of the anti-counterfeiting code based on the DFT spectral image features. It can be translated into a frequency domain operation and can be written, regardless of noise, as: where P(u, v), Q(u, v), and H(u, v) are the 2D DFT transforms of p(x, y), q(x, y), and h(x, y), respectively. Figure 10 shows one clear and four blurred codes, including their DFT spectrograms. It is obvious that the low-frequency region of a clear code is concentrated in an approximate rectangle. For defocus blur codes, the larger the blur radius, the fainter it appears to the naked eye, the more regular the circle formed by the low-frequency region of its Fourier spectrum, and the smaller the spectrum radius. For motion blur codes, the low-frequency region of the spectrum has an elliptical fringe with a fringe width inversely proportional to the displacement length and a fringe direction perpendicular to the displacement direction. Based on the blurred images above, it can be seen that the shape of the low-frequency region is strongly characterized by its magnitude and azimuthal features, as shown in Figure 11. The quality assessment algorithm, MAF, in this paper is described in detail below:  Step 1: Transform to the DFT domain and calculate low-frequency values in fou rections. (1) Perform DFT frequency domain transformation on the anti-counterfei code, (2) move the DC component to the center of the spectrum, (3) calculate the norm ization of the spectrum amplitude, (4) perform threshold process to obtain a binar spectrogram, and (5) calculate ， ， , and (white areas in the spectrogram the four directions of X-axis, Y-axis, X'-axis, and Y'-axis.
Step 2: Determine how blurred the image is and calculate the quality score of the c according to the following formula: and describe the magnitude feature and the azimuthal feature of the l   Step 1: Transform to the DFT domain and calculate low-freq rections. (1) Perform DFT frequency domain transformation on code, (2) move the DC component to the center of the spectrum, ization of the spectrum amplitude, (4) perform threshold proce spectrogram, and (5) calculate ， ， , and (white area the four directions of X-axis, Y-axis, X'-axis, and Y'-axis.
Step 2: Determine how blurred the image is and calculate the according to the following formula: = + Figure 11. DFT spectrum of an anti-counterfeiting code.
Step 1: Transform to the DFT domain and calculate low-frequency values in four directions. (1) Perform DFT frequency domain transformation on the anti-counterfeiting code, (2) move the DC component to the center of the spectrum, (3) calculate the normalization of the spectrum amplitude, (4) perform threshold process to obtain a binarized spectrogram, and (5) calculate C X , C Y , C X , and C Y (white areas in the spectrogram) in the four directions of X-axis, Y-axis, X'-axis, and Y'-axis.
Step 2: Determine how blurred the image is and calculate the quality score of the code according to the following formula: where MF and AF describe the magnitude feature and the azimuthal feature of the lowfrequency region of the anti-counterfeiting code, respectively. The MAF is the quality score which is proportional to the sharpness of the code. If the score is greater than the threshold k, the code is determined to be clear, otherwise, the code is determined to be blurred.
Step 3: Determine the type of blurred code by using the following relation: where pro1 and pro2 are the ratios of low-frequency regions on both axes, and the type of blur can be judged based on the values of pro1 and pro2. The di f is the error value; if pro1 > 1 − di f and pro2 > 1 − di f , the code is a defocused blur, otherwise the code is a motion blur.

Decodability Analysis
In this paper, random texture patterns are combined with refined QR codes to generate anti-counterfeiting codes. Due to the integration of QR codes, anti-counterfeiting codes do not require other special position symbols or marked information and can be directly decoded by a decoding program.
Printing or capturing comes with channel distortion and noise, and the decodability varies after the code is passed through different channels. For genuine codes that have been printed and captured only once, the resulting distortion and noise are small, and codes can still be recognized by the decoding device. For illegal channels that undergo multiple replicas, more severe distortions and noise are generated, with obvious forgery traces, and substantial texture details are lost. Stochastic diffusion phenomena exhibit different diffusion patterns, which can cause decoding to fail. Therefore, the decodability of the code to be tested can be used as an evaluation metric, and those codes that cannot be decoded are identified as fakes.
In the actual process of counterfeiting, the counterfeiters resort to superior-quality enlarged copies. On the one hand, consumers generally do not know the size of the code. The original size of the code is generally small, and a copy enlarged within two times will not make a particularly noticeable difference. On the other hand, product packaging includes not only a single outer package but also a boxed package. The use of enlarged anti-counterfeiting codes on the whole box packaging is not against the law and will deceive consumers. As shown in Figure 12, it can be seen that the texture details of the genuine code are rich, while the counterfeit code is glued and cannot be decoded by a code decoding device and can therefore be directly identified as a fake. The enlarged copies reconstruct texture details better than the equal copy, part of the codes can be decoded, and the first-level feature fails. Therefore, to ensure accuracy, it is also necessary to send the decoded code to the second-level detection, the DFT spectral feature.
counterfeiting codes on the whole box packaging is not against the law and will deceive consumers. As shown in Figure 12, it can be seen that the texture details of the genuine code are rich, while the counterfeit code is glued and cannot be decoded by a code decoding device and can therefore be directly identified as a fake. The enlarged copies reconstruct texture details better than the equal copy, part of the codes can be decoded, and the first-level feature fails. Therefore, to ensure accuracy, it is also necessary to send the decoded code to the second-level detection, the DFT spectral feature.

DFT Spectral Feature
The code can be regarded as a 2D discrete signal. The Discrete Fourier Transform (DFT) decomposes the signal into several sinusoidal plane waves and converts the code from the spatial domain to the frequency domain. It can be represented by the following equation: where x and y are values of the space domain; u and v are values of the frequency domain, u takes 0 to M − 1, v takes 0 to N − 1; and F(u, v) is the transform coefficients of f (x, y). F(u, v) can also be expressed as: where ∅(u, v) is the transformed phase angle; R(u, v) and I(u, v) denote, respectively, real and imaginary parts of F(u, v); F(u, v) is periodic and symmetric, which states that the Fourier spectral magnitude is concentrated at the origin: The frequency of an image represents the grayscale gradient, which represents the difference between a point and its neighborhood on a grayscale image. Figure 13 shows the spectrogram of a genuine anti-counterfeiting code and Figure 14 shows the spectrograms of the counterfeit codes at different scales. Regions where the grayscale varies gradually are represented by low-frequency coefficients and mainly include contours. The region where the grayscale changes sharply are represented by high-frequency coefficients, which mainly include noise and edges. Important feature points of the genuine code are clear and symmetric, but the points of the counterfeit code essentially vanish. difference between a point and its neighborhood on a grayscale image. Figure 13 shows the spectrogram of a genuine anti-counterfeiting code and Figure 14 shows the spectrograms of the counterfeit codes at different scales. Regions where the grayscale varies gradually are represented by low-frequency coefficients and mainly include contours. The region where the grayscale changes sharply are represented by high-frequency coefficients, which mainly include noise and edges. Important feature points of the genuine code are clear and symmetric, but the points of the counterfeit code essentially vanish.  In this paper, the macro structure information and micro structure information of the code are extracted for authentication. The Normalized Correlation (NC) can be used to measure the overall spectral similarity between the code to be tested and the corresponding sample code to be obtained to yield the score of the objective evaluation, the formula for which is: where and are the row and column of the spectrogram; the is between 0 and 1.
A larger indicates a higher similarity between two images. However, the overall features of some counterfeit codes are not significantly different from the genuine ones, but the differences in local features are more pronounced. Thus, this paper proposes the Pixel Ratio ( ) to extract four characteristic regions from the spectrogram. The higher the proportion of low-frequency in the characteristic region, the more likely it is to be a genuine code. The can describe this feature according to the following formula: where is the w-th characteristic region; ( , ) is the pixel value of the w-th characteristic region, which ranges from 0 to 255; and is the pixel length of a characteristic region; the is between 0 and 1. Authentication can be achieved most effectively if the two metrics ( and ) are combined, here named _ . Only if ≥ 1 and ≥ 2 is the code judged to be a genuine code, otherwise it is judged to be a counterfeit code. Here, both 1 and 2 are thresholds and can be selected to have values in a certain range.

The Design Parameters of Anti-Counterfeiting Codes
The design parameters of the anti-counterfeiting code include the size of the code points, the expectation value of the random distribution, and the size of the physical print. Proper parameters can make the decoding of the counterfeit code fail to the greatest ex- In this paper, the macro structure information and micro structure information of the code are extracted for authentication. The Normalized Correlation (NC) can be used to measure the overall spectral similarity between the code to be tested T and the corresponding sample code to be obtained S to yield the score of the objective evaluation, the formula for which is: where M and N are the row and column of the spectrogram; the NC is between 0 and 1. A larger NC indicates a higher similarity between two images. However, the overall features of some counterfeit codes are not significantly different from the genuine ones, but the differences in local features are more pronounced. Thus, this paper proposes the Pixel Ratio (PR) to extract four characteristic regions from the spectrogram. The higher the proportion of low-frequency in the characteristic region, the more likely it is to be a genuine code. The PR can describe this feature according to the following formula: where w is the w-th characteristic region; C w (x, y) is the pixel value of the w-th characteristic region, which ranges from 0 to 255; and d is the pixel length of a characteristic region; the PR is between 0 and 1. Authentication can be achieved most effectively if the two metrics (NC and PR) are combined, here named NC_PR. Only if NC ≥ k1 and PR ≥ k2 is the code judged to be a genuine code, otherwise it is judged to be a counterfeit code. Here, both k1 and k2 are thresholds and can be selected to have values in a certain range.

The Design Parameters of Anti-Counterfeiting Codes
The design parameters of the anti-counterfeiting code include the size of the code points, the expectation value of the random distribution, and the size of the physical print. Proper parameters can make the decoding of the counterfeit code fail to the greatest extent, provided that the decoding of the genuine code is guaranteed. This paper experimentally tests the effect of different parameters on the decoding performance and finally selects the parameters.

Size of Code Points
After selecting version number 3 and error correction level H to generate the original QR code, the modules of the QR code need to be refined to code points. The larger the code points, the more visual it is, the faster the decoding, and the smaller the area of the texture pattern. Thus, it is necessary to choose an appropriate code point size. Figure 15 shows anti-counterfeiting codes with different code points sizes of 2 × 2, 3 × 3, 4 × 4, 5 × 5, 6 × 6, and 7 × 7 and their enlarged details. texture pattern. Thus, it is necessary to choose an appropriate code point size. Figure 15 shows anti-counterfeiting codes with different code points sizes of 2 × 2, 3 × 3, 4 × 4, 5 × 5, 6 × 6, and 7 × 7 and their enlarged details. Five genuine codes with code points sizes of 2 × 2, 3 × 3, 4 × 4, 5 × 5, 6 × 6, and 7 × 7 are generated, among which, the expectation of Gaussian distribution is selected as 120, the physical print size is 1.2 cm, and the pixel size is 580 × 580. After printing, the same printer is used for copying and enlarging to obtain 15 counterfeit codes, for a total of 30 genuine codes and 90 counterfeit codes in six groups. The decoding experiment is shown in Figure 16. It can be seen that when the pixel sizes of the code points are 2 × 2, 3 × 3, and 4 × 4, the genuine codes cannot be decoded 100%, so they cannot be applied to the anticounterfeiting code. When the pixel sizes of the code points are 5 × 5, 6 × 6, and 7 × 7, all genuine codes can be fully decoded and the decoding rates of the fake codes are 13%, 53%, and 100%, respectively. Therefore, considering the comprehensive guarantee of the decoding robustness of genuine codes and the decoding fragility of counterfeit codes, the size of code points is selected as 5 × 5 pixels.

Expectation of Gaussian Distribution
In the generation stage of anti-counterfeiting texture patterns, a random distribution function is used to generate detailed random texture patterns. The different Gaussian random distribution expectation ( ) determines the mean level of the pixel value of the tex- Five genuine codes with code points sizes of 2 × 2, 3 × 3, 4 × 4, 5 × 5, 6 × 6, and 7 × 7 are generated, among which, the expectation of Gaussian distribution is selected as 120, the physical print size is 1.2 cm, and the pixel size is 580 × 580. After printing, the same printer is used for copying and enlarging to obtain 15 counterfeit codes, for a total of 30 genuine codes and 90 counterfeit codes in six groups. The decoding experiment is shown in Figure 16. It can be seen that when the pixel sizes of the code points are 2 × 2, 3 × 3, and 4 × 4, the genuine codes cannot be decoded 100%, so they cannot be applied to the anti-counterfeiting code. When the pixel sizes of the code points are 5 × 5, 6 × 6, and 7 × 7, all genuine codes can be fully decoded and the decoding rates of the fake codes are 13%, 53%, and 100%, respectively. Therefore, considering the comprehensive guarantee of the decoding robustness of genuine codes and the decoding fragility of counterfeit codes, the size of code points is selected as 5 × 5 pixels.
Sensors 2023, 23, x FOR PEER REVIEW 13 of 24 texture pattern. Thus, it is necessary to choose an appropriate code point size. Figure 15 shows anti-counterfeiting codes with different code points sizes of 2 × 2, 3 × 3, 4 × 4, 5 × 5, 6 × 6, and 7 × 7 and their enlarged details. Five genuine codes with code points sizes of 2 × 2, 3 × 3, 4 × 4, 5 × 5, 6 × 6, and 7 × 7 are generated, among which, the expectation of Gaussian distribution is selected as 120, the physical print size is 1.2 cm, and the pixel size is 580 × 580. After printing, the same printer is used for copying and enlarging to obtain 15 counterfeit codes, for a total of 30 genuine codes and 90 counterfeit codes in six groups. The decoding experiment is shown in Figure 16. It can be seen that when the pixel sizes of the code points are 2 × 2, 3 × 3, and 4 × 4, the genuine codes cannot be decoded 100%, so they cannot be applied to the anticounterfeiting code. When the pixel sizes of the code points are 5 × 5, 6 × 6, and 7 × 7, all genuine codes can be fully decoded and the decoding rates of the fake codes are 13%, 53%, and 100%, respectively. Therefore, considering the comprehensive guarantee of the decoding robustness of genuine codes and the decoding fragility of counterfeit codes, the size of code points is selected as 5 × 5 pixels.

Expectation of Gaussian Distribution
In the generation stage of anti-counterfeiting texture patterns, a random distribution function is used to generate detailed random texture patterns. The different Gaussian random distribution expectation ( ) determines the mean level of the pixel value of the tex-

Expectation of Gaussian Distribution
In the generation stage of anti-counterfeiting texture patterns, a random distribution function is used to generate detailed random texture patterns. The different Gaussian random distribution expectation (µ) determines the mean level of the pixel value of the texture patterns, which affects the visual effect of texture patterns and the decoding performance after combining with the QR code. The higher the µ, the higher the mean of pixels and the whiter the visual appearance; the lower the µ, the lower the mean of pixels and the darker the pattern tone. Figure 17 shows the codes with a µ of 80, 100, 120, and 140. Five codes with Gaussian expectations of 80, 100, 120, and 140 are generated. Among them, the QR code version and error correction level are 3 and H, the code point size is 5 × 5, the print size is 1.2 cm, and the pixel size is 580 × 580. After printing, the same printer was used to copy and enlarge the copy to obtain 15 fake codes. In total, there are 20 authentic and 60 counterfeit codes. The decoding experiments were then performed and the results are shown in Figure 18. As can be seen, only the μ value of 120 and above can guarantee the decoding rate of the genuine code is 100%. When the μ value is 120, the decoding rate of the fake code is 13%, when the mu value is 140, the decoding rate of the fake code is 20%. At this time, the image field of view is white, the code points are obvious, and the code points are not well hidden. Therefore, in order to consider the visual hiding effect of code points and ensure the gap between the genuine and fake decoding rate, the μ is selected as 120 in this paper.

Size of Physical Print
After the anti-counterfeiting code is generated, the code is printed and made into a label. Different print sizes can affect the decoding performance of the code. The larger the physical print size, the more complete the details and the easier the code to decode. Similarly, counterfeit codes that have been illegally copied can be easily decoded. Figure 19 shows the codes and their enlarged details for the print sizes 0.8 cm, 1 cm, 1.2 cm, 1.5 cm, and 2 cm. DPI is an important parameter that describes the printing accuracy of a printer. The higher the DPI, the more points are displayed within an inch, and the higher the printing accuracy. Current market circulation printers are generally 600 DPI or 1200 DPI. Different print sizes correspond to different pixel sizes, which are formulated as follows: where is the actual physical printed size. Five codes with Gaussian expectations of 80, 100, 120, and 140 are generated. Among them, the QR code version and error correction level are 3 and H, the code point size is 5 × 5, the print size is 1.2 cm, and the pixel size is 580 × 580. After printing, the same printer was used to copy and enlarge the copy to obtain 15 fake codes. In total, there are 20 authentic and 60 counterfeit codes. The decoding experiments were then performed and the results are shown in Figure 18. As can be seen, only the µ value of 120 and above can guarantee the decoding rate of the genuine code is 100%. When the µ value is 120, the decoding rate of the fake code is 13%, when the mu value is 140, the decoding rate of the fake code is 20%. At this time, the image field of view is white, the code points are obvious, and the code points are not well hidden. Therefore, in order to consider the visual hiding effect of code points and ensure the gap between the genuine and fake decoding rate, the µ is selected as 120 in this paper. Five codes with Gaussian expectations of 80, 100, 120, and 140 are generated. A them, the QR code version and error correction level are 3 and H, the code point si × 5, the print size is 1.2 cm, and the pixel size is 580 × 580. After printing, the same p was used to copy and enlarge the copy to obtain 15 fake codes. In total, there are thentic and 60 counterfeit codes. The decoding experiments were then performed a results are shown in Figure 18. As can be seen, only the μ value of 120 and abov guarantee the decoding rate of the genuine code is 100%. When the μ value is 12 decoding rate of the fake code is 13%, when the mu value is 140, the decoding rate fake code is 20%. At this time, the image field of view is white, the code points are ob and the code points are not well hidden. Therefore, in order to consider the visual h effect of code points and ensure the gap between the genuine and fake decoding ra μ is selected as 120 in this paper.

Size of Physical Print
After the anti-counterfeiting code is generated, the code is printed and made label. Different print sizes can affect the decoding performance of the code. The larg physical print size, the more complete the details and the easier the code to decode. larly, counterfeit codes that have been illegally copied can be easily decoded. Fig  shows the codes and their enlarged details for the print sizes 0.8 cm, 1 cm, 1.2 cm, 1  and 2 cm. DPI is an important parameter that describes the printing accuracy of a p The higher the DPI, the more points are displayed within an inch, and the high printing accuracy. Current market circulation printers are generally 600 DPI or 120

Size of Physical Print
After the anti-counterfeiting code is generated, the code is printed and made into a label. Different print sizes can affect the decoding performance of the code. The larger the physical print size, the more complete the details and the easier the code to decode. Similarly, counterfeit codes that have been illegally copied can be easily decoded. Figure 19 shows the codes and their enlarged details for the print sizes 0.8 cm, 1 cm, 1.2 cm, 1.5 cm, and 2 cm. DPI is an important parameter that describes the printing accuracy of a printer. The higher the DPI, the more points are displayed within an inch, and the higher the printing accuracy. Current market circulation printers are generally 600 DPI or 1200 DPI. Different print sizes correspond to different pixel sizes, which are formulated as follows: where unit is the actual physical printed size. Five codes with print sizes of 0.8 cm, 1 cm, 1.2 cm, 1.5 cm, and 2 cm are generated and printed. Among them, the QR code version and error correction level are 3 and H, and the code point sizes are all 5 × 5. Therefore, the pixel sizes are 348 × 348, 464 × 464, 580 × 580, 696 × 696, and 928 × 928, respectively. After that, the same printer is used to copy and enlarge the copy, resulting in 15 fake codes. The five groups have a total of 25 genuine codes and 75 fake codes. The decoding results are shown in Figure 20, where it can be seen that the decoding accuracy of the genuine codes is not guaranteed when the print size is below 1.2 cm. In contrast, when the print size is larger than 1.5 cm, the decoding accuracy of the counterfeit codes is not guaranteed. Therefore, the print size of 1.2 cm is chosen in this paper to maximize the decoding performance for both genuine and fake products.

Datasets
In this paper, three datasets are constructed: the genuine and counterfeit codes dataset, the attacked codes dataset, and the quality assessment codes dataset. Of these, the first one is used to test the performance of the algorithm, the second one includes genuine codes with different cutting proportions and sizes to test the anti-attacking of the algorithm, and the third one is used to test the performance of the proposed quality assessment algorithm.
(1) Genuine and counterfeit codes dataset Five codes with print sizes of 0.8 cm, 1 cm, 1.2 cm, 1.5 cm, and 2 cm are generated and printed. Among them, the QR code version and error correction level are 3 and H, and the code point sizes are all 5 × 5. Therefore, the pixel sizes are 348 × 348, 464 × 464, 580 × 580, 696 × 696, and 928 × 928, respectively. After that, the same printer is used to copy and enlarge the copy, resulting in 15 fake codes. The five groups have a total of 25 genuine codes and 75 fake codes. The decoding results are shown in Figure 20, where it can be seen that the decoding accuracy of the genuine codes is not guaranteed when the print size is below 1.2 cm. In contrast, when the print size is larger than 1.5 cm, the decoding accuracy of the counterfeit codes is not guaranteed. Therefore, the print size of 1.2 cm is chosen in this paper to maximize the decoding performance for both genuine and fake products.
Sensors 2023, 23, x FOR PEER REVIEW 1 Figure 19. Anti-counterfeiting codes with different sizes of physical print and their enlarged d Five codes with print sizes of 0.8 cm, 1 cm, 1.2 cm, 1.5 cm, and 2 cm are gene and printed. Among them, the QR code version and error correction level are 3 a and the code point sizes are all 5 × 5. Therefore, the pixel sizes are 348 × 348, 464 × 46 × 580, 696 × 696, and 928 × 928, respectively. After that, the same printer is used to and enlarge the copy, resulting in 15 fake codes. The five groups have a total of 25 ge codes and 75 fake codes. The decoding results are shown in Figure 20, where it can b that the decoding accuracy of the genuine codes is not guaranteed when the print below 1.2 cm. In contrast, when the print size is larger than 1.5 cm, the decoding acc of the counterfeit codes is not guaranteed. Therefore, the print size of 1.2 cm is cho this paper to maximize the decoding performance for both genuine and fake produ

Datasets
In this paper, three datasets are constructed: the genuine and counterfeit cod taset, the attacked codes dataset, and the quality assessment codes dataset. Of thes first one is used to test the performance of the algorithm, the second one includes ge

Datasets
In this paper, three datasets are constructed: the genuine and counterfeit codes dataset, the attacked codes dataset, and the quality assessment codes dataset. Of these, the first one is used to test the performance of the algorithm, the second one includes genuine codes with different cutting proportions and sizes to test the anti-attacking of the algorithm, and the third one is used to test the performance of the proposed quality assessment algorithm.
(1) Genuine and counterfeit codes dataset Generate genuine and counterfeit paper codes: a computer generates 10 electronic codes with different semantics, and then prints out 10 paper codes. After that, ten printers of different brands or models, including the official one, are used to make an equal copy. Then, eight printers are used to make 1.5 times and 2 times enlarged copies of the original code, resulting in 260 counterfeit paper codes. Collect sample codes: the portable microscope camera, Anyty, is used to collect 10 genuine paper codes. Collect genuine and counterfeit codes: six mobile phones of different brands or models are used to photograph each paper genuine code five times in different environments. In addition, the mobiles are used to take pictures of each paper counterfeit code one time. The dataset consists of 10 groups, each with a different 16-bit random number for the semantics of the codes. The data of each group includes 1 sample code, 30 genuine codes, and 156 counterfeit codes (among them, 60 are 1 time copies, 48 are 1.5 times copies, and 48 are 2 times copies). The dataset information is shown in Table 1. (2) Attacked codes dataset Since counterfeit codes will not be recognized as genuine after the attack, only an attack on the genuine codes is performed to check the authenticity algorithm. The size of the 300 genuine codes is reduced in various proportions to 12%, 24%, 36%, and 48% of the original code size. The 300 genuine codes are cut to different degrees, with cut areas of 1%, 3%, 5%, 7%, and 9% of the original code. Figure 21 shows the legend for codes with different reduced proportions and cut ratios. The dataset information is shown in Table 2. Generate genuine and counterfeit paper codes: a computer generates 10 electronic codes with different semantics, and then prints out 10 paper codes. After that, ten printers of different brands or models, including the official one, are used to make an equal copy. Then, eight printers are used to make 1.5 times and 2 times enlarged copies of the original code, resulting in 260 counterfeit paper codes. Collect sample codes: the portable microscope camera, Anyty, is used to collect 10 genuine paper codes. Collect genuine and counterfeit codes: six mobile phones of different brands or models are used to photograph each paper genuine code five times in different environments. In addition, the mobiles are used to take pictures of each paper counterfeit code one time. The dataset consists of 10 groups, each with a different 16-bit random number for the semantics of the codes. The data of each group includes 1 sample code, 30 genuine codes, and 156 counterfeit codes (among them, 60 are 1 time copies, 48 are 1.5 times copies, and 48 are 2 times copies). The dataset information is shown in Table 1. (2) Attacked codes dataset Since counterfeit codes will not be recognized as genuine after the attack, only an attack on the genuine codes is performed to check the authenticity algorithm. The size of the 300 genuine codes is reduced in various proportions to 12%, 24%, 36%, and 48% of the original code size. The 300 genuine codes are cut to different degrees, with cut areas of 1%, 3%, 5%, 7%, and 9% of the original code. Figure 21 shows the legend for codes with different reduced proportions and cut ratios. The dataset information is shown in Table 2.    (3) Quality assessment codes dataset Different degrees of defocus blur (1, 2, 3, 4, and 5) and motion blur (1, 2, 3, 4, and 5) are added to 300 clear digital genuine codes to test the performance of the quality assessment algorithm in this paper. The dataset is presented in Table 3. In the experiments, the printer information used for printing and copying is shown in Table 4, and the smartphone information used for collecting is shown in Table 5. Table 3. Quality assessment codes dataset.

Evaluation Metrics
To evaluate the performance of the anti-counterfeiting codes and algorithms, three evaluation metrics are formulated as follows: where TP denotes the number of genuine codes judged to be genuine, FN denotes the number of genuine codes judged to be counterfeit, FP denotes the number of counterfeit codes judged to be genuine, and TN denotes the number of counterfeit codes judged to be counterfeit.
For the methods that need to be trained and tested, the following experiments randomly select half of the Table 1 dataset as the training set, however, the testing set is different, which is displayed in the following experiments. The final evaluation metric is the average accuracy of the five experiments randomly combined.

Quality Assessment Algorithm Experiments
The dataset shown in Table 3 is used to validate the effectiveness of the proposed quality assessment algorithm, which is compared with several common algorithms, including Variance, Information Entropy, Tenengrad Gradient, and Fuzzy Probability. The results are shown in Table 6. In this paper, the optimal threshold is chosen by the smaller intra-class variance and the larger inter-class variance. Variance, Information Entropy, and Fuzzy Probability are almost ineffective, and the scores of clear and blurry images are mixed in large numbers. The Tenengrad Gradient can be distinguished to some extent, but there is a large number of crossings. It can be seen that the proposed method outperforms other methods in terms of accuracy, precision, and recall. At the same time, the gap between the other four algorithms is not obvious. Meanwhile, the quality evaluation method in this paper is able to further distinguish the blur types with 95% accuracy for blurred codes. The specific results are shown in Table 7. The time consumption for processing one code is shown in Figure 22.  Judging whether the code can be decoded correctly is the first p process which can quickly screen out counterfeit codes. In this pa counterfeit codes dataset (Table 1) is decoded through the QR cod and the result is shown in Table 8. It can be seen that the genuine cod decoded, while the counterfeit codes with an equal ratio have a 5.83%. However, the enlarged copy codes can reconstruct more de

Decodability Analysis
Judging whether the code can be decoded correctly is the first part of the authenticity process which can quickly screen out counterfeit codes. In this paper, the genuine and counterfeit codes dataset (Table 1) is decoded through the QR code decoding program, and the result is shown in Table 8. It can be seen that the genuine codes can be successfully decoded, while the counterfeit codes with an equal ratio have a decoding rate of only 5.83%. However, the enlarged copy codes can reconstruct more details and the decoding rate is significantly improved. The decoding rate is 17.5% for the 1.5 times copy codes and higher for the 2 times copy codes, up to 22.50%. Thus, the genuine code is not necessarily the only one successfully decoded, and the algorithm needs to be further checked to ensure accuracy. QR codes have some error correction capability and up to 30% of the area covered can still be correctly decoded. In this paper, patterns with anti-counterfeiting capability are incorporated into QR codes to ensure some degree of error correction capability. Figure 23a shows the decoding for codes with different reduced proportions. It can be seen that the smaller the proportion, the lower the decoding accuracy. The anti-counterfeiting codes in this paper are resistant to up to 48%. As can be seen in Figure 23b, codes with a maximum cut area of up to 5% can still be guaranteed to decode 100%. In the actual decoding process, the image sizes are also different due to the differences in mobile devices. are incorporated into QR codes to ensure some degree of error correction capability. Figure 23a shows the decoding for codes with different reduced proportions. It can be seen that the smaller the proportion, the lower the decoding accuracy. The anti-counterfeiting codes in this paper are resistant to up to 48%. As can be seen in Figure 23b, codes with a maximum cut area of up to 5% can still be guaranteed to decode 100%. In the actual decoding process, the image sizes are also different due to the differences in mobile devices.   Table 2 dataset.

DFT Spectral Feature
The comparison of DFT spectral features is the second part of the discrimination procedure to ensure accuracy. The test consists of two metrics: NC and PR, and a code is identified as genuine only if both metrics reach a threshold. Figure 24a,b shows scatter plots of the two metrics for genuine and counterfeit codes. It can be seen that the distinction between codes is obvious, but there is some crossover in the middle region. To improve the accuracy, the appropriate threshold should be chosen experimentally. Figure  24c,d shows the accuracy results for the genuine and counterfeit codes when the two metrics are chosen with different thresholds. When the NC is in the range of 0.88 to 0.90 and the PR is in the range of 0.4 to 0.5, the accuracy can reach a high level. After selecting the threshold values for the NC and PR, the algorithm is further evaluated, and the result is shown in Table 9. It can be seen that with double feature detection, NC_PR, achieves 100% accuracy, precision, and recall, which is better than using either the NC value or the PR value alone.

DFT Spectral Feature
The comparison of DFT spectral features is the second part of the discrimination procedure to ensure accuracy. The test consists of two metrics: NC and PR, and a code is identified as genuine only if both metrics reach a threshold. Figure 24a,b shows scatter plots of the two metrics for genuine and counterfeit codes. It can be seen that the distinction between codes is obvious, but there is some crossover in the middle region. To improve the accuracy, the appropriate threshold should be chosen experimentally. Figure 24c,d shows the accuracy results for the genuine and counterfeit codes when the two metrics are chosen with different thresholds. When the NC is in the range of 0.88 to 0.90 and the PR is in the range of 0.4 to 0.5, the accuracy can reach a high level. After selecting the threshold values for the NC and PR, the algorithm is further evaluated, and the result is shown in Table 9. It can be seen that with double feature detection, NC_PR, achieves 100% accuracy, precision, and recall, which is better than using either the NC value or the PR value alone.    To further verify the superiority of the proposed dual feature algorithm, the genuine and counterfeit codes dataset shown in Table 1 is used to compare it with several existing popular texture methods and corner methods. For the methods that need to be trained and tested, the following experiments randomly select half of the Table 1 dataset as the testing set. As can be seen in Table 10, the accuracy, precision, and recall ratios of the proposed method all reach 100%. The identification effects of the corner methods (SIFT [34], SURF [35], and BRISK [36]) are relatively general. Some representative texture algorithms (2LQR [24], LBP [37], CLBP [38], CLBC [39] ECLBP [40], COV_LBPD [41], MRELBP [42], JRLP [43], MCDR [44], RALBGC [45], LDEP [46], and LGONBP [47]) can also achieve good results with accuracies above 99%, and some algorithms are close to or reach 100%. In terms of time, to process an image of the same size, the proposed algorithm DFDA needs 0.25 s, which is at the upper level. The shortest time is obtained by [24], only 0.01 s and the longest time is from [46], 146.3 s, followed by [34], 17.08 s. The rest of the methods are within 2 s. (2) Attacked test This paper experimentally verifies the robustness of the proposed anti-counterfeiting code and the corresponding algorithm in view of the possible abrasion phenomenon during the use of the code. The dataset in Table 2 is used as the test set. Table 11 shows the accuracy results of the different methods for different reduced proportions. The accuracy of [34][35][36][37][38][39]46,47] and other methods is above 90% when the size is 12%, 24%, or 36% of the original figure. The accuracy of [34,[38][39][40]46,47] and other methods is more than 90% when the size of the original image is 64%. When the size is 48% of the original image, only the accuracy of [40] is above 90% (94.39%). The proposed method maintains 100% accuracy during the size ratio reduction from 12% to 48%, which is a significant advantage. Table 12 shows the results of different methods under different cut ratio attacks. The  [34][35][36][37][38]42,45] can still maintain more than 90% accuracy under a 1% cut attack, the methods in [34][35][36]45] can still maintain more than 90% accuracy under a 3% cut attack, and the methods in [34,36] can still maintain more than 90% accuracy with a 5% cut attack. The accuracy of the proposed method is 100% during the size reduction from 1% to 5%, which significantly outperforms other methods.

Conclusions
In this paper, a texture-hidden anti-counterfeiting QR code and a related authentication scheme for mobile devices are proposed. The authentication scheme includes a quality assessment algorithm and dual feature detection. In the test of quality assessment algorithms, the proposed algorithm is compared with several current common algorithms without reference and the superiority of the proposed algorithm is verified. In the authenticity test, the proposed dual feature method is compared with various texture and corner methods. The proposed method achieves an accuracy, precision, and recall of up to 100%, and it also performs well on attacked datasets with reduction and cut. In the following research work, it is necessary to expand the data set (attacks of various physical sizes, higher forgery technologies, and complex application scenarios) to more comprehensively evaluate the practicality of the codes and authentication schemes to achieve convenient pre-sale anti-counterfeit measures.
The dataset used in this paper is obtained by smartphones shooting under indoor conditions, but the collection of 2D codes will also encounter some abnormal conditions, such as insufficient illumination, severe shaking, etc. How to efficiently recover codes and authenticate them is a problem that requires further work. In addition, with multiple forgery devices available, how to authenticate codes using only genuine samples is an important research direction.