A method and system for inspecting printed marks on food packaging

CN123016068APending Publication Date: 2026-10-30ZHONGSHUANGYUAN (HANGZHOU) TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611145838.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-30
Publication Date
2026-10-30

AI Technical Summary

Technical Problem

在高程度几何畸变的工业场景中,对齐残差往往难以完全避免

Benefits of technology

[0018]本发明通过构建基于固有笔画走向先验模型的双边引导滤波图像金字塔,在多尺度下采样过程中保持印刷标识的关键边缘和主导笔画结构,减少结构信息丢失与边缘模糊;在金字塔顶层结合CIELab色彩空间和结构化色彩梯度直方图特征进行粗对齐,降低光照变化和色彩偏差对匹配结果的影响,为后续精对齐提供可靠的初始变换矩阵;在逐层精对齐过程中,利用相位相关性与结构相似性度量加权的能量函数进行变换参数优化,并根据畸变程度和对齐残差自适应分配权重,提高对平移、旋转、缩放及剪切等形变的校正能力;同时,将几何变换矩阵分解后输入调制网络,对孪生卷积网络的特征提取过程进行调节,使空间变换信息参与特征补偿,降低几何畸变及插值残差造成的特征偏移;并根据图像整体畸变程度动态设定判定阈值,减少正常形变引起的误检,提升食品包装印刷标识缺陷检验的准确性、稳定性和适应性。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123016068A_ABST
    Figure CN123016068A_ABST
Patent Text Reader

Abstract

The application provides a food packaging printing mark inspection method and system, which comprises collecting standard and to-be-inspected mark images, constructing stroke direction prior model based on the standard images, constructing image pyramid in combination with bilateral guided filtering, completing coarse alignment based on the structured color gradient histogram in the CIELab color space, and solving an initial transformation matrix; performing layer-by-layer iterative fine alignment from the top layer to the bottom layer of the pyramid, taking the transformation matrix of the previous layer as an initial value, optimizing a phase correlation and structure similarity weighted energy function and adjusting the weight, and solving a final transformation matrix to correct the to-be-inspected image; then extracting two groups of image deep features through a twin convolution network, decomposing the transformation matrix and sending it into a modulation network to adjust the convolution feature map, judging the printing defects according to the feature cosine distance, updating the judgment threshold with the overall distortion degree of the image, and realizing packaging printing mark defect detection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of food packaging, and in particular relates to a method and system for inspecting printed labels on food packaging. Background Technology

[0002] With the rapid development of the food industry, food packaging not only bears the basic function of protecting food safety, but its printed labels, such as production date, shelf life, product batch number, and brand trademark, are also important carriers of key information to consumers. On modern high-speed packaging printing production lines, factors such as printing equipment vibration, packaging material tension fluctuations, changes in ambient light, and uneven ink distribution can easily lead to quality defects in printed labels, such as missing prints, broken strokes, blurring, color deviation, and ghosting. To ensure the compliance and visual quality of food packaging, the use of machine vision technology for defect inspection of printed labels has become a common practice in the industry. Existing visual inspection methods are mostly based on template matching strategies, which involve aligning and comparing the real-time acquired image of the label to be inspected with a preset standard label image. However, food packaging materials are mostly flexible and prone to translation, rotation, scaling, and even local geometric distortion during production transmission and image acquisition. If the alignment process is not precise enough, residual deformation will create alignment residuals during the comparison process, making it difficult for conventional algorithms to distinguish between genuine printing defects and normal material deformation. Meanwhile, when traditional methods use conventional multi-scale downsampling during image alignment, they are prone to blurring the marked edges and losing structured information such as the direction of key strokes, resulting in insufficient accuracy of large-scale coarse alignment. In the gradual fine alignment stage, a single similarity measure is difficult to adapt to different types of geometric distortions, so that the generated corrected image may still have positional or structural deviations.

[0003] Existing defect detection systems have begun to utilize deep learning models to extract high-dimensional image features to enhance their adaptability to changes in illumination and noise interference, but shortcomings remain in practical applications. Traditional deep neural networks typically employ fixed network structures and static judgment criteria when performing feature extraction and difference measurement, failing to fully consider the intensity of geometric transformations experienced by the image under inspection during alignment. In industrial scenarios with high degrees of geometric distortion, alignment residuals are often difficult to completely avoid. If the system lacks the ability to perceive distortion states, fixed threshold judgments can easily misjudge slight alignment errors caused by material stretching or transmission offsets as printing defects; conversely, blindly relaxing thresholds to reduce false alarm rates may lead to the missed detection of genuine defects such as minor broken strokes or ink gaps. Therefore, how to maintain the core structural features of printed markings during multi-scale alignment, achieve high-precision geometric correction, and enable the feature extraction network and judgment mechanism to adapt to the degree of image geometric distortion, while balancing low false alarm rates and high recall rates in actual production environments, is a pressing technical problem to be solved in the field of food packaging printing marking defect inspection. Summary of the Invention

[0004] According to a first aspect of the present invention, a method for inspecting printed labels on food packaging is proposed, which enables the feature extraction network and the decision mechanism to adapt to the degree of geometric distortion of the image, and balances low false positive rate and high recall rate in defect inspection under actual production environment, comprising the following steps: Obtain a standard logo image and a logo image to be inspected. Calculate the inherent stroke direction prior model of the printed logo based on the standard logo image. Construct an image pyramid using bilateral guided filtering downsampling. The guided image generates edges that maintain consistency with the key structural direction based on the inherent stroke direction prior model. Calculate the structured color gradient histogram features of the standard logo image and the logo image to be inspected in the CIELab color space at the top layer of the image pyramid and perform coarse alignment to obtain the initial transformation matrix. The image pyramid is finely aligned layer by layer from the second-to-last layer to the bottom layer. The initial transformation matrix obtained by the coarse alignment of the top layer or the transformation matrix updated by the adjacent lower resolution layer is scaled and used as the initial value of the current layer. The transformation matrix is ​​updated by an energy function weighted by phase correlation and structural similarity measures. The weights are allocated according to the degree of distortion and alignment residual to obtain the final transformation matrix. The final transformation matrix is ​​used to perform geometric transformation on the image to be inspected to generate a corrected image to be inspected. The standard label image and the corrected label image are input into a Siamese convolutional network to extract depth features. The final transformation matrix is ​​decomposed and input into a modulation network to generate gain and bias. The feature maps of the convolutional layers of the Siamese convolutional network are adjusted, and the cosine distance between depth features is calculated. When the cosine distance is greater than the judgment threshold, a defect is determined to exist. The judgment threshold is adjusted based on the overall distortion degree of the final transformation matrix.

[0005] Optionally, the calculation of the inherent stroke direction prior model of the printed logo based on the standard logo image includes: Extract the morphological skeleton of the standard identifier image; At the skeleton pixel position corresponding to the morphological skeleton, a gradient direction histogram is calculated based on the standard identifier image; The orthogonal directions of the N most frequent gradient directions are selected as the inherent stroke directions of the printed mark, and the prior model of the inherent stroke direction is constructed.

