Image similarity detection method and device, equipment and storage medium

By using brightness difference compensation and contrast limitation enhancement processing, combined with foreground-background separation and weighted aggregation, the problem of misjudgment in traditional image similarity detection methods under noise and illumination changes is solved, and more stable and automated image similarity calculation is achieved.

CN121999249APending Publication Date: 2026-05-08STORAGEX TECH INC
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202610001240.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-01-04
Publication Date
2026-05-08

AI Technical Summary

Technical Problem

Traditional image similarity calculation methods are prone to misjudgment in scenarios with noise interference, lighting changes, and similar textures, and they are highly dependent on manual parameter tuning, resulting in unstable detection results and low automation.

Method used

Enhanced preprocessing through brightness difference compensation and contrast limitation, combined with a region similarity calculation mechanism for foreground-background separation, employs a sliding window for image separation and weighted aggregation to reduce noise sensitivity, adaptively adjust weights, and reduce the need for manual parameter tuning.

Benefits of technology

It improves the accuracy and adaptability of image similarity detection, reduces the impact of noise interference and lighting changes, and ensures the stability and automation of detection results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121999249A_ABST
    Figure CN121999249A_ABST
Patent Text Reader

Abstract

The invention discloses an image similarity detection method and device, equipment and a storage medium, and relates to the field of image processing. Respectively detecting image brightness and contrast of the target image and the reference image, and performing brightness difference compensation and contrast limit enhancement; performing foreground and background separation on the to-be-processed areas of the two preprocessed images through a sliding window; selecting an ith target area of the target image, traversing all to-be-compared areas in the reference image, and performing similarity calculation on the foreground image and the background image to obtain a score of the ith area; and sliding and traversing all target areas of the target image, performing weighted aggregation on scores of all the areas, and outputting a global similarity value of the image. According to the scheme, the adaptability and accuracy of the algorithm in a complex scene are improved through brightness difference compensation and contrast limit enhancement preprocessing in combination with a region similarity calculation mechanism of foreground and background separation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of image processing, and in particular to an image similarity detection method, apparatus, device, and storage medium. Background Technology

[0002] In the field of image processing, image similarity calculation is a core technology supporting applications such as image retrieval, content moderation, and copyright protection. Related technologies are mainly divided into two categories: traditional pixel-based algorithms and data-driven deep learning methods.

[0003] Traditional algorithms rely on manually designed feature extractors and metric functions to assess similarity by deconstructing the brightness, contrast, and structural information of an image. They offer advantages such as high computational efficiency, strong logical interpretability, robustness in specific scenarios, and the ability to perform without training data. However, these methods face multiple challenges in practical applications: when images are noisy, the algorithm's output is easily distorted; in scenarios with similar texture features but different semantic content, misjudgments are prone to occur; furthermore, the algorithm's performance is highly dependent on manually set thresholds, weights, and other parameters, making parameter adjustment cumbersome and lacking universality, significantly increasing the barrier to entry and uncertainty.

[0004] While deep learning methods can improve feature discrimination capabilities through data-driven approaches and demonstrate strong adaptability in complex scenarios, their training process relies on large-scale labeled datasets. This makes it difficult to meet the prerequisites in scenarios with scarce data or specific domains, thus limiting the flexibility of practical deployment.

[0005] The aforementioned problems render traditional methods unreliable in similarity calculations when processing images with inconsistent brightness, significant contrast differences, or mixed foreground and background, making it difficult to balance accuracy and efficiency. Therefore, existing technologies urgently need improvement to address these issues. Summary of the Invention

[0006] This application provides an image similarity detection method, apparatus, device, and storage medium. By enhancing preprocessing through brightness difference compensation and contrast limitation, and combining a region similarity calculation mechanism for foreground-background separation, the algorithm's adaptability and accuracy in complex scenes are improved.

[0007] On the one hand, this application provides an image similarity detection method, the method comprising: The brightness and contrast of the target image and the reference image are detected separately, and brightness difference compensation and contrast limitation enhancement are performed. The foreground and background of the two preprocessed images are separated sequentially using a sliding window. Select the i-th target region in the target image, slide through all the regions to be compared in the reference image, calculate the similarity between the foreground image and the background image respectively, and obtain the score of the i-th region; The algorithm iterates through all target regions of the target image and aggregates the scores of all regions by weighting to output the global similarity value of the image.

[0008] Specifically, the similarity calculation between the foreground image and the background image includes: Calculate the brightness similarity separately Contrast similarity Similarity to structure and texture ; Based on brightness similarity Contrast similarity Similarity to structure and texture Calculate tile similarity ; indicates the following:

[0009] in, Indicates the weighting coefficient; The score of the i-th region is calculated based on foreground similarity and background similarity.

[0010] Specifically, the calculation of the score for the i-th region based on foreground similarity and background similarity includes: Calculate the foreground similarity and background similarity between the i-th target region and each region to be compared in the reference image, and combine the foreground similarity and background similarity to calculate a similarity score; All similarity scores are sorted, and the highest similarity score is determined as the score of the i-th target region.

[0011] Specifically, the calculation of the similarity score by combining the foreground similarity and the background similarity includes: Obtain the number of non-zero pixels in each of the two image patches. and And calculate the foreground difference compensation value. , means as follows:

