Patent Description:
The present disclosure relates to the field of image recognition, and in particular, to a method, apparatus, and storage medium for calculating image similarity.

Image similarity calculation is mainly applied to give a score for the similarity degree between the content of two images, and the similarity degree of the image content is judged according to the level of the score. It may be used for computer vision detection and the acquisition of a position of a tracking target, and find an area close to that in the image according to an existing template. On the other hand, it may be used for image retrieval based on image content, which is usually known as search by image.

Image similarity algorithms include comparison of basic features of statistical images such as histogram matching, mathematical matrix decomposition, and image similarity calculation based on feature points. The comparison of the basic features of statistical images involves extracting the basic features of an original image and a target image, such as grayscale statistical features (grayscale histogram) and image texture features (energy, entropy, moment of inertia, local stationarity, etc. for a grayscale co-occurrence matrix), and then comparing the resultant basic feature values of the original image and the target image to obtain the similarity between the images. The histogram matching reflects the probability distribution of the grayscale values of the image pixels, ignoring the position information of the pixels. Each image has its own feature points that characterize some of relatively important locations in the image that are similar to knee points in a function. Moreover, this method of comparing image similarity is based on statistical features, which reflects the globality of the image, and does not reflect the local features of the image well, so the comparison result will have relatively large errors.

The image similarity algorithm based on feature points judges whether two images are consistent by the number of matching points found. Since mismatch may occur in the feature points matching, the image similarity algorithm based on feature points has a high error rate. The patent document of publication No. <CIT> discloses an image similarity calculation system which performs grayscale processing on a first image and a second image respectively to obtain a first grayscale image and a second grayscale image, and process the second grayscale image according to the size of the first grayscale image and the second grayscale image to obtain a target image. The system then matches each of the pixels in the first grayscale image to a respective pixel in the target image to construct a set of pixel point pairs. Finally, the system calculates the similarity between the first image and the second image according to the obtained grayscale value of each of the pixel points in the set of pixel point pairs. However, mismatch readily occurs during the pixel point matching, resulting in large errors in the final result.

The paper document "<NPL>) discloses an improved algorithm based on multipurication in PCB matching and positioning, to address the scale invariance and mismatching problems of ORB (oriented FAST and rotated BRIEF).

Therefore, how to improve the accuracy of the image similarity judgment result is an issue that needs to be solved urgently.

The above-mentioned feature point-based image similarity algorithm is easy to cause mismatching and the like. The present disclosure provides a method for calculating image similarity, which comprises the steps of:.

wherein the step S5 specifically comprises the steps of:.

Further, an approach for extracting the feature points in the step S1 comprises a sift, orb, surf, or brisk feature point extraction algorithm. Therefore, the approach of extracting feature points is more diverse and is extensively applicable.

Further, the sift feature point extraction algorithm specifically comprises the steps of:.

Further, the first distances in the step S2 are an Euclidean distance, a Manhattan distance or a Minkowski distance, and minimum distance classification is adopted as a criterion of the similarity between the feature points in the first image and the second image. By determining the similarity between the feature points in the first image and the second image, the feature points with the highest similarity in the first image and the second image can be obtained as reference points, thereby effectively reducing errors caused by the feature point mismatching.

Further, in the step S4 the respectively calculating the relative positions of the remaining feature points in the first image and the second image relative to the reference points adopts the following formula: <MAT>.

Wherein x<NUM> represents a relative position in the first image or the second image in a coordinate axis x direction, x<NUM> represents a coordinate position of a remaining feature point in the first image or the second image in the x direction, and x<NUM> represents a coordinate position of a reference point in the first image or the second image in the x direction, y<NUM> represents a relative position in the first image or the second image in a coordinate axis y direction, y<NUM> represents a coordinate position of a remaining feature point in the first image or the second image in the x direction, and y<NUM> represents a coordinate position of a reference point in the first image or the second image in the y direction. The calculation is more accurate by respectively calculating the relative positions of the remaining feature points in the first image and the second image relative to the reference points and by setting them as relative position vectors.

Further, the X-axis distance and the Y-axis distance in the step S5 comprise an included-angle cosine distance, a Manhattan distance, or a Chebyshev distance. By calculating as the criterion for the image similarity the X-axis distance and the Y-axis distance of the X-direction or Y-direction relative position vectors of the remaining feature points in the first image and the second image and the reference points, the accuracy of image similarity determination is further ensured.

Further, the included-angle cosine distance is calculated as: <MAT>.

Wherein Ai and Bi represent components of vector A and vector B, respectively.

Further, the step S5 further comprises summing the X-axis distance and the Y-axis distance, and setting a threshold range for the summed value, wherein exceeding the threshold range indicates a similar image, or a different image otherwise.