[0006] Optionally, the construction of the image pyramid using bilateral guided filtering downsampling, wherein the guided map generates edges that maintain consistency with the orientation of key structures based on the prior model of inherent stroke orientation, includes: The structure tensor of the image is calculated and the eigenvalues ​​and corresponding eigenvectors are solved. The eigenvectors corresponding to small eigenvalues ​​are extracted as local stroke extension directions. Based on the prior model of the inherent stroke direction, high weights are assigned to the structure tensor of the local stroke extension direction that is consistent with the inherent stroke direction of the printed mark, and a gradient structure salience map is generated as a guide map. The guided image is used to perform bilateral filtering on the image to be processed, and downsampling is performed at a fixed ratio to obtain the pyramid images of each layer.

[0007] Optionally, the step of coarsely aligning the structured color gradient histogram features of the standard identifier image and the identifier image to be inspected in the CIELab color space at the top layer of the image pyramid to obtain the initial transformation matrix includes: Convert the image to the CIELab color space, extract the key points of the image, and calculate the pixel gradient magnitude and direction of each channel; Based on the prior model of the inherent stroke direction, the gradient direction in the neighborhood of the key point is non-uniformly discretely mapped to generate the local structured color gradient histogram feature of the key point. The initial transformation matrix is ​​calculated by using the least squares method to calculate the key points corresponding to the cross-correlation matching space of the local structured color gradient histogram features.

[0008] Optionally, the fine alignment from the second-to-last layer of the image pyramid to the bottom layer, using the initial transformation matrix obtained from the coarse alignment of the top layer or the transformation matrix updated from adjacent lower resolution layers after scale transformation as the initial value of the current layer, optimizes the energy function weighted by phase correlation and structural similarity measures to update the transformation matrix, with weights allocated according to the degree of distortion and alignment residual, to obtain the final transformation matrix, including: Calculate the phase correlation and structural similarity measures of local image patches; If the alignment residual of the local image patch is higher than a preset residual threshold, the weight ratio of the phase correlation metric is increased. A gradient-free optimization algorithm is used to solve for the transformation matrix parameters that maximize the energy function.

[0009] Optionally, the step of decomposing the final transformation matrix into the modulation network to generate gain and bias, and adjusting the feature maps of the convolutional layers of the Siamese convolutional network, includes: The final transformation matrix is ​​decomposed into translation parameters, rotation angles, scaling factors, and shearing parameters; The decomposed parameters are normalized and then input into a modulation network containing fully connected layers. The output is a gain vector and a bias vector that match the number of channels of a specific convolutional layer in the Siamese convolutional network. Channel-level affine transformation is then performed on the feature map of the convolutional layer.

[0010] Optionally, the calculation of the cosine distance between depth features, and the determination of a defect when the cosine distance is greater than a judgment threshold, wherein the judgment threshold is adjusted based on the overall distortion degree of the final transformation matrix, including: Extract the affine transformation sub-matrix after removing the translation parameters from the final transformation matrix, calculate the normalized norm error between the affine transformation sub-matrix and the identity matrix, and combine it with the corrected image alignment residual as the overall distortion degree; Based on a preset basic threshold, when the overall distortion increases, the judgment threshold is relaxed proportionally. When the overall distortion level decreases, the determination threshold is tightened accordingly.

[0011] According to a second aspect of the present invention, a food packaging printing label inspection system is provided, comprising the following modules: The module is used to acquire a standard logo image and a logo image to be inspected. Based on the standard logo image, it calculates the inherent stroke direction prior model of the printed logo. It constructs an image pyramid using bilateral guided filtering downsampling. The guided image generates edges that are consistent with the direction of key structures based on the inherent stroke direction prior model. At the top of the image pyramid, it calculates the structured color gradient histogram features of the standard logo image and the logo image to be inspected in the CIELab color space and performs coarse alignment to obtain the initial transformation matrix. The generation module is used to perform fine alignment layer by layer from the second-to-last layer to the bottom layer of the image pyramid. The initial transformation matrix obtained by coarse alignment of the top layer or the transformation matrix updated by adjacent lower resolution layers is scaled and used as the initial value of the current layer. The transformation matrix is ​​updated by an energy function weighted by phase correlation and structural similarity measures. The weights are allocated according to the degree of distortion and alignment residual to obtain the final transformation matrix. The final transformation matrix is ​​used to perform geometric transformation on the image to be inspected to generate a corrected image to be inspected. The determination module is used to input the standard identification image and the corrected identification image into a Siamese convolutional network to extract depth features, decompose the final transformation matrix into a modulation network to generate gain and bias, adjust the feature maps of the convolutional layers of the Siamese convolutional network, calculate the cosine distance between depth features, and determine that there is a defect when the cosine distance is greater than the determination threshold. The determination threshold is adjusted based on the overall distortion degree of the final transformation matrix.

[0012] Preferably, the prior model for calculating the inherent stroke direction of the printed logo based on the standard logo image includes: Extract the morphological skeleton of the standard identifier image; At the skeleton pixel position corresponding to the morphological skeleton, a gradient direction histogram is calculated based on the standard identifier image; The orthogonal directions of the N most frequent gradient directions are selected as the inherent stroke directions of the printed mark, and the prior model of the inherent stroke direction is constructed.

[0013] Preferably, the method of constructing an image pyramid using bilateral guided filtering downsampling, wherein the guided map generates edges that maintain consistency with the direction of key structures based on the prior model of inherent stroke direction, includes: The structure tensor of the image is calculated and the eigenvalues ​​and corresponding eigenvectors are solved. The eigenvectors corresponding to small eigenvalues ​​are extracted as local stroke extension directions. Based on the prior model of the inherent stroke direction, high weights are assigned to the structure tensor of the local stroke extension direction that is consistent with the inherent stroke direction of the printed mark, and a gradient structure salience map is generated as a guide map. The guided image is used to perform bilateral filtering on the image to be processed, and downsampling is performed at a fixed ratio to obtain the pyramid images of each layer.

[0014] Preferably, the step of coarsely aligning the structured color gradient histogram features of the standard identifier image and the identifier image to be inspected in the CIELab color space at the top layer of the image pyramid to obtain the initial transformation matrix includes: Convert the image to the CIELab color space, extract the key points of the image, and calculate the pixel gradient magnitude and direction of each channel; Based on the prior model of the inherent stroke direction, the gradient direction in the neighborhood of the key point is non-uniformly discretely mapped to generate the local structured color gradient histogram feature of the key point. The initial transformation matrix is ​​calculated by using the least squares method to calculate the key points corresponding to the cross-correlation matching space of the local structured color gradient histogram features.