[0012] A similarity score is obtained by weighting the foreground difference compensation value, foreground similarity, and background similarity. , means as follows:

[0013] in, These represent the foreground similarity value, foreground difference compensation value, and background similarity value, respectively. This is the proportionality coefficient.

[0014] Specifically, the sliding traversal of all target regions of the target image, and the weighted aggregation of all region scores, outputs a global image similarity value, including:

[0015] This is the global similarity value. This represents the number of regions that can be traversed in the target graph. This represents the regional score of the i-th target region.

[0016] Specifically, brightness difference compensation includes: Calculate the image brightness of the target image and the reference image respectively. And calculate the image brightness difference. , means as follows:

[0017]

[0018]

[0019] Based on the image brightness difference, the weak brightness image Image enhancement is represented as follows:

[0020] in, Represents pixels in an RGB image Maximum channel brightness value, Indicates image size, and Indicates the brightness of two images; This indicates the brightness of the image after brightness enhancement.

[0021] Specifically, enhanced contrast limiting includes: The image after brightness difference compensation is divided into several sub-image patches, and the contrast limiting coefficient is calculated. , means as follows:

[0022] Obtain the original histogram of each subplot. It will exceed The count is truncated, and the excess pixels are evenly redistributed to all gray levels to obtain the clipping histogram. ; Based on the cumulative clipping histogram and brightness mapping, the contrast-limited enhanced output image is calculated as follows:

[0023]

[0024] in, This is the contrast limiting factor. For pixels in a sub-tile, Image grayscale levels, For sub-tiles, the gray level does not exceed the initial pixel value. The total number of pixels, To enhance the output of balanced pixel values ​​by limiting contrast, This represents the rounding function.

[0025] On the other hand, this application provides an image similarity detection device, the device comprising: The image preprocessing module is used to detect the brightness and contrast of the target image and the reference image respectively, and to perform brightness difference compensation and contrast limitation enhancement processing. The foreground and background separation module is used to separate the foreground and background of the areas to be processed in two preprocessed images sequentially through a sliding window. The similarity calculation module is used to select the i-th target region in the target image, slide through all the regions to be compared in the reference image, calculate the similarity between the foreground image and the background image respectively, and obtain the score of the i-th region; The weighted aggregation module is used to slide through all target regions of the target image, perform weighted aggregation of the scores of all regions, and output the global similarity value of the image.

[0026] In another aspect, this application provides a computer device including a processor and a memory, wherein the memory stores at least one instruction, at least one program, code set or instruction set, wherein the at least one instruction, the at least one program, the code set or instruction set is loaded and executed by the processor to implement the image similarity detection method described above.

[0027] In another aspect, this application provides a computer-readable storage medium storing at least one instruction, at least one program, code set, or instruction set, wherein the at least one instruction, the at least one program, the code set, or the instruction set is loaded and executed by a processor to implement the image similarity detection method described above.

[0028] The beneficial effects of the technical solution provided in this application include at least the following: This application enhances the input image through brightness difference compensation and contrast limitation, reducing sensitivity to noise and avoiding misjudgments caused by local lighting changes or image interference. Through a foreground and background separation mechanism, similarity calculation distinguishes between foreground and background, preventing erroneous matching when background textures are highly similar, thereby solving the problem of texture similarity misjudgment. The weighted aggregation process of region scores adaptively integrates information based on actual matching quality, eliminating the need for manually set similarity thresholds, significantly reducing parameter tuning requirements, and making the global similarity output more accurately reflect the semantic consistency of image content. Attached Figure Description

[0029] Figure 1 This is a flowchart of the image similarity detection method provided in the embodiments of this application; Figure 2 This is a schematic diagram of a target image to be compared and a reference image provided in an exemplary embodiment; Figure 3 This is a flowchart of the image similarity detection method provided in the embodiments of this application; Figure 4 This is a comparison diagram of a low-brightness image after contrast-limited enhancement. Figure 5 It is a heatmap comparing the differences between two images; Figure 6 This is a schematic diagram of the global similarity values ​​output after comparing two images; Figure 7 This paper shows a structural block diagram of the image similarity detection device provided in an embodiment of this application; Figure 8 A structural block diagram of a computer device provided in an exemplary embodiment of this application is shown. Detailed Implementation

[0030] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.

[0031] In this article, "multiple" refers to two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone. The character " / " generally indicates that the preceding and following related objects have an "or" relationship.

[0032] In traditional image similarity detection techniques, pixel-based algorithms are prone to misjudging differences in brightness caused by changes in ambient lighting as differences in image content, resulting in sensitivity to imaging noise. When there are highly similar textures in the background area of ​​an image, the algorithm has difficulty effectively distinguishing between foreground objects and background interference, leading to misjudgments. In addition, the setting of similarity thresholds is highly dependent on human experience for adjustment, which limits the adaptability of the system in different scenarios and affects the stability and automation of the detection results.

[0033] For example, in the scenario of product surface defect detection on an industrial automated production line, the brightness of images of metal parts acquired at different times varies due to fluctuations in lighting conditions. Traditional algorithms identify such brightness differences as content differences. At the same time, the local texture similarity between normal texture areas and minor scratch areas on the surface of the parts is high, and the algorithm cannot accurately separate the foreground defects from the background texture, misjudging the scratches as normal areas. Operators need to repeatedly adjust the similarity threshold based on experience to adapt to different batches of products, which increases the complexity of operation and system debugging time.

