Image comparison method, device, electronic device and computer readable storage medium
By determining the feature values of image regions, the problem of inconsistent image size or rotation in image recognition is solved, and accurate image recognition is achieved under conditions of rotation or size change.
Patent Information
- Application Number
- CN202210536810.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-17
- Publication Date
- 2025-11-25
- Estimated Expiration
- 2042-05-17
AI Technical Summary
Existing technologies struggle to handle inconsistent image sizes or rotations during image recognition, resulting in poor recognition performance, and artificial intelligence methods are also costly.
By determining the regional feature values of the target image and the image to be compared, and comparing the pixel feature values of the target region and the image to be compared, image similarity can be identified.
It can accurately identify image similarity when images are rotated or resized, reducing computational complexity and cost.
Smart Images

Figure CN114972819B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing, and more specifically, to an image comparison method, apparatus, electronic device, and computer-readable storage medium. Background Technology
[0002] In related technologies, one approach to identifying similar images is to use edit distance, such as Hamming distance or Lewinstein distance, to calculate the similarity between the images. During image recognition, the images are typically denoised and binarized. The binarized image information is then searched, and if the similarity calculated by the similarity algorithm meets a threshold, the current image is considered similar to the target image. Another approach is to use artificial intelligence, learning from large amounts of data to acquire the ability to recognize images.
[0003] However, when using edit distance to calculate similarity, recognition fails if the target image and the current image are of different sizes or if the image has been rotated. In real-world scenarios, it's almost common for images to vary in size and be rotated. Therefore, existing image recognition methods using edit distance are limited to scenarios where some images are of equal size, neatly arranged, and not rotated. Using artificial intelligence for image recognition requires powerful servers and a large amount of training data. Each time a new image is added, extensive training on that image is necessary, resulting in high costs.
[0004] There is currently no effective solution to the above problems. Summary of the Invention
[0005] This invention provides an image comparison method, apparatus, electronic device, and computer-readable storage medium to at least solve the technical problem in the related art where it is difficult to identify similar images when the images are rotated or their size is changed.
[0006] According to one aspect of the present invention, an image comparison method is provided, comprising: determining a target region of a target image and a comparison region of an image to be compared; determining a target contour corresponding to the target region and a plurality of target pixels on the target contour, and a comparison contour corresponding to the comparison region and a plurality of comparison pixels on the comparison contour; determining a target region feature value corresponding to the target region and a comparison region feature value corresponding to the comparison region based on the plurality of target pixels and the plurality of comparison pixels; and obtaining a comparison result between the target image and the image to be compared based on the target region feature value and the comparison region feature value.
[0007] Optionally, based on the plurality of target pixels and the plurality of pixels to be compared, determining the target region feature value corresponding to the target region and the comparison region feature value corresponding to the comparison region includes: determining a first distance from the plurality of target pixels to a first predetermined pixel among the plurality of target pixels that conforms to a predetermined rule, and a second distance from the plurality of pixels to be compared to a second predetermined pixel among the plurality of pixels to be compared that conforms to the predetermined rule; determining a first ratio of the first distance to a third distance, and determining a second ratio of the second distance to a fourth distance, wherein the third distance is the distance between the two farthest target pixels among the plurality of target pixels, and the fourth distance is the distance between the two farthest comparison pixels among the plurality of comparison pixels; determining the ratio of the first ratio to the number of the plurality of target pixels as the target region feature value corresponding to the target region, and the ratio of the second ratio to the number of the plurality of comparison pixels as the comparison region feature value corresponding to the comparison region.
[0008] Optionally, determining the target region feature value corresponding to the target region and the comparison region feature value corresponding to the comparison region includes: when the target region and / or the comparison region has an irregular shape, dividing the target region and / or the comparison region into multiple sub-regions with regular shapes according to a predetermined method; determining the contours of multiple sub-regions corresponding to the multiple sub-regions and multiple sets of sub-pixels on the contours of the multiple sub-regions; determining the feature values of multiple sub-regions corresponding to the sub-regions based on the multiple sets of sub-pixels; and determining the sum of the feature values of the multiple sub-regions as the feature value of the target region and / or the feature value of the comparison region.
[0009] Optionally, obtaining the comparison result between the target image and the image to be compared based on the feature value of the target region and the feature value of the region to be compared includes: determining a similarity value between the feature value of the target region and the feature value of the region to be compared, wherein the similarity value is obtained by calculating the target region feature value using the absolute value of the difference between the feature value of the target region and the feature value of the region to be compared; and obtaining a comparison result in which the target image and the image to be compared are not the same image if the similarity value is less than or equal to a predetermined threshold.
[0010] Optionally, obtaining the comparison result between the target image and the image to be compared based on the feature value of the target region and the feature value of the region to be compared includes: determining the target position of the target region and the comparison position of the image to be compared when the similarity value is greater than a predetermined threshold; and obtaining the comparison result between the target image and the image to be compared based on the target position and the comparison position.
[0011] Optionally, determining the target region of the target image and the comparison region of the image to be compared further includes: determining the target region as the region with the same pixel value and being adjacent in the target image, and the comparison region as the region with the same pixel value and being adjacent in the image to be compared.
[0012] Optionally, before determining the target region of the target image and the comparison region of the image to be compared, the method further includes: performing image binarization processing on the target image and the image to be compared.
[0013] According to one aspect of the present invention, an image comparison apparatus is provided, comprising: a first determining module, configured to determine a target region of a target image and a comparison region of an image to be compared, wherein the target region is a region in the target image that has the same pixel value and is adjacent, and the comparison region is a region in the image to be compared that has the same pixel value and is adjacent; a second determining module, configured to determine a target contour corresponding to the target region and a plurality of target pixels on the target contour, and a comparison contour corresponding to the comparison region and a plurality of comparison pixels on the comparison contour; a third determining module, configured to determine a target region feature value corresponding to the target region and a comparison region feature value corresponding to the comparison region based on the plurality of target pixels and the plurality of comparison pixels; and a comparison module, configured to obtain a comparison result between the target image and the image to be compared based on the target region feature value and the comparison region feature value.
[0014] According to one aspect of the present invention, an electronic device is provided, comprising: a processor; and a memory for storing processor-executable instructions; wherein the processor is configured to execute the instructions to implement the image comparison method described in any of the preceding claims.
[0015] According to one aspect of the present invention, a computer-readable storage medium is provided, wherein when the instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to perform the image comparison method described in any of the preceding claims.
[0016] According to one aspect of the present invention, a computer program product is provided, including a computer program that, when executed by a processor, implements the image comparison method described in any of the preceding claims.
[0017] In this embodiment of the invention, by determining the target region of the target image and the comparison region of the image to be compared, and by determining the target contour corresponding to the target region and multiple target pixels on the target contour, as well as the comparison contour corresponding to the comparison region and multiple comparison pixels on the comparison contour, the target region feature value corresponding to the target region and the comparison region feature value corresponding to the comparison region can be determined based on the multiple target pixels and the multiple comparison pixels. Thus, the comparison result between the target image and the image to be compared is obtained based on the target region feature value and the comparison region feature value. Because the image comparison result is obtained based on the region feature value, and the region feature value is obtained based on the pixels on the image contour, it is possible to identify whether the images are similar when the image is rotated or its size changes. This solves the technical problem in related technologies where it is difficult to identify similar images when the image is rotated or its size changes.
[0018] It should be noted that the method and apparatus of the present invention can be used in image processing in the financial field, as well as in image processing in any field other than the financial field. The application field of the present invention is not limited. Attached Figure Description
[0019] The accompanying drawings, which are included to provide a further understanding of the invention and form part of this application, illustrate exemplary embodiments of the invention and, together with their description, serve to explain the invention and do not constitute an undue limitation thereof. In the drawings:
[0020] Figure 1 This is a flowchart of an image comparison method according to an embodiment of the present invention;
[0021] Figure 2 This is a schematic diagram of an image similarity determination method in an optional embodiment of the present invention;
[0022] Figure 3 This is a structural block diagram of an image comparison device according to an embodiment of the present invention. Detailed Implementation
[0023] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0024] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0025] First, some nouns or terms that appear in the description of the embodiments of this application shall be interpreted as follows:
[0026] A closed figure is a closed figure composed of n (n is a positive integer) line segments or arcs. Here, it refers to a closed figure in a two-dimensional plane, such as a triangle or a rectangle.
[0027] Connected region: Generally refers to an image region composed of foreground pixels with the same pixel value and adjacent positions.
[0028] Euler distance: the straight-line distance between two points. Let P(xp,yp) and Q(xq,yq) be the two points, then the Euler distance D is:
[0029] D4 Distance: Distance within the city limits. Let there be two points P(xp,yp) and Q(xq,yq). Travel between P and Q is only possible in two directions: horizontal and vertical. D is defined as: D4(P,Q) = |x... p -x q |+|y p -y q |
[0030] D8 Distance: Chessboard distance. Let there be two points P(xp,yp) and Q(xq,yq). The distance between P and Q can be either a straight line or a diagonal line. D is: D8(P,Q) = max(x... p -x q |,|y p -y q |).
[0031] Example 1
[0032] According to an embodiment of the present invention, an embodiment of an image comparison method is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0033] Figure 1 This is a flowchart of an image comparison method according to an embodiment of the present invention, such as... Figure 1 As shown, the method includes the following steps:
[0034] Step S102: Determine the target region of the target image and the comparison region of the image to be compared;
[0035] Step S104: Determine the target contour corresponding to the target region and multiple target pixels on the target contour, as well as the comparison contour corresponding to the comparison region and multiple comparison pixels on the comparison contour.
[0036] Step S106: Based on multiple target pixels and multiple pixels to be compared, determine the target region feature value corresponding to the target region and the comparison region feature value corresponding to the comparison region.
[0037] Step S108: Based on the feature values of the target region and the feature values of the region to be compared, obtain the comparison result between the target image and the image to be compared.
[0038] By determining the target region of the target image and the comparison region of the image to be compared, and identifying the target contour and multiple target pixels on the target contour, as well as the comparison contour and multiple comparison pixels on the comparison contour, the feature values of the target region and the comparison region can be determined based on these multiple target pixels and comparison pixels. Thus, the comparison result between the target image and the image to be compared is obtained. Since the image comparison result is obtained based on region feature values, which in turn are obtained based on pixels on the image contour, it is possible to identify whether images are similar even when the images are rotated or resized. This solves the technical problem in related technologies where it is difficult to identify similar images when they are rotated or resized.
[0039] As an optional embodiment, a target region of the target image and a comparison region of the image to be compared are determined. The target region and the comparison region can be adjacent regions with the same pixel values in the target image and the comparison image, respectively. Since if two images are similar, their pixel value distributions should also be similar, regions with the same and adjacent pixel values in the target image and the comparison image can be extracted based on pixel values to determine image similarity. This makes the method proposed in this optional embodiment more targeted.
[0040] It should be noted that before determining the target region of the target image and the comparison region of the image to be compared, image binarization can be performed on both images to select the target region of the binarized image and the comparison region of the image to be compared. Image binarization ensures that the image contains only black and white pixels, i.e., 0 and 1 pixel values, significantly reducing the computational load and accelerating the image similarity detection process.
[0041] As an optional embodiment, the target region determined above includes the target contour and the connected regions within the target; the region to be compared includes the comparison contour and the connected regions within the comparison contour. Only the target contour corresponding to the target region and multiple target pixels on the target contour, and the comparison contour corresponding to the region to be compared and multiple comparison pixels on the comparison contour, can be determined. Subsequent similarity judgments can then be made based on these multiple target pixels and multiple comparison pixels. Because the contour reveals the direction and shape of adjacent regions with the same pixel values in the image, determining the pixels on the contour and judging the relationships between these pixels allows for a simple, direct, and effective determination of whether the target region and the region to be compared are similar.
[0042] As an optional embodiment, based on multiple target pixels and multiple comparison pixels, the target region feature value corresponding to the target region and the comparison region feature value corresponding to the comparison region are determined. The region feature value can be a feature value that can represent the flatness of the region; that is, the flatness of the region can be determined through the pixels on the contour. The similarity between the target region and the comparison region is then determined based on the region flatness. Since the flatness of the region is not affected by image rotation or size changes, determining the similarity between the target region and the comparison region based on region flatness can solve the problem that image recognition algorithms based on edit distance similarity calculation cannot recognize images of different sizes or rotations. Furthermore, this method of determining image similarity is not affected by the number of pixels, resulting in high accuracy.
[0043] As an optional embodiment, when determining the target region feature value corresponding to the target region and the comparison region feature value corresponding to the comparison region based on multiple target pixels and multiple comparison pixels, the following method can be adopted: Determine a first distance from multiple target pixels to a first predetermined pixel among the multiple target pixels that conforms to a predetermined rule, and a second distance from multiple comparison pixels to a second predetermined pixel among the multiple comparison pixels that conforms to a predetermined rule. The predetermined rule can be a rule of selecting the pixel farthest from the selected pixel as the predetermined pixel. The distance calculation method can use Eulerian distance, D4 distance, or D8 distance. Then, determine a first ratio between the first distance and a third distance, and a second ratio between the second distance and a fourth distance. The third distance is the distance between the two farthest target pixels among the multiple target pixels, and the fourth distance is the distance between the two farthest comparison pixels among the multiple comparison pixels. Finally, determine the ratio of the first ratio to the number of multiple target pixels as the target region feature value corresponding to the target region, and the ratio of the second ratio to the number of multiple comparison pixels as the comparison region feature value corresponding to the comparison region. Taking a target pixel as an example, we determine the outer contour of the target region and multiple target pixels located on the target contour, denoted as n. Let lp be the distance between a pixel p in the target region and the farthest pixel in the outer contour of the target region. Let l be the maximum value of lp among all pixels in the target region, which is the distance between the two farthest pixels in the target region. Let the feature value of this graphic be C. The image feature values obtained in this way can accurately reflect the flatness of the image, with a value range of 0.75 to 1. When C is 0.75, the image is a one-dimensional straight line; when C is 1, the image is a two-dimensional circle. C increases with the number of sides of the regular polygon, which can also be understood as the roundness of the image. Therefore, since the selected target area and the comparison area are areas with the same pixel values, and the image feature values here can reflect whether the target area and the comparison area are similar in shape, it is possible to determine whether the target image and the comparison image are similar.
[0044] It should be noted that when determining the feature values of the target region and the region to be compared, the process also includes cases where the target region and / or the region to be compared are irregular in shape. In this case, the target region and / or the region to be compared are divided into multiple sub-regions with regular shapes according to a predetermined rule. The contours of the multiple sub-regions and the sets of sub-pixels on the contours of the multiple sub-regions are determined. Based on the sets of sub-pixels, the feature values of the multiple sub-regions are determined. The sum of the feature values of the multiple sub-regions is determined as the feature value of the target region and / or the feature value of the region to be compared. This method can identify polygonal and irregular regions and solves the problem of inaccurate identification of polygonal and irregular regions.
[0045] As an optional embodiment, the comparison result between the target image and the image to be compared is obtained based on the feature values of the target region and the feature values of the region to be compared. This can be achieved by determining a similarity value between the feature values of the target region and the region to be compared, where the similarity value is obtained by proportionally calculating the absolute value of the difference between the feature values of the target region and the region to be compared, and the feature value of the target region. When there is only one target region and one region to be compared, the similarity between the target region and the region to be compared is determined based on their feature values. If the similarity value is less than or equal to a predetermined threshold, a comparison result indicating that the target image and the image to be compared are not identical is obtained. When there are multiple target regions and multiple regions to be compared, the similarity between the multiple target regions and their corresponding regions to be compared is determined based on their feature values. If any similarity value is less than or equal to a predetermined threshold, a comparison result indicating that the target image and the image to be compared are not identical is obtained.
[0046] As an optional embodiment, when there is only one target region and one region to be compared, and the similarity value is greater than a predetermined threshold; or when there are multiple target regions and multiple regions to be compared, and the similarity value is greater than the predetermined threshold for all of them, the target position of the target region and the comparison position of the image to be compared are determined. Based on the target position and the comparison position, the comparison result between the target image and the image to be compared is obtained. This avoids the problem of two images with different positions but the same shape being identified as similar images. Therefore, since the selected target region and the comparison region are regions with the same pixel values and similar image feature values, reflecting that the target region and the comparison region are similar in shape, and by determining that the target position of the target region and the comparison position of the image to be compared are relative positions, it is possible to more accurately determine whether the target image and the comparison image are similar.
[0047] Based on the above embodiments and optional embodiments, an optional implementation method is provided, which is described in detail below.
[0048] An optional embodiment of the present invention provides a method for determining image similarity, which can support the recognition of images of arbitrary size and rotation angle. Figure 2 This is an image illustration of the image similarity judgment method in an optional embodiment of the present invention, such as... Figure 2 As shown, the method provided by the optional embodiments of the present invention will be described below:
[0049] S1, preprocess the target image and the image to be compared, wherein the preprocessing can be image binarization;
[0050] S2, set the target region in the target image. The target region is the region to be compared with the image to be compared, such as... Figure 2 As shown, the target region includes an outer contour region (same as the target contour mentioned above) and an inner connected region. Similarly, a region to be compared is determined in the image to be compared. The region to be compared is the region to be compared with the target region. The region to be compared also includes an outer contour region (same as the comparison contour mentioned above) and an inner connected region.
[0051] S3, compare the target region with the region to be compared, and determine the region to be compared that is similar to the target region by calculating the similarity between the target region and the region to be compared. During the comparison, the successfully identified regions can be marked to accelerate the filtering.
[0052] It should be noted that the following method can be used when calculating similarity:
[0053] Determine the outer contour of the target region and the multiple target pixels on the target contour, denoted as n. Let lp be the distance between a pixel p in the target region and the farthest pixel in the outer contour of the target region. Let l be the maximum value of lp among all pixels in the target region, representing the distance between the two farthest pixels in the target region. This distance can be calculated using Eulerian distance, D4 distance, or D8 distance. Let the feature value of this graphic be C.
[0054] Then, based on the graphic feature values, the similarity between the target region and the region to be compared is determined. Let the feature values of the target region and the region to be compared be C1 and C2, respectively, and let the similarity be S. A threshold is set for the image based on the actual scenario. When the similarity S > the threshold, the target region is considered to be similar to the region to be compared.
[0055] It should also be noted that when the target region and / or the region to be compared is irregular in shape, the target region and / or the region to be compared is divided into multiple sub-regions with regular shapes according to a predetermined method, the feature values of the multiple sub-regions corresponding to the sub-regions are determined, and the sum of the feature values of the multiple sub-regions is determined as the feature value of the target region and / or the feature value of the region to be compared.
[0056] S4. Based on the comparison results of all target regions and regions to be compared, determine whether the target image and the image to be compared are similar images.
[0057] The above optional implementation methods can achieve at least the following beneficial effects:
[0058] (1) It solves the problem that the image recognition algorithm based on editing distance calculation similarity cannot recognize images of different sizes and rotated images;
[0059] (2) Solved the problem of inaccurate identification of polygonal and irregular regions;
[0060] (3) The similarity results are not affected by the number of pixels, and the accuracy is high.
[0061] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that the present invention is not limited to the described order of actions, because according to the present invention, some steps can be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to the present invention.
[0062] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods according to the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods of the various embodiments of the present invention.
[0063] Example 2
[0064] According to embodiments of the present invention, an apparatus for implementing the above-described image comparison method is also provided. Figure 3 This is a structural block diagram of an image comparison device according to an embodiment of the present invention, such as... Figure 3As shown, the device includes: a first determining module 302, a second determining module 304, a third determining module 306, and a comparison module 308. The device will be described in detail below.
[0065] The first determining module 302 is used to determine the target region of the target image and the comparison region of the image to be compared, wherein the target region is a region in the target image that has the same pixel value and is adjacent, and the comparison region is a region in the comparison image that has the same pixel value and is adjacent; the second determining module 304 is connected to the first determining module 302, and is used to determine the target contour corresponding to the target region and multiple target pixels on the target contour, and the comparison contour corresponding to the comparison region and multiple comparison pixels on the comparison contour; the third determining module 306 is connected to the second determining module 304, and is used to determine the target region feature value corresponding to the target region and the comparison region feature value corresponding to the comparison region based on the multiple target pixels and the multiple comparison pixels; the comparison module 308 is connected to the third determining module 306, and is used to obtain the comparison result between the target image and the comparison image based on the target region feature value and the comparison region feature value.
[0066] It should be noted here that the first determining module 302, the second determining module 304, the third determining module 306 and the comparison module 308 mentioned above correspond to steps S102 to S108 in the implementation of the image comparison method. The multiple modules and the corresponding steps are the same in terms of implementation examples and application scenarios, but are not limited to the content disclosed in the above embodiment 1.
[0067] Example 3
[0068] According to another aspect of the present invention, an electronic device is also provided, comprising: a processor; and a memory for storing processor-executable instructions, wherein the processor is configured to execute instructions to implement the image comparison method of any of the above embodiments.
[0069] Example 4
[0070] According to another aspect of the present invention, a computer-readable storage medium is also provided, which, when the instructions in the computer-readable storage medium are executed by a processor of an electronic device, enables the electronic device to perform any of the above-described image comparison methods.
[0071] Example 5
[0072] According to another aspect of the present invention, a computer program product is also provided, including a computer program that, when executed by a processor, implements the image comparison method described in any of the preceding claims.
[0073] The sequence numbers of the above embodiments of the present invention are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0074] In the above embodiments of the present invention, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0075] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. The device embodiments described above are merely illustrative; for example, the division of units can be a logical functional division, and in actual implementation, there may be other division methods. For instance, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the displayed or discussed mutual coupling, direct coupling, or communication connection may be through some interfaces; the indirect coupling or communication connection between units or modules may be electrical or other forms.
[0076] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0077] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0078] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.
[0079] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. An image comparison method, characterized in that, include: Determine the target region of the target image and the comparison region of the image to be compared, wherein the target region and the comparison region are adjacent regions with the same pixel value in the target image and the image to be compared. Determine the target contour corresponding to the target region and multiple target pixels on the target contour, as well as the comparison contour corresponding to the comparison region and multiple comparison pixels on the comparison contour; Based on the plurality of target pixels and the plurality of pixels to be compared, the target region feature value corresponding to the target region and the comparison region feature value corresponding to the comparison region are determined, wherein the region feature value represents the feature value of region flatness; Based on the feature values of the target region and the feature values of the region to be compared, the comparison result between the target image and the image to be compared is obtained. The comparison result is determined based on the similarity value between the feature values of the target region and the feature values of the region to be compared and a predetermined threshold. When there is only one target region and one region to be compared, if the similarity value is greater than the predetermined threshold, or when there are multiple target regions and multiple regions to be compared, if the similarity value is greater than the predetermined threshold, the target position of the target region and the comparison position of the image to be compared are determined. Based on the target position and the comparison position, the comparison result between the target image and the image to be compared is obtained. The process of determining the target region feature value corresponding to the target region and the comparison region feature value corresponding to the comparison region based on the plurality of target pixels and the plurality of comparison pixels includes: determining a first distance from the plurality of target pixels to a first predetermined pixel among the plurality of target pixels that conforms to a predetermined rule, and a second distance from the plurality of comparison pixels to a second predetermined pixel among the plurality of comparison pixels that conforms to the predetermined rule; determining a first ratio between the first distance and a third distance, and determining a second ratio between the second distance and a fourth distance, wherein the third distance is the distance between the two farthest target pixels among the plurality of target pixels, and the fourth distance is the distance between the two farthest comparison pixels among the plurality of comparison pixels; determining the ratio of the first ratio to the number of the plurality of target pixels as the target region feature value corresponding to the target region, and the ratio of the second ratio to the number of the plurality of comparison pixels as the comparison region feature value corresponding to the comparison region.
2. The method according to claim 1, characterized in that, Determining the feature values of the target region corresponding to the target region and the feature values of the region to be compared corresponding to the region to be compared includes: If the target region and / or the region to be compared has an irregular shape, the target region and / or the region to be compared is divided into multiple sub-regions, each with a regular shape, according to a predetermined method. Determine the contours of multiple sub-regions corresponding to the multiple sub-regions and the multiple sets of sub-pixel points located on the contours of the multiple sub-regions; Based on the multiple sets of sub-pixels, determine multiple sub-region feature values corresponding to the sub-region; The sum of the feature values of the plurality of sub-regions is determined to be the feature value of the target region and / or the feature value of the region to be compared.
3. The method according to claim 1, characterized in that, Based on the feature values of the target region and the feature values of the region to be compared, the comparison result between the target image and the image to be compared is obtained, including: Determine the similarity value between the feature value of the target region and the feature value of the region to be compared, wherein the similarity value is obtained by calculating the absolute value of the difference between the feature value of the target region and the feature value of the region to be compared with the feature value of the target region; If the similarity value is less than or equal to a predetermined threshold, a comparison result is obtained in which the target image and the image to be compared are not the same image.
4. The method according to claim 3, characterized in that, Based on the feature values of the target region and the feature values of the region to be compared, the comparison result between the target image and the image to be compared is obtained, including: If the similarity value is greater than a predetermined threshold, the target location of the target region and the comparison location of the image to be compared are determined. Based on the target location and the comparison location, the comparison result between the target image and the comparison image is obtained.
5. The method according to claim 1, characterized in that, Before determining the target region of the target image and the comparison region of the image to be compared, the following steps are also included: The target image and the image to be compared are subjected to image binarization processing.
6. An image comparison device, characterized in that, include: The first determining module is used to determine the target region of the target image and the comparison region of the image to be compared, wherein the target region is a region in the target image that has the same pixel value and is adjacent, and the comparison region is a region in the image to be compared that has the same pixel value and is adjacent; the target region and the comparison region are regions in the target image and the image to be compared that have the same pixel value and are adjacent. The second determining module is used to determine the target contour corresponding to the target region and a plurality of target pixels on the target contour, as well as the comparison contour corresponding to the comparison region and a plurality of comparison pixels on the comparison contour. The third determining module is used to determine the target region feature value corresponding to the target region and the comparison region feature value corresponding to the comparison region based on the plurality of target pixels and the plurality of comparison pixels, wherein the region feature value represents the feature value of region flatness; The comparison module is used to obtain the comparison result between the target image and the image to be compared based on the feature value of the target region and the feature value of the region to be compared. The comparison result is determined based on the similarity value between the feature value of the target region and the feature value of the region to be compared and a predetermined threshold. When there is only one target region and one region to be compared, and the similarity value is greater than the predetermined threshold, or when there are multiple target regions and multiple regions to be compared, and the similarity value is greater than the predetermined threshold, the target position of the target region and the comparison position of the image to be compared are determined. Based on the target position and the comparison position, the comparison result between the target image and the image to be compared is obtained. The third determining module is further configured to: determine a first distance from the plurality of target pixels to a first predetermined pixel among the plurality of target pixels that conforms to a predetermined rule, and a second distance from the plurality of pixels to be compared to a second predetermined pixel among the plurality of pixels to be compared that conforms to the predetermined rule; determine a first ratio of the first distance to the third distance, and a second ratio of the second distance to the fourth distance, wherein the third distance is the distance between the two farthest target pixels among the plurality of target pixels, and the fourth distance is the distance between the two farthest pixels to be compared among the plurality of pixels to be compared; determine the ratio of the first ratio to the number of the plurality of target pixels as the target region feature value corresponding to the target region, and the ratio of the second ratio to the number of the plurality of pixels to be compared as the comparison region feature value corresponding to the comparison region.
7. An electronic device, characterized in that, include: processor; Memory used to store the processor's executable instructions; The processor is configured to execute the instructions to implement the image comparison method as described in any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that, When the instructions in the computer-readable storage medium are executed by the processor of the electronic device, the electronic device is enabled to perform the image comparison method as described in any one of claims 1 to 5.
9. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by the processor, it implements the image comparison method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Form feature describing and indexing method of image object
CN101996245A
Face recognition method and device, electronic equipment and readable storage medium
CN111832346A
Image similarity calculation method and device
CN114398990A