[0015] Preferably, the fine alignment from the second-to-last layer of the image pyramid to the bottom layer, using the initial transformation matrix obtained from the coarse alignment of the top layer or the transformation matrix updated from adjacent lower resolution layers after scale transformation as the initial value of the current layer, optimizes the energy function weighted by phase correlation and structural similarity measures to update the transformation matrix, with weights allocated according to the degree of distortion and alignment residuals, to obtain the final transformation matrix, including: Calculate the phase correlation and structural similarity measures of local image patches; If the alignment residual of the local image patch is higher than a preset residual threshold, the weight ratio of the phase correlation metric is increased. A gradient-free optimization algorithm is used to solve for the transformation matrix parameters that maximize the energy function.

[0016] Preferably, the step of decomposing the final transformation matrix into the modulation network to generate gain and bias, and adjusting the feature maps of the convolutional layers of the Siamese convolutional network, includes: The final transformation matrix is ​​decomposed into translation parameters, rotation angles, scaling factors, and shearing parameters; The decomposed parameters are normalized and then input into a modulation network containing fully connected layers. The output is a gain vector and a bias vector that match the number of channels of a specific convolutional layer in the Siamese convolutional network. Channel-level affine transformation is then performed on the feature map of the convolutional layer.

[0017] Preferably, the calculation of the cosine distance between depth features, and the determination of a defect when the cosine distance is greater than a judgment threshold, wherein the judgment threshold is adjusted based on the overall distortion degree of the final transformation matrix, including: Extract the affine transformation sub-matrix after removing the translation parameters from the final transformation matrix, calculate the normalized norm error between the affine transformation sub-matrix and the identity matrix, and combine it with the corrected image alignment residual as the overall distortion degree; Based on a preset basic threshold, when the overall distortion increases, the judgment threshold is relaxed proportionally. When the overall distortion level decreases, the determination threshold is tightened accordingly.

[0018] This invention constructs a bilateral guided filtering image pyramid based on a prior model of inherent stroke direction. During multi-scale downsampling, it preserves the key edges and dominant stroke structure of printed labels, reducing structural information loss and edge blurring. At the top of the pyramid, coarse alignment is performed using CIELab color space and structured color gradient histogram features, reducing the impact of illumination changes and color deviations on the matching results and providing a reliable initial transformation matrix for subsequent fine alignment. In the layer-by-layer fine alignment process, a transformation parameter optimization is performed using an energy function weighted by phase correlation and structural similarity measures. Weights are adaptively allocated based on the degree of distortion and alignment residuals, improving the ability to correct for deformations such as translation, rotation, scaling, and shearing. Simultaneously, the geometric transformation matrix is ​​decomposed and input into a modulation network to adjust the feature extraction process of the twin convolutional network, allowing spatial transformation information to participate in feature compensation and reducing feature shifts caused by geometric distortion and interpolation residuals. Furthermore, a judgment threshold is dynamically set based on the overall image distortion degree, reducing false detections caused by normal deformation and improving the accuracy, stability, and adaptability of defect inspection for printed food packaging labels. Attached Figure Description

[0019] Figure 1 A flowchart of the first embodiment; Figure 2 Image for food packaging labeling; Figure 3 This is a schematic diagram of the top-level structured color gradient descriptor distribution and the normalized cross-correlation curve. Detailed Implementation

[0020] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0021] In the first embodiment, the present invention proposes a method, such as Figure 1 It includes the following steps: S1. Obtain a standard logo image and a logo image to be inspected. Calculate the inherent stroke direction prior model of the printed logo based on the standard logo image. Construct an image pyramid using bilateral guided filtering downsampling. The guided image generates edges that maintain consistency with the key structural direction based on the inherent stroke direction prior model. Calculate the structured color gradient histogram features of the standard logo image and the logo image to be inspected in the CIELab color space at the top layer of the image pyramid and perform coarse alignment to obtain the initial transformation matrix.

[0022] High-resolution, defect-free standard packaging label images and real-time images of packaging labels to be inspected, captured by an industrial camera, are read separately and converted into three-channel floating-point tensor data. Tubular structure features of text and patterns in the standard label image are extracted. The eigenvalues ​​and eigenvectors of the Hessian matrix for each pixel are calculated. The orthogonal direction of the eigenvector corresponding to the largest absolute eigenvalue is taken as the inherent stroke direction at that pixel, representing the stroke extension direction rather than the stroke normal direction. An anisotropic Gaussian kernel is used to smooth the aforementioned direction field across the entire image space domain to construct a prior model of the inherent stroke direction. Both images are converted from RGB color space to CIELab color space. During the construction of the image pyramid, each layer is spatially downsampled. The gradient structure saliency map generated by the inherent stroke direction prior model is used as the guide map for joint bilateral filtering. A joint bilateral filter is instantiated and used to smooth the current layer image while preserving edge direction. The downsampling function is called to perform spatial downsampling at a 50% ratio. This bilateral guided filtering and downsampling operation is repeated five times to construct a six-layer image pyramid with progressively decreasing resolution.

[0023] At the top layer of the image pyramid, which has the lowest resolution, structured color gradient histogram features are calculated for both the standard label image and the label image to be inspected. The horizontal and vertical gradients of the L, a, and b channels are calculated respectively. The spatial weights of each pixel are calculated using the inherent stroke direction prior model. The gradient magnitudes of each channel are multiplied by these weights, and the regions are divided to statistically analyze the color gradient histograms in 24 directions, followed by L2 norm normalization. Nearest neighbor search matching is performed on the histogram feature descriptors of the two top-level images to obtain initial matching point pairs. These matching point pairs are input into the affine transformation estimation function, and RANSAC algorithm flags are configured to remove spatial mismatches. A 3×3 homogeneous affine initial transformation matrix containing translation, rotation, scaling, and shearing parameters is calculated using least squares fitting, where the two-dimensional affine parameters are embedded in the 3×3 matrix in homogeneous coordinate form.

[0024] In an optional embodiment, the calculation of the inherent stroke direction prior model of the printed logo based on the standard logo image includes: Extract the morphological skeleton of the standard identifier image; At the skeleton pixel position corresponding to the morphological skeleton, a gradient direction histogram is calculated based on the standard identifier image; The orthogonal directions of the N most frequent gradient directions are selected as the inherent stroke directions of the printed mark, and the prior model of the inherent stroke direction is constructed.