[0034] If the above problems are not solved, the reliability of image similarity detection results will be significantly reduced, which may lead to misjudgments and omissions in automated quality inspection systems. In key application areas such as medical image comparison, incorrect similarity judgments may lead to inaccurate diagnostic criteria. System maintenance costs will increase, as continuous reliance on manual intervention to maintain basic functions will hinder the automation evolution of the detection process.

[0035] To address this, this application provides an image similarity detection method, such as... Figure 1 As shown, it includes the following steps: S1. Detect the image brightness and contrast of the target image and the reference image respectively, and perform brightness difference compensation and contrast limitation enhancement. In this embodiment, the image similarity detection method addresses the issues of sensitivity to noise, misjudgment when textures are similar, and high reliance on manual parameter tuning. The target image and the reference image are two images to be compared. Brightness difference compensation involves calculating the brightness of the two images, filtering out the weaker image with lower brightness, and compensating for its brightness to achieve consistency between the two images, facilitating subsequent comparison. In practical applications, histogram matching techniques can be used, for example, linearly mapping the brightness histogram of the target image to the histogram of the reference image to eliminate brightness deviations caused by different lighting conditions.

[0036] Furthermore, contrast-limited enhancement applies an upper limit when enhancing image contrast to prevent over-enhancement. Specifically, it can be achieved by combining adaptive contrast enhancement with saturation thresholding, for example, setting the maximum contrast gain threshold to 1.2 times. This is primarily to suppress noise amplification while enhancing image details. This step is a preprocessing step designed to improve detection accuracy.

[0037] S2. Separate the foreground and background of the two preprocessed images in sequence using a sliding window; This process requires setting a sliding window to sequentially separate the foreground and background of the regions to be processed (i.e., ROI regions) in two preprocessed images, dividing the selected ROI region into the subject and background. As a preferred implementation, an edge detection-based segmentation algorithm can be used, such as using the Canny operator to detect edges and then performing region growing, mainly to focus similarity calculations on key parts of the image content.

[0038] S3. Select the i-th target region in the target image, slide through all the regions to be compared in the reference image, calculate the similarity between the foreground image and the background image respectively, and obtain the score of the i-th region; This application describes the operation using the target image as the object of operation. The i-th target region (i.e., the i-th ROI region) in the image is selected using a sliding window. Then, all regions to be compared in the reference image (i.e., the ROI regions of the image, usually the two sliding windows are the same size) are traversed by sliding window. The similarity is calculated for the foreground image and the background image respectively. Figure 2 An example diagram of the target image and the reference image is given. That is, after selecting a ROI region in image A, a 1-to-n comparison is made with all ROI regions in image B one by one. The comparison is divided into foreground and background images, which are calculated separately.

[0039] The region score can be obtained by averaging the similarity scores, for example, by taking the average of the similarity calculation results of all compared regions. This is mainly to represent the matching quality of the target region.

[0040] S4. Slide through all target regions of the target image and aggregate the scores of all regions by weight to output the global similarity value of the image.

[0041] Figure 3This is a flowchart of the image similarity detection method provided in this application embodiment. Taking a target image as an example, it is necessary to traverse all target regions of the target image through a sliding window and then aggregate the scores of all regions with weights to obtain the final global similarity value. Specifically, a weighted average method based on the number of pixels in the region can be used, for example, by assigning weight coefficients according to the size of the region, which is mainly for outputting the global similarity value of the image.

[0042] The preprocessed image is sequentially separated into foreground and background using a sliding window. This mechanism dynamically divides the subject and background regions based on local image content, focusing similarity calculations on foreground objects rather than overall texture, effectively distinguishing between real content similarity and background interference. After selecting a specific target region in the target image, all regions to be compared in the reference image are traversed, and similarity calculations are performed on the foreground and background images respectively. The region score dynamically obtains the highest value through the matching process. Furthermore, all target regions in the target image are traversed, and the scores of each region are weighted and aggregated to output a global similarity value reflecting the overall matching quality. This process adaptively integrates local information, reducing reliance on preset thresholds.

[0043] In summary, this method significantly improves the reliability of image similarity detection. The combined effect of brightness difference compensation and contrast limitation enhancement effectively reduces sensitivity to noise, avoiding misjudgments caused by local lighting variations or image interference. The foreground-background separation mechanism focuses the analysis on the structural features of the main image subject, preventing erroneous matching when background textures are highly similar, thus solving the problem of texture similarity misjudgment. The weighted aggregation process of region scores adaptively integrates information based on actual matching quality, eliminating the need for manually set similarity thresholds, significantly reducing parameter tuning requirements, and enabling the global similarity output to more accurately reflect the semantic consistency of image content.

[0044] Traditional image similarity detection methods have limitations when calculating the similarity between foreground and background images. They rely solely on pixel-level direct comparisons and lack comprehensive consideration of image brightness, contrast, and texture. This makes them prone to misjudgment in noisy, unevenly lit, or textured scenes. Furthermore, they heavily rely on manual parameter tuning to adapt to different image characteristics, making it difficult to reliably distinguish the true semantic differences between foreground and background.