An apparatus for image similarity calculation is further proposed which comprises a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that when executing the computer program the processor implements the steps of any one of the methods described above.

A computer-readable storage medium storing a computer program is further proposed, which computer program, when executed by a processor, implements the steps of any one of the methods described above.

With regard to the image similarity algorithm based on feature points, it is found that when the two images contain the same object, the layouts of the feature points in the two images are basically the same. When the two images contain different objects, the layouts of the feature points in the two images differ significantly. Therefore, the present disclosure proposes a method, apparatus, and storage medium for calculating image similarity, which use relative position information based on feature points to detect the similarity between two pictures. First, feature points and corresponding feature vectors in the first image and the second image are extracted, the feature points are compared, and the most matching feature points act as reference points to measure the distance between the remaining points and the reference points. It is statistically judged whether the two images are similar images according to the distance relationship. This approach can effectively overcome the detection error caused by the mismatch of the feature points, providing an effective way for image similarity calculation.

In order to more clearly illustrate the technical solutions in the embodiments of the present disclosure, the following drawings will be briefly described in the description of the embodiments. It is apparent that the drawings in the following description are only some of the embodiments of the present disclosure, and that other drawings can be obtained by those skilled in the art based on these drawings without paying any inventive effort.

In order to render the objectives, technical solutions and advantages of the present disclosure more apparent, the present disclosure will be further described in detail with reference to the accompanying drawings. It is apparent that the described embodiments are only a part of the embodiments of the present disclosure, and not all of them. All other embodiments obtained by a person of ordinary skill in the art based on the embodiments of the present disclosure without paying inventive effort fall within the scope of the disclosure.

An embodiment of the present disclosure discloses a method for calculating image similarity as shown in <FIG>, which includes the following steps:.

An approach for extracting the feature points in the step S1 includes one or more of a sift feature point extraction algorithm, an orb feature point extraction algorithm, a surf feature point extraction algorithm, or a brisk feature point extraction algorithm. Finally, the feature points and the feature vectors of the first image and the second image are obtained.

In a preferred embodiment, as shown in <FIG>, the sift feature point extraction algorithm specifically includes the following steps:.

In another specific embodiment, the orb feature point extraction algorithm specifically includes the following steps:.

In another specific embodiment, the surf feature point extraction algorithm specifically includes the following steps:.

In another specific embodiment, the brisk feature point extraction algorithm specifically includes the following steps:.

It is determined which feature point extraction algorithm(s) are adopted according to the specific conditions of the first image and the second image, and thus it can be seen that the method is extensively applicable without being limited by the category of the feature point extraction algorithm. Sift and surf can provide relatively high accuracy and stable results. Sift is somewhat more accurate than surf, but it is slower in speed. Brisk sometimes has the best accuracy. Orb is very fast, but it is the most prone to problems in terms of the accuracy. Therefore, an appropriate feature point extraction approach can be selected according to specific situations and usage conditions.

In addition, the first distances in the step S2 are an Euclidean distance, a Manhattan distance or a Minkowski distance, and minimum distance classification is adopted as a criterion of the similarity between the feature points in the first image and the second image. By determining the similarity of the feature points in the first image and the second image, it is possible to obtain top N feature points in the first image and the second image that have the highest similarity, from which n feature points are randomly selected as the reference points, thus effectively reducing errors due to feature point mismatching.

In a preferred embodiment, the Euclidean distance may be selected as the distance calculation approach in the minimum distance classification. The Euclidean distance is calculated as follows.

Assuming an n-dimensional vector a = (x<NUM>, x<NUM>,. , x<NUM>n) and an n-dimensional vector b = (x<NUM>, x<NUM>,. , x2n), the Euclidean distance between the vectors a and b is calculated as: <MAT>.

In another specific embodiment, the Manhattan distance may also be used as the distance calculation approach in the minimum distance classification. The Manhattan distance is calculated as follows.

Assuming two n-dimensional vectors a = (x<NUM>, x<NUM>,. , x<NUM>n) and b = (x<NUM>, x<NUM>,. x2n), the Manhattan distance between the vectors a and b is calculated as: <MAT>.

In another specific embodiment, the Minkowski distance may also be used as the distance calculation approach in the minimum distance classification. The Minkowski distance is calculated as follows.

Assuming two n-dimensional vectors a = (x<NUM>, x<NUM>,. , x<NUM>n) and b = (x<NUM>, x<NUM>,. , x2n), the Minkowski distance between the vectors a and b is calculated as: <MAT> Where p is a variable parameter.