[0025] Obtain a standard identifier image, such as a grayscale image with a resolution of 1024×1024. Extract the morphological skeleton by iteratively stripping the stroke regions down to connected line segments of single-pixel width, resulting in a binarized skeleton image where the skeleton pixel value is 1 and the background pixel value is 0. Calculate the gradient magnitude and gradient direction at the skeleton pixel positions in the original standard image, ranging from 0 to 180 degrees. Divide the gradient direction from 0 to 180 degrees into 36 equal-width intervals, each spanning 5 degrees. Statistically analyze the gradient direction distribution corresponding to all skeleton pixel positions in the original standard image to generate an initial gradient direction histogram. Smooth the generated gradient direction histogram using a one-dimensional Gaussian filter with a standard deviation of 1.0, and sort it from high to low frequency. Extract the center values ​​of the gradient direction intervals corresponding to the N most frequent local peaks. The parameter N is preferably set to 3, for example, extracting gradient directions corresponding to peaks at 0 degrees, 90 degrees, and 45 degrees. The orthogonal directions of the three gradient directions are calculated by adding 90 degrees to each and taking the modulus of 180 degrees, resulting in example orthogonal directions of 90 degrees, 0 degrees, and 135 degrees, which are set as the inherent stroke directions of printed logos. A prior model of the inherent stroke direction is constructed, consisting of these three dominant direction angles and their corresponding normalized frequency weights.

[0026] In an optional embodiment, the construction of the image pyramid using bilateral guided filtering downsampling, wherein the guided map generates edges that maintain consistency with the orientation of key structures based on the intrinsic stroke orientation prior model, includes: The structure tensor of the image is calculated and the eigenvalues ​​and corresponding eigenvectors are solved. The eigenvectors corresponding to small eigenvalues ​​are extracted as local stroke extension directions. Based on the prior model of the inherent stroke direction, high weights are assigned to the structure tensor of the local stroke extension direction that is consistent with the inherent stroke direction of the printed mark, and a gradient structure salience map is generated as a guide map. The guided image is used to perform bilateral filtering on the image to be processed, and downsampling is performed at a fixed ratio to obtain the pyramid images of each layer.

[0027] Using a Gaussian derivative filter with a standard deviation of 1.0, the spatial gradient components in the horizontal and vertical directions of the current layer's image are calculated, constructing a 2×2 structure tensor matrix. The tensor elements are then smoothed using a 5×5 Gaussian window. Eigenvalue decomposition is performed on the structure tensor at each pixel location, extracting the feature vector corresponding to the smaller eigenvalue as the local stroke extension direction. This feature vector is orthogonal to the local gradient normal direction and represents the tangential direction of the local texture or stroke. The angle difference between this feature vector and the dominant directions in the prior model of the inherent stroke direction is calculated. The angle difference is calculated along an undirected axis, considering directions differing by 180 degrees as consistent, and taking the minimum angle difference between the current direction and the dominant direction as the angle difference. The minimum angle difference ranges from 0 to 90 degrees. Angle differences are converted into weight values ​​using a Gaussian decay function. When the angle difference is less than 15 degrees, a high weight between 0.8 and 1.0 is assigned. The trace of the weighted structure tensor matrix is ​​used to generate a gradient structure saliency map with values ​​ranging from 0 to 255. This map is then normalized to the 0-1 range and used as a guide map for subsequent filtering. The generated gradient structure saliency map is used as the reference image input for the joint bilateral filter, and joint bilateral filtering is performed on the image to be processed in the current layer. In this process, the standard deviation of the spatial domain Gaussian kernel is preferably set to 2.5, and the standard deviation of the value domain intensity Gaussian kernel is preferably set to 0.15 based on the guide map, ensuring that the key edges consistent with the stroke direction of the printed logo are preserved while smoothing the image background. After filtering, a bicubic interpolation algorithm is used to downsample at a fixed ratio of 0.5, that is, the image length and width are halved. The above guide filtering and downsampling steps are repeated until a six-layer image pyramid is constructed. The pyramid levels are numbered sequentially from level 0 to level 5, with level 0 being the original resolution layer and level 5 being the lowest resolution top layer.

[0028] In an optional embodiment, the step of coarsely aligning the structured color gradient histogram features of the standard identifier image and the identifier image to be inspected in the CIELab color space at the top layer of the image pyramid to obtain an initial transformation matrix includes: Convert the image to the CIELab color space, extract the key points of the image, and calculate the pixel gradient magnitude and direction of each channel; Based on the prior model of the inherent stroke direction, the gradient direction in the neighborhood of the key point is non-uniformly discretely mapped to generate the local structured color gradient histogram feature of the key point. The initial transformation matrix is ​​calculated by using the least squares method to calculate the key points corresponding to the cross-correlation matching space of the local structured color gradient histogram features.

[0029] The standard label image and the label image to be inspected, located at the top of the image pyramid, are converted from the RGB color space to the CIELab color space to separate the brightness channel L and the color-opposite channels a and b. Key points of the image are extracted, with a detection threshold preferably set to 0.05. For each extracted key point, the gradient magnitude and gradient direction of each pixel in the L, a, and b channels are calculated. Using preset channel weight coefficients, such as L, a, and b channel weights of 0.5, 0.25, and 0.25 respectively, the gradient magnitudes of each channel are weighted and fused. The gradient direction corresponding to the maximum fused magnitude is extracted as the main gradient direction of that pixel. A 16×16 pixel neighborhood around the key point is defined as the feature description region, and this region is divided into 4×4 sub-blocks of size 4×4. When performing non-uniform discrete mapping of gradient directions based on the prior model of inherent stroke direction, comparisons are uniformly performed within the stroke extension direction domain: First, the principal gradient direction of each pixel is rotated by 90 degrees and modulo 180 degrees to obtain the corresponding local stroke extension direction; then, the minimum angle difference between this local stroke extension direction and each dominant stroke direction in the prior model of inherent stroke direction is calculated; for local directions whose angle difference with the dominant stroke direction is less than a preset angle range, fine-grained angle judgment is applied, and they are mapped to the corresponding dominant direction statistical slot; other non-dominant directions are mapped to the remaining direction statistical slots according to a wider angle range, thus forming an 8-dimensional direction statistical vector for each sub-block. The local stroke extension directions of pixels within each sub-block are mapped to discrete intervals, and the gradient magnitude is accumulated by combining Gaussian space weights with a standard deviation of 8.0. The 8-dimensional direction statistical vectors of 16 sub-blocks are concatenated to generate a 128-dimensional local structured color gradient histogram feature. The normalized cross-correlation of histogram features between two images is calculated. Keypoint pairs with a correlation greater than 0.7 and satisfying bidirectional consistency checks are retained. After removing outliers using the RANSAC algorithm, affine transformation parameters are fitted to the inlier pairs using the least squares method. A 3×3 initial transformation matrix containing translation, rotation, scaling, and shearing parameters is then obtained, completing the top-level coarse alignment. (Example: Food packaging standard label sample) Figure 2 As shown.

[0030] S2, finely align each layer from the second-to-last layer to the bottom layer of the image pyramid. Use the initial transformation matrix obtained from the coarse alignment of the top layer or the transformation matrix obtained from the update of the adjacent lower resolution layer after scale transformation as the initial value of the current layer. Optimize the energy function weighted by phase correlation and structural similarity measures to update the transformation matrix. The weights are allocated according to the degree of distortion and alignment residual to obtain the final transformation matrix. Use the final transformation matrix to perform geometric transformation on the image to be inspected to generate a corrected image to be inspected.