[0045] Therefore, this application comprehensively considers factors such as brightness, contrast, and texture. For the two selected regions, it calculates the similarity between the foreground and background images, specifically calculating the brightness similarity. Contrast similarity Similarity to structure and texture ; indicates the following:

[0046]

[0047]

[0048]

[0049] in, This indicates the selected foreground or background image block in either of the two images; and These represent the average brightness of the two image blocks, respectively. and These represent the standard deviations of the two image patches, Indicates the covariance between two image patches; and These represent the pixels of the two image blocks, Indicates the number of pixels in the corresponding image block; These represent the luminance stability constant, contrast stability constant, and structural stability parameter, respectively. Based on brightness similarity Contrast similarity Similarity to structure and texture Calculate tile similarity ; indicates the following:

[0050] in, Indicates the weighting coefficient; The score for region i is calculated based on foreground similarity and background similarity.

[0051] Among them, brightness similarity It is a normalized ratio based on the average brightness of image patches, which can be achieved through logarithmic domain transformation or gamma correction preprocessing. The aim is to suppress the interference of background light variations on similarity evaluation. Contrast Similarity This can be understood as a symmetrical comparison mechanism utilizing the standard deviation of image patches. It can be implemented using local histogram equalization or adaptive contrast mapping, aiming to effectively capture local contrast distortion and ensure computational stability in low-contrast regions. (Structural texture similarity) It is an index that measures structural correlation through the covariance between pixels. It can be implemented using wavelet transform coefficients or Gabor filter responses, with the aim of distinguishing regions with similar textures but different structures.

[0052] Because the foreground and background are calculated separately, for the selected i-th region of the target image, the foreground similarity is obtained by traversing all regions of the B image. Score set and background similarity The score set is then fused with the foreground and background similarity sets to obtain the score for the i-th region.

[0053] The above technical solutions effectively suppress mismatches caused by random pixel fluctuations in noisy scenarios, significantly improve the accuracy of similarity assessment under uneven lighting conditions, and reduce reliance on manual parameter tuning through the adaptive adjustment mechanism of weight coefficients, thereby achieving stable differentiation between foreground and background semantic differences. In some embodiments described above in this application, since what is obtained is foreground similarity... Score set and background similarity The score set, directly using these scores or weighted scores may lead to regional scores being affected by suboptimal matching, failing to accurately reflect the optimal matching degree. Therefore, further fusion calculation is needed to obtain the score of the i-th region. This application provides a calculation method, including: 1. Calculate the foreground similarity and background similarity between the i-th target region and each region to be compared in the reference image, and combine the foreground similarity and background similarity to calculate the similarity score; 2. Sort all similarity scores and determine the highest similarity score as the score of the i-th region of the i-th target region.

[0054] Specifically, the proposed scheme first independently calculates the foreground and background similarity between each target region and all regions to be compared, achieving a refined evaluation of local image features. Then, the foreground and background similarities are combined to generate a comprehensive similarity score, ensuring the comprehensiveness of the matching evaluation. Based on this, all similarity scores are ranked, effectively highlighting the best matching result. Finally, the highest score is selected as the region score, avoiding interference from suboptimal matches. This sequence design ensures that each target region can be accurately associated with the most similar region in the referenced image, thus providing a reliable foundation for global similarity aggregation.

[0055] The above technical solution effectively avoids the problem of regional scores being interfered with by suboptimal matching, ensuring that the score of each target region accurately reflects the best matching degree with the reference image, thereby improving the accuracy of global image similarity calculation. In some embodiments of this application, a score for the i-th region is calculated based on foreground and background similarity. However, in its implementation, when there is a difference in the actual coverage of the foreground region between the target image and the reference image, directly combining foreground and background similarity can lead to distorted similarity scores because the mismatch in the number of foreground pixels is not considered. This introduces the risk of misjudgment in local image region comparison, especially affecting detection accuracy in scenarios where the foreground region sizes are inconsistent. Therefore, this application requires separate difference compensation for the foreground image before comprehensively calculating the similarity score. , means as follows: 1. Count the number of non-zero pixels in each of the two image blocks. and And calculate the foreground difference compensation value. , means as follows:

[0056] 2. A similarity score is obtained by weighting the foreground difference compensation value, foreground similarity, and background similarity. , means as follows:

[0057] in, These represent the foreground similarity value, foreground difference compensation value, and background similarity value, respectively. This is the proportionality coefficient.

[0058] Foreground difference compensation value This refers to a correction factor calculated based on the difference in the number of foreground pixels. It can be dynamically adjusted based on the relative difference in pixel count to compensate for similarity deviations caused by inconsistent foreground coverage. This mechanism ensures that when the foreground region size is inconsistent, The value can dynamically correct similarity calculations, avoiding distortion caused by mismatched pixel counts. and The solution captures pixel-level structure and background stability separately. The configurability of the scaling factors allows the solution to adapt to different scenarios, thereby achieving robust evaluation of changes in foreground scale as a whole. The three scaling factors are usually selected as 0.6, 0.3 and 0.1 to achieve the best results.