The formula is different dependent upon different values of p, so with the different parameter p, the Minkowski distance can be expressed as a category of distance. The minimum distance calculation formula can be used to intuitively embody the minimum distance between the feature vectors in the first image and the second image, and is suitable for the similarity metric of the feature points of the first image and the second image. the respectively calculating the relative positions of the remaining feature points in the first image and the second image relative to the reference points in the step S4 adopts the following formula: <MAT> Where x<NUM> represents a relative position in the first image or the second image in a coordinate axis x direction, x<NUM> represents a coordinate position of a remaining feature point in the first image or the second image in the x direction, and x<NUM> represents a coordinate position of a reference point in the first image or the second image in the x direction, y<NUM> represents a relative position in the first image or the second image in a coordinate axis y direction, y<NUM> represents a coordinate position of a remaining feature point in the first image or the second image in the x direction, and y<NUM> represents a coordinate position of a reference point in the first image or the second image in the y direction. This way, the relative positions of the remaining feature points in the first image or the second image relative to the reference points can be obtained by selecting from the most similar N feature point pairs n feature points as the reference points.

As shown in <FIG>, step S5 includes the following steps:.

The X-axis distance and the Y-axis distance in the step S5 comprise an included-angle cosine distance, a Manhattan distance, or a Chebyshev distance.

In a preferred embodiment, the X-axis distance and the Y-axis distance are an included-angle cosine distance, which is calculated as: <MAT> Where Ai and Bi represent components of vector A and vector B, respectively.

In another specific embodiment, the X-axis distance and the Y-axis distance may also be a Manhattan distance, which is calculated as: <MAT>.

In another specific embodiment, the X-axis distance and the Y-axis distance may also be a Chebyshev distance, which is calculated as: <MAT> Where max means taking the maximum value.

The X-axis distance and the Y-axis distance may be calculated according to the actual situation using a reasonable distance formula.

Step S5 further includes summing the X-axis distance and the Y-axis distance, and setting a threshold range for the summed value, wherein exceeding the threshold range indicates a similar image, or a different image otherwise. The threshold range may be adjusted according to specific situations.

Additionally, each of the instances of the present disclosure may be implemented with a data processing program executed by a data processing device such as a computer. Apparently, the data processing program constitutes the present disclosure. Further, the data processing program that is usually stored in a storage medium is executed by directly reading the program from the storage medium or by installing or copying the program to a storage device (such as a hard disk and/or a memory) of the data processing device. Therefore, such a storage medium also constitutes the present disclosure. The storage medium can use any type of recording means, such as a paper storage medium (such as a paper tape, etc.), a magnetic storage medium (such as a floppy disk, a hard disk, a flash memory, etc.), an optical storage medium (such as a CD-ROM, etc.), a magneto-optical storage medium (such as a MO, etc.), and the like.

The present disclosure therefore further discloses a non-volatile storage medium in which a data processing program is stored for performing any one of the instances of the above-described methods of the present disclosure.

In addition, the method steps described in the present disclosure may be implemented with a data processing program, and may also be implemented with hardware, for example, logic gates, switches, an application specific integrated circuit (ASIC), a programmable logic controller, an embedded controller, and the like. Thus, such hardware that can implement the methods of the present disclosure may also constitute the present disclosure.

Claim 1:
A method for calculating image similarity, comprising the steps of:
S1: extracting feature points and corresponding feature vectors from a first image and a second image, respectively;
S2: pairing all the feature points in the first image with all the feature points in the second image according to similarity by comparing first distances between the feature vectors in the first image and the feature vectors in the second image;
S3: sorting the paired feature points according to the similarity from high to low, and selecting top N feature point pairs in the first image and the second image;
S4: respectively randomly selecting n reference points from the top N feature point pairs in the first image and the second image, and respectively calculating X-direction and Y-direction relative positions of remaining feature points relative to the n reference points in the first image, and respectively calculating X-direction and Y-direction relative positions of remaining feature points relative to the n reference points in the second image; and
S5: calculating an X-axis distance according to the X-direction relative positions of the remaining feature points relative to the reference points respectively in the first image and the second image, calculating a Y-axis distance according to the Y-direction relative positions of the remaining feature points relative to the reference points respectively in the first image and the second image, and with respect to the calculated X-axis distance and the Y-axis distance, setting a threshold range to determine whether the first image and the second image are a same image,
wherein the step S5 specifically comprises the steps of:
S51: setting the X-direction relative positions x<NUM>, ... , x1i, ... , x1n of one of the remaining feature points relative to the n reference points in the first image as vector A;
S52: setting the X-direction relative positions x<NUM>, ... , c2i, ... , x2n of one of the remaining feature points relative to the n reference points in the second image as vector B;
S53: calculating the X-axis distance between vector A and vector B;
S54: calculating in a same manner the Y-axis distance between vectors of the Y-direction relative positions of one of the remaining feature points in the first image and the second image with respect to the n reference points.