[0031] The process then proceeds to a coarse-to-fine iterative alignment phase between pyramid levels. For each pyramid level from the fourth to the zeroth level of the original resolution image, the homogeneous affine transformation matrix obtained from the previous lower resolution level is used as the transfer matrix. When transferred to the current level, the translation component is multiplied by 2 to become the initial transformation matrix for that level. Similarly, when the initial homogeneous affine transformation matrix obtained from the fifth coarse alignment is transferred to the fourth level, its translation component is also multiplied by 2. A joint energy function is constructed for the current image level. This energy function is a linear combination of a phase correlation term and a structural similarity metric term. The phase correlation term is not used alone to solve for rotation, scaling, and shearing parameters. Instead, after each candidate affine transformation parameter is applied, the peak cross-power spectrum response between the standard image patch and the image patch to be examined after the candidate affine transformation is calculated to evaluate residual translation consistency. The structural similarity metric term is obtained by calculating the correlation between the local brightness, contrast, and structural covariance within the sliding window of both images. The rotation, scaling, and shearing parameters are optimized by the initial values ​​of the top-level coarse alignment, the structural similarity metric term, and the constraints of the affine parameters. Subsequently, a weighting strategy for the energy function is set, the 2×2 affine transformation sub-matrix is ​​extracted from the current initial transformation matrix, the normalized norm error between the affine transformation sub-matrix and the identity matrix is ​​calculated, the overall distortion degree of the current layer is evaluated, and the current layer image is divided into multiple overlapping local image blocks. The local alignment residual of each local image block under the action of the current transformation matrix is ​​calculated. When the local alignment residual of a certain local image block is higher than a preset residual threshold, or the overall distortion degree of the current layer is greater than a preset distortion threshold, the local image block is assigned a weight of 0.7 for the phase correlation term and a weight of 0.3 for the structural similarity term to prioritize enhancing the alignment stability under larger displacement errors. Conversely, if the local image block is not significantly different, it indicates that the current local image block is well aligned, and the local image block is assigned a weight of 0.7 for the structural similarity term and a weight of 0.3 for the phase correlation term to improve the alignment accuracy of detailed structures.

[0032] The two metrics are weighted and summed using assigned weights to form the total similarity energy function. A gradient-free optimization algorithm is used as the solver, and the negative of the total similarity energy function is used as the loss function to be minimized. This is equivalent to solving for the six-degree-of-freedom affine transformation parameters that maximize the total similarity energy function, and updating the transformation matrix of the current layer accordingly. This calculation process is iteratively performed layer by layer towards higher resolution layers until the calculation of the bottom layer (layer zero) is completed, outputting the final transformation matrix with the highest accuracy. The first two rows of the final transformation matrix are extracted to form a 2×3 affine transformation matrix, or the 3×3 homogeneous affine transformation matrix can be directly used. Through affine geometric transformation methods combined with linear interpolation strategies, global affine correction is performed on the original image of the target label to remove geometric deformations caused by shooting posture, material stretching, and transmission offset, generating a corrected image of the target label. The distribution of the top-level gradient descriptors and the matching correlation results between the standard label and the target label are as follows: Figure 3 As shown.

[0033] In an optional embodiment, the fine alignment from the second-to-last layer of the image pyramid to the bottom layer, using the initial transformation matrix obtained from the coarse alignment of the top layer or the transformation matrix updated from adjacent lower resolution layers after scale transformation as the initial value of the current layer, optimizes the energy function weighted by phase correlation and structural similarity measures to update the transformation matrix, with weights allocated according to the degree of distortion and alignment residual, to obtain the final transformation matrix, including: Calculate the phase correlation and structural similarity measures of local image patches; If the alignment residual of the local image patch is higher than a preset residual threshold, the weight ratio of the phase correlation metric is increased. A gradient-free optimization algorithm is used to solve for the transformation matrix parameters that maximize the energy function.

[0034] In the layer-by-layer fine alignment process of the image pyramid from the second-to-last layer to the bottom layer, the image is divided into overlapping local image blocks of size 32×32, with a sliding step size of 16 pixels. For each local image block, a two-dimensional fast Fourier transform is used to transform the image block to the frequency domain, and the inverse Fourier transform of the cross-power spectrum is calculated. The pulse peak value is extracted as a phase correlation metric between 0 and 1 to identify large-scale translational shifts. Simultaneously, the structural similarity index of the image block is calculated in the spatial domain, with the weighting coefficients for brightness, contrast, and structure all set to 1 to obtain the structural similarity metric, which is used to identify subtle textures and structural deformations. The root mean square error of the corresponding pixel of the local image block under the current transformation matrix is ​​calculated as the alignment residual, and the preset residual threshold is set to 12 gray levels. A weighted energy function including phase correlation and structural similarity metrics is designed, with the initial weight ratios of the two set to 0.3 and 0.7, respectively. The weighted energy function uses the summation or averaging of the weighted similarity of each local image block as the overall optimization objective. For each image patch, a conditional judgment is performed. If the calculated alignment residual is greater than the preset residual threshold, the weight allocation is adjusted, increasing the weight ratio of the phase correlation metric to 0.7 and correspondingly decreasing the weight ratio of the structural similarity metric to 0.3, thereby enhancing the alignment stability of displacement in severely distorted regions. The six affine parameters of the transformation matrix, including two translations and four deformations, are used as optimization variables. A maximum number of iterations is set to 200, and the convergence tolerance is 1e-4. The goal is to maximize the overall weighted similarity energy function, or equivalently, to minimize the negative value of this overall weighted similarity energy function, through iterative solving to achieve high-precision updates of the transformation matrix parameters for the current pyramid layer.

[0035] S3, input the standard label image and the corrected label image to be inspected into a Siamese convolutional network to extract depth features, decompose the final transformation matrix into a modulation network to generate gain and bias, adjust the feature map of the convolutional layer of the Siamese convolutional network, calculate the cosine distance between depth features, and determine that there is a defect when the cosine distance is greater than the judgment threshold. The judgment threshold is adjusted based on the overall distortion degree of the final transformation matrix.