[0059] Through the above scheme, this application effectively avoids similarity score distortion in scenarios where the size of the foreground region is inconsistent, significantly reduces the risk of misjudgment caused by the mismatch in the number of foreground pixels, and improves the accuracy and robustness of local region comparison in the image. Furthermore, for the i-th target region in the selected target map (i.e., map A), after polling all the regions to be compared in the reference map (map B), the best region is selected. Through foreground similarity, foreground difference compensation, and background similarity fusion, the final similarity score of the two ROI regions is obtained. .according to Figure 3 The window polling logic iterates through all ROI regions in image A, obtaining scores for each ROI region. Then, the scores are weighted and aggregated to output the global image similarity value. , means as follows:

[0060] This is the global similarity value. This represents the number of regions that can be traversed in the target graph. This represents the regional score of the i-th target region.

[0061] In summary, this application employs an equal-weighted arithmetic average of all region scores, ensuring that the calculation of the global similarity value does not rely on manually set weight parameters, thus eliminating subjective interference. Simultaneously, since each region's score contributes equally to the final result, this aggregation method effectively suppresses scoring biases caused by noise or local feature anomalies in individual regions, enabling the global similarity assessment to more comprehensively reflect the overall image similarity. This mechanism, together with the sliding traversal operation, forms a complete technical system. First, it systematically traverses to obtain local similarity information for all target regions; second, it eliminates the uncertainty of weight allocation through standardized aggregation; and finally, it outputs a statistically stable global index. The objectivity and repeatability of the global image similarity assessment are significantly improved, avoiding evaluation biases caused by subjective weight allocation, and enhancing the consistency of the method across images of different sizes. In addition, this application also provides a brightness difference compensation method and a contrast limitation enhancement method, the image processing process of which is described below.

[0062] Brightness difference compensation: 1. Calculate the image brightness of the target image and the reference image respectively. And calculate the image brightness difference. , means as follows:

[0063]

[0064]

[0065] 2. Identifying weaker images based on their brightness differences. Image enhancement is represented as follows:

[0066] in, Represents pixels in an RGB image Maximum channel brightness value, Indicates image size, and Indicates the brightness of two images; This indicates the brightness of the image after brightness enhancement.

[0067] by Figure 2 Using the content as an example, it can be clearly seen that image A has lower brightness and is a low-brightness image. This step involves brightness compensation for image A. Specifically, the brightness difference compensation scheme first selects each pixel in the image, determines the maximum brightness value in the three channels, and then averages the maximum brightness values ​​of all pixels in the image. This average brightness value is then used for comparison and compensation. This execution order ensures that brightness differences are accurately quantified and compensated specifically, avoiding the insufficient adaptability of fixed compensation values ​​in complex scenes, while also preventing overcompensation. This provides balanced input conditions for subsequent foreground / background separation and similarity calculation.

[0068] Enhanced contrast limiting: 1. Divide the image after brightness difference compensation into several sub-image patches and calculate the contrast limiting coefficient. , means as follows:

[0069] 2. Obtain the original histogram of each sub-plot. It will exceed The count is truncated, and the excess pixels are evenly redistributed to all gray levels to obtain the clipping histogram. ; 3. Based on the cumulative clipping histogram and brightness mapping, calculate the contrast-limited enhanced output image, as shown below:

[0070]

[0071] in, This is the contrast limiting factor. For pixels in a sub-tile, Image grayscale levels, For sub-tiles, the gray level does not exceed the initial pixel value. The total number of pixels, To enhance the output of balanced pixel values ​​by limiting contrast, This represents the rounding function.

[0072] In this scheme, the image after brightness difference compensation is first divided into several sub-patterns (local processing units). This can be achieved using fixed grid partitioning or adaptive region segmentation based on edge detection. The aim is to allow contrast enhancement to be independently adjusted according to local lighting characteristics, avoiding the shortcomings of global processing in uneven lighting scenarios. The contrast limiting coefficient is then calculated. It dynamically sets the histogram truncation threshold, which can achieve different levels of noise suppression by adjusting the range of parameter α. The purpose is to prevent noise amplification caused by excessive enhancement in low-texture areas.

[0073] Obtaining and truncating the original histogram is for peak limiting of the pixel distribution, reducing the histogram count to over 100%. The values ​​are partially truncated and redistributed to all gray levels linearly or non-linearly to suppress noise amplification while maintaining histogram continuity. Finally, a pixel value mapping relationship is generated based on the truncated histogram to preserve local contrast information and ensure the usability of the processing results. Figure 4 This is a comparison diagram after contrast enhancement processing.

[0074] This local adaptive histogram processing mechanism, through the synergistic effect of sub-block partitioning, dynamic threshold setting, histogram optimization, and pixel mapping, enables the contrast enhancement process to not only improve the clarity of image details but also effectively suppress the noise amplification problem of images after brightness difference compensation in uneven lighting or low-contrast scenes. It also reduces the loss of details and missegmentation during the foreground-background separation process, thus providing a more reliable pixel-level input basis for image similarity calculation.

[0075] Regarding the foreground and background separation process, this application can employ methods such as specific color methods, fixed threshold methods, and automatic threshold methods to extract the foreground and background. Furthermore, the separation operation may result in broken edges or noise interference in the foreground image, and holes in the background image. These defects introduce errors into subsequent similarity calculations, affecting the accuracy of the global similarity value.

