Gray value-based image local comparison method, device, equipment and medium
By performing Gaussian blurring and grayscale processing on the original image, the grayscale value is reduced, and binary and connected domain segmentation are performed. The P hash algorithm is used to generate binary integer strings for comparison, which solves the problems of slow image comparison speed and large storage occupancy, and realizes efficient and accurate local image comparison.
Patent Information
- Application Number
- CN202010886190.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-08-28
- Publication Date
- 2025-04-01
- Estimated Expiration
- 2040-08-28
AI Technical Summary
The traditional image comparison process is slow, the storage occupies a lot, and it is difficult to find local or subtle plagiarism patterns.
By performing Gaussian blurring and grayscale processing on the original image, the grayscale value of each pixel point is reduced to a preset range, divided into grayscale images of the same order, and binary processing and connecting domain segmentation are carried out to build a minimum rectangular box, and binarization is used to obtain a binary integer string and compare it.
It greatly saves the speed of comparison processing and memory required for storage, improves the accuracy and efficiency of local image comparison, and can effectively discover locally similar images.
Smart Images

Figure CN111986277B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing technology, and in particular to a grayscale value-based local image comparison method, device, equipment and medium. Background Art
[0002] Image comparison is increasingly needed in various scenarios, such as identifying plagiarized or copied patterns. As plagiarism becomes increasingly subtle, it's often necessary to perform partial comparisons of the pattern's color, shape, and other aspects.
[0003] The traditional image comparison process requires comparing the image to be compared with the images in the database one by one, such as using the feature vectors extracted from the image for comparison. However, an image contains a large number of feature vectors or pixel memories, which results in a large number of comparisons and a very slow comparison speed. In addition, the data storage in the image database is also very large, and local or subtle plagiarism patterns are often not discovered. Summary of the Invention
[0004] In view of the above-mentioned shortcomings of the prior art, the purpose of the present application is to provide a grayscale-based local image comparison method, device, equipment and medium to solve at least one problem existing in the prior art.
[0005] To achieve the above-mentioned object and other related objects, the present application provides a grayscale-based local image comparison method, the method comprising: performing Gaussian blur processing and grayscale value processing on the acquired original image; proportionally reducing the grayscale value of each pixel to within a preset range, and dividing the grayscale value images into multiple images of the same grayscale value corresponding to different integer grayscale values based on the reduced grayscale value of each pixel; binarizing each image of the same grayscale value, and combining pixels with the same grayscale value to form one or more connected domains; selecting one or more connected domains containing independent complete patterns based on a screening condition, and constructing a minimum rectangular frame for each connected domain to cover all the independent complete patterns; binarizing the pixels within each minimum rectangular frame using a P-hash algorithm to obtain a binary integer string, so as to determine whether there is an image that is at least partially similar in an image database by comparing the binary integer strings.
[0006] In one embodiment of the present application, the grayscale value of each pixel is proportionally reduced to a preset range, and divided into multiple same-order grayscale value images corresponding to different integer grayscale values based on the grayscale value of each pixel after reduction, including: proportionally reducing the grayscale value of each pixel from the range of 0-255×255 to the range of 0-N; for the reduced grayscale value, rounding the non-integer grayscale value to an integer grayscale value; and selecting corresponding pixel points according to the grayscale values belonging to the same integer in 0-N to obtain N+1 same-order grayscale value images containing only pixel points with the same integer grayscale value.
[0007] In one embodiment of the present application, the binarization processing of each image of the same grayscale value and the combination of pixels with the same grayscale value to form one or more connected domains include: setting the grayscale value of each image of the same grayscale value belonging to the same selected integer to 1, and setting the grayscale value not belonging to the same selected integer to 0, so that the grayscale value of each image of the same grayscale value is only 0 or 1; combining the pixel points with a grayscale value of 0 to form one or more connected domains; and / or combining the pixel points with a grayscale value of 1 to form one or more connected domains.
[0008] In one embodiment of the present application, the screening conditions include any one or more combinations of the following: 1)
[0009] The number of pixels in the connected domain is greater than 121; 2) the area of the connected domain occupies at most one-third of the entire image of the same grayscale value; 3) the ratio of the longest length to the longest width in the connected domain is between 0.2 and 5.
[0010] In one embodiment of the present application, the pixel points within each of the minimum rectangular frames are binarized using the P hash algorithm to obtain a binary integer string, including: dividing the minimum rectangular frame into n×n small blocks in an n×n grid; calculating the sum of the grayscale values of all pixels in each small block; averaging the sum of the non-zero grayscale values in all small blocks, and comparing the sum of the grayscale values of each non-zero small block with the average value; if it is less than the average value, the value corresponding to the non-zero small block is recorded as 0; if it is greater than or equal to the average value, the value corresponding to the non-zero small block is recorded as 1; in a manner of gradually diffusing from the center position of the minimum rectangular frame to the outer circle, the values corresponding to the small block at the center position and the values corresponding to each small block on each outer circle from the inside to the outside are sequentially counted to obtain a binary integer string corresponding to an image of the same order grayscale value.
[0011] In one embodiment of the present application, the writing format of the binary integer string includes: corresponding to the center position and the segments of the binary integer string counted in each layer of outer circle from the inside to the outside, the segments of each binary integer string are arranged in sequence from high to low in order from the inside to the outside; the high to low position corresponds to from right to left or from left to right; and / or, starting from the value corresponding to the small block in the upper left corner of each layer of outer circle, the values corresponding to each small block on the outer circle are counted in a clockwise direction, and written in order from low to high.
[0012] In one embodiment of the present application, determining whether there are partially similar images in an image database by comparing binary integer strings includes: setting a comparison line for the binary integer string to compare the high-order segments of the binary integer string to the right or left of the comparison line with the values of the binary integer segments corresponding to each integer in the image database; wherein the comparison line can be adjusted according to the comparison situation or scene requirements to adjust the comparison accuracy; if the comparison of the high-order segments of the binary integer strings is the same, then the corresponding binary integer strings are determined to be similar; if the comparisons of the binary integer strings corresponding to images of the same grayscale value are respectively similar, then it is determined that an image that is partially similar to the original image exists in the image database.
[0013] To achieve the above-mentioned purpose and other related purposes, the present application provides a grayscale-based local image comparison device, the device comprising: a first processing module, configured to perform Gaussian blur processing and grayscale value processing on the acquired original image; proportionally reduce the grayscale value of each pixel point to within a preset range, and divide the image into multiple images of the same grayscale value corresponding to different integer grayscale values based on the reduced grayscale value of each pixel point; a second processing module, configured to binarize the images of the same grayscale value and combine pixels of the same grayscale value to form one or more connected domains; select one or more connected domains containing independent complete patterns based on a screening condition, and construct a minimum rectangular frame for each connected domain to cover all the independent complete patterns; and binarize the pixels within each of the minimum rectangular frames using a P-hash algorithm to obtain a binary integer string, so as to determine whether there is an image that is at least partially similar in an image database by comparing the binary integer strings.
[0014] To achieve the above-mentioned purpose and other related purposes, the present application provides a computer device, which includes: a memory and a processor; the memory is used to store computer instructions; and the processor executes the computer instructions to implement the above-mentioned method.
[0015] To achieve the above-mentioned purpose and other related purposes, the present application provides a computer-readable storage medium storing computer instructions, which execute the above-mentioned method when executed.
[0016] In summary, the present application provides a grayscale-based local image comparison method, device, equipment and medium, which performs Gaussian blur processing and grayscale value processing on the acquired original image; proportionally reduces the grayscale value of each pixel to within a preset range, and divides it into multiple grayscale value images of the same order corresponding to different integer grayscale values based on the grayscale value of each pixel after reduction; binarizes each grayscale value image of the same order, and combines pixels with the same grayscale value to form one or more connected domains; selects one or more connected domains containing independent complete patterns based on a screening condition, and constructs a minimum rectangular frame for each connected domain to cover all the independent complete patterns; binarizes the pixels within each of the minimum rectangular frames using the P-hash algorithm to obtain a binary integer string, so as to determine whether there is an image that is at least partially similar in the image database by comparing the binary integer strings.
[0017] It has the following beneficial effects:
[0018] This application binarizes image features based on grayscale values, and converts the features of local image details into binary numerical strings through connected domain segmentation, which is convenient for storage and comparison, greatly saving the comparison processing speed and the memory required for storage, and improving the accuracy and efficiency of local image comparison. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] Figure 1 Shown is a flowchart of a grayscale-based local image comparison method in one embodiment of the present application.
[0020] Figures 2A-2C The diagram shows a scenario in which the pixel points within each of the minimum rectangular frames are binarized using the P-hash algorithm to obtain a binary integer string in one embodiment of the present application.
[0021] Figure 3 Shown is a module diagram of a grayscale-based local image comparison device in one embodiment of the present application.
[0022] Figure 4 Shown is a schematic structural diagram of a computer device in one embodiment of the present application. DETAILED DESCRIPTION
[0023] The following describes the embodiments of the present application through specific examples. Those skilled in the art can easily understand the other advantages and effects of the present application from the content disclosed in this specification. The present application can also be implemented or applied through other different specific embodiments. The details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of the present application. It should be noted that the following embodiments and features in the embodiments can be combined with each other unless they conflict.
[0024] It should be noted that the illustrations provided in the following embodiments are only schematic illustrations of the basic concept of the present application. Although the illustrations only show components related to the present application and are not drawn according to the number, shape and size of components in actual implementation, the type, quantity and proportion of each component in actual implementation can be changed arbitrarily, and the component layout type may also be more complex.
[0025] Throughout this specification, when a part is said to be "connected" to another part, this includes not only "direct connection" but also "indirect connection" with other elements interposed therebetween. Furthermore, when a part is said to "include" a certain component, unless otherwise stated, this does not exclude the other component but rather implies that the other component may be included.
[0026] The terms "first," "second," and "third" are used to describe various parts, components, regions, layers, and / or segments, but are not intended to be limiting. These terms are used solely to distinguish one part, component, region, layer, or segment from another. Therefore, a reference to a first part, component, region, layer, or segment below may also refer to a second part, component, region, layer, or segment without departing from the scope of this application.
[0027] Furthermore, as used herein, the singular forms "a", "an", and "the" are intended to include the plural forms as well, unless the context indicates otherwise. It should be further understood that the terms "comprise", "include" indicate the presence of the described features, operations, elements, components, items, kinds, and / or groups, but do not exclude the presence, occurrence, or addition of one or more other features, operations, elements, components, items, kinds, and / or groups. The terms "or" and "and / or" used herein are interpreted as inclusive, or mean any one or any combination. Thus, "A, B, or C" or "A, B, and / or C" means "any of the following: A; B; C; A and B; A and C; B and C; A, B, and C". Exceptions to this definition occur only when the combination of elements, functions, or operations is inherently mutually exclusive in some way.
[0028] The traditional image comparison process requires comparing the image to be compared with the images in the database one by one, such as using the feature vectors extracted from the image for comparison. However, an image contains a large number of feature vectors or pixel memories, which results in a large number of comparisons and a very slow comparison speed. In addition, local or subtle plagiarized patterns are often not discovered. In addition, the data storage space in the image database is also very large.
[0029] To solve the above problems, the present application proposes a grayscale-based local image comparison method, apparatus, device and medium, which converts the feature values of the image into integer form for easy storage and comparison, greatly saving the comparison speed and the memory required for storage.
[0030] like Figure 1 FIG. 1 is a flow chart of a grayscale-based local image comparison method according to an embodiment of the present invention. As shown in the figure, the method includes:
[0031] Step S101: performing Gaussian blur processing and grayscale value processing on the acquired original image.
[0032] In this embodiment, the Gaussian blur processing is performed on the acquired original image mainly for noise removal.
[0033] Gaussian blur, also known as Gaussian smoothing, is a widely used processing effect in image processing software such as Adobe Photoshop, GIMP, and Paint.NET. It is commonly used to reduce image noise and reduce the level of detail. Gaussian smoothing is also used in the pre-processing stage of computer vision algorithms to enhance the image quality at different scales (see scale space representation and scale space implementation). From a mathematical perspective, the Gaussian blurring process is the convolution of the image with a normal distribution. Since the normal distribution is also called the Gaussian distribution, this technique is called Gaussian blurring.
[0034] Preferably, this step further includes: reducing the RGBA four channels of the original image to RGB three channels.
[0035] Typically, an original image has four channels, RGBA, representing the color space of Red, Green, Blue, and Alpha. However, it is actually just an RGB model with additional information. The colors used are usually RGB, and the Alpha channel is generally used as an opacity parameter. Therefore, this application removes the Alpha channel, which has little or no influence during the image comparison process, to reduce the number of channels and thus reduce the data used for comparison.
[0036] In this embodiment, the grayscale value processing in this step mainly converts the RGB three-channel pixels of each pixel into grayscale values, such as converting the pixel coordinates (x, y, rgb) of a certain pixel into grayscale value coordinates (x, y, g).
[0037] Step S102: scaling down the grayscale value of each pixel to within a preset range, and dividing the image into a plurality of images of the same grayscale value corresponding to different integer grayscale values according to the scaled-down grayscale value of each pixel.
[0038] In one embodiment of the present application,
[0039] A. Reduce the grayscale value of each pixel from the range of 0-255×255 to the range of 0-N.
[0040] For example, after converting the three RGB color channels of a pixel to grayscale values, the grayscale value range is usually (0-255×255). Assuming N is 15, a coefficient G is set here: G = 255×255 ÷ 15 = 4335. Therefore, by dividing the grayscale value of each pixel in the original image by the coefficient G, the grayscale value of each pixel can be proportionally reduced to the range of 0-15.
[0041] B. For the reduced grayscale value, round the non-integer grayscale value to an integer grayscale value.
[0042] Continuing with the above example, after the grayscale value of each pixel is divided by the coefficient G, the resulting grayscale value is either a non-integer with a decimal or an integer. Therefore, this application converts non-integer values into integers by rounding off.
[0043] C. Select corresponding pixels according to the grayscale values that belong to the same integer from 0 to N, so as to obtain N+1 images of the same grayscale value that only contain pixels with the same integer grayscale value.
[0044] For example, by selecting pixels whose grayscale values are adjusted to 0 and setting the corresponding unselected pixels to blank, we can obtain an image with grayscale values of only 0. Similarly, if N is 15, we can obtain 16 such images with grayscale values of the same order. However, it should be noted that N is not limited to 15 and can also be a number below 10 or 100. For example, when the pixel size of the original image is not large, a single-digit number can be used. When the pixel size of the original image is very large, any two-digit number below 100 can also be used.
[0045] For another example, assuming that the original image is a face image, it may be divided into multiple images of the same grayscale value corresponding to different integer grayscale values. The pixel points in one image of the same grayscale value appear as facial contours, the pixel points in another image of the same grayscale value appear as eyes, and the pixel points in another image of the same grayscale value appear as hair, etc. That is, the original image is layered by grayscale value, and each image of the same grayscale value constitutes a sub-image of different angles, thereby greatly refining the local features of the image. Even in the case of plagiarism or copying of small image elements, a good comparison effect can be obtained.
[0046] Step S103: performing binarization processing on each image with the same gray value, and combining pixels with the same gray value to form one or more connected components.
[0047] This step specifically includes:
[0048] A. setting the grayscale values of the same-order grayscale value images that belong to the selected same integer to 1, and setting the grayscale values of the same-order grayscale value images that do not belong to the selected same integer to 0, so that the grayscale values of the same-order grayscale value images are only 0 or 1;
[0049] B. Combine pixels with a grayscale value of 0 and pixels with a grayscale value of 1 to form one or more connected domains.
[0050] Continuing with the above example, for an image of the same grayscale value, assuming that it contains only N grayscale values of the same integer, it can be binarized using the following formula so that the values of all pixels in the image are 1 or 0.
[0051]
[0052] Among them, g , Indicates the grayscale value after proportional reduction.
[0053] After the grayscale values of the image with the same grayscale value become only 0 or 1, the pixels with a grayscale value of 0 can be connected, and the pixels with a grayscale value of 1 can be connected, so as to obtain one or more connected domains containing independent complete patterns.
[0054] It should be noted that the connected domains formed by the same grayscale value in this step actually highlight any describable and meaningful small pattern or complete pattern. Therefore, each connected domain theory has a certain comparison value.
[0055] Generally speaking, an image with the same grayscale value can obtain dozens or even hundreds of connected domains containing independent and complete patterns, and each connected domain can be represented as a valuable subgraph.
[0056] Step S104: selecting one or more connected domains containing independent complete patterns according to the screening condition, and constructing a minimum rectangular frame for each connected domain to cover all the independent complete patterns.
[0057] It should be noted that the patterns of one or more connected domains obtained in the same grayscale value image may be large or small, tall or short, fat or thin, or tend to be full, and have various shapes. Therefore, not every connected domain meets the requirements of the subsequent calculation of the method described in this application. Therefore, this application selects suitable connected domains containing independent and complete patterns by presetting screening conditions.
[0058] In one embodiment of the present application, the screening conditions include any one or more combinations of the following:
[0059] 1) The number of pixels in the connected domain is greater than 121. Preferably, the length and width are greater than 11.
[0060] It should be noted that the purpose of requiring the number of pixels to be greater than 121 is that in step S105, the image of the same grayscale value needs to be divided into n×n grids, and in this application, 11×11 is a more preferred segmentation grid. Therefore, it is hoped that the number of pixels in the connected domain is not less than 121. In addition, the size of the original image is not scaled in this application, so the size of the original image is theoretically relatively large. Limiting the number of pixels in the connected domain to 121 here actually limits the minimum size of the independent complete pattern screened out. Because, in actual operation, a pixel number that is too small contains fewer valuable image elements, and it will also increase the number of comparisons and prolong the processing time.
[0061] 2) The area of the connected domain is at most one-third of the entire image of the same grayscale value.
[0062] The purpose of this screening condition is to make the image more detailed locally to improve the accuracy of finding similar elements in complex images. Moreover, areas that are too large are likely to be background and are not suitable for finding local similar patterns in this application. Preferably, the entire image is reduced to 11x11 size before performing P hashing (Phash) operation, which makes it easier to find overall similarities. However, if the comparison area is too large, it will interfere with finding different images.
[0063] 3) The ratio of the longest length to the longest width in the connected domain is between 0.2 and 5.
[0064] It should be noted that the ratio of the longest length to the longest width described here is the aspect ratio of the corresponding connected domain. Because a rectangular frame covering the connected domain will be constructed later, the more saturated the shape of the connected domain, the better, such as a circle or a shape close to a square. Therefore, in this application, it is desirable that the aspect ratio of the connected domain be limited to between 0.2 and 5, that is, the length is no more than 5 times the width, or less than 1 / 5 of the width.
[0065] Step S105: binarizing the pixels within each of the minimum rectangular frames using the P-hash algorithm to obtain a binary integer string, so as to determine whether there is an image that is at least partially similar by comparing the binary integer string in the image database.
[0066] In one embodiment of the present application, the pixel points within each of the minimum rectangular frames are binarized using a P-hash algorithm to obtain a binary integer string, including:
[0067] A. Divide the minimum rectangular frame into n×n small blocks evenly according to an n×n grid.
[0068] Preferably, n is an odd number, such as 1, 3, 5, 7, 9, 11, 13, etc. This is because an n×n grid with an odd number n allows the divided blocks to form layers of outer rings extending outward from the center. For example, a 5×5 grid can be divided into 25 blocks, which can form a central block, an inner ring near the center, and an outermost outer ring.
[0069] It should be noted that in actual operation, the minimum rectangular frame is preferably no less than 11×11 in an n×n grid. The grid size of less than 11×11 is used in this application for illustration only, and this also corresponds to the connected domain screening condition, where the number of pixels in the connected domain is greater than 121. Preferably, the length and width are preferably greater than 11.
[0070] B. Calculate the sum of the grayscale values of all pixels in each small block.
[0071] Since the size of the original image is not limited, the size of the connected domain obtained from the corresponding images of the same grayscale value is not small. Therefore, although it is divided into small blocks, each small block may contain multiple pixels, and each pixel in the small block may be 1 or 0. Therefore, the sum of the grayscale values of all pixels in each small block is to add the values of 0 or 1 corresponding to each pixel.
[0072] like Figure 2A As shown in the figure, it is assumed that the minimum rectangular frame is evenly divided into 25 blocks according to the 5×5 grid. Among them, the total grayscale value of the small block in a connected domain in the figure is 2. There are 2×2 pixels in the small block, which are 0, 1, 0, and 1 respectively. Therefore, the total grayscale value of the small block is 2.
[0073] It should be noted that although Figure 2A The edge of the connected domain shown in the figure only occupies half of the small block with a total gray value of 2. However, it should be noted that when the connected domain is constructed, the pixels with a gray value of 1 are connected after the images of the same gray value are binarized. Therefore, if the connected domain is enlarged to a size that can display each pixel, the edge of the connected domain is composed of pixel units. Therefore, in fact, the connected domain will not occupy only half of the pixels, but the entire pixel is used as a component of the edge. Figure 2A The size is simply displayed to the size of the small block, so it appears to occupy half of the small block.
[0074] C. Calculate the average value of the sum of the non-zero grayscale values in all small blocks, and compare the sum of the grayscale values of each non-zero small block with the average value.
[0075] The grayscale values of all pixels in a small block are summed. If the grayscale values of all pixels in a small block are 0, then the grayscale sum is also 0. For example, the grayscale sum of the area far from the edge of the connected domain in the rectangular frame is often 0. The average of the grayscale sums of these non-zero small blocks is then calculated, and the non-zero grayscale sum is compared with the average.
[0076] D. If it is less than the average value, the value corresponding to the non-zero small block is recorded as 0; if it is greater than or equal to the average value, the value corresponding to the non-zero small block is recorded as 1;
[0077] For example, if Figure 2B As shown in the figure, a 3×3 rectangular block is shown, and the sum of the grayscale values of each small block is shown in the figure. Among them, there are 7 small blocks with a non-zero grayscale value sum, and the total sum of the grayscale values of these 7 small blocks is 14, and the average is 2. Then the sum of the grayscale values of these 7 small blocks is compared with 2. The values corresponding to the small blocks less than 2 are recorded as 0, and the values corresponding to the small blocks greater than or equal to 2 are recorded as 1.
[0078] E. In a manner of gradually diffusing from the center position of the minimum rectangular frame to the outer circle, the values corresponding to the small blocks at the center position and the values corresponding to the small blocks on the outer circles of each layer from the inside to the outside are counted in sequence to obtain a binary integer string corresponding to an image of the same grayscale value.
[0079] It should be noted that, corresponding to this embodiment, steps AE here are similar to the P-hash algorithm in the art.
[0080] In one embodiment of the present application, the writing format of the binary integer string includes:
[0081] 1) corresponding to the center position and the segments of the binary integer strings counted in each outer circle from the inside out, the segments of each binary integer string are arranged from high to low in order from the inside out; the high to low position corresponds to from right to left or from left to right;
[0082] and / or,
[0083] 2) Starting from the value corresponding to the small block in the upper left corner of each layer's outer circle, count the values corresponding to each small block on the outer circle in a clockwise direction and write them in order from low to high.
[0084] In this embodiment, the closer the value is to the center point, the higher the corresponding weight is, and the higher the weight is placed. The high position to the low position can correspond to from right to left or from left to right.
[0085] For example, if Figure 2CAs shown, the binary integer counted at the center position is 1, and its corresponding segment is A; the binary integer counted at the outer circle adjacent to the center position is 00100101, and its corresponding segment is B; the binary integer counted at the outermost outer circle is 01110011011101110, and its corresponding segment is C. Assuming that the high bit to the low bit can be corresponded from right to left, then the corresponding Figure 2C After the processing of step AE, the binary integer string corresponding to the same grayscale value image is:
[0086] 01110011011101110 / 00100101 / 1;
[0087] Among them, " / " is only used to distinguish different segments and does not belong to the numerical value or character in the binary integer string.
[0088] In one embodiment of the present application, the determining whether there are partially similar images in the image database by comparing binary integer strings includes:
[0089] A. setting a comparison line for the binary integer string, so that a high-order segment of the binary integer string to the right or left of the comparison line is compared with the values of the binary integer segments corresponding to each integer in the image database; wherein the comparison line can be adjusted according to the comparison situation or scene requirements to adjust the comparison accuracy;
[0090] It's important to note that, as shown in the example above, the format of the binary integer string indicates that the higher-order values correspond to the center of the image at the same grayscale value, while the lower-order values correspond to the edges of the image at the same grayscale value. Therefore, comparing the values corresponding to the center is more meaningful and provides higher accuracy.
[0091] B. If the comparison of the high-order segments of the binary integer strings is the same, the corresponding binary integer strings are determined to be similar.
[0092] C. If the comparisons of the m binary integer strings corresponding to the images of the same grayscale value are respectively similar, it is determined that there is an image in the image database that is partially similar to the original image.
[0093] It should be noted that the comparison of the high-order segments of the binary integer strings here can be identical or different, but the entire binary integer strings corresponding to the same binary integer segment are unlikely to be identical, so they can only be judged to be similar. However, since the valuable content in the pattern is more concentrated in the center, if the comparison of the high-order segments of the binary integer strings is identical, the two compared binary integer strings can be judged to be similar. Based on this, if the comparison of the high-order segments of the binary integer strings corresponding to m images of the same grayscale value is identical, it can be determined that an image partially similar to the original image exists in the image database. In some feasible embodiments, if m is 3 or 4, it can be accurately determined that an image partially similar to the original image exists in the image database.
[0094] Generally speaking, this application aims to slice images of the same grayscale value according to connected regions, slicing a single image into hundreds of valuable subgraphs. Each subgraph is converted into a hash integer, and subgraph searches are converted into database integer range comparisons. For an image of the same grayscale value, dozens or hundreds of binary integer strings can be generated, while for an original image, hundreds or even thousands of binary integer strings can be generated. This allows for more refined local image comparisons.
[0095] In summary, the present application proposes a method, device, equipment and medium for local image comparison based on grayscale values, which binarizes image features based on grayscale values, and converts the features of local image details into binary numerical strings through the segmentation of connected domains, which is convenient for storage and comparison, greatly saves the comparison processing speed and the memory required for storage, and further improves the accuracy and efficiency of local image comparison.
[0096] like Figure 3 FIG. 3 is a block diagram of a grayscale-based local image comparison device according to an embodiment of the present invention. As shown in the figure, the device 300 includes:
[0097] The first processing module 301 is used to perform Gaussian blur processing and grayscale value processing on the acquired original image; the grayscale value of each pixel is proportionally reduced to within a preset range, and based on the grayscale value of each pixel after reduction, the image is divided into multiple images of the same grayscale value corresponding to different integer grayscale values;
[0098] The second processing module 302 is used to binarize each image with the same grayscale value and combine pixels with the same grayscale value to form one or more connected domains; select one or more connected domains containing independent complete patterns based on the screening conditions, and construct a minimum rectangular frame for each connected domain to cover all of the independent complete patterns; binarize the pixels within each minimum rectangular frame using the P-hash algorithm to obtain a binary integer string, which is used for comparing the binary integer string in the image database to determine whether there is an image that is at least partially similar.
[0099] It should be noted that the information interaction, execution process, etc. between the modules / units of the above-mentioned device are based on the same concept as the method embodiment described in this application, and the technical effects they bring are the same as those of the method embodiment of this application. For specific contents, please refer to the description in the method embodiment shown above in this application, and no further details will be given here.
[0100] It should also be noted that the division of the various modules of the above device is merely a division of logical functions. In actual implementation, they can be fully or partially integrated into a single physical entity or physically separated. Furthermore, these units can be implemented entirely in the form of software called by a processing element; or entirely in the form of hardware; or some modules can be implemented in the form of software called by a processing element, and some modules can be implemented in the form of hardware. For example, the second processing module 302 can be a separate processing element, or it can be integrated into a chip of the above system. Furthermore, it can be stored in the form of program code in the memory of the above system, and called by a processing element of the above device to perform the functions of the second processing module 302. The implementation of other modules is similar. Furthermore, these modules can be fully or partially integrated together, or implemented independently. The processing element described here can be an integrated circuit with signal processing capabilities. During implementation, each step of the above method or each of the above modules can be completed by hardware integrated logic circuits in the processor element or by software instructions.
[0101] For example, the above modules may be one or more integrated circuits configured to implement the above methods, such as one or more application-specific integrated circuits (ASICs), one or more digital signal processors (DSPs), or one or more field programmable gate arrays (FPGAs). For another example, when a module is implemented by scheduling program code through a processing element, the processing element may be a general-purpose processor, such as a central processing unit (CPU) or other processor that can call program code. For another example, these modules may be integrated together and implemented in the form of a system-on-a-chip (SOC).
[0102] like Figure 4As shown, it is a schematic diagram of the structure of a computer device in one embodiment of the present application. As shown in the figure, the computer device 400 includes: a memory 401 and a processor 402; the memory 401 is used to store computer instructions; the processor 402 executes the computer instructions to implement the following Figure 1 The method described.
[0103] In some embodiments, the number of the memory 401 in the computer device 400 can be one or more, the number of the processor 402 can be one or more, and Figure 4 Take one as an example.
[0104] In one embodiment of the present application, the processor 402 in the computer device 400 will follow the following steps: Figure 1 The steps described above load one or more instructions corresponding to the application process into the memory 401, and the processor 402 runs the application stored in the memory 401, thereby achieving the following Figure 1 The method described.
[0105] The memory 401 may include random access memory (RAM) or non-volatile memory, such as at least one disk storage. The memory 401 stores an operating system and operating instructions, executable modules, or data structures, or subsets thereof, or extended sets thereof, wherein the operating instructions may include various operating instructions for implementing various operations. The operating system may include various system programs for implementing various basic services and processing hardware-based tasks.
[0106] The processor 402 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0107] In some specific applications, the various components of the computer device 400 are coupled together via a bus system, wherein the bus system may include a power bus, a control bus, and a status signal bus in addition to a data bus. However, for the sake of clarity, Figure 4 In Chinese, all kinds of buses are called bus systems.
[0108] In one embodiment of the present application, the present application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the following Figure 1 The method described.
[0109] At any possible level of technical detail combination, the present application may be a system, method and / or computer program product. The computer program product may include a computer-readable storage medium carrying computer-readable program instructions for causing a processor to implement various aspects of the present application.
[0110] Computer-readable storage media can be a tangible device that can hold and store the instructions used by the instruction execution device. Computer-readable storage media can be, for example, (but not limited to) an electrical storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination thereof. More specific examples (non-exhaustive list) of computer-readable storage media include: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a static random access memory (SRAM), a portable compact disc read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, for example, a punch card or a convex structure in a groove on which instructions are stored, and any suitable combination thereof. Computer-readable storage media used herein is not interpreted as a transient signal itself, such as radio waves or other freely propagating electromagnetic waves, electromagnetic waves propagated by waveguides or other transmission media (for example, light pulses by fiber optic cables), or electrical signals transmitted by wires.
[0111] The computer-readable program described herein can be downloaded from a computer-readable storage medium to each computing / processing device, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network can include copper transmission cables, fiber optic transmission, wireless transmission, routers, firewalls, switches, gateway computers, and / or edge servers. The network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions to be stored in the computer-readable storage medium in each computing / processing device.
[0112] The computer program instructions for performing the operation of the present application can be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-related instructions, microcode, firmware instructions, state setting data, integrated circuit configuration data or source code or object code written in any combination of one or more programming languages, wherein the programming language includes object-oriented programming languages such as Smalltalk, C++, and procedural programming languages such as "C" language or similar programming languages. Computer-readable program instructions can be executed completely on the user's computer, partially on the user's computer, executed as an independent software package, partially on the user's computer and partially on a remote computer, or executed completely on a remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer by any type of network including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (such as by using an Internet service provider to connect to the Internet). In certain embodiments, by utilizing the state information of computer-readable program instructions to personalize electronic circuits, such as programmable logic circuits, field programmable gate arrays (FPGAs) or programmable logic arrays (PLAs), the electronic circuits can execute computer-readable program instructions, thereby realizing various aspects of the present application.
[0113] In summary, the present application provides a grayscale-based local image comparison method, device, equipment and medium, which performs Gaussian blur processing and grayscale value processing on the acquired original image; proportionally reduces the grayscale value of each pixel to within a preset range, and divides it into multiple grayscale value images of the same order corresponding to different integer grayscale values based on the grayscale value of each pixel after reduction; binarizes each grayscale value image of the same order, and combines pixels with the same grayscale value to form one or more connected domains; selects one or more connected domains containing independent complete patterns based on a screening condition, and constructs a minimum rectangular frame for each connected domain to cover all the independent complete patterns; binarizes the pixels within each of the minimum rectangular frames using the P-hash algorithm to obtain a binary integer string, so as to determine whether there is an image that is at least partially similar in the image database by comparing the binary integer strings.
[0114] This application effectively overcomes various shortcomings of the prior art and has high industrial utilization value.
[0115] The above embodiments are merely illustrative of the principles and effects of this application and are not intended to limit the present invention. Anyone skilled in the art may modify or alter the above embodiments without departing from the spirit and scope of this application. Therefore, all equivalent modifications or alterations made by persons of ordinary skill in the art without departing from the spirit and technical concepts disclosed herein shall be encompassed by the claims of this application.
Claims
1. A gray value-based image local comparison method, characterized in that: The method comprises: Perform Gaussian blur processing and gray value processing on the acquired original image; The grayscale value of each pixel is proportionally reduced to a preset range, and divided into a plurality of grayscale value images of the same order corresponding to different integer grayscale values according to the reduced grayscale value of each pixel; Binarization is performed on each image with the same gray value, and pixels with the same gray value are combined to form one or more connected domains; Selecting one or more connected domains containing independent complete patterns according to the screening conditions, and constructing a minimum rectangular frame for covering all the independent complete patterns for each of the connected domains; Binarizing the pixels within each of the minimum rectangular frames using the Phash algorithm to obtain a binary integer string, so as to determine whether there is an image that is at least partially similar in the image database by comparing the binary integer string; The pixel points within each of the minimum rectangular frames are binarized using the Phash algorithm to obtain a binary integer string, including: The minimum rectangular frame is evenly divided into n×n small blocks according to n×n grids; wherein n is a division coefficient of the minimum rectangular frame, and n is an odd number not less than 11; Calculate the sum of the grayscale values of all pixels in each small block; The sum of the non-zero gray values in all small blocks is averaged, and the sum of the gray values of each non-zero small block is compared with the average; If it is less than the average value, the value corresponding to the non-zero small block is recorded as 0; If it is greater than or equal to the average value, the value corresponding to the non-zero small block is recorded as 1; In a manner of gradually diffusing from the center position of the minimum rectangular frame to the outer circle, the values corresponding to the small blocks at the center position and the values corresponding to the small blocks on the outer circles from the inside to the outside are counted in sequence to obtain a binary integer string corresponding to an image of the same grayscale value.
2. The method according to claim 1, characterized in that: The grayscale value of each pixel is proportionally reduced to a preset range, and divided into a plurality of grayscale value images of the same order corresponding to different integer grayscale values according to the reduced grayscale value of each pixel, including: The grayscale value of each pixel is proportionally reduced from the range of 0-255×255 to the range of 0-N; wherein N is the proportional reduction coefficient of the grayscale value of each pixel, and N is any two-digit positive integer less than 100; For the reduced grayscale value, the non-integer grayscale value is rounded to an integer grayscale value; According to the grayscale values belonging to the same integer in 0-N, the corresponding pixels are selected respectively to obtain N+1 images of the same grayscale value which only contain pixels of the same integer grayscale value.
3. The method according to claim 2, characterized in that The binarization process is performed on each image with the same gray value, and pixels with the same gray value are combined to form one or more connected domains, including: The grayscale values of the same-order grayscale value images belonging to the selected same integer are set to 1, and the grayscale values of the same-order grayscale value images not belonging to the selected same integer are set to 0, so that the grayscale values of the same-order grayscale value images are only 0 or 1; Pixel points with a gray value of 0 are combined to form one or more connected domains; and / or, pixel points with a gray value of 1 are combined to form one or more connected domains.
4. The method according to claim 1, characterized in that The screening conditions include any one or more combinations of the following: 1) The number of pixels in the connected domain is greater than 121; 2) The area of the connected domain is at most one third of the entire image of the same grayscale value; 3) The ratio of the longest length to the longest width in the connected domain is between 0.2 and 5.
5. The method according to claim 1, characterized in that The writing format of the binary integer string includes: The segments of the binary integer strings respectively corresponding to the center position and the outer circles of each layer from the inside to the outside are arranged from high to low in order from the inside to the outside; the high to low corresponds to from right to left or from left to right; And / or, starting from the value corresponding to the small block in the upper left corner of each layer of the outer circle, the values corresponding to the small blocks on the outer circle are counted in a clockwise direction and written in order from low to high.
6. The method according to claim 1, characterized in that The step of judging whether there are partially similar images in the image database by comparing binary integer strings includes: A comparison line is set for the binary integer string, so that the high-order segment of the binary integer string on the right or left side of the comparison line in the binary integer string is compared with the value of the binary integer segment corresponding to each integer in the image database; wherein the comparison line can be adjusted according to the comparison situation or scene requirements to adjust the comparison accuracy; If the comparison of the high-order segments of the binary integer strings is the same, then the corresponding binary integer strings are determined to be similar; If the comparisons of the binary integer strings of m corresponding images of the same grayscale value are respectively similar, it is determined that there is an image in the image database that is partially similar to the original image.
7. A gray value-based local image comparison device, characterized in that: The device comprises: The first processing module is used to perform Gaussian blur processing and gray value processing on the acquired original image; the gray value of each pixel is proportionally reduced to a preset range, and according to the reduced gray value of each pixel, it is divided into a plurality of gray value images of the same order corresponding to different integer gray values; The second processing module is used to perform binarization processing on each image with the same gray value, and combine the pixels with the same gray value to form one or more connected domains; select one or more connected domains containing independent complete patterns according to the screening conditions, and respectively construct a minimum rectangular frame for covering all the independent complete patterns for each of the connected domains; perform binarization processing on the pixels in each of the minimum rectangular frames using the Phash algorithm to obtain a binary integer string, so as to determine whether there is an image that is at least partially similar by comparing the binary integer string in the image database; The second processing module is also used to divide the minimum rectangular frame into n×n small blocks in an even manner according to an n×n grid; wherein n is the division coefficient of the minimum rectangular frame, and n is an odd number not less than 11; calculate the sum of the grayscale values of all pixels in each small block; average the sum of the non-zero grayscale values in all small blocks, and compare the sum of the grayscale values of each non-zero small block with the average value; if it is less than the average value, the value corresponding to the non-zero small block is recorded as 0; if it is greater than or equal to the average value, the value corresponding to the non-zero small block is recorded as 1; in a manner of gradually diffusing from the center position of the minimum rectangular frame to the outer circle, the values corresponding to the small block at the center position and the values corresponding to each small block on each outer circle from the inside to the outside are sequentially counted to obtain a binary integer string corresponding to an image of the same grayscale value.
8. A computer device, characterized in that: The computer device comprises: a memory and a processor; the memory is used to store computer instructions; the processor executes the computer instructions to implement the method according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: Computer instructions are stored, and when the computer instructions are executed, the method according to any one of claims 1 to 6 is performed.
Citation Information
Patent Citations
Image retrieval method based on local block binary encoding features
CN103714122A
Image processing method and device
CN106296578A