[0036] A Siamese convolutional neural network model was constructed. The backbone feature extractor of this network adopted a pre-trained residual convolutional network, and the top classification layer was removed, retaining convolutional residual blocks from multiple stages to extract deep semantic features and spatial structural features of the image. The standard label image and the corrected label image were combined in the batch dimension and input into the weight-shared Siamese convolutional network branch to extract the corresponding high-dimensional spatial feature tensors. To compensate for the local feature domain artifact bias caused by spatial alignment interpolation, the translation parameters in the third column were directly read from the 3×3 homogeneous affine final transformation matrix. Then, the 2×2 affine transformation sub-matrix in the upper left corner was extracted. The 2×2 affine transformation sub-matrix was subjected to extreme decomposition, QR decomposition, or singular value decomposition to obtain one rotation angle, two anisotropic scaling factors, and one shearing parameter. The above parameters, together with the two translation parameters, are flattened and concatenated into a 6-dimensional one-dimensional context feature vector. This vector is then input into a multilayer perceptron feature modulation network constructed from two linear fully connected layers. After being mapped by the LeakyReLU nonlinear activation function, the output consists of a channel scaling gain coefficient tensor and a channel offset term tensor that are aligned with the number of channels in the feature map of the convolutional layer to be modulated in the Siamese convolutional network.

[0037] During the model training phase, multiple batches of real, qualified, defect-free label samples, defect-free samples enhanced from standard templates, and abnormal samples containing defects such as missing prints, broken strokes, color casts, ghosting, and blurring are collected. Defect-free samples are subjected to translation, rotation, scaling, and shearing transformations within a preset range, while simultaneously overlaying illumination perturbations, imaging noise, and interpolation degradation to generate normal distortion samples. Abnormal samples are subjected to the same range of geometric distortion to generate defect distortion samples. During training, the enhanced sample pairs are first processed by the aforementioned coarse alignment and layer-by-layer fine alignment modules. The estimated final transformation matrix output by these modules is used as the input to the modulation network, instead of directly using manually applied real transformation parameters, ensuring consistency between the training and online verification phases. The sample pairs are input into the Siamese convolutional network and the modulation network for end-to-end training. Contrastive loss or triplet loss is used to constrain the feature distance of defect-free, normally distorted sample pairs to be less than the feature distance of defective sample pairs. The parameters of the Siamese convolutional network and the modulation network are updated using a defect binary classification cross-entropy loss, enabling the modulation network to learn the feature compensation relationship under different geometric transformation parameters. After training, the parameters of the twin convolutional network and modulation network are fixed or fine-tuned for feature modulation and defect determination in the online inspection phase.

[0038] Using the aforementioned generated gain coefficient tensor and bias term tensor, a channel-by-channel element-wise operation is applied to the high-dimensional spatial feature tensor of the branch of the image to be inspected, performing an affine feature modulation operation similar to the FiLM mechanism to calibrate the statistical distribution shift of the feature map caused by geometric correction and interpolation. The feature tensor of the standard image branch remains unmodulated as a reference feature, or undergoes only identity modulation. The FiLM mechanism generates channel-level gain and bias through external conditions, performing scaling and translation modulation on the feature map, enabling the network features to adaptively adjust with the input state. Subsequently, global average pooling is performed on the standard image reference feature tensor and the modulated and calibrated feature tensor of the image to be inspected, respectively, to obtain two one-dimensional depth feature vectors, and then the cosine distance between them is calculated. A baseline defect judgment threshold of 0.85 is set, and a baseline distortion reference value is also set. For example, 0.1; extract the 2×2 affine transformation submatrix in the upper left corner of the final transformation matrix, calculate the Frobenius norm between the affine transformation submatrix and the 2×2 identity matrix, or calculate the area scaling deviation |det(A)-1| and combine it with the absolute value of the shearing parameter to obtain the affine deviation, where A represents the 2×2 affine transformation submatrix; normalize the affine deviation to the first distortion component. The corrected pixel residuals or structural similarity residuals in the overlapping region are normalized into a second distortion component. and in accordance with Calculate the overall distortion scalar factor D, where α is the preset fusion weight. Use the baseline judgment threshold plus an adjustment coefficient and (D-) The product of these two variables yields the adjusted decision threshold variable, which is then clamped to limit it to a preset minimum threshold. Compared with the preset maximum threshold Between; when the cosine distance is normalized to the interval between 0 and 1, Take 0, The threshold is set to 1, thus relaxing the judgment threshold when the overall distortion level is higher than the baseline distortion level, and tightening the judgment threshold when the overall distortion level is lower than the baseline distortion level. A comparison logic statement is written to numerically compare the cosine distance output by the network with the judgment threshold. If the current cosine distance is greater than the judgment threshold, the image similarity is judged to be low, and the system outputs a Boolean value of "true" indicating the presence of a printing defect. Conversely, if the distance is less than or equal to the threshold, a Boolean value of "false" is output, indicating that the product is qualified, thus achieving closed-loop inspection of the defect identification.

[0039] In an optional embodiment, the step of decomposing the final transformation matrix into the input modulation network to generate gain and bias, and adjusting the feature maps of the convolutional layers of the Siamese convolutional network, includes: The final transformation matrix is ​​decomposed into translation parameters, rotation angles, scaling factors, and shearing parameters; The decomposed parameters are normalized and then input into a modulation network containing fully connected layers. The output is a gain vector and a bias vector that match the number of channels of a specific convolutional layer in the Siamese convolutional network. Channel-level affine transformation is then performed on the feature map of the convolutional layer.

[0040] For the final 3×3 homogeneous affine transformation matrix output after fine alignment, the elements representing translation are directly read to obtain two translation parameters on the X and Y axes. Then, the 2×2 affine transformation submatrix in the upper left corner is extracted and parameterized to separate the core quantities describing geometric distortion characteristics, including a global rotation angle, two scaling factors on the X and Y axes, and a shearing parameter. After extracting these parameters, they are combined with the two translation parameters to form a 6-dimensional affine parameter vector. This 6-dimensional affine parameter vector is then normalized to a minimum and maximum value based on the pre-statistical range of parameters from normal printed samples. For example, the translation parameter is mapped to the interval -1 to 1, the rotation angle divided by 180 degrees is mapped to the interval -1 to 1, the scaling factor is mapped to the interval 0 to 2 centered at 1.0, and the shearing parameter is mapped to the interval -1 to 1. These are then concatenated to obtain a one-dimensional parameter vector containing translation, rotation, scaling, and shearing information, which serves as the input to the modulation network.

[0041] This involves two neural network models: a Siamese convolutional network (Siamese CNN) and a modulation network. The Siamese CNN takes an image from which features are to be extracted as input and outputs a deep feature map with semantic information. Its network structure employs a weight-sharing residual network architecture, containing multiple cascaded residual blocks. The modulation network takes a one-dimensional parameter vector, denoted as v, containing translation, rotation, scaling, and shearing information as input and outputs a gain vector γ and a bias vector β, both of length C, where C is the number of feature map channels in the Siamese CNN's modulation convolutional layer. For example, in a specific stage of ResNet50, C is 256. The modulation network uses a multilayer perceptron structure with two fully connected layers. The first fully connected layer contains 64 neurons and uses a linear rectified function for non-linear activation; the calculation process can be represented as an intermediate variable. The hidden layer feature h is the output of z after activation by a linear rectified function, where and These are the weight matrix and bias vector of the first fully connected layer, respectively; the second fully connected layer contains 2C neurons and does not use a non-linear activation function, and its calculation process can be expressed as follows: ,in and Here, represents the weight matrix and bias vector of the second fully connected layer, and o is the output 2C-dimensional vector. The output vector o of the modulation network is divided into two parts, serving as a gain vector and a bias vector of length C, respectively. Using instance normalization, the extracted deep feature map is multiplied by the gain vector in the channel dimension and then the bias vector is added, completing the channel-level affine transformation of the feature map. This allows the feature response to implicitly compensate for the deformation error remaining from geometric alignment during subsequent feature comparisons.