[0076] Therefore, this design can also perform morphological repairs, including the following: Foreground and background images can be extracted using specific color methods, fixed threshold methods, or automatic threshold methods. Create an elliptical shape operation kernel, perform an opening operation on the foreground image, and repair the foreground edges; Create an elliptical kernel to perform a closing operation on the background image and repair background holes.

[0077] Elliptical morphological operation kernels refer to structural elements with elliptical geometry, which can be implemented using elliptical kernels with different aspect ratios, aiming to fit the curved edge features commonly found in natural images; opening operation refers to morphological processing that performs erosion operation followed by dilation operation, which can be used to eliminate isolated noise points and broken edges in foreground images, aiming to restore the continuity and integrity of the foreground region; closing operation refers to morphological processing that performs dilation operation followed by erosion operation, which can be used to fill tiny holes in background images and connect scattered areas, aiming to ensure the smoothness and consistency of the background region.

[0078] As a preferred embodiment, the solution of this application is specifically implemented as follows: In the image processing flow, an elliptical operation kernel with a major axis to minor axis ratio of 2:1 is created using the OpenCV library; an opening operation is applied to the foreground image to effectively remove discrete noise points at the edges and connect broken contour lines; a closing operation is applied to the background image to fill in internal micro-holes and smooth the boundary areas; thereby obtaining an optimized image with continuous edges and a complete background for similarity calculation.

[0079] By employing the above-mentioned method, this application effectively eliminates the interference of foreground image edge breaks and background image holes on similarity calculation, significantly improving the accuracy and reliability of global image similarity values. The following is based on Figure 2 Taking the two images in the example, a specific implementation method is provided: 1. Convert the image color channels to HSV vectors, and use the V vectors to calculate the brightness difference between image A and image B; 2. Apply the linear transformation method to calculate the brightness difference value and compensate for it on the darker image; 3. Apply contrast-limiting enhancement to darker images; 4. Set the sliding window size, which is generally 40% to 80% of the input image size; in this article, 60% is used. 5. The sliding window in Figure A traverses all the sliding windows in Figure B respectively, and calculates the similarity of each pair of window images; The following is the process of calculating a pair of window images: 1) Select the appropriate method to separate the foreground and background based on the application scenario: specific color method, fixed threshold method, or automatic threshold method; The specific color method involves setting a color range and extracting the foreground based on that range.

[0080] The fixed threshold method involves setting a fixed threshold to extract the foreground.

[0081] Automatic thresholding uses adaptive or OUTS methods to automatically segment the foreground and background.

[0082] 2) Create an ellipse shape and perform an opening operation on the foreground to repair the foreground edges; Create an ellipse shape, perform a closing operation on the background, and repair background holes; 3) The SSIM algorithm takes the foreground images of Figure A and Figure B as input and calculates the foreground similarity score a; 4) Count the number of non-zero pixels in the foreground images of A and B, and calculate the difference score b between the number of non-zero pixels in A and B using symmetric normalization; 5) The SSIM algorithm takes the background images of Figure A and Figure B as input and calculates the background similarity score c; 6) Set weight scores r1, r2, r3. Generally, the foreground SSIM score has the highest weight, while the background SSIM score and the foreground difference score have the same weight. 7) The final window similarity score win_score = a*r1 + b*r2 + c*r3; 6. Following the steps above, the final similarity score set between all windows in Figure A and all windows in Figure B is obtained as [[win1_score1, win1_score2,….], [win2_score1, win2_score2….]….]. Figure 5 This is an example of a heatmap showing the differences between two images.

[0083] 7. Retain the maximum value of each subset in the set [win1_max_score, win2_max_score, ….]; calculate the average of the scores in the set to obtain the global similarity score of the final complete image.

[0084] Figure 6 This is the global similarity score output after comparison. The global similarity score between image A and image B is 0.73, with a foreground similarity score of 0.8 and a foreground difference compensation score of 0.83.

[0085] In some other embodiments, when an image contains text content, conventional foreground-background separation techniques are difficult to accurately separate text characters from the background due to the low contrast or uneven lighting conditions in the text area. This leads to distortion in the similarity calculation of the text portion, which in turn affects the reliability of the overall similarity assessment.

[0086] Therefore, the following extensions can be made: When an image contains text content or text regions, after foreground-background separation and morphological processing, the identified foreground regions are further analyzed to identify potential text regions. This can be done through connected component analysis, which identifies connected regions whose size, aspect ratio, density, and other features match the text characters or strings.

[0087] For potential text regions, the system applies local adaptive thresholding (such as local versions of the Otsu or Sauvola algorithms) to better separate text characters from their background, especially under low-contrast or uneven lighting conditions. At the same time, it can combine local contrast enhancement (different from global contrast-limited enhancement, but local enhancement for text regions) to further optimize the readability of the text and prepare for subsequent feature extraction.

