Image detection method, device and electronic equipment
By sampling images and calculating similarity indices, the problems of low efficiency and low accuracy in image similarity detection are solved, achieving efficient and accurate image similarity detection.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- NSFOCUS INFORMATION TECHNOLOGY CO LTD
- Filing Date
- 2023-09-22
- Publication Date
- 2026-05-01
AI Technical Summary
Existing image similarity detection methods are inefficient and inaccurate, especially in their inability to recognize changes in attributes such as grayscale and transparency after image modification.
The image is sampled by a preset image sampling unit to generate an image sampling region. The similarity index of the sampling region is calculated using a preset similarity algorithm. The image similarity is determined based on the similarity index and the critical value. The detection accuracy is improved by using a two-dimensional matrix and normalization processing.
It simplifies computational resource requirements, improves the efficiency and accuracy of image similarity detection, and can identify subtle changes in images.
Smart Images

Figure CN117237674B_ABST
Abstract
Description
An image detection method, apparatus and electronic device Technical Field
[0001] This application relates to the field of image detection technology, and in particular to an image detection method, apparatus and electronic device. Background Technology
[0002] With the rapid development of internet technology, image resources are being used more widely, such as in various social media and collage scenarios. However, the malicious use of images has been exacerbated by the use of various image editing software (such as Photoshop) and MD5 (Message-Digest Algorithm) modification tools to tamper with images.
[0003] In related technologies, machine learning is commonly used to detect image similarity. However, machine learning methods are heavily influenced by the training model, requiring a large amount of sample data for model training and parameter tuning, consuming significant computational resources and impacting detection efficiency. Another image similarity detection method identifies similar images by comparing their MD5 values. However, this method cannot identify images whose MD5 values have changed due to modifications to additional image attributes such as grayscale or transparency, resulting in low accuracy in image similarity detection. Summary of the Invention
[0004] To address the issues of low detection efficiency and low detection accuracy in existing image similarity detection methods, embodiments of this application provide an image detection method, apparatus, and electronic device.
[0005] In a first aspect, embodiments of this application provide an image detection method, including:
[0006] Acquire the first and second images to be detected;
[0007] The first image and the second image are sampled according to the preset image sampling unit to obtain each first image sampling region after the first image is sampled, and each second image sampling region after the second image is sampled.
[0008] A preset first similarity algorithm is used to determine the similarity index between each first image sampling region and each of the second image sampling regions. The first similarity algorithm is used to calculate the degree of similarity between two image sampling regions.
[0009] Based on the similarity index and the set similarity index threshold, the similarity index between the first image and the second image is determined by a preset second similarity algorithm to obtain the image detection result. The second similarity algorithm is used to calculate the degree of similarity between the two images.
[0010] In one embodiment, the first image and the second image are sampled according to a preset image sampling unit to obtain each first image sampling region after sampling the first image and each second image sampling region after sampling the second image, specifically including:
[0011] The first image is sampled according to a preset number of samples by a preset image sampling unit to obtain a corresponding number of first image sampling regions;
[0012] The pixels of the second image are sampled according to the preset image sampling unit to obtain each second image sampling region after the second image is sampled.
[0013] In one implementation, a preset first similarity algorithm is used to determine the similarity index between each first image sampling region and each of the second image sampling regions, specifically including:
[0014] For each first image sampling region, a two-dimensional matrix of the first image sampling region is generated based on the decimal color values of each pixel in the first image sampling region.
[0015] For each second image sampling region, a two-dimensional matrix of the second image sampling region is generated based on the decimal color values of each pixel in the second image sampling region;
[0016] For each first image sampling region, based on the two-dimensional matrix corresponding to the first image sampling region and the two-dimensional matrix corresponding to each second image sampling region, a similarity index between the first image sampling region and each of the second image sampling regions is determined.
[0017] In one embodiment, the similarity index between the first image sampling region and any second image sampling region is the similarity between the two-dimensional matrix corresponding to the first image sampling region and the two-dimensional matrix corresponding to any second image sampling region.
[0018] In one embodiment, before determining the similarity indices between the first image sampling region and each of the second image sampling regions based on the two-dimensional matrix corresponding to the first image sampling region and the two-dimensional matrices corresponding to each of the second image sampling regions, the method further includes:
[0019] The two-dimensional matrix corresponding to the first image sampling region is normalized, and the two-dimensional matrix corresponding to the second image sampling region is also normalized.
[0020] In one implementation, the similarity index threshold is set in the following manner:
[0021] A similarity index threshold value is pre-specified for each of the first image sampling regions; or
[0022] The critical value of the similarity index is determined based on the two-dimensional matrix corresponding to each of the first image sampling regions.
[0023] In one implementation, determining the corresponding similarity index threshold value based on the two-dimensional matrix corresponding to each first image sampling region specifically includes:
[0024] For each two-dimensional matrix corresponding to the first image sampling region, the decimal color values of each pixel in the two-dimensional matrix corresponding to the first image sampling region are rearranged to generate a set number of new two-dimensional matrices.
[0025] Calculate the similarity index between the two-dimensional matrix corresponding to the first image sampling region and each new two-dimensional matrix to obtain the candidate similarity index;
[0026] The critical value of the similarity index of the first image sampling region is determined based on preset conditions and the candidate similarity index.
[0027] In one implementation, determining a critical value for the similarity index of the first image sampling region based on preset conditions and the candidate similarity index specifically includes:
[0028] Based on the distribution of the candidate similarity indices, determine the confidence interval under the preset confidence conditions;
[0029] The lower limit of the confidence interval is determined as the critical value of the similarity index of the first image sampling region.
[0030] In one implementation, the similarity index between the first image and the second image is determined using a preset second similarity algorithm based on a similarity index and a set similarity index threshold, including:
[0031] The first number of first image sampling regions whose similarity indices are greater than or equal to or only greater than the similarity index threshold of each of the second image sampling regions is counted.
[0032] The ratio of the first quantity to the preset sampling quantity is determined as the similarity index between the first image and the second image.
[0033] In one implementation, the similarity index between the first image and the second image is determined using a preset second similarity algorithm based on a similarity index and a set similarity index threshold, including:
[0034] For each first image sampling region, from the similarity indices between the first image sampling region and each of the second image sampling regions, the similarity index with the same position in order of size is designated as the designated similarity index of the first image sampling region;
[0035] A first vector is generated based on the specified similarity index for each of the first image sampling regions;
[0036] A second vector is generated based on the similarity index threshold value corresponding to each of the first image sampling regions;
[0037] Based on the similarity between the first vector and the second vector, a similarity index between the first image and the second image is determined.
[0038] In one implementation, the similarity index between the first image and the second image is determined using a preset second similarity algorithm based on a similarity index and a set similarity index threshold, including:
[0039] For each first image sampling region, from the similarity indices between the first image sampling region and each of the second image sampling regions, the similarity index with the same position in order of size is designated as the designated similarity index of the first image sampling region;
[0040] The specified similarity index, which is greater than or equal to the similarity index threshold, is assigned a first fixed value; the specified similarity index, which is less than the similarity index threshold, is assigned a second fixed value; or
[0041] The specified similarity index that is greater than the similarity index threshold is assigned a first fixed value, and the specified similarity index that is less than or equal to the similarity index threshold is assigned a second fixed value;
[0042] A first vector is generated based on a first fixed value and a second fixed value for each of the first image sampling regions;
[0043] A second vector is generated based on the similarity index threshold value corresponding to each of the first image sampling regions;
[0044] Based on the similarity between the first vector and the second vector, a similarity index between the first image and the second image is determined.
[0045] In one implementation, the similarity index, which is greater than or equal to or only greater than the similarity index threshold, or the specified similarity index, includes the largest similarity index among the various similarity indices of the first image sampling region and each of the second image sampling regions.
[0046] Secondly, embodiments of this application provide an image detection apparatus, comprising:
[0047] The acquisition unit is used to acquire the first image and the second image to be detected.
[0048] A sampling unit is used to sample the first image and the second image according to a preset image sampling unit, respectively, to obtain each first image sampling region after sampling the first image and each second image sampling region after sampling the second image;
[0049] The determining unit is used to determine each similarity index between each first image sampling region and each of the second image sampling regions by using a preset first similarity algorithm, wherein the first similarity algorithm is used to calculate the degree of similarity between two image sampling regions;
[0050] The detection unit is used to determine the similarity index between the first image and the second image based on the similarity index and a set similarity index threshold, and to obtain the image detection result. The second similarity algorithm is used to calculate the degree of similarity between the two images.
[0051] In one embodiment, the sampling unit is specifically used to sample the first image according to a preset sampling number by a preset image sampling unit to obtain a corresponding number of first image sampling regions; and to sample the pixels of the second image according to the preset image sampling unit to obtain each second image sampling region after the second image is sampled.
[0052] In one embodiment, the determining unit is specifically configured to: generate a two-dimensional matrix of the first image sampling region based on the decimal color values of each pixel in the first image sampling region for each first image sampling region; generate a two-dimensional matrix of the second image sampling region based on the decimal color values of each pixel in the second image sampling region for each second image sampling region; and, for each first image sampling region, determine a similarity index between the first image sampling region and each of the second image sampling regions based on the two-dimensional matrix corresponding to the first image sampling region and the two-dimensional matrix corresponding to each of the second image sampling regions.
[0053] In one embodiment, the similarity index between the first image sampling region and any second image sampling region is the similarity between the two-dimensional matrix corresponding to the first image sampling region and the two-dimensional matrix corresponding to any second image sampling region.
[0054] In one embodiment, the device further includes:
[0055] The normalization unit is used to normalize the two-dimensional matrix corresponding to the first image sampling region and the two-dimensional matrix corresponding to each of the second image sampling regions before determining the similarity index between the first image sampling region and each of the second image sampling regions based on the two-dimensional matrix corresponding to the first image sampling region and the two-dimensional matrix corresponding to each of the second image sampling regions.
[0056] In one embodiment, the detection unit is specifically configured to set the similarity index threshold by: pre-specifying the similarity index threshold for each first image sampling region; or determining the corresponding similarity index threshold based on the two-dimensional matrix corresponding to each first image sampling region.
[0057] In one embodiment, the detection unit is specifically configured to, for each two-dimensional matrix corresponding to the first image sampling region, rearrange the decimal color values of each pixel in the two-dimensional matrix corresponding to the first image sampling region to generate a set number of new two-dimensional matrices; calculate the similarity index between the two-dimensional matrix corresponding to the first image sampling region and each new two-dimensional matrix to obtain a candidate similarity index; and determine the critical value of the similarity index of the first image sampling region based on preset conditions and the candidate similarity index.
[0058] In one embodiment, the detection unit is specifically used to determine a confidence interval under a preset confidence condition based on the distribution of the candidate similarity index; and to determine the lower limit of the confidence interval as the critical value of the similarity index of the first image sampling region.
[0059] In one embodiment, the detection unit is specifically used to count a first number of first image sampling regions whose similarity indices with each of the second image sampling regions contain a similarity index greater than or equal to or only greater than the similarity index threshold; and to determine the ratio of the first number to the preset sampling number as the similarity index between the first image and the second image.
[0060] In one embodiment, the detection unit is specifically configured to, for each first image sampling region, specify a similarity index of the same order in terms of size among the similarity indices of the first image sampling region and each second image sampling region as a specified similarity index of the first image sampling region; generate a first vector based on the specified similarity index of each first image sampling region; generate a second vector based on the critical value of the similarity index corresponding to each first image sampling region; and determine the similarity index between the first image and the second image based on the similarity between the first vector and the second vector.
[0061] In one embodiment, the detection unit is specifically configured to, for each first image sampling region, specify a similarity index of the same rank in order of size among the similarity indices of the first image sampling region and each of the second image sampling regions as a specified similarity index of the first image sampling region; assign a first fixed value to the specified similarity index that is greater than or equal to the similarity index threshold, and assign a second fixed value to the specified similarity index that is less than the similarity index threshold; or assign a first fixed value to the specified similarity index that is greater than the similarity index threshold, and assign a second fixed value to the specified similarity index that is less than or equal to the similarity index threshold; generate a first vector based on the first fixed value and the second fixed value of each first image sampling region; generate a second vector based on the similarity index threshold corresponding to each first image sampling region; and determine the similarity index between the first image and the second image based on the similarity between the first vector and the second vector.
[0062] In one implementation, the similarity index, which is greater than or equal to or only greater than the similarity index threshold, or the specified similarity index, includes the largest similarity index among the various similarity indices of the first image sampling region and each of the second image sampling regions.
[0063] Thirdly, embodiments of this application provide an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the image detection method described in this application.
[0064] Fourthly, embodiments of this application provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the image detection method described in this application.
[0065] The beneficial effects of this application are as follows:
[0066] The image detection method, apparatus, and electronic device provided in this application acquire a first image and a second image to be detected. They sample the first and second images respectively according to a preset image sampling unit, obtaining each first image sampling region after sampling the first image and each second image sampling region after sampling the second image. A preset first similarity algorithm is used to determine each similarity index between each first image sampling region and each second image sampling region. The first similarity algorithm is used to calculate the degree of similarity between two image sampling regions. Based on the similarity index and a set similarity index threshold, a preset second similarity algorithm is used to determine a second similarity index between the first image and the second image, obtaining the image detection result. The second similarity algorithm is used to calculate the degree of similarity between two images, and the similarity index threshold is used to measure the reliability of the similarity index of the image sampling regions. Compared with the prior art, this application... In this embodiment, a preset image sampling unit is used to sample the first image to obtain each first image sampling region, and the second image is sampled to obtain each second image sampling region. By calculating the similarity index between each first image sampling region and each second image sampling region, the degree of similarity between each first image sampling region and each second image is measured. Then, based on the similarity index between each first image sampling region and each second image sampling region, and a set similarity index threshold, the similarity index between the first image and the second image is calculated. The similarity index between the first image and the second image is used to measure the degree of similarity between the first image and the second image. The above image similarity detection method is simple to calculate and requires less computing resources, thus improving detection efficiency. Furthermore, it is significantly different from the color level, grayscale, and sub-image hash methods commonly used in traditional image processing, thereby improving the accuracy of image similarity detection.
[0067] Other features and advantages of this application will be set forth in the description which follows, and will be apparent in part from the description, or may be learned by practicing the application. The objectives and other advantages of this application may be realized and obtained by means of the structures particularly pointed out in the written description, claims, and drawings. Attached Figure Description
[0068] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:
[0069] Figure 1 is a schematic diagram of the implementation process of the image detection method provided in the embodiments of this application;
[0070] Figure 2 is a first image sampling example diagram provided in an embodiment of this application;
[0071] Figure 3 is a second image sampling example provided in an embodiment of this application;
[0072] Figure 4 is a schematic diagram of the implementation process for determining the similarity index between each first image sampling region and each second image sampling region according to an embodiment of this application;
[0073] Figure 5 is a schematic diagram of another implementation process for determining the similarity index between the first image sampling region and the second image sampling region provided in an embodiment of this application;
[0074] Figure 6 is a schematic diagram of the implementation process for determining the critical value of the similarity index provided in the embodiments of this application;
[0075] Figure 7 is a schematic diagram of the implementation process for determining the similarity index between the first image and the second image according to an embodiment of this application;
[0076] Figure 8 is a schematic diagram of another implementation process for determining the similarity index between the first image and the second image provided in an embodiment of this application;
[0077] Figure 9 is a schematic diagram of another implementation process for determining the similarity index between the first image and the second image provided in an embodiment of this application;
[0078] Figure 10 is a schematic diagram of the image detection device provided in an embodiment of this application;
[0079] Figure 11 is a schematic diagram of the structure of the electronic device provided in the embodiment of this application. Detailed Implementation
[0080] To address the issues of low detection efficiency and low detection accuracy in existing image similarity detection methods, embodiments of this application provide an image detection method, apparatus, and electronic device.
[0081] The preferred embodiments of this application are described below with reference to the accompanying drawings. It should be understood that the preferred embodiments described herein are for illustration and explanation only and are not intended to limit this application. Furthermore, the embodiments and features in the embodiments of this application can be combined with each other without conflict.
[0082] The image detection method provided in this application can be applied to servers or to terminal devices with computing capabilities; this application does not limit the application in this regard.
[0083] The server can be a standalone physical server or a cloud server that provides basic cloud computing services such as cloud servers, cloud databases, and cloud storage. The terminal device can be, but is not limited to, smartphones, tablets, laptops, desktop computers, etc.; this application does not limit this.
[0084] Based on the above application scenarios, exemplary embodiments of this application will be described in more detail below with reference to Figures 2-4. It should be noted that the above application scenarios are only shown to facilitate understanding of the spirit and principles of this application, and the implementation of this application is not limited in any way. On the contrary, the implementation of this application can be applied to any applicable scenario.
[0085] Figure 1 shows a schematic diagram of the implementation process of the image detection method provided in this application embodiment. This image detection method can be applied to a server or terminal device and may include the following steps:
[0086] S11. Obtain the first and second images to be detected.
[0087] In specific implementations, if applied to image similarity detection in image tampering detection scenarios, the first image can be the original image, and the second image can be the image used to detect whether it has been tampered with compared to the original image. If applied to other scenarios where only the similarity between two arbitrary images needs to be determined, such as jigsaw puzzle scenarios or similar image filtering scenarios, the first image and the second image can be any two images, and this application embodiment does not limit this.
[0088] S12. Sample the first image and the second image according to the preset image sampling unit to obtain each first image sampling region after sampling the first image and each second image sampling region after sampling the second image.
[0089] In specific implementation, the first image can be sampled according to the preset image sampling unit and the preset sampling quantity to obtain the corresponding number of first image sampling areas. In the implementation process, the first image can be sampled according to the preset image sampling unit and the preset sampling quantity, or the first image can be sampled pixel by pixel according to the preset image sampling unit and the preset sampling quantity, or other arbitrary uniform sampling methods can be used. This application embodiment does not limit this.
[0090] The preset image sampling unit can be a rectangular area for sampling an image. The size of the image sampling unit can be preset, such as M×N, representing a rectangular area of M rows and N columns containing M×N pixels. The size M×N and the sampling quantity C of the image sampling unit can be set according to actual needs. For example, the size of the preset image sampling unit can be set to 10×4, but this embodiment does not limit this. To ensure detection accuracy, the sampling quantity C can be set based on the size of the image sampling unit and the total number of pixels in the image. The ratio of the total number of sampled pixels to the total number of pixels in the image can be set to be no less than a set threshold. The total number of sampled pixels is equal to the product of the number of pixels contained in the image sampling unit and the sampling quantity: M×N×C. The threshold can be set according to needs, such as setting the total number of sampled pixels to be no less than 80% of the total number of pixels in the image, but this embodiment does not limit this.
[0091] Assuming the first image is as shown in Figure 2, the image sampling unit size is 6×4. Sampling is performed on the first image according to the preset sampling number to obtain the corresponding number of first image sampling regions. Figure 2 only shows one first image sampling region. The size of each first image sampling region is 6×4, containing 24 pixels.
[0092] In practice, the second image can be sampled pixel by pixel according to the preset image sampling unit to obtain each sampled area of the second image. Alternatively, the second image can be randomly sampled according to the preset image sampling unit. This application does not limit this.
[0093] In one implementation, to further improve the accuracy of detection, the second image sampling is performed pixel-by-pixel according to a preset image sampling unit to obtain each second image sampling region that is the same as the first image sampling region.
[0094] Assuming the second image is as shown in Figure 3, and the preset pattern sampling unit size is still 6×4, then sampling is performed pixel by pixel in the second image to obtain each second image sampling region. For ease of viewing, only six second image sampling regions are shown in Figure 3. The size of each second image sampling region is also 6×4, containing 24 pixels.
[0095] S13. Using a preset first similarity algorithm, determine the similarity index between each first image sampling region and each second image sampling region.
[0096] In specific implementation, the first similarity algorithm is used to calculate the similarity between two image sampling regions. The similarity index between the first image sampling region and any second image sampling region is the similarity between the two-dimensional matrix corresponding to the first image sampling region and the two-dimensional matrix corresponding to the any second image sampling region.
[0097] Specifically, the similarity index between each first image sampling region and each second image sampling region can be determined according to the process shown in Figure 4, including the following steps:
[0098] S21. For each first image sampling region, generate a two-dimensional matrix of the first image sampling region based on the decimal color values of each pixel in the first image sampling region.
[0099] In practice, for each pixel, its decimal color value can be calculated based on its RGB values. Specifically, the R, G, and B values of the pixel are converted to hexadecimal numbers, and these hexadecimal numbers are concatenated to obtain a concatenated hexadecimal number. This concatenated hexadecimal number is then converted to decimal, and this decimal number is the decimal color value of the pixel. For example, if a pixel has an R value of 10, a G value of 255, and a B value of 10, then the hexadecimal value corresponding to the R value is 0A, the hexadecimal value corresponding to the G value is FF, and the hexadecimal value corresponding to the B value is 0A. The concatenated hexadecimal number is 0AFF0A. Converting 0AFF0A to decimal gives 720650, so the decimal color value of this pixel is 720650.
[0100] In implementation, for each first image sampling area, a two-dimensional matrix is generated by arranging the position of each pixel in the first image sampling area and the decimal color value of the corresponding pixel. This matrix is the two-dimensional matrix corresponding to the first image sampling area.
[0101] For example, in Figure 2, the decimal color values of the pixels in the first row of the first image sampling area are 3, 5, 14, 0; the decimal color values of the pixels in the second row are 7, 3, 3, 2; the decimal color values of the pixels in the third row are 7, 3, 2, 2; the decimal color values of the pixels in the fourth row are 3, 2, 5, 1; the decimal color values of the pixels in the fifth row are 0, 0, 0, 0; and the decimal color values of the pixels in the sixth row are 9, 3, 7, 0. Arranging the decimal color values of each pixel in this first image sampling area according to their position within the first image sampling area forms the following two-dimensional matrix corresponding to this first image sampling area:
[0102]
[0103] The same method is used to generate a two-dimensional matrix corresponding to each of the first image sampling regions.
[0104] S22. For each second image sampling region, generate a two-dimensional matrix of the second image sampling region based on the decimal color values of each pixel in the second image sampling region.
[0105] In practice, for each second image sampling area, a two-dimensional matrix is generated by arranging the position of each pixel in the second image sampling area and the decimal color value of the corresponding pixel. This matrix is the two-dimensional matrix corresponding to the second image sampling area.
[0106] The two-dimensional matrix corresponding to the second image sampling region (such as the second image sampling region in the lower left corner) in Figure 3 is obtained in the same way as step S21:
[0107]
[0108] The two-dimensional matrix corresponding to each second image sampling region is generated in the same manner.
[0109] S23. For each first image sampling region, determine the similarity index between the first image sampling region and each second image sampling region based on the two-dimensional matrix corresponding to the first image sampling region and the two-dimensional matrix corresponding to each second image sampling region.
[0110] The similarity index represents the degree of similarity, and the similarity index between the first image sampling region and the second image sampling region represents the degree of similarity between the first image sampling region and the second image sampling region.
[0111] In practice, for each two-dimensional matrix corresponding to the first image sampling region and each two-dimensional matrix corresponding to the second image sampling region, the similarity index between the first image sampling region and the second image sampling region can be determined by calculating the similarity between the two-dimensional matrix corresponding to the first image sampling region and the two-dimensional matrix corresponding to the second image sampling region.
[0112] Specifically, the similarity between the two-dimensional matrix corresponding to the first image sampling region and the two-dimensional matrix corresponding to the second image sampling region can be calculated using algorithms such as cosine similarity, Euclidean distance, Manhattan distance, Jaccard similarity coefficient, and Pearson correlation coefficient. This application does not limit the specific algorithms used.
[0113] In one embodiment, before calculating the similarity between the two-dimensional matrix corresponding to the first image sampling region and the two-dimensional matrix corresponding to the second image sampling region, the two-dimensional matrix corresponding to the first image sampling region can be normalized, and the two-dimensional matrix corresponding to the second image sampling region can be normalized. The similarity between the normalized two-dimensional matrix corresponding to the first image sampling region and the normalized two-dimensional matrix corresponding to the second image sampling region is then calculated as the similarity index between the first image sampling region and the second image sampling region.
[0114] In this embodiment, the similarity index between the first image sampling region and the second image sampling region can be determined according to the process shown in Figure 5:
[0115] S31. Normalize the decimal color values of each pixel in the two-dimensional matrix corresponding to the first image sampling area and normalize the decimal color values of each pixel in the two-dimensional matrix corresponding to the second image sampling area to obtain the normalized two-dimensional matrix corresponding to the first image sampling area and the normalized two-dimensional matrix corresponding to the second image sampling area.
[0116] In practice, when calculating the similarity index between a first image sampling region and a second image sampling region, the decimal color values of each pixel in the two-dimensional matrix corresponding to the first image sampling region are first normalized to obtain the normalized two-dimensional matrix corresponding to the first image sampling region. In other words, the values in the normalized two-dimensional matrix corresponding to the first image sampling region are the normalized values of the decimal color values of each pixel in the two-dimensional matrix corresponding to the first image sampling region. Similarly, the decimal color values of each pixel in the two-dimensional matrix corresponding to the second image sampling region are normalized to obtain the normalized two-dimensional matrix corresponding to the second image sampling region. That is, the values in the normalized two-dimensional matrix corresponding to the second image sampling region are the normalized values of the decimal color values of each pixel in the two-dimensional matrix corresponding to the second image sampling region.
[0117] Specifically, the decimal color values of each pixel in the two-dimensional matrix corresponding to the first image sampling region can be normalized according to the following formula, but not limited to, to obtain the normalized decimal color values of each pixel:
[0118]
[0119] Among them, X i X represents the normalized decimal color value of the i-th pixel in the two-dimensional matrix corresponding to the first image sampling region, i.e., X. i Let be the i-th value of the two-dimensional matrix corresponding to the first image sampling region after normalization, i = 1, 2, ..., n, where n = M × N.
[0120] Similarly, the decimal color values of each pixel in the two-dimensional matrix corresponding to the second image sampling area can be normalized according to the following formula to obtain the normalized value of the decimal color value of each pixel:
[0121]
[0122] Among them, Y i This represents the normalized decimal color value of the i-th pixel in the two-dimensional matrix corresponding to the second image sampling region, i.e., Y. i Let be the i-th value of the two-dimensional matrix corresponding to the normalized second image sampling region, i = 1, 2, ..., n, n = M × N.
[0123] Continuing with the previous example, the two-dimensional matrix corresponding to the first image sampling region is:
[0124]
[0125] The normalized two-dimensional matrix corresponding to the first image sampling region is obtained by calculating using the above formula:
[0126]
[0127] The two-dimensional matrix corresponding to the second image sampling region is:
[0128]
[0129] The two-dimensional matrix corresponding to the normalized second image sampling region is:
[0130]
[0131] S32. Based on the two-dimensional matrix corresponding to the normalized first image sampling region and the two-dimensional matrix corresponding to the normalized second image sampling region, determine the similarity index between the first image sampling region and the second image sampling region.
[0132] In one implementation, the similarity index between the first image sampling region and the second image sampling region can be calculated using the following formula:
[0133]
[0134] Where P represents the similarity between the two-dimensional matrix corresponding to the first image sampling region and the two-dimensional matrix corresponding to the second image sampling region. The similarity P between the two-dimensional matrix corresponding to the first image sampling region and the two-dimensional matrix corresponding to the second image sampling region is used as the similarity index between the first image sampling region and the second image sampling region.
[0135] X i Y represents the i-th value in the two-dimensional matrix corresponding to the first image sampling region after normalization, which is also the normalized decimal color value of the i-th pixel in the two-dimensional matrix corresponding to the first image sampling region. i This represents the i-th value in the two-dimensional matrix corresponding to the normalized second image sampling region, which is also the normalized decimal color value of the i-th pixel in the two-dimensional matrix corresponding to the second image sampling region, i = 1, 2, ..., n.
[0136] The similarity index P of the sampling regions ranges from 0 to 1. The larger the P value, the higher the similarity between the two sampling regions. When P = 0, it indicates that the difference between the two sampling regions is the greatest, that is, they are completely inconsistent. If P = 1, it indicates that there is no difference between the two sampling regions, and they are completely identical.
[0137] Continuing with the previous example, the similarity index of the first image sampling region and the second image sampling region was calculated to be 0.683.
[0138] The similarity index between the first image sampling region and the second image sampling region can also be determined by calculating the cosine similarity, Euclidean distance, Manhattan distance, Jaccard similarity coefficient, or Pearson correlation coefficient between the two-dimensional matrix corresponding to the normalized first image sampling region and the two-dimensional matrix corresponding to the normalized second image sampling region. This application does not limit this.
[0139] Then, the similarity index of each first image sampling region and each second image sampling region is calculated.
[0140] S14. Based on the similarity index and the set similarity index threshold, the similarity index between the first image and the second image is determined by a preset second similarity algorithm to obtain the image detection result.
[0141] In practice, the second similarity algorithm is used to calculate the degree of similarity between two images, and the similarity index between the first image and the second image represents the degree of similarity between the first image and the second image.
[0142] The similarity index threshold (i.e., the similarity index threshold of the sampling region) is used to measure the reliability of the similarity index of the image sampling region. The similarity index threshold of each first image sampling region can be pre-specified based on empirical values, or the corresponding similarity index threshold can be determined based on the two-dimensional matrix corresponding to each first image sampling region, or the similarity index threshold can be obtained based on other methods. This application does not limit this.
[0143] Specifically, the similarity index threshold value corresponding to the region used in each first image can be determined according to the process shown in Figure 6, including the following steps:
[0144] S41. For each two-dimensional matrix corresponding to the first image sampling area, rearrange the decimal color values of each pixel in the two-dimensional matrix corresponding to the first image sampling area to generate a set number of new two-dimensional matrices.
[0145] In specific implementation, for each two-dimensional matrix corresponding to an image sampling region, the unidrnd function in Matlab (or the Random function in Python, or any other random function) can be used to randomly shuffle the decimal color values of each pixel in the two-dimensional matrix corresponding to the first image sampling region and rearrange them into a new two-dimensional matrix with the same rows and columns. This rearrangement can be performed a set number of times to generate a set number of new two-dimensional matrices. The set number of times is equal to the set number, which can be set according to requirements, for example, 20000. This embodiment does not limit this. The samples obtained by sampling using the unidrnd function (or the Random function) conform to a normal distribution.
[0146] S42. Calculate the similarity index between the two-dimensional matrix corresponding to the first image sampling region and each new two-dimensional matrix to obtain the candidate similarity index.
[0147] In practice, for each two-dimensional matrix corresponding to the first image sampling region and the corresponding newly generated two-dimensional matrix, the similarity index of the two-dimensional matrix corresponding to the first image sampling region and the corresponding newly generated two-dimensional matrix are calculated respectively to obtain each candidate similarity index, which can also obtain a set number (such as the 20,000 set above).
[0148] S43. Determine the critical value of the similarity index of the first image sampling region based on preset conditions and candidate similarity indices.
[0149] In practice, the confidence interval under the preset confidence condition can be determined based on the distribution of the candidate similarity index, and the lower limit of the confidence interval can be determined as the critical value of the similarity index of the region used in the first image.
[0150] Specifically, the probability distribution function (i.e., probability distribution curve) of the candidate similarity index is determined based on the candidate similarity index. Under the pre-set confidence level, the confidence interval is determined based on the mean and standard deviation of the candidate similarity index. The lower limit of the confidence interval is determined as the critical value of the similarity index of the first image sampling area. The pre-set confidence level can be set according to the requirements, and its value range is (0, 1). For example, the confidence level can be set to 95%. This application embodiment does not limit this.
[0151] In practice, the confidence interval can be calculated using the following formula:
[0152]
[0153] Where Q1 represents the lower limit of the confidence interval;
[0154] μ represents the mean of the candidate similarity index;
[0155] σ represents the standard deviation of the candidate similarity index;
[0156] α represents the pre-set confidence level, or confidence level.
[0157] z α / 2 This represents the cumulative probability in the standard normal distribution. The z-score is a constant that can be found in the standard normal distribution table;
[0158] L represents the sample size, which is also the number of candidate similarity indices, or the set number.
[0159]
[0160] Where Q2 represents the upper limit of the confidence interval.
[0161] In this embodiment of the application, the lower limit of the confidence interval, Q1, is used as the critical value of the similarity index of the first image sampling region.
[0162] Continuing with the previous example, assuming a pre-set confidence level of 95%, the mean of the calculated candidate similarity index is 0.67066 and the standard deviation is 0.05501. Then, the critical value of the similarity index of the first image sampling region is Q1 = 0.56283.
[0163] Furthermore, the similarity index between the first image and the second image can be determined based on the similarity indices between each first image sampling region and each second sampling region, the critical value of the similarity index of each first image sampling region, and the preset sampling quantity. Specifically, the similarity index between the first image and the second image can be determined according to the process shown in Figure 7, including the following steps:
[0164] S51. Count the number of first image sampling regions that have a similarity index greater than or equal to or only greater than the similarity index threshold among the similarity indices of each second image sampling region.
[0165] In specific implementation, for each similarity index between each first image sampling region and each second image sampling region, it is determined whether there is a similarity index greater than or equal to the similarity threshold of the first image sampling region. The number of first image sampling regions containing a similarity index greater than or equal to the similarity threshold of the first image sampling region is counted and recorded as the first number. Alternatively, it is determined whether there is a similarity index that is only greater than the similarity threshold of the first image sampling region. The number of first image sampling regions containing a similarity index that is only greater than the similarity threshold of the first image sampling region is counted and recorded as the first number. This application embodiment does not limit this. Among them, the similarity index that is greater than or equal to or only greater than the similarity index threshold includes the largest similarity index among the various similarity indices between the first image sampling region and each second image sampling region.
[0166] S52. The ratio of the first quantity to the preset sampling quantity is determined as the similarity index between the first image and the second image.
[0167] In practice, the similarity index between the first image and the second image can be calculated using the following formula:
[0168]
[0169] Among them, S AB This represents the similarity index between the first image and the second image;
[0170] D represents the first number of first image sampling regions that contain a similarity index greater than or equal to, or only greater than, the similarity index threshold value among the various similarity indices of each second image sampling region;
[0171] C represents the preset number of samples.
[0172] In one implementation, the similarity index of the first image and the second image can also be determined by directly counting the second number of the largest similarity index that is greater than the similarity index threshold, and the ratio of the second number to the preset sampling number.
[0173] In specific implementation, for each first image sampling region, the maximum similarity index among the similarity indices between the first image sampling region and each second image sampling region is obtained. In this way, with C first image sampling regions, the maximum similarity index between the C first image sampling regions and the second image sampling regions can be obtained. The number of the maximum similarity indices among these C maximum similarity indices that are greater than the similarity index threshold of their respective first image sampling regions can be recorded as the second number.
[0174] Taking Figures 2 and 3 as examples, we will explain the maximum similarity index between the first image sampling region and the second image sampling region. Assuming that the similarity indices between the first image sampling region shown in Figure 2 and the six second image sampling regions shown in Figure 3 are 0.214, 0.312, 0.445, 0.618, 0.683, and 0.521, respectively, the maximum similarity index between the first image sampling region and the second image sampling region is 0.683.
[0175] The similarity index between the first image and the second image can be calculated using the following formula:
[0176]
[0177] Among them, S AB This represents the similarity index between the first image and the second image;
[0178] D' represents the second number of the largest similarity index values that are greater than the similarity index threshold;
[0179] C represents the preset number of samples.
[0180] In one implementation, the similarity index between the first image and the second image can be determined based on the similarity indices between each first image sampling region and each second sampling region, and the critical value of the similarity index for each first image sampling region. Specifically, the similarity index between the first image and the second image can be determined according to the process shown in Figure 8, which may include the following steps:
[0181] S61. For each first image sampling region, from the similarity indices between the first image sampling region and each second image sampling region, specify the similarity index with the same position in order of size as the specified similarity index of the first image sampling region.
[0182] In specific implementation, for each first image sampling region, the similarity indices between the first image sampling region and each of the second image sampling regions are arranged in descending order (or in ascending order). The similarity index that ranks in the same position among the similarity indices of each first image sampling region and each of the second image sampling regions is determined as the designated similarity index of each first image sampling region. The designated similarity index of the first image sampling region includes the maximum similarity index among the various similarity indices of the first image sampling region and each of the second image sampling regions.
[0183] For example, suppose sampling the first image yields 5 first image sampling regions, and sampling the second image yields 10 second image sampling regions. Then, each first image sampling region and each of the 10 second image sampling regions has 10 similarity indices, resulting in five sets of 10 similarity indices. These five sets of 10 similarity indices are sorted in ascending order. The similarity indices at the same position in each of the five sorted sets can be used as the designated similarity indices for the 5 first image sampling regions. For example, the maximum similarity index in each set can be used as the designated similarity index for each of the 5 first image sampling regions. The specified similarity index of the regions can be sorted in descending order, that is, the first similarity index of each group can be used as the specified similarity index of each first image sampling region. Alternatively, the second largest value in each group can be used as the specified similarity index of these 5 first image sampling regions, that is, the second similarity index in each group can be used as the specified similarity index of each first image sampling region. Or, the similarity index in each group that is ranked in any same position can be used as the specified similarity index of each first image sampling region. This application does not limit this.
[0184] S62. Generate a first vector based on the specified similarity index of each first image sampling region.
[0185] S63. Generate a second vector based on the critical value of the similarity index corresponding to each of the first image sampling regions.
[0186] S64. Based on the similarity between the first vector and the second vector, determine the similarity index between the first image and the second image.
[0187] In practice, the similarity index between the first image and the second image can be calculated using the following formula:
[0188]
[0189] Among them, S AB This represents the similarity index between the first image and the second image;
[0190] P i The specified similarity index represents the similarity index between the i-th first image sampling region and each second image sampling region, where i = 1 to C, and C represents the preset number of samples for the first image sampling region;
[0191] P i ′ This represents the critical value of the similarity index for the i-th first image sampling region.
[0192] Besides the method of this application, there are many publicly available algorithms for vector similarity, so one or more applicable vector similarity algorithms can be arbitrarily selected, and this application does not limit them.
[0193] The similarity index between the first image and the second image reflects the degree of similarity between them. The higher the similarity index, the higher the degree of similarity between the first image and the second image; the lower the similarity index, the lower the degree of similarity between the first image and the second image.
[0194] In one implementation, the similarity index between the first image and the second image can also be determined according to the process shown in Figure 9, which may include the following steps:
[0195] S71. For each first image sampling region, from the similarity indices between the first image sampling region and each second image sampling region, specify the similarity index with the same position in order of size as the specified similarity index of the first image sampling region.
[0196] The implementation of this step can be referred to step S61, and will not be repeated here.
[0197] S72. Assign a first fixed value to a specified similarity index that is greater than or equal to the similarity index threshold, and assign a second fixed value to a specified similarity index that is less than the similarity index threshold; or assign a first fixed value to a specified similarity index that is greater than the similarity index threshold, and assign a second fixed value to a specified similarity index that is less than or equal to the similarity index threshold.
[0198] In practice, after obtaining the specified similarity index for each first image sampling region, each specified similarity index can be processed according to the critical value of the similarity index for each first image sampling region as follows:
[0199] In one implementation, a specified similarity index that is greater than or equal to the similarity index threshold of the first image sampling region can be assigned a first fixed value, and a specified similarity index that is less than the similarity index threshold of the first image sampling region can be assigned a second fixed value.
[0200] Specifically, for each first image sampling region, a specified similarity index of the image sampling region is compared with a similarity index threshold value of the image sampling region. If the specified similarity index is greater than or equal to the similarity index threshold value, the specified similarity index is assigned a first fixed value. If the specified similarity index is less than the similarity index threshold value, the specified similarity index is assigned a second fixed value.
[0201] In one implementation, a specified similarity index greater than the similarity index threshold of the first image sampling region may be assigned a first fixed value, and a specified similarity index less than or equal to the similarity index threshold of the first image sampling region may be assigned a second fixed value.
[0202] Specifically, for each first image sampling region, a specified similarity index of the image sampling region is compared with a similarity index threshold value of the image sampling region. If the specified similarity index is greater than the similarity index threshold value, the specified similarity index is assigned a first fixed value. If the specified similarity index is less than or equal to the similarity index threshold value, the specified similarity index is assigned a second fixed value.
[0203] The first fixed value and the second fixed value can be set according to the requirements. For example, the first fixed value can be set to 1 and the second fixed value can be set to 0. They can also be set to any other arbitrary values. This application embodiment does not limit this.
[0204] S73. Generate a first vector based on the first fixed value and the second fixed value of each first image sampling region.
[0205] In this step, a first vector is generated based on a first fixed value and a second fixed value after assigning a similarity index to each first image sampling region.
[0206] S74. Generate a second vector based on the similarity index threshold value corresponding to each of the first image sampling regions.
[0207] S75. Based on the similarity between the first vector and the second vector, determine the similarity index between the first image and the second image.
[0208] In practice, the similarity index between the first image and the second image can be calculated using the following formula:
[0209]
[0210] Among them, S AB This represents the similarity index between the first image and the second image;
[0211] This represents the first or second fixed value after assigning a specified similarity index among the similarity indices of the i-th first image sampling region and each second image sampling region, where i = 1 to C, and C represents the preset sampling number of the first image sampling region;
[0212] P i ′ This represents the critical value of the similarity index for the i-th first image sampling region.
[0213] Besides the method of this application, there are numerous publicly available algorithms for vector similarity. Therefore, one or more applicable vector similarity algorithms can be arbitrarily selected, and this application does not limit them. The image detection method provided in this application, based on the RGB values of image pixels, transforms the image sampling area into a two-dimensional matrix containing the decimal color values and relative position information of the pixels. It uses sampling unit sampling, similarity calculation, and saliency analysis to determine the similarity between two images. This is significantly different from the color level, grayscale, and sub-image hashing methods commonly used in traditional image processing, improving the accuracy of image similarity detection. By adjusting the size and number of sampling units, pixel-level comparison can be achieved. The introduction of random sampling uses local (i.e., sampling units) analysis of the overall image, which is quite different from methods such as MD5 and machine learning, and can better analyze nested images, jigsaw puzzles, and other scenarios. Furthermore, the image processing process is visible, standardized, and the results are quantifiable (i.e., a new technical indicator for measuring the degree of image similarity: the image similarity index). It has a wide range of applications and is independent, such as being applicable to image similarity detection in image tampering detection scenarios, jigsaw puzzle scenarios, and image nesting scenarios. It eliminates the need for extensive model training and complex parameter tuning, requiring only simple calculations and minimal computational resources, thus improving the efficiency of image similarity detection. Due to the properties of matrices (changes to the overall matrix do not affect the similarity between two matrices), it is better suited for image editing scenarios, such as maintaining high accuracy in detecting image similarity even when grayscale and transparency are adjusted.
[0214] Based on the same inventive concept, this application also provides an image detection device. Since the principle of solving the problem by the above-mentioned image detection device is similar to that of the above-mentioned image detection method, the implementation of the above-mentioned device can refer to the implementation of the method, and the repeated parts will not be described again.
[0215] Figure 10 shows a schematic diagram of the image detection device provided in an embodiment of this application. The image detection device may include:
[0216] Acquisition unit 81 is used to acquire the first image and the second image to be detected;
[0217] The sampling unit 82 is used to sample the first image and the second image according to the preset image sampling unit, respectively, to obtain each first image sampling region after sampling the first image and each second image sampling region after sampling the second image;
[0218] The determining unit 83 is used to determine each similarity index between each first image sampling region and each of the second image sampling regions by using a preset first similarity algorithm. The first similarity algorithm is used to calculate the degree of similarity between two image sampling regions.
[0219] The detection unit 84 is used to determine the similarity index between the first image and the second image based on the similarity index and a set similarity index threshold, and to obtain the image detection result. The second similarity algorithm is used to calculate the degree of similarity between the two images.
[0220] In one embodiment, the sampling unit 82 is specifically used to sample the first image according to a preset sampling number by a preset image sampling unit to obtain a corresponding number of first image sampling regions; and to sample the pixels of the second image according to the preset image sampling unit to obtain each second image sampling region after the second image is sampled.
[0221] In one embodiment, the determining unit 83 is specifically configured to: generate a two-dimensional matrix of the first image sampling region based on the decimal color values of each pixel in the first image sampling region for each first image sampling region; generate a two-dimensional matrix of the second image sampling region based on the decimal color values of each pixel in the second image sampling region for each second image sampling region; and, for each first image sampling region, determine a similarity index between the first image sampling region and each of the second image sampling regions based on the two-dimensional matrix corresponding to the first image sampling region and the two-dimensional matrix corresponding to each of the second image sampling regions.
[0222] In one embodiment, the similarity index between the first image sampling region and any second image sampling region is the similarity between the two-dimensional matrix corresponding to the first image sampling region and the two-dimensional matrix corresponding to any second image sampling region.
[0223] In one embodiment, the device further includes:
[0224] The normalization unit is used to normalize the two-dimensional matrix corresponding to the first image sampling region and the two-dimensional matrix corresponding to each of the second image sampling regions before determining the similarity index between the first image sampling region and each of the second image sampling regions based on the two-dimensional matrix corresponding to the first image sampling region and the two-dimensional matrix corresponding to each of the second image sampling regions.
[0225] In one embodiment, the detection unit 84 is specifically configured to set the similarity index threshold by: pre-specifying the similarity index threshold for each first image sampling region; or determining the corresponding similarity index threshold based on the two-dimensional matrix corresponding to each first image sampling region.
[0226] In one embodiment, the detection unit 84 is specifically configured to, for each two-dimensional matrix corresponding to the first image sampling region, rearrange the decimal color values of each pixel in the two-dimensional matrix corresponding to the first image sampling region to generate a set number of new two-dimensional matrices; calculate the similarity index between the two-dimensional matrix corresponding to the first image sampling region and each new two-dimensional matrix to obtain a candidate similarity index; and determine the critical value of the similarity index of the first image sampling region based on preset conditions and the candidate similarity index.
[0227] In one embodiment, the detection unit 84 is specifically used to determine a confidence interval under a preset confidence condition based on the distribution of the candidate similarity index; and to determine the lower limit of the confidence interval as the critical value of the similarity index of the first image sampling region.
[0228] In one embodiment, the detection unit 84 is specifically used to count a first number of first image sampling regions whose similarity indices with each of the second image sampling regions contain a similarity index greater than or equal to or only greater than the similarity index threshold; and to determine the ratio of the first number to the preset sampling number as the similarity index between the first image and the second image.
[0229] In one embodiment, the detection unit 84 is specifically configured to, for each first image sampling region, specify a similarity index of the same order in terms of size among the similarity indices of the first image sampling region and each second image sampling region as a specified similarity index of the first image sampling region; generate a first vector based on the specified similarity index of each first image sampling region; generate a second vector based on the critical value of the similarity index corresponding to each first image sampling region; and determine the similarity index between the first image and the second image based on the similarity between the first vector and the second vector.
[0230] In one embodiment, the detection unit 84 is specifically configured to, for each first image sampling region, specify a similarity index of the same rank in order of size among the similarity indices of the first image sampling region and each of the second image sampling regions as a specified similarity index of the first image sampling region; assign a first fixed value to the specified similarity index that is greater than or equal to the similarity index threshold, and assign a second fixed value to the specified similarity index that is less than the similarity index threshold; or assign a first fixed value to the specified similarity index that is greater than the similarity index threshold, and assign a second fixed value to the specified similarity index that is less than or equal to the similarity index threshold; generate a first vector based on the first fixed value and the second fixed value of each first image sampling region; generate a second vector based on the similarity index threshold corresponding to each first image sampling region; and determine the similarity index between the first image and the second image based on the similarity between the first vector and the second vector.
[0231] In one implementation, the similarity index, which is greater than or equal to or only greater than the similarity index threshold, or the specified similarity index, includes the largest similarity index among the various similarity indices of the first image sampling region and each of the second image sampling regions.
[0232] Based on the same technical concept, this application also provides an electronic device 900. Referring to FIG11, the electronic device 900 is used to implement the image detection method described in the above method embodiments. The electronic device 900 of this embodiment may include: a memory 901, a processor 902, and a computer program stored in the memory and executable on the processor, such as an image detection program. When the processor executes the computer program, it implements the steps in the above-described image detection method embodiments, such as step S11 shown in FIG1.
[0233] This application embodiment does not limit the specific connection medium between the memory 901 and the processor 902. In Figure 11, the memory 901 and the processor 902 are connected via a bus 903, which is represented by a thick line. The connection methods between other components are only for illustrative purposes and are not intended to be limiting. The bus 903 can be divided into address bus, data bus, control bus, etc. For ease of illustration, only one thick line is used in Figure 11, but this does not mean that there is only one bus or one type of bus.
[0234] Memory 901 may be volatile memory, such as random-access memory (RAM); memory 901 may also be non-volatile memory, such as read-only memory, flash memory, hard disk drive (HDD), or solid-state drive (SSD); or memory 901 may be any other medium capable of carrying or storing desired program code in the form of instructions or data structures and accessible by a computer, but is not limited thereto. Memory 901 may be a combination of the above-mentioned memories.
[0235] The processor 902 is used to implement the image detection method provided in the embodiments of this application.
[0236] This application also provides a computer-readable storage medium storing computer-executable instructions required to execute the processor, including a program required to execute the processor.
[0237] In some possible implementations, various aspects of the image detection method provided in this application may also be implemented as a program product comprising program code that, when the program product is run on an electronic device, causes the electronic device to perform the steps of the image detection method according to the various exemplary embodiments of this application described above.
[0238] Those skilled in the art will understand that embodiments of this application can be provided as methods, apparatus, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0239] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (devices), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in one or more blocks of the flowchart illustrations and / or one or more blocks of the block diagrams.
[0240] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means that implement the functions specified in one or more flowcharts and / or one or more block diagrams.
[0241] These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer-implemented process, such that the instructions, which execute on the computer or other programmable apparatus, provide steps for implementing the functions specified in one or more flowcharts and / or one or more block diagrams.
[0242] Although preferred embodiments of this application have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of this application.
[0243] Obviously, those skilled in the art can make various modifications and variations to this application without departing from the spirit and scope of this application. Therefore, if such modifications and variations fall within the scope of the claims of this application and their equivalents, this application also intends to include such modifications and variations.
Claims
1. An image detection method, characterized in that, include: A first image and a second image to be detected are acquired; the first image and the second image are sampled according to a preset image sampling unit to obtain each first image sampling region after sampling the first image and each second image sampling region after sampling the second image; a preset first similarity algorithm is used to determine each similarity index between each first image sampling region and each second image sampling region, wherein the first similarity algorithm is used to calculate the degree of similarity between two image sampling regions; Based on the similarity index and the set similarity index threshold, the similarity index between the first image and the second image is determined by a preset second similarity algorithm to obtain the image detection result. The second similarity algorithm is used to calculate the degree of similarity between the two images. Based on the similarity index and a set similarity index threshold, the similarity index between the first image and the second image is determined by a preset second similarity algorithm, including: counting the first number of first image sampling regions whose similarity index with each of the sampling regions of the second image contains a similarity index greater than or equal to or only greater than the similarity index threshold; and determining the ratio of the first number to the preset sampling number as the similarity index between the first image and the second image.
2. The method as described in claim 1, characterized in that, The method involves sampling the first image and the second image according to a preset image sampling unit to obtain each first image sampling region after sampling the first image and each second image sampling region after sampling the second image. Specifically, this includes: sampling the first image according to a preset sampling number using the preset image sampling unit to obtain a corresponding number of first image sampling regions; and sampling the pixels of the second image according to the preset image sampling unit to obtain each second image sampling region after sampling the second image.
3. The method as described in claim 1, characterized in that, Using a preset first similarity algorithm, the similarity index between each first image sampling region and each of the second image sampling regions is determined. Specifically, this includes: for each first image sampling region, generating a two-dimensional matrix of the first image sampling region based on the decimal color values of each pixel in the first image sampling region; for each second image sampling region, generating a two-dimensional matrix of the second image sampling region based on the decimal color values of each pixel in the second image sampling region; and for each first image sampling region, determining the similarity index between the first image sampling region and each of the second image sampling regions based on the two-dimensional matrix corresponding to the first image sampling region and the two-dimensional matrix corresponding to each of the second image sampling regions.
4. The method as described in claim 3, characterized in that, The similarity index between the first image sampling region and any second image sampling region is the similarity between the two-dimensional matrix corresponding to the first image sampling region and the two-dimensional matrix corresponding to any second image sampling region.
5. The method as described in claim 3 or 4, characterized in that, Before determining the similarity indices between the first image sampling region and each of the second image sampling regions based on the two-dimensional matrix corresponding to the first image sampling region and the two-dimensional matrix corresponding to each of the second image sampling regions, the method further includes: normalizing the two-dimensional matrix corresponding to the first image sampling region and normalizing the two-dimensional matrix corresponding to the second image sampling region.
6. The method as described in claim 1, characterized in that, The similarity index threshold is set in the following ways: pre-specifying the similarity index threshold for each of the first image sampling regions; or determining the corresponding similarity index threshold based on the two-dimensional matrix corresponding to each of the first image sampling regions.
7. The method as described in claim 6, characterized in that, Determining the critical value of the similarity index for each of the two-dimensional matrices corresponding to each first image sampling region specifically includes: for each of the two-dimensional matrices corresponding to the first image sampling region, rearranging the decimal color values of each pixel in the two-dimensional matrix corresponding to the first image sampling region to generate a set number of new two-dimensional matrices; calculating the similarity index between the two-dimensional matrix corresponding to the first image sampling region and each of the new two-dimensional matrices to obtain candidate similarity indices; and determining the critical value of the similarity index for the first image sampling region based on preset conditions and the candidate similarity indices.
8. The method as described in claim 7, characterized in that, The similarity index threshold of the first image sampling region is determined based on preset conditions and the candidate similarity index, specifically including: determining the confidence interval under preset confidence conditions according to the distribution of the candidate similarity index; and determining the lower limit of the confidence interval as the similarity index threshold of the first image sampling region.
9. The method as described in claim 1, characterized in that, Based on the similarity index and a set similarity index threshold, the similarity index between the first image and the second image is determined by a preset second similarity algorithm. The method further includes: for each first image sampling region, selecting a similarity index with the same rank in order of size from the similarity indices between the first image sampling region and each second image sampling region as a specified similarity index for the first image sampling region; generating a first vector based on the specified similarity index for each first image sampling region; generating a second vector based on the similarity index threshold corresponding to each first image sampling region; and determining the similarity index between the first image and the second image based on the similarity between the first vector and the second vector.
10. The method as described in claim 1, characterized in that, Based on a similarity index and a set similarity index threshold, the similarity index between the first image and the second image is determined using a preset second similarity algorithm. The method further includes: for each first image sampling region, selecting similarity indices with the same rank in order of size from the similarity indices between the first image sampling region and each second image sampling region as a designated similarity index for the first image sampling region; assigning a first fixed value to the designated similarity index greater than or equal to the similarity index threshold, and assigning a second fixed value to the designated similarity index less than the similarity index threshold; or assigning a first fixed value to the designated similarity index greater than the similarity index threshold, and assigning a second fixed value to the designated similarity index less than or equal to the similarity index threshold; generating a first vector based on the first and second fixed values for each first image sampling region; generating a second vector based on the similarity index threshold corresponding to each first image sampling region; and determining the similarity index between the first image and the second image based on the similarity between the first vector and the second vector.
11. The method as described in claim 9 or 10, characterized in that, The similarity index, which is greater than or equal to or only greater than the similarity index threshold, or the specified similarity index, includes the largest similarity index among the various similarity indices of the first image sampling region and each of the second image sampling regions.
12. An image detection device, characterized in that, include: The acquisition unit is used to acquire a first image and a second image to be detected; the sampling unit is used to sample the first image and the second image respectively according to the preset image sampling unit to obtain each first image sampling region after sampling the first image and each second image sampling region after sampling the second image. The determining unit is used to determine each similarity index between each first image sampling region and each of the second image sampling regions by using a preset first similarity algorithm, wherein the first similarity algorithm is used to calculate the degree of similarity between two image sampling regions; The detection unit is used to determine the similarity index between the first image and the second image based on the similarity index and a set similarity index threshold, and to obtain the image detection result. The second similarity algorithm is used to calculate the degree of similarity between the two images. The detection unit is specifically used to count the first number of first image sampling regions that have a similarity index greater than or equal to or only greater than the similarity index threshold in each similarity index of each second image sampling region; and to determine the ratio of the first number to the preset sampling number as the similarity index between the first image and the second image.
13. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the image detection method as described in any one of claims 1 to 11.
Citation Information
Patent Citations
Character image matching method, device and equipment and computer storage medium
CN111898544A
Virtual camera validity detection method and device, electronic equipment and storage medium
CN115880569A