[0042] In an optional embodiment, the calculation of the cosine distance between depth features, and the determination of a defect when the cosine distance is greater than a judgment threshold, wherein the judgment threshold is adjusted based on the overall distortion degree of the final transformation matrix, including: Extract the affine transformation sub-matrix after removing the translation parameters from the final transformation matrix, calculate the normalized norm error between the affine transformation sub-matrix and the identity matrix, and combine it with the corrected image alignment residual as the overall distortion degree; Based on a preset basic threshold, when the overall distortion increases, the judgment threshold is relaxed proportionally. When the overall distortion level decreases, the determination threshold is tightened accordingly.

[0043] From the 3×3 final transformation matrix obtained through layer-by-layer fine alignment of the image pyramid, the third column vector responsible for spatial translation and the homogeneous coordinates of the third row are stripped away, and the 2×2 affine transformation sub-matrix in the upper left corner is extracted. To measure the alignment effect caused by affine geometric deformation or residual geometric distortion, a 2×2 standard identity matrix is ​​constructed, and the difference matrix between the affine transformation sub-matrix and the standard identity matrix is ​​calculated. The Frobenius norm of this difference matrix is ​​calculated, which is the square root of the sum of the squares of the absolute values ​​of the matrix elements, to obtain the affine deviation. The affine deviation is normalized according to a preset normal transformation range and then weighted and fused with the corrected pixel residuals or structural similarity residuals of the overlapping area to obtain the overall distortion index D. Specifically, the affine deviation is normalized into the first distortion component. The corrected pixel residuals or structural similarity residuals in the overlapping region are normalized into a second distortion component. and in accordance with Calculate the overall distortion index D, where α is the preset fusion weight, with a value ranging from 0 to 1, preferably 0.6; and All values ​​are normalized to the range of 0 to 1. The affine deviation reflects the intensity of rotation, scaling, and shearing experienced by the image under inspection. The corrected image alignment residual is a robust residual after removing highly disparate suspected defect areas, or a residual calculated from the RANSAC in-point matching region, background region, or non-defect candidate region, reflecting the actual residual error after geometric correction. A preset base threshold for cosine distance used to determine defects is set to 0.85, and a reference value of 0.1 is set as the baseline distortion level for determining if the image quality is in a standard state. An adjustment coefficient of 0.2 is input, and the initial judgment threshold is calculated by adding the adjustment coefficient to the product of the base threshold and the difference between the current distortion level and the baseline distortion level. The calculated initial judgment threshold is then clamped, limiting it to between a preset minimum threshold and a preset maximum threshold. When the cosine distance is normalized to the range of 0 to 1, the preset minimum threshold is 0, and the preset maximum threshold is 1. When the calculated overall distortion increases, for example, when the calculated value is 0.3 and greater than the baseline value of 0.1, it indicates that the image under inspection has undergone severe geometric distortion. The residual noise after alignment is prone to interfering with feature extraction. At this time, the judgment threshold is calculated to be 0.89, and the threshold is relaxed proportionally to avoid misjudging the deformation alignment residual as a printing defect. Conversely, when the overall distortion decreases, for example, when the calculated value is 0.05 and less than the baseline value of 0.1, it indicates high alignment accuracy. The judgment threshold is tightened accordingly to 0.84 to improve the detection sensitivity of minor printing defects such as ink droplet splashes and fine scratches.

[0044] In a second embodiment, the present invention also proposes a system comprising the following modules: The module is used to acquire a standard logo image and a logo image to be inspected. Based on the standard logo image, it calculates the inherent stroke direction prior model of the printed logo. It constructs an image pyramid using bilateral guided filtering downsampling. The guided image generates edges that are consistent with the direction of key structures based on the inherent stroke direction prior model. At the top of the image pyramid, it calculates the structured color gradient histogram features of the standard logo image and the logo image to be inspected in the CIELab color space and performs coarse alignment to obtain the initial transformation matrix. The generation module is used to perform fine alignment layer by layer from the second-to-last layer to the bottom layer of the image pyramid. The initial transformation matrix obtained by coarse alignment of the top layer or the transformation matrix updated by adjacent lower resolution layers is scaled and used as the initial value of the current layer. The transformation matrix is ​​updated by an energy function weighted by phase correlation and structural similarity measures. The weights are allocated according to the degree of distortion and alignment residual to obtain the final transformation matrix. The final transformation matrix is ​​used to perform geometric transformation on the image to be inspected to generate a corrected image to be inspected. The determination module is used to input the standard identification image and the corrected identification image into a Siamese convolutional network to extract depth features, decompose the final transformation matrix into a modulation network to generate gain and bias, adjust the feature maps of the convolutional layers of the Siamese convolutional network, calculate the cosine distance between depth features, and determine that there is a defect when the cosine distance is greater than the determination threshold. The determination threshold is adjusted based on the overall distortion degree of the final transformation matrix.

[0045] The above description represents the preferred embodiments of the present invention. It should be noted that, for those skilled in the art, various improvements and modifications can be made without departing from the principles of the present invention, and these improvements and modifications are also considered to be within the scope of protection of the present invention.

Claims

1. A method for inspecting printed labels on food packaging, characterized in that, include: Obtain a standard logo image and a logo image to be inspected. Calculate the inherent stroke direction prior model of the printed logo based on the standard logo image. Construct an image pyramid using bilateral guided filtering downsampling. The guided image generates edges that maintain consistency with the key structural direction based on the inherent stroke direction prior model. Calculate the structured color gradient histogram features of the standard logo image and the logo image to be inspected in the CIELab color space at the top layer of the image pyramid and perform coarse alignment to obtain the initial transformation matrix. The image pyramid is finely aligned layer by layer from the second-to-last layer to the bottom layer. The initial transformation matrix obtained by the coarse alignment of the top layer or the transformation matrix updated by the adjacent lower resolution layer is scaled and used as the initial value of the current layer. The transformation matrix is ​​updated by an energy function weighted by phase correlation and structural similarity measures. The weights are allocated according to the degree of distortion and alignment residual to obtain the final transformation matrix. The final transformation matrix is ​​used to perform geometric transformation on the image to be inspected to generate a corrected image to be inspected. The standard label image and the corrected label image are input into a Siamese convolutional network to extract depth features. The final transformation matrix is ​​decomposed and input into a modulation network to generate gain and bias. The feature maps of the convolutional layers of the Siamese convolutional network are adjusted, and the cosine distance between depth features is calculated. When the cosine distance is greater than the judgment threshold, a defect is determined to exist. The judgment threshold is adjusted based on the overall distortion degree of the final transformation matrix.