[0088] When sliding and matching windows on the target image and the reference image, if the current window contains the recognized text area, in addition to the original SSIM and foreground difference compensation calculations, the verification of the text content will be additionally triggered; Character contour feature extraction: For the text area within the window, the system will extract the contour features of each character; this includes the geometric attributes of the character, such as area, perimeter, centroid, and Hu invariant moments, etc.; Hu invariant moments are a set of features that are invariant to scale, rotation, and translation, and can robustly describe the shape of the character, even in the presence of slight deformation or printing differences; Character sequence matching and similarity calculation: The system will match the character contour features extracted from the corresponding windows of the target image and the reference image respectively; methods such as nearest neighbor matching or the Hungarian algorithm can be used to pair each character in the target image with the most similar character in the reference image; For each paired character, calculate the Euclidean distance or cosine similarity of its contour features to obtain the character-level similarity score; at the same time, check whether the number and relative position of the characters are consistent to ensure the integrity and order of the text; Average the similarity scores of all characters, and combine the consistency of the number and position of the characters to generate a text content similarity score; this score will focus more on the semantic shape and arrangement of the characters rather than pixel-level exact matching, and is added to the final weighted comprehensive score.

[0089] As a preferred embodiment, the solution of this application is specifically implemented as follows: In the scenario of document image similarity detection, when the sliding window covers the text area of "patent examination" in the target image, the system first identifies that the window contains text content through connected component analysis, and then triggers the text verification process. The system uses Canny edge detection to obtain the character contours, and calculates the area, perimeter, and seventh-order Hu invariant moments of each character as feature vectors. For the contour of the character "专", the system extracts its Hu invariant moment feature value and stores it as a feature descriptor. Subsequently, the system executes the Hungarian algorithm in the corresponding window of the reference image to globally optimally match the feature of the character "专" in the target image with all character features in the reference image to determine the most similar character object. For the successfully matched character pair, the system calculates the cosine similarity of its Hu invariant moment feature vector as the character-level score, and at the same time verifies that the total number of characters in both images is 4 and the arrangement directions are the same. Finally, the system averages the similarity scores of the four characters, and combines the character number consistency weight to generate a text content similarity score, which is incorporated into the calculation of the weighted comprehensive score of the window area.

[0090] Through the above scheme, this application effectively distinguishes between semantic shape and pixel-level differences of characters in text region similarity detection. When the image has printing blur or uneven local lighting, the system can accurately identify the semantic consistency of the text content and avoid misjudging slight changes in character shape as content differences, thereby significantly improving the reliability and applicability of document image comparison.

[0091] Figure 7 This is a structural block diagram of the image similarity detection device provided in the embodiments of this application. The device includes: The image preprocessing module 710 is used to detect the image brightness and contrast of the target image and the reference image respectively, and to perform brightness difference compensation and contrast limitation enhancement processing. The foreground and background separation module 720 is used to separate the foreground and background of the areas to be processed in two preprocessed images sequentially through a sliding window; The similarity calculation module 730 is used to select the i-th target region in the target image, slide through all the regions to be compared in the reference image, calculate the similarity between the foreground image and the background image respectively, and obtain the score of the i-th region; The weighted aggregation module 740 is used to slide through all target regions of the target image, and to perform weighted aggregation of the scores of all regions to output the global similarity value of the image.

[0092] It should be noted that the image similarity detection device provided in this embodiment is only illustrated by the above-described division of functional modules / units. In practical applications, the above functions can be assigned to different functional modules / units as needed, that is, the internal structure of the image similarity detection device can be divided into different functional modules / units to complete all or part of the functions described above. Furthermore, the implementation methods of the image similarity detection method provided in the above-described method embodiments and the implementation methods of the image similarity detection device provided in this embodiment belong to the same concept. The specific implementation process of the image similarity detection device provided in this embodiment is detailed in the above-described method embodiments and will not be repeated here.

[0093] Figure 8This illustration shows a structural block diagram of a computer device provided in an exemplary embodiment of this application. The device can be a desktop computer, laptop computer, handheld computer, or cloud server, among other computer devices. The computer device may include, but is not limited to, a processor and a memory. The memory stores at least one instruction, at least one program, a code set, or an instruction set. The processor loads and executes the at least one instruction, at least one program, code set, or instruction set to implement the GPU scheduling policy execution method described above. The processor and memory can be connected via a bus or other means. The processor can be a Central Processing Unit (CPU). The processor can also be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, graphics processing units (GPUs), embedded neural network processing units (NPUs), or other dedicated deep learning coprocessors, discrete gate or transistor logic devices, discrete hardware components, or combinations of the above types of chips.

[0094] The processor may include one or more processing cores, such as a quad-core processor or an octa-core processor. The processor may be implemented using at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), or PLA (Programmable Logic Array). The processor may also include a main processor and coprocessors. The main processor, also known as the CPU (Central Processing Unit), is used to process data in the wake-up state; the coprocessor is a low-power processor used to process data in the standby state. In some embodiments, the processor may integrate a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content required to be displayed on the screen. In some embodiments, the processor may also include an AI (Artificial Intelligence) processor, which is used to handle computational operations related to machine learning.

[0095] In some embodiments, the computer device may also optionally include: a peripheral device interface and at least one peripheral device. The processor, memory, and peripheral device interface can be connected via a bus or signal lines. Each peripheral device can be connected to the peripheral device interface via a bus, signal lines, or a circuit board. Specifically, the peripheral device includes: a physical network interface card (NIC), and at least one of a radio frequency circuit, a display screen, and a keyboard.

