Image similarity detection method, device, equipment and storage medium
By calculating the dispersion of pictures and using pre-constructed filters and pyramids for feature extraction, the problem of low computational efficiency and accuracy of high-resolution pictures and large-scale data sets in the prior art is solved, and efficient and accurate image similarity detection is achieved to adapt to the needs of multiple scenarios and fields.
Patent Information
- Application Number
- CN202510222626.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-27
- Publication Date
- 2025-06-06
- Estimated Expiration
- 2045-02-27
AI Technical Summary
The prior art has low computational efficiency and accuracy when processing high-resolution pictures or large-scale data sets, and deep learning-based methods have limited generalization capabilities for small sample scenarios and cross-domain tasks, making it difficult to meet the real-time and practical application needs of multiple scenarios and multiple fields.
By calculating the dispersion of the initial picture, the foreground and background parts are determined, the final picture is obtained, and the pre-constructed picture filter and differential pyramid are used for convolution and feature extraction, the direction modulus value and feature vector of feature points are calculated, and finally the Euclidean distance is calculated to evaluate the image similarity.
It improves the efficiency and accuracy of image similarity calculation, adapts to the needs of different scenarios and fields, reduces the demand for computing resources, and enhances the processing ability of small sample scenarios.
Smart Images

Figure CN119723123B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image detection technology, and in particular to an image similarity detection method, device, equipment and storage medium. Background Art
[0002] In the related technology, the methods of calculating image similarity are mainly divided into feature matching-based methods and deep learning-based methods. Among them, the feature matching-based methods match by extracting local features or global features of the image, such as the SIFT algorithm (Scale Invariant Feature Transform), which realizes similarity calculation by constructing key point descriptors of the image; the deep learning-based methods map the image to a low-dimensional feature space for matching by training a specific embedding model.
[0003] However, among the related technologies, the feature matching-based methods have low computational efficiency and accuracy for high-resolution images or large-scale data sets; while the deep learning-based methods require higher computing resources, have limited generalization capabilities for small sample scenarios or cross-domain tasks, and are difficult to meet real-time requirements, and cannot meet the actual application needs of multiple scenarios and multiple fields, and are in urgent need of improvement. Summary of the invention
[0004] The present invention provides a method, device, equipment and storage medium for detecting image similarity, so as to at least solve the technical problems in the related art, such as the need for high computing resources for high-resolution images or large-scale data sets, low computing efficiency and accuracy, limited generalization ability for small sample scenes or cross-domain tasks, difficulty in meeting real-time requirements, and inability to meet the actual application needs of multiple scenes and multiple fields.
[0005] The present invention provides a method for detecting image similarity, comprising the following steps: obtaining at least two initial images, and respectively calculating the discreteness of the at least two initial images, so as to respectively determine the foreground part and the background part of the corresponding initial images according to the discreteness satisfying different preset discrete conditions, and separating the background part to obtain the corresponding final image; respectively convolving the pre-constructed image filters with the final images to obtain the corresponding convolved images; determining at least one feature point in the convolved images based on a pre-constructed differential pyramid and a preset feature point threshold; calculating the direction module value of the at least one feature point in at least four target directions, and determining the feature vector corresponding to the at least one feature point by using the at least four target directions and the direction module value; and calculating the Euclidean distance of at least one feature point in different final images by using the feature vector, so as to obtain the similarity between the different final images based on the Euclidean distance.
[0006] The present invention also provides a picture similarity detection device, comprising: a first acquisition module, used to acquire at least two initial pictures, and respectively calculate the discreteness of the at least two initial pictures, so as to respectively determine the foreground part and the background part of the corresponding initial pictures according to the discreteness satisfying different preset discrete conditions, and separate the background part to obtain the corresponding final picture; a convolution module, used to convolve the pre-constructed picture filter with the final picture respectively, so as to obtain the corresponding convolution picture; a determination module, used to determine at least one feature point in the convolution picture based on a pre-constructed differential pyramid and a preset feature point threshold; a calculation module, used to calculate the direction module value of the at least one feature point in at least four target directions, and determine the feature vector corresponding to the at least one feature point by using the at least four target directions and the direction module value; a first generation module, used to calculate the Euclidean distance of at least one feature point in different final pictures by using the feature vector, so as to obtain the similarity between the different final pictures based on the Euclidean distance.
[0007] The present invention also provides an electronic device, comprising: a memory for storing a computer program; and a processor for implementing the steps of any one of the above-mentioned image similarity detection methods when executing the computer program.
[0008] The present invention also provides a computer-readable storage medium, in which a computer program is stored, wherein when the computer program is executed by a processor, the steps of any of the above-mentioned image similarity detection methods are implemented.
[0009] The present invention also provides a computer program product, including a computer program, which implements the steps of any of the above-mentioned image similarity detection methods when executed by a processor.
[0010] Through the present invention, the foreground and background parts of the initial picture can be determined by calculating the discreteness of the initial picture, and the background part can be separated to obtain the corresponding final picture, and the final picture can be convolved with a pre-constructed picture filter to obtain a convolved picture, and the feature points can be determined by a pre-constructed differential pyramid and a certain feature point threshold, and the directional modulus of the feature points in the target direction can be calculated to obtain the corresponding feature vector, and the Euclidean distance can be calculated to obtain the similarity between different pictures. Therefore, it can solve the technical problems of requiring higher computing resources for high-resolution pictures or large-scale data sets, low computing efficiency and accuracy, limited generalization ability for small sample scenes or cross-domain tasks, difficulty in meeting real-time requirements, and inability to meet the actual application requirements of multiple scenes and multiple fields, so as to achieve the technical effect of quickly extracting and calculating relevant features, improving the computing efficiency of picture similarity, and effectively avoiding the influence of factors such as picture rotation. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] In order to more clearly illustrate the embodiments of the present invention, the following briefly introduces the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0012] Figure 1 A flowchart of a method for detecting image similarity provided by an embodiment of the present invention;
[0013] Figure 2 A flowchart of calculating the discreteness of an image provided by an embodiment of the present invention;
[0014] Figure 3 A flowchart of constructing an image filter provided by an embodiment of the present invention;
[0015] Figure 4 A flowchart of constructing a differential pyramid provided by an embodiment of the present invention;
[0016] Figure 5 A flow chart of generating feature points provided by an embodiment of the present invention;
[0017] Figure 6 A block diagram of the detection effect of the image similarity detection method provided by an embodiment of the present invention;
[0018] Figure 7 A block diagram of the SIFT detection effect provided by an embodiment of the present invention;
[0019] Figure 8 A flowchart of the working principle of a method for detecting image similarity according to an embodiment of the present invention;
[0020] Fig. 9 A block diagram of a device for detecting image similarity according to an embodiment of the present invention.
[0021] Reference numerals:
[0022] Among them, 10-image similarity detection device, 100-first acquisition module, 200-convolution module, 300-determination module, 400-calculation module, 500-first generation module. DETAILED DESCRIPTION
[0023] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0024] It should be noted that, in the description of the present invention, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. The terms "first", "second", etc. in the present invention are used to distinguish similar objects, and are not used to describe a specific order or sequence.
[0025] In order to enable those skilled in the art to better understand the scheme of the present invention, the present invention is further described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0026] An embodiment of the present invention provides a method for detecting image similarity. The method is described in detail in conjunction with the execution flow of the method for detecting image similarity.
[0027] Specifically, Figure 1 The present invention provides a flowchart of a method for detecting image similarity.
[0028] like Figure 1 As shown, the image similarity detection method includes the following steps:
[0029] In step S101, at least two initial pictures are obtained, and the discreteness of the at least two initial pictures is calculated respectively, so as to determine the foreground part and the background part of the corresponding initial pictures respectively according to the discreteness satisfying different preset discrete conditions, and separate the background part to obtain the corresponding final picture.
[0030] It can be understood that the initial image of the embodiment of the present invention can be obtained from a series of image sequences or image data sets, or can be obtained by a camera or other image acquisition device. The specific settings can be made by technicians in this field according to actual conditions, and the present invention does not make any specific limitations.
[0031] In addition, it should be noted that the dispersion of the embodiment of the present invention is an important indicator for measuring the degree of dispersion of data distribution. Its calculation method may include but is not limited to standard deviation, variance and range, etc., and the present invention does not make specific restrictions.
[0032] As a possible implementation method, the embodiment of the present invention can first calculate the discreteness of at least two initial pictures, and then determine the discreteness that satisfies different certain discrete conditions, and determine the foreground part and the background part in the picture according to the different certain discrete conditions, and separate the background part, so as to obtain the corresponding final picture. Among them, the at least two initial pictures can include two initial pictures, and can also include three initial pictures, and can also include multiple initial pictures, which can be specifically set by those skilled in the art according to actual conditions, and the present invention does not make specific restrictions.
[0033] For example, an embodiment of the present invention selects two initial pictures from a target data set, which can be represented by but not limited to picture A and picture B, calculates discreteness A of picture A and discreteness B of picture B respectively, and determines foreground part A and background part A of picture A according to discreteness A and certain discrete condition A, determines foreground part B and background part B of picture B according to discreteness B and certain discrete condition B, and then separates background part A and background part B respectively, thereby obtaining final picture A and final picture B.
[0034] The embodiment of the present invention can accurately identify the foreground and background parts of a picture by calculating the discreteness. The foreground and background parts of the picture can be clearly separated through the discreteness and discrete conditions, which is conducive to more accurate extraction and calculation of relevant features, adapting to the image processing needs in different scenarios, thereby effectively improving the calculation accuracy of image similarity.
[0035] Optionally, in one embodiment of the present invention, the discreteness of at least two initial images is calculated respectively, including: performing grayscale conversion on the corresponding initial image to obtain the corresponding initial grayscale image; obtaining the grayscale value of each pixel in the initial grayscale image, and counting the corresponding first grayscale quantity according to the grayscale value; sorting the grayscale values according to a preset grayscale condition to obtain a sorted grayscale sequence; determining the number of grouping groups when grouping the grayscale values based on the first grayscale quantity and the grayscale sequence; calculating the second grayscale quantity corresponding to the grayscale sequence in at least one group based on the first grayscale quantity and the number of grouping groups; calculating the average value of the grayscale sequences in different groups based on the number of grouping groups and the second grayscale quantity, so as to calculate the discreteness in different groups based on the average value.
[0036] In some embodiments, the process of calculating the discreteness of an image in an embodiment of the present invention is as follows: Figure 2 As shown, its main contents are:
[0037] Step S201: Obtain an initial image.
[0038] Step S202: Perform grayscale conversion.
[0039] Among them, the embodiment of the present invention can convert the initial image into an initial grayscale image.
[0040] Step S203: Calculate the grayscale histogram and count the first grayscale quantity of each grayscale value.
[0041] In the embodiment of the present invention, the grayscale value of each pixel in the initial grayscale image can be first obtained, and then the grayscale histogram can be calculated, so as to count the corresponding first grayscale quantity according to the grayscale value. In the embodiment of the present invention, the calculation formula of the first grayscale quantity can be but is not limited to:
[0042] ,
[0043] in, Represents the gray value, represents the pixel intensity table, Indicates count.
[0044] Step S204: sorting the grayscale values according to a certain grayscale condition, thereby obtaining a sorted grayscale sequence.
[0045] Among them, in the embodiment of the present invention, a certain grayscale condition can be from large to small, or from small to large, which can be specifically set by technicians in this field according to actual conditions, and the present invention does not make any specific limitations.
[0046] Furthermore, the embodiment of the present invention sorts the grayscale values from large to small according to the grayscale values, and then obtains a sorted grayscale sequence, and the expression of the grayscale sequence can be but is not limited to:
[0047] ,
[0048] in, (.) represents the sorting function, Indicates that the sorting is not done in descending order. Indicates the sorting by Sort.
[0049] Step S205: Determine the number of groupings, and calculate the number of second grayscales corresponding to the grayscale sequence assigned to each group.
[0050] The embodiment of the present invention divides the group into groups K and calculates the second grayscale quantity corresponding to the grayscale sequence assigned to each group. The expression thereof may be, but is not limited to, as follows:
[0051] ,
[0052] Step S206: Grouping and calculating the dispersion of each group.
[0053] In this embodiment of the present invention, the grouping expression may be, but is not limited to:
[0054] ,
[0055] in, Represents the kth group of grayscale values.
[0056] The calculation formula of the discreteness can be but is not limited to:
[0057] ,
[0058] in, is the total number of pixels in the kth group; is the average grayscale value of all pixels in the kth group.
[0059] The embodiment of the present invention removes the interference of color information through grayscale conversion to improve computing efficiency. By counting grayscale values, the brightness distribution of the image can be quickly understood. Sorting and grouping grayscale values can more carefully analyze the brightness changes of the image, thereby more accurately reflecting the discreteness of the image.
[0060] Optionally, in one embodiment of the present invention, the foreground and background parts of the corresponding initial image are respectively determined according to the discreteness that satisfies different preset discrete conditions, including: determining the gray value threshold for dividing the foreground and background parts based on the first gray value number and the discreteness that satisfies different preset discrete conditions; determining the background gray interval of the background part based on the gray value threshold and the gray sequence; determining the background gray value in the gray value that is located in the background gray interval; determining the background part based on the background gray value, and obtaining the foreground part based on the background part.
[0061] As a possible implementation method, an embodiment of the present invention can first determine the grayscale value threshold for dividing the foreground part and the background part, and determine the background grayscale interval of the background part through the grayscale value threshold, and then obtain the background grayscale value located in the background grayscale interval, thereby separating the background part and obtaining the foreground part.
[0062] Exemplarily, an embodiment of the present invention calculates the grayscale values of all pixels on the four edges of an image to obtain a corresponding grayscale histogram, and then counts the number of each grayscale value, and uses the grayscale value with the largest number of pixels as a reference, and the grayscale value threshold as the upper and lower limits of the grayscale value variation, to determine the background grayscale interval of the background pixels, and then starting from the four edges of the image, calculates the grayscale value of each pixel, connects the pixels in the image whose grayscale values belong to the background grayscale interval and whose positions are adjacent, and obtains a connected domain in which all background grayscale values are located in the interval, and the connected domain is the background part of the image.
[0063] Furthermore, the embodiment of the present invention can extract the background part of the image, such as setting all the grayscale values of the background part to 0, and can also perform other operations, which can be specifically set by technicians in this field according to actual conditions, and the present invention does not make specific limitations.
[0064] In addition, in the embodiment of the present invention, background distinction is only performed on the edge area, and background distinction is not performed on the middle area, so as to improve the calculation efficiency and avoid the misjudgment of effective features.
[0065] For example, an embodiment of the present invention can first determine the grayscale value threshold. If the grayscale value threshold is T, then the background grayscale interval can be expressed as [0, T), and then all pixels whose grayscale values are in the background grayscale interval are classified as the background part. By excluding the background part, the remaining pixels are the foreground part, and the grayscale values of the background part are all set to 0.
[0066] The embodiment of the present invention can accurately determine a grayscale value threshold, and then further determine the grayscale interval of the background part, accurately extract background information, and achieve accurate division of the foreground and background parts, thereby improving the efficiency of image processing and enhancing the effect of image analysis.
[0067] Optionally, in one embodiment of the present invention, before convolving the pre-constructed image filter with the final image respectively, it also includes: constructing an initial image filter based on a standard deviation that satisfies preset filtering conditions; obtaining an aspect ratio, phase angle and / or control angle suitable for the initial image filter; and correcting the initial image filter using the aspect ratio, phase angle and / or control angle to construct the image filter.
[0068] As a possible implementation method, the process of constructing the image filter in the embodiment of the present invention is as follows: Figure 3 As shown, the main contents are:
[0069] Step S301: Obtain the final image.
[0070] Step S302: constructing an initial image filter based on a standard deviation that satisfies certain filtering conditions.
[0071] Among them, certain filtering conditions can be set by technicians in this field according to actual conditions, and the present invention does not make specific limitations.
[0072] Exemplarily, the expression of the initial image filter constructed in the embodiment of the present invention may be, but is not limited to,:
[0073] ,
[0074] Among them, σ is the standard deviation of the Gaussian function, which is determined by experience. Represents the coordinates of a pixel.
[0075] The initial image filter constructed by the embodiment of the present invention ensures that the filter is local, that is, each pixel value is mainly affected by its neighboring pixels, rather than the entire image. In this way, the image is smoothed and noise is reduced. At the same time, due to the characteristics of weight distribution, it can better maintain the edge information of the image.
[0076] Step S303: increasing the shape control capability of the initial image filter.
[0077] Among them, the embodiment of the present invention can increase the aspect ratio in the initial image filter to increase the shape control ability of the initial image filter. The expression of the initial image filter after increasing the aspect ratio can be but is not limited to:
[0078] ,
[0079] in, is the aspect ratio in the x and y directions, which controls the shape of the filter.
[0080] Step S304: adding sinusoidal modulation to enhance texture and edge features.
[0081] In this embodiment of the present invention, sinusoidal modulation can be added through the phase angle to enhance texture and edge features. At this time, the expression of the initial image filter can be, but is not limited to,:
[0082] ,
[0083] in, is the initial phase angle.
[0084] Step S305: adding coordinate rotation parameters to control the directionality of filtering.
[0085] In this embodiment of the present invention, the coordinate rotation parameter can be added by controlling the angle to control the directionality of the filter. At this time, the expression of the image filter can be but is not limited to:
[0086] ,
[0087] ,
[0088] ,
[0089] in, is the direction control angle.
[0090] The embodiment of the present invention can effectively increase the signal characteristics of specific frequencies by adding sinusoidal modulation, enrich the image information, and help improve the accuracy of similarity calculation. By increasing the coordinate rotation parameters and controlling the control angle, multi-directional filtering can be achieved, features in more directions can be extracted, and the comprehensiveness of image features can be enhanced.
[0091] In step S102, the pre-constructed image filters are convolved with the final image to obtain corresponding convolved images.
[0092] Those skilled in the art will appreciate that, in the embodiments of the present invention, the pre-constructed image filters may be convolved with the final image to obtain a convolved image, so as to filter out invalid features in the image.
[0093] The embodiments of the present invention can effectively extract features in a picture and enhance the details of the picture through a pre-built picture filter to meet different picture processing requirements and realize more complex picture processing tasks.
[0094] Optionally, in one embodiment of the present invention, before determining at least one feature point in the convolution image based on a pre-constructed differential pyramid and a preset feature point threshold, the method further includes: upsampling the convolution image at most once and downsampling at least once to obtain scale images of different scales; obtaining a smoothness coefficient corresponding to the scale image; dividing the scale image into layer images of different numbers of layers using the smoothness coefficient; and constructing a differential pyramid based on the layer images.
[0095] As a possible implementation method, the process of constructing a differential pyramid in an embodiment of the present invention is as follows: Figure 4 As shown, the main contents are:
[0096] Step S401: Obtain a convolution image.
[0097] Step S402: upsampling the convolution image to obtain a scaled image of a certain scale.
[0098] Among them, the embodiment of the present invention can perform an upsampling process on the convolution image, so that the image size becomes 4 times of the original, such as the length becomes 2 times of the original, and the width becomes 2 times of the original, and the present invention does not make specific limitations.
[0099] Step S403: performing Gaussian filtering on the scaled image.
[0100] In this embodiment of the present invention, the expression of Gaussian filtering may be, but is not limited to,:
[0101] ,
[0102] in, is the standard deviation of the Gaussian function, determined by experience; is the grayscale value of the image, is the Gaussian kernel.
[0103] Step S404: using the smoothness coefficient to divide the scaled image into layer images of different numbers.
[0104] The smoothness coefficient of the embodiment of the present invention can be obtained by the standard deviation of the Gaussian function: and coefficient k, where the smoothing coefficient expression of images of different scales can be but is not limited to: [ ],in, It represents the hyperparameter, which is determined through experiments according to the actual image effect, and then the scale images of the same scale are layered, and N+3 layers are set to obtain the corresponding layer images, which makes image processing more flexible and efficient. Targeted processing can be performed at the appropriate level according to the specific characteristics and requirements of the image.
[0105] The introduction of the smoothness coefficient makes the details and features of images at different levels different. At the coarser level, the main features and structure of the image are retained, while the detail information is smoothed out, which helps to extract the main contours and features of the image; at the finer level, the detail information of the image is retained, which helps to perform more detailed feature extraction and analysis.
[0106] Step S405: perform down sampling.
[0107] Among them, in the embodiment of the present invention, the next set of features is sampled from the Nth layer of the previous set, and down-sampled through maximum pooling, and the scale becomes 1 / 4 times of the original, such as the length becomes 1 / 2 times of the original, and the width becomes 1 / 2 times of the original. The present invention does not make specific limitations.
[0108] Step S406: Divide the scaled image into layer images of different numbers using the smoothness coefficient.
[0109] The smoothness coefficient of the embodiment of the present invention is the same as the smoothing coefficient of step S404, and the scaled image after downsampling is layered and set to N+3 layers, thereby obtaining a corresponding layer image.
[0110] Step S407: Continue downsampling and repeat the above process until the construction of the feature pyramid is completed.
[0111] Among them, the feature pyramid of the embodiment of the present invention can be set to M groups, each group has N+3 layers, which can be specifically set by technicians in this field according to actual conditions, and the present invention does not make any specific limitations.
[0112] Step S408: construct a difference pyramid.
[0113] In the embodiment of the present invention, each group of adjacent layers of the feature pyramid is subtracted to obtain a difference pyramid, with a total of M groups and N+2 layers.
[0114] The embodiments of the present invention obtain scale images of different scales by upsampling and downsampling, so as to capture the features of images at different scales, and use the corresponding smoothness coefficient to smooth the scale images, thereby reducing noise and interference in the images and enhancing the edge features of the images. The differential pyramid can highlight the details and changes in the images by capturing the differences between adjacent scale images, thereby improving the accuracy and robustness of feature point detection and adapting to different scenarios and requirements.
[0115] In step S103, at least one feature point in the convolution image is determined based on the pre-constructed difference pyramid and a preset feature point threshold.
[0116] In the actual implementation process, the embodiment of the present invention can extract features in the convolution image through a pre-constructed differential pyramid, and then determine the corresponding feature points through a certain feature point threshold.
[0117] The threshold of certain feature points may be set by those skilled in the art according to actual conditions, and the present invention does not impose any specific limitation thereto.
[0118] The embodiment of the present invention determines feature points by using a certain feature point threshold, and no longer performs complex key point calculations, thereby greatly simplifying the calculation process and improving execution efficiency.
[0119] Optionally, in one embodiment of the present invention, at least one feature point in a convolution image is determined based on a pre-constructed differential pyramid and a preset feature point threshold, including: calculating the difference between each pixel in the convolution image and at least one surrounding pixel; based on the difference, determining at least one initial feature point in the convolution image; judging whether the grayscale value of at least one initial feature point is greater than a preset feature point threshold; if the grayscale value is greater than the preset feature point threshold, obtaining at least one feature point based on at least one initial feature point; if the grayscale value is less than or equal to the preset feature point threshold, deleting at least one initial feature point, and iteratively judging the next at least one initial feature point until the grayscale value is greater than the preset feature point threshold to obtain at least one feature point.
[0120] In some embodiments, the process of generating feature points in the embodiment of the present invention is as follows: Figure 5 As shown, its main contents are:
[0121] Step S501: Calculate the difference between each pixel and surrounding pixels to obtain initial feature points.
[0122] Among them, the embodiment of the present invention can calculate the difference between each pixel point in the convolution image and the surrounding 26 points, and then obtain at least one initial feature point.
[0123] Among them, in the embodiment of the present invention, 26 points means that with this point as the center, there are 8 points in the current plane, 9 points in the upper plane, and 9 points in the lower plane, totaling 26 points. Therefore, there will be no distribution of feature points in the starting layer and the ending layer, as well as the boundary of each layer, thereby comprehensively capturing the local change information in the image and improving the accuracy of feature extraction. Other pixel points can also be selected, which can be specifically set by technicians in this field according to actual conditions, and the present invention does not make specific limitations.
[0124] Step S502: Determine whether the grayscale value of the initial feature point is greater than a certain feature point threshold.
[0125] The judgment formula of the embodiment of the present invention may be, but is not limited to,:
[0126] ,
[0127] in, Indicates the gray value of the pixel at the current position; Indicates the grayscale value of 26 pixels around the current pixel; Indicates the set threshold.
[0128] Step S503: If it is greater than, it is determined to be a feature point.
[0129] Step S504: If it is less than or equal to, then delete the initial feature point, and iterate to determine the next initial feature point until all feature points are obtained.
[0130] The embodiment of the present invention achieves accurate positioning of feature points by calculating the difference between each pixel and the surrounding pixels, and effectively screens out significant feature points in the image through a certain feature point threshold, thereby reducing the complexity of subsequent processing and ensuring the representativeness and significance of the feature points, thereby enhancing the adaptability and robustness of the algorithm.
[0131] In step S104, the direction module of at least one feature point in at least four target directions is calculated, and a feature vector corresponding to the at least one feature point is determined using the at least four target directions and the direction module.
[0132] In the actual implementation process, the embodiment of the present invention can determine the corresponding feature vector by calculating the direction modulus of the feature point in the target direction. The target direction can be set by those skilled in the art according to actual conditions, and the present invention does not impose any specific limitation.
[0133] Exemplarily, in the embodiment of the present invention, after determining the feature points, the direction modulus of each feature point can be calculated according to the target direction, and the calculation formula can be but is not limited to:
[0134] ,
[0135] ,
[0136] ,
[0137] ,
[0138] ,
[0139] ,
[0140] ,
[0141] ,
[0142] Among them, v represents the gray value of the corresponding pixel.
[0143] Furthermore, corresponding to the direction modulus value, the embodiment of the present invention calculates the direction of the feature point, which may be but is not limited to: [0°, 45°, 90°, 135°, 180°, 225°, 270°, 315°], and encodes the feature point to form a feature vector.
[0144] Optionally, in one embodiment of the present invention, at least four target directions and directional modulus values are used to determine a feature vector corresponding to at least one feature point, including: determining a first direction that satisfies a preset direction condition based on at least four target directions and directional modulus values; adjusting the directional modulus value based on the first direction to obtain a corresponding first modulus value; encoding at least one feature point based on the first direction and the first modulus value to obtain a feature vector.
[0145] In the embodiment of the present invention, the first direction satisfying the certain direction condition can be determined by the target direction and the direction modulus, and the direction modulus can be adjusted based on the first direction to obtain the corresponding first modulus; thereby encoding the feature point to obtain the corresponding feature vector. The certain direction condition can be set by a person skilled in the art according to actual conditions, and the present invention does not impose any specific limitation.
[0146] Exemplarily, the features extracted by the embodiment of the present invention include three elements: [position, modulus, direction], where the modulus can be divided into 8 dimensions and the direction can be divided into 8 dimensions. The specific encoding format is [x, y, m1, m2, m3.m4, m5, m6, m7, m8, r1, r2, r3, r4, r5, r6, r7, r8].
[0147] Furthermore, after encoding different pictures, an embodiment of the present invention determines a first direction that satisfies certain directional conditions, such as a peak direction, wherein the peak direction can be understood as the direction corresponding to the maximum value of the largest number of pixels after all pixels are encoded [r1, r2, r3, r4, r5, r6, r7, r8].
[0148] Furthermore, the embodiment of the present invention calculates the corresponding direction index based on the peak direction, and its expression may be, but is not limited to,:
[0149] ,
[0150] in, is the peak direction, mod means remainder, Represents the feature direction, whose characteristics include one of the three elements [position, modulus, direction].
[0151] Then the embodiment of the present invention can be based on Adjust the corresponding direction modulus values so that the adjusted modulus order corresponds to the direction order. (According to the maximum value direction, rotate a specific angle and sort them, such as the sorted order [3,4,5,6,7,0,1,2]).
[0152] Therefore, the embodiment of the present invention encodes the feature points to obtain corresponding feature vectors.
[0153] The embodiment of the present invention aligns the angle peak directions of different images before calculating the similarity, which can effectively avoid the influence of factors such as image rotation on the similarity calculation and improve the robustness and qualitativeness of the calculation.
[0154] In step S105 , the Euclidean distance of at least one feature point in different final images is calculated using the feature vector, so as to obtain the similarity between the different final images based on the Euclidean distance.
[0155] As a possible implementation method, the embodiment of the present invention can use feature vectors to calculate the Euclidean distances of feature points between different final images one by one, and use the two features with the closest distances as matching features to obtain the similarity between the images.
[0156] The calculation formula of the Euclidean distance in the embodiment of the present invention may be, but is not limited to,:
[0157] ,
[0158] in, Indicates the first picture The modulus of the group, Indicates the second picture The modulus of the group, Indicates the number of groups.
[0159] The calculation formula of similarity can be but not limited to:
[0160] ,
[0161] Where m is the total number of matching feature pairs. Indicates The Euclidean distance of the features.
[0162] In summary, the embodiment of the present invention is compared with the SIFT algorithm, and the comparison effect is as follows: Figure 6 and Figure 7 As shown, the number of effective matching points is 40 using the SIFT algorithm, while the number of effective detection points in the embodiment of the present invention is 62, which improves the effect by more than 50%.
[0163] Combine the following Figure 8 As shown, the working principle of the image similarity detection method proposed in the embodiment of the present invention is introduced with a specific embodiment.
[0164] in, Figure 8 The following is a flow chart showing the working principle of a method for detecting image similarity according to an embodiment of the present invention.
[0165] Step S801: Obtain an initial image.
[0166] Step S802: Convert the initial image into an initial grayscale image.
[0167] Step S803: Grouping grayscale values that are similar and calculating the dispersion.
[0168] Step S804: Divide the foreground part and the background part.
[0169] Step S805: Separate the background portion to obtain the corresponding final image.
[0170] Step S806: convolve the final image through the pre-constructed image filter to obtain the corresponding convolved image.
[0171] Step S807: extract features using the pre-built differential pyramid to determine feature points in the image.
[0172] Step S808: Perform feature encoding using the target direction and the direction modulus value to determine the corresponding feature vector.
[0173] Step S809: Similarity calculation.
[0174] Among them, the embodiment of the present invention can first extract the background part of the image through the grayscale value of the image, and then convolve the final image through a pre-constructed image filter to obtain a corresponding convolution image, and then extract features from the convolution image through a pre-constructed differential pyramid, and finally calculate the similarity between different images, thereby effectively improving the generalization ability and detection accuracy of similarity detection.
[0175] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method.
[0176] The embodiment of the present invention also provides a device for detecting image similarity.
[0177] Figure 6 It is a block diagram of a device for detecting image similarity according to an embodiment of the present invention.
[0178] like Figure 6 As shown, the image similarity detection device 10 includes: a first acquisition module 100, a convolution module 200, a determination module 300, a calculation module 400 and a first generation module 500.
[0179] Among them, the first acquisition module 100 is used to obtain at least two initial pictures and calculate the discreteness of the at least two initial pictures respectively, so as to determine the foreground part and the background part of the corresponding initial pictures according to the discreteness that meets different preset discrete conditions, and separate the background part to obtain the corresponding final picture.
[0180] The convolution module 200 is used to convolve the pre-constructed image filters with the final image respectively to obtain the corresponding convolution image.
[0181] The determination module 300 is used to determine at least one feature point in the convolution image based on a pre-constructed difference pyramid and a preset feature point threshold.
[0182] The calculation module 400 is used to calculate the direction module of at least one feature point in at least four target directions, and determine the feature vector corresponding to the at least one feature point using the at least four target directions and the direction module.
[0183] The first generating module 500 is used to calculate the Euclidean distance of at least one feature point in different final images by using the feature vector, so as to obtain the similarity between the different final images based on the Euclidean distance.
[0184] Optionally, in one embodiment of the present invention, the first acquisition module 100 includes: a first generation unit, an acquisition unit, a sorting unit, a first determination unit, a first calculation unit and a second calculation unit.
[0185] The first generating unit is used to perform grayscale conversion on the corresponding initial image to obtain the corresponding initial grayscale image.
[0186] The acquisition unit is used to acquire the grayscale value of each pixel in the initial grayscale image and count the corresponding first grayscale quantity according to the grayscale value.
[0187] The sorting unit is used to sort the grayscale values according to a preset grayscale condition to obtain a sorted grayscale sequence.
[0188] The first determining unit is used to determine the number of groups when grayscale values are grouped based on the first grayscale quantity and the grayscale sequence.
[0189] The first calculation unit is used to calculate the second grayscale quantity corresponding to the grayscale sequence in at least one group based on the first grayscale quantity and the grouping number.
[0190] The second calculation unit is used to calculate the average value of the grayscale sequences in different groups based on the grouping group number and the second grayscale quantity, so as to calculate the dispersion in different groups based on the average value.
[0191] Optionally, in one embodiment of the present invention, the first acquisition module 100 includes: a second determination unit, a third determination unit, a fourth determination unit and a fifth determination unit.
[0192] The second determination unit is used to determine the gray value threshold for dividing the foreground part and the background part based on the first gray quantity and the discreteness satisfying different preset discrete conditions.
[0193] The third determining unit is used to determine the background grayscale interval of the background part based on the grayscale value threshold and the grayscale sequence.
[0194] The fourth determining unit is used to determine the background grayscale value in the background grayscale interval.
[0195] The fifth determining unit is used to determine the background part based on the background gray value, and obtain the foreground part according to the background part.
[0196] Optionally, in one embodiment of the present invention, it further includes: a first building module, a second acquiring module and a second building module.
[0197] The first construction module is used to construct an initial image filter based on a standard deviation that satisfies a preset filtering condition before convolving the pre-constructed image filter with the final image respectively.
[0198] The second acquisition module is used to acquire an aspect ratio, a phase angle and / or a control angle suitable for an initial picture filter.
[0199] The second construction module is used to modify the initial image filter by using the aspect ratio, the phase angle and / or the control angle to construct the image filter.
[0200] Optionally, in one embodiment of the present invention, it further includes: a second generating module, a third acquiring module, a dividing module and a third building module.
[0201] Among them, the second generation module is used to upsample the convolution image at most once and downsample it at least once to obtain scale images of different scales before determining at least one feature point in the convolution image based on a pre-constructed differential pyramid and a preset feature point threshold.
[0202] The third acquisition module is used to obtain the smoothness coefficient corresponding to the scaled image.
[0203] The division module is used to divide the scaled image into layer images with different numbers of layers by using the smoothness coefficient.
[0204] The third building module is used to build a difference pyramid based on the layer image.
[0205] Optionally, in one embodiment of the present invention, the determination module 300 includes: a third calculation unit, a sixth determination unit, a judgment unit, a second generation unit and a third generation unit.
[0206] The third calculation unit is used to calculate the difference between each pixel in the convolution image and at least one surrounding pixel.
[0207] The sixth determining unit is used to determine at least one initial feature point in the convolution image based on the difference.
[0208] The judging unit is used to judge whether the gray value of at least one initial feature point is greater than a preset feature point threshold.
[0209] The second generating unit is used to obtain at least one feature point based on at least one initial feature point when the gray value is greater than a preset feature point threshold.
[0210] The third generating unit is used to delete at least one initial feature point when the gray value is less than or equal to the preset feature point threshold, and iteratively determine the next at least one initial feature point until the gray value is greater than the preset feature point threshold to obtain at least one feature point.
[0211] Optionally, in one embodiment of the present invention, the calculation module 400 includes: a seventh determination unit, an adjustment unit and an encoding unit.
[0212] The seventh determination unit is used to determine a first direction that meets a preset direction condition based on at least four target directions and direction modulus values.
[0213] The adjustment unit is used to adjust the direction modulus value based on the first direction to obtain the corresponding first modulus value.
[0214] The encoding unit is used to encode at least one feature point based on the first direction and the first modulus value to obtain a feature vector.
[0215] For the description of the features in the embodiment corresponding to the image similarity detection device, reference may be made to the relevant description of the embodiment corresponding to the image similarity detection method, which will not be described in detail here.
[0216] An embodiment of the present invention further provides an electronic device, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any of the above-mentioned picture similarity detection method embodiments.
[0217] An embodiment of the present invention further provides a computer-readable storage medium, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above-mentioned picture similarity detection method embodiments when running.
[0218] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk.
[0219] An embodiment of the present invention further provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the steps in any one of the above-mentioned picture similarity detection method embodiments are implemented.
[0220] An embodiment of the present invention further provides another computer program product, including a non-volatile computer-readable storage medium, wherein the non-volatile computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in any of the above-mentioned picture similarity detection method embodiments are implemented.
[0221] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0222] The above is a detailed introduction to a method for detecting image similarity provided by the present invention. This article uses specific examples to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of the present invention, the present invention can also be improved and modified in a number of ways, and these improvements and modifications also fall within the scope of protection of the claims of the present invention.
Claims
1. A method for detecting image similarity, characterized in that: The following steps are involved: Acquire at least two initial images, and respectively calculate the discreteness of the at least two initial images, so as to respectively determine the foreground part and the background part of the corresponding initial images according to the discreteness satisfying different preset discrete conditions, and separate the background part to obtain the corresponding final image; Convolving the pre-constructed image filters with the final image respectively to obtain corresponding convolved images; Determine at least one feature point in the convolution image based on a pre-constructed difference pyramid and a preset feature point threshold; Calculating the direction modulus of the at least one feature point in at least four target directions, and determining a feature vector corresponding to the at least one feature point using the at least four target directions and the direction modulus; Calculating the Euclidean distance of at least one feature point in different final images using the feature vector, so as to obtain the similarity between the different final images based on the Euclidean distance; The separately calculating the discreteness of the at least two initial pictures includes: Convert the corresponding initial image into grayscale to obtain the corresponding initial grayscale image; Obtaining a grayscale value of each pixel in the initial grayscale image, and counting the corresponding first grayscale quantity according to the grayscale value; Sorting the grayscale values according to a preset grayscale condition to obtain a sorted grayscale sequence; Based on the first grayscale quantity and the grayscale sequence, determining the number of groups when the grayscale values are grouped; Based on the first grayscale quantity and the grouping number, calculating the second grayscale quantity corresponding to the grayscale sequence in at least one group; Based on the grouping group number and the second grayscale quantity, calculating the average value of the grayscale sequences in different groups, so as to calculate the dispersion in the different groups based on the average value; The determining at least one feature point in the convolution image based on a pre-constructed difference pyramid and a preset feature point threshold comprises: Calculate the difference between each pixel in the convolution image and at least one surrounding pixel; Based on the difference, determining at least one initial feature point in the convolution image; Determining whether the grayscale value of the at least one initial feature point is greater than the preset feature point threshold; If the grayscale value is greater than the preset feature point threshold, obtaining the at least one feature point based on the at least one initial feature point; If the grayscale value is less than or equal to the preset feature point threshold, the at least one initial feature point is deleted, and the next at least one initial feature point is iteratively determined until the grayscale value is greater than the preset feature point threshold to obtain the at least one feature point.
2. The image similarity detection method according to claim 1, characterized in that: The foreground part and the background part of the corresponding initial picture are determined respectively according to the discreteness satisfying different preset discrete conditions, including: Determining a gray value threshold for dividing the foreground portion and the background portion based on the first grayscale quantity and the discreteness satisfying different preset discrete conditions; Based on the gray value threshold and the gray sequence, determining the background gray interval of the background part; Determine a background grayscale value in the background grayscale interval among the grayscale values; Based on the background grayscale value, the background portion is determined, and the foreground portion is obtained according to the background portion.
3. The method according to claim 1, characterized in that Before convolving the pre-constructed image filters with the final image respectively, the method further includes: Constructing an initial image filter based on the standard deviation that meets the preset filtering conditions; Obtaining an aspect ratio, a phase angle and / or a control angle applicable to the initial picture filter; The initial picture filter is modified using the aspect ratio, the phase angle and / or the control angle to construct a picture filter.
4. The image similarity detection method according to claim 1, characterized in that: Before determining at least one feature point in the convolution image based on the pre-built difference pyramid and the preset feature point threshold, the method further includes: Performing upsampling at most once and downsampling at least once on the convolution image to obtain scale images of different scales; Obtaining a smoothness coefficient corresponding to the scale image; Dividing the scaled image into layer images with different numbers of layers by using the smoothness coefficient; Based on the layer pictures, a difference pyramid is constructed.
5. The image similarity detection method according to claim 1, characterized in that: The determining the feature vector corresponding to the at least one feature point by using the at least four target directions and the direction modulus value includes: Based on the at least four target directions and the direction module value, determining a first direction that satisfies a preset direction condition; Based on the first direction, adjusting the direction modulus value to obtain a corresponding first modulus value; The at least one feature point is encoded based on the first direction and the first modulus value to obtain the feature vector.
6. A device for detecting image similarity, characterized in that: include: A first acquisition module is used to acquire at least two initial images, and respectively calculate the discreteness of the at least two initial images, so as to respectively determine the foreground part and the background part of the corresponding initial images according to the discreteness satisfying different preset discrete conditions, and separate the background part to obtain the corresponding final image; A convolution module, used to convolve the pre-built image filters with the final image respectively to obtain a corresponding convolution image; A determination module, configured to determine at least one feature point in the convolution image based on a pre-constructed difference pyramid and a preset feature point threshold; A calculation module, used to calculate the direction module of the at least one feature point in at least four target directions, and determine the feature vector corresponding to the at least one feature point using the at least four target directions and the direction module; A generating module, configured to calculate the Euclidean distance of at least one feature point in different final images using the feature vector, so as to obtain the similarity between the different final images based on the Euclidean distance; Wherein, the first acquisition module includes: A first generating unit, configured to perform grayscale conversion on the corresponding initial image to obtain a corresponding initial grayscale image; An acquisition unit, configured to acquire a grayscale value of each pixel in the initial grayscale image, and count the corresponding first grayscale quantity according to the grayscale value; A sorting unit, used for sorting the grayscale values according to a preset grayscale condition to obtain a sorted grayscale sequence; A first determining unit, configured to determine the number of groups when the grayscale values are grouped based on the first grayscale quantity and the grayscale sequence; A first calculating unit, configured to calculate a second grayscale quantity corresponding to the grayscale sequence in at least one group based on the first grayscale quantity and the grouping number; a second calculating unit, configured to calculate an average value of the grayscale sequences in different groups based on the number of grouping groups and the second grayscale quantity, so as to calculate the dispersion in the different groups based on the average value; The determining module comprises: A third calculation unit, used to calculate the difference between each pixel in the convolution image and at least one surrounding pixel; a sixth determining unit, configured to determine at least one initial feature point in the convolution image based on the difference; A judging unit, configured to judge whether the gray value of the at least one initial feature point is greater than the preset feature point threshold; A second generating unit, configured to obtain the at least one feature point based on the at least one initial feature point when the gray value is greater than the preset feature point threshold; The third generating unit is used to delete the at least one initial feature point when the grayscale value is less than or equal to the preset feature point threshold, and iteratively determine the next at least one initial feature point until the grayscale value is greater than the preset feature point threshold to obtain the at least one feature point.
7. The image similarity detection device according to claim 6, characterized in that: The first acquisition module includes: A second determining unit, configured to determine a gray value threshold for dividing the foreground portion and the background portion based on the first gray value quantity and the discreteness satisfying different preset discrete conditions; A third determining unit, configured to determine a background grayscale interval of the background part based on the grayscale value threshold and the grayscale sequence; A fourth determining unit, configured to determine a background grayscale value in the background grayscale interval among the grayscale values; The fifth determining unit is used to determine the background part based on the background grayscale value, and obtain the foreground part according to the background part.
8. The image similarity detection device according to claim 6, characterized in that: Also includes: A first construction module is used to construct an initial image filter based on a standard deviation that satisfies a preset filtering condition before convolving the pre-constructed image filter with the final image respectively; A second acquisition module, used for acquiring an aspect ratio, a phase angle and / or a control angle applicable to the initial picture filter; The second construction module is used to modify the initial picture filter by using the aspect ratio, the phase angle and / or the control angle to construct a picture filter.
9. The image similarity detection device according to claim 6, characterized in that: Also includes: A second generating module is used to perform upsampling at most once and downsampling at least once on the convolution image before determining at least one feature point in the convolution image based on a pre-constructed difference pyramid and a preset feature point threshold, so as to obtain scale images of different scales; A third acquisition module is used to obtain a smoothness coefficient corresponding to the scale image; A division module, used for dividing the scaled image into layer images of different numbers of layers by using the smoothness coefficient; The third construction module is used to construct a difference pyramid based on the layer picture.
10. An electronic device, characterized in that: include: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the image similarity detection method according to any one of claims 1 to 5.
11. A computer-readable storage medium having a computer program stored thereon, characterized in that: The program is executed by a processor to implement the image similarity detection method according to any one of claims 1 to 5.
Citation Information
Patent Citations
R-SIFT chip hardware Trojan horse image registration method based on template matching
CN112288009A
Image processing method and apparatus
WO2017012418A1