2. The method according to claim 1, characterized in that, The prior model for calculating the inherent stroke direction of printed logos based on the standard logo image includes: Extract the morphological skeleton of the standard identifier image; At the skeleton pixel position corresponding to the morphological skeleton, a gradient direction histogram is calculated based on the standard identifier image; The orthogonal directions of the N most frequent gradient directions are selected as the inherent stroke directions of the printed mark, and the prior model of the inherent stroke direction is constructed.

3. The method according to claim 1, characterized in that, The method of constructing an image pyramid using bilateral guided filtering downsampling, wherein the guided map generates edges that maintain consistency with the direction of key structures based on the prior model of inherent stroke direction, includes: The structure tensor of the image is calculated and the eigenvalues ​​and corresponding eigenvectors are solved. The eigenvectors corresponding to small eigenvalues ​​are extracted as local stroke extension directions. Based on the prior model of the inherent stroke direction, high weights are assigned to the structure tensor of the local stroke extension direction that is consistent with the inherent stroke direction of the printed mark, and a gradient structure salience map is generated as a guide map. The guided image is used to perform bilateral filtering on the image to be processed, and downsampling is performed at a fixed ratio to obtain the pyramid images of each layer.

4. The method according to claim 3, characterized in that, The initial transformation matrix is ​​obtained by coarsely aligning the structured color gradient histogram features of the standard identifier image and the identifier image to be detected in the CIELab color space at the top layer of the image pyramid, including: Convert the image to the CIELab color space, extract the key points of the image, and calculate the pixel gradient magnitude and direction of each channel; Based on the prior model of the inherent stroke direction, the gradient direction in the neighborhood of the key point is non-uniformly discretely mapped to generate the local structured color gradient histogram feature of the key point. The initial transformation matrix is ​​calculated by using the least squares method to calculate the key points corresponding to the cross-correlation matching space of the local structured color gradient histogram features.

5. The method according to claim 1, characterized in that, The process involves fine alignment layer by layer from the second-to-last layer of the image pyramid to the bottom layer. The initial transformation matrix obtained from the coarse alignment at the top layer, or the transformation matrix updated from adjacent lower-resolution layers, is scaled and used as the initial value for the current layer. The transformation matrix is ​​then optimized using an energy function weighted by phase correlation and structural similarity measures. Weights are allocated based on the degree of distortion and alignment residuals to obtain the final transformation matrix, including: Calculate the phase correlation and structural similarity measures of local image patches; If the alignment residual of the local image patch is higher than a preset residual threshold, the weight ratio of the phase correlation metric is increased. A gradient-free optimization algorithm is used to solve for the transformation matrix parameters that maximize the energy function.

6. The method according to claim 1 or 5, characterized in that, The step of decomposing the final transformation matrix into the modulation network to generate gain and bias, and adjusting the feature maps of the convolutional layers of the Siamese convolutional network, includes: The final transformation matrix is ​​decomposed into translation parameters, rotation angles, scaling factors, and shearing parameters; The decomposed parameters are normalized and then input into a modulation network containing fully connected layers. The output is a gain vector and a bias vector that match the number of channels of a specific convolutional layer in the Siamese convolutional network. Channel-level affine transformation is then performed on the feature map of the convolutional layer.

7. The method according to claim 1, characterized in that, The cosine distance between depth features is calculated. When the cosine distance is greater than a judgment threshold, a defect is determined to exist. The judgment threshold is adjusted based on the overall distortion degree of the final transformation matrix, including: Extract the affine transformation sub-matrix after removing the translation parameters from the final transformation matrix, calculate the normalized norm error between the affine transformation sub-matrix and the identity matrix, and combine it with the corrected image alignment residual as the overall distortion degree; Based on a preset basic threshold, when the overall distortion increases, the judgment threshold is relaxed proportionally. When the overall distortion level decreases, the determination threshold is tightened accordingly.

8. A food packaging printing label inspection system, characterized in that, include: The module is used to acquire a standard logo image and a logo image to be inspected. Based on the standard logo image, it calculates the inherent stroke direction prior model of the printed logo. It constructs an image pyramid using bilateral guided filtering downsampling. The guided image generates edges that are consistent with the direction of key structures based on the inherent stroke direction prior model. At the top of the image pyramid, it calculates the structured color gradient histogram features of the standard logo image and the logo image to be inspected in the CIELab color space and performs coarse alignment to obtain the initial transformation matrix. The generation module is used to perform fine alignment layer by layer from the second-to-last layer to the bottom layer of the image pyramid. The initial transformation matrix obtained by coarse alignment of the top layer or the transformation matrix updated by adjacent lower resolution layers is scaled and used as the initial value of the current layer. The transformation matrix is ​​updated by an energy function weighted by phase correlation and structural similarity measures. The weights are allocated according to the degree of distortion and alignment residual to obtain the final transformation matrix. The final transformation matrix is ​​used to perform geometric transformation on the image to be inspected to generate a corrected image to be inspected. The determination module is used to input the standard identification image and the corrected identification image into a Siamese convolutional network to extract depth features, decompose the final transformation matrix into a modulation network to generate gain and bias, adjust the feature maps of the convolutional layers of the Siamese convolutional network, calculate the cosine distance between depth features, and determine that there is a defect when the cosine distance is greater than the determination threshold. The determination threshold is adjusted based on the overall distortion degree of the final transformation matrix.

9. The system according to claim 8, characterized in that, The prior model for calculating the inherent stroke direction of printed logos based on the standard logo image includes: Extract the morphological skeleton of the standard identifier image; At the skeleton pixel position corresponding to the morphological skeleton, a gradient direction histogram is calculated based on the standard identifier image; The orthogonal directions of the N most frequent gradient directions are selected as the inherent stroke directions of the printed mark, and the prior model of the inherent stroke direction is constructed.

10. The system according to claim 8, characterized in that, The method of constructing an image pyramid using bilateral guided filtering downsampling, wherein the guided map generates edges that maintain consistency with the direction of key structures based on the prior model of inherent stroke direction, includes: The structure tensor of the image is calculated and the eigenvalues ​​and corresponding eigenvectors are solved. The eigenvectors corresponding to small eigenvalues ​​are extracted as local stroke extension directions. Based on the prior model of the inherent stroke direction, high weights are assigned to the structure tensor of the local stroke extension direction that is consistent with the inherent stroke direction of the printed mark, and a gradient structure salience map is generated as a guide map. The guided image is used to perform bilateral filtering on the image to be processed, and downsampling is performed at a fixed ratio to obtain the pyramid images of each layer.