[0096] This application also discloses a computer-readable storage medium. Specifically, the computer-readable storage medium is used to store a computer program, which, when executed by a processor, implements the methods described in the above-described method embodiments. Those skilled in the art will understand that implementing all or part of the processes in the methods described in the above-described embodiments of this application can be accomplished by a computer program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, it can include the processes of the embodiments described above. The storage medium can be a magnetic disk, optical disk, read-only memory (ROM), random access memory (RAM), flash memory, hard disk drive (HDD), or solid-state drive (SSD), etc.; the storage medium can also include combinations of the above types of memory.

[0097] This specific embodiment is merely an explanation of the present invention and is not intended to limit the invention. After reading this specification, those skilled in the art can make modifications to this embodiment without contributing any inventive step, but such modifications are protected by patent law as long as they fall within the scope of the claims of the present invention.

Claims

1. An image similarity detection method, characterized in that, The method includes: The brightness and contrast of the target image and the reference image are detected separately, and brightness difference compensation and contrast limitation enhancement are performed. The foreground and background of the two preprocessed images are separated sequentially using a sliding window. Select the i-th target region in the target image, slide through all the regions to be compared in the reference image, calculate the similarity between the foreground image and the background image respectively, and obtain the score of the i-th region; The algorithm iterates through all target regions of the target image and aggregates the scores of all regions by weighting to output the global similarity value of the image.

2. The method according to claim 1, characterized in that, The similarity calculation between the foreground image and the background image includes: Calculate the brightness similarity separately Contrast similarity Similarity to structure and texture ; Based on brightness similarity Contrast similarity Similarity to structure and texture Calculate tile similarity ; indicates the following: in, Indicates the weighting coefficient; The score of the i-th region is calculated based on foreground similarity and background similarity.

3. The method according to claim 2, characterized in that, The calculation of the score for the i-th region based on foreground similarity and background similarity includes: Calculate the foreground similarity and background similarity between the i-th target region and each region to be compared in the reference image, and combine the foreground similarity and background similarity to calculate a similarity score; All similarity scores are sorted, and the highest similarity score is determined as the score of the i-th target region.

4. The method according to claim 3, characterized in that, The calculation of the similarity score by combining the foreground similarity and the background similarity includes: Obtain the number of non-zero pixels in each of the two image patches. and And calculate the foreground difference compensation value. , means as follows: A similarity score is obtained by weighting the foreground difference compensation value, foreground similarity, and background similarity. , means as follows: in, These represent the foreground similarity value, foreground difference compensation value, and background similarity value, respectively. This is the proportionality coefficient.

5. The method according to claim 1, characterized in that, The process involves sliding through all target regions of the target image, weighting and aggregating the scores of all regions, and outputting a global image similarity value, including: This is the global similarity value. The number of regions that can be traversed in the target graph. This represents the regional score of the i-th target region.

6. The method according to any one of claims 1-5, characterized in that, Brightness difference compensation includes: Calculate the image brightness of the target image and the reference image respectively. And calculate the image brightness difference. , means as follows: Based on the image brightness difference, the weak brightness image Image enhancement is represented as follows: in, Represents pixels in an RGB image Maximum channel brightness value, Indicates image size, and Indicates the brightness of two images; This indicates the brightness of the image after brightness enhancement.

7. The method according to claim 6, characterized in that, Contrast limiting enhancements include: The image after brightness difference compensation is divided into several sub-image patches, and the contrast limiting coefficient is calculated. , means as follows: Obtain the original histogram of each subplot. It will exceed The count is truncated, and the excess pixels are evenly redistributed to all gray levels to obtain the clipping histogram. ; Based on the cumulative clipping histogram and brightness mapping, the contrast-limited enhanced output image is calculated as follows: in, This is the contrast limiting factor. For pixels in a sub-tile, Image grayscale levels, For sub-tiles, the gray level does not exceed the initial pixel value. The total number of pixels, To enhance the output of balanced pixel values ​​by limiting contrast, This represents the rounding function.

8. An image similarity detection device, characterized in that, The device includes: The image preprocessing module is used to detect the brightness and contrast of the target image and the reference image respectively, and to perform brightness difference compensation and contrast limitation enhancement processing. The foreground and background separation module is used to separate the foreground and background of the areas to be processed in two preprocessed images sequentially through a sliding window. The similarity calculation module is used to select the i-th target region in the target image, slide through all the regions to be compared in the reference image, calculate the similarity between the foreground image and the background image respectively, and obtain the score of the i-th region; The weighted aggregation module is used to slide through all target regions of the target image, perform weighted aggregation of the scores of all regions, and output the global similarity value of the image.

9. A computer device, characterized in that, The computer device includes a processor and a memory, the memory storing at least one instruction, at least one program, a code set, or an instruction set, the at least one instruction, the at least one program, the code set, or the instruction set being loaded and executed by the processor to implement the image similarity detection method as described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, The readable storage medium stores at least one instruction, at least one program, code set, or instruction set, wherein the at least one instruction, the at least one program, the code set, or the instruction set is loaded and executed by a processor to implement image similarity detection as described in any one of claims 1 to 7.