Image comparison test method

The image comparison test method addresses inefficiencies in existing methods by incorporating image validity checks and the SSIM method, enhancing accuracy and efficiency in image similarity assessments across various formats and types.

CN119206258APending Publication Date: 2024-12-27HAINAN CHEYOUJIA INFORMATION TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411214823.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-30
Publication Date
2024-12-27

AI Technical Summary

Technical Problem

Existing image comparison methods lack efficiency and accuracy, and are not optimized for various aspects such as image format, size, and content verification, leading to suboptimal performance in practical applications.

Method used

An image comparison test method utilizing image validity verification, size determination, and the SSIM (Structural Similarity Index Method) to assess structural similarity between images, incorporating pre-processing with cvtColor and GaussianBlur methods from OpenCV, and outputting results in various formats.

Benefits of technology

Improves the accuracy and reliability of image similarity comparison, reduces computing power consumption, and enhances efficiency by using the SSIM method, applicable to diverse image types, including grayscale and color images, with applications in digital media, video encoding, image compression, and image quality assessment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure SMS_1
    Figure SMS_1
  • Figure QLYQS_1
    Figure QLYQS_1
  • Figure QLYQS_2
    Figure QLYQS_2
Patent Text Reader

Abstract

The invention belongs to the technical field of image processing, and discloses an image comparison test method, which specifically comprises the following steps: step 1, image input and processing: a user needs to firstly input an image needing to be compared, and provides a comparison parameter; and 2, image validity verification: before comparison, the application program carries out image validity verification. The method has the advantages that the accuracy and reliability of image similarity comparison are improved, and the conditions of errors and missing detection in practical application are avoided; the application range is wide, and the method can be used for comparison of various image types; the method is widely applied to the field of digital media, and can be used for video coding, image compression, image denoising and the like; image quality evaluation and optimization are supported, the method can be used for image similarity comparison, and the SSIM comparison method can also be used for image quality evaluation and optimization, so that the image is more vivid and real; the method can be applied to image search, image recognition and the like to carry out accurate search and recognition.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the technical field of image processing, and in particular relates to an image comparison test method. Background Art

[0002] With the development of image processing technology, image comparison has gradually become an indispensable part of applications in various industries. There are many image comparison methods on the market, such as MSE (mean square error) method, PSNR (peak signal-to-noise ratio) method, CORR (correlation) method, etc.

[0003] The MSE method is a simple and commonly used image comparison method. It calculates the square of the difference in pixel values ​​between two images and uses the average of the sum of these square errors as a measure of similarity. In addition, the PSNR method can calculate the peak signal-to-noise ratio by comparing the ratio of the maximum pixel values ​​between the two images. Based on the CORR (correlation) method, the comparison result is a value that varies between -1 and +1: when the CORR value is 1, it means that the two images are completely consistent, when it is -1, the two images show a completely opposite relationship, and when it is 0, there is no information relationship between the two images. Although these methods perform well in some specific scenarios, each method has its limitations and cannot involve multiple aspects such as accuracy and efficiency. Therefore, different image comparison methods need to be selected for different scenarios and deeply optimized in practical applications to meet business needs and improve accuracy and efficiency. In the future, with the continuous advancement of technology, the application demand for image comparison technology in various industries will become higher and higher. Therefore, continuous in-depth research and optimization of image comparison methods to improve comparison accuracy and efficiency will become an important development trend in this field. Summary of the invention

[0004] In view of the deficiencies in the prior art, the present invention provides an image comparison test method, which has the advantages of improving efficiency and accuracy in image comparison and saving computing power and resources.

[0005] To achieve the above object, the present invention provides the following technical solution: an image comparison test method, the specific steps are as follows:

[0006] Step 1: Image input and processing:

[0007] In the application of the present invention, the user needs to first input the image to be compared and provide comparison parameters;

[0008] Step 2: Image validity check:

[0009] Before comparison, the application will perform image validity verification to ensure that the files being compared are valid and compliant;

[0010] Step 3: Image size determination:

[0011] If size comparison is required, the app will first determine whether the image sizes are the same. If the sizes are different, the app will come to a different conclusion without further comparison;

[0012] Step 4: Use the SSIM method for comparison:

[0013] If the image format and size are checked, the application will use the SSIM (structural similarity) method for comparison. If the similarity between two images is greater than the user-specified threshold, the application will determine that they are similar, otherwise they are considered dissimilar;

[0014] Step 5: Compare the results output and display:

[0015] Finally, the application will output the comparison results and display them to the user;

[0016] Step 6: Code example:

[0017] / / Calculate the similarity between two images

[0018] 1usage

[0019] private static double calculateImagesimilarityScore(Mat imagel, Matimage2){

[0020] / / Convert the original image to a grayscale image

[0021] Mat image1Gray = new Mat();

[0022] Mat image2Gray = new Mat();

[0023] Imgproc.cvtColor(image1, image1Gray, Imgproc.COLOR_BGR2GRAY);

[0024] Imgproc.cvtColor(image2, image2Gray, Imgproc.COLOR_BGR2GRAY);

[0025] / / Define the convolution kernel size of the Gaussian filter

[0026] Size kernelSize=new Size(width: 11, height: 11);

[0027] / / Gaussian filter on grayscale image

[0028] Mat mu1 = new Mat();

[0029] Mat mu2 = new Mat();

[0030] Imgproc.GaussianBlur(image1Gray, mu1, kernelSize, sigmaX: 1.5);

[0031] Imgproc.GaussionBlur(image2Gray, mu2, kernelSize, sigmaX: 1.5);

[0032] / / Calculate the mean and variance of the image

[0033] Mat mu1Square = newNat();

[0034] Mat mu2Square = new Mat();

[0035] Mat mu1mu2 = new Mat();

[0036] Mat sigma1Square=new Mat();

[0037] Mat sigma2Square=new Mat();

[0038] Mat sigma12 = new Hat();

[0039] Core.multiply(mu1, mu1, mu1Square);

[0040] Core.multiply(mu2,mu2,mu2Square);

[0041] Core.multiply(mu1,mu2,mu1mu2);

[0042] Imgproc.GaussianBtur(image1Gray, sigma1Square, kernelSize, sigmax: 1.5);

[0043] Core.multiply(sigma1Square, sigma1Square, sigma1Square);

[0044] Ingproc.GaussianBlur(image2Gray, sigma2Square, kernelSize, sigmaX: 1.5);

[0045] Core.multiply(sigma2Square, sigma2Square, sigma2Square);

[0046] Imgproc.GaussianBLur(mu1mu2, sigma12, kernelSize, sigmaX: 1.5);

[0047] core.multiply(sigma12,sigma12,sigma12);

[0048] / / Calculate the numerator and denominator of SSIM based on the mean and variance of the image

[0049] Mat ssimNumerator=new Mat();

[0050] Mat ssimDenominator1=new Mat();

[0051] Mat ssimDenominator2=new Mat();

[0052] Mat ssimDenominator=new Mat();

[0053] doubte c1=Math.pow(0.01*255, 2);

[0054] double c2=Math.pow(0.03*255, 2);

[0055] Core.addWeighted(mu1mu2, alpha: 2, sigma12, beta: 1, c2, ssimNumerator);

[0056] Core.addWeighted(mu1Square, alpha: 1, mu2Square, beta: 1, c1, ssimDenominator1);

[0057] Core.addWeighted(sigma1Square, alpha: 1, sigma2Square, beta: 1, c1, ssimDenominator2);

[0058] Core.addWeighted(ssimDenominator1, alpha: 1, ssimDenominator2, beta: 1, c2, ssimDenominator);

[0059] / / Take a weighted average of the SSIM numerator and denominator to get the SSIM index

[0060] Mat ssimMap = new Mat();

[0061] Core.divide(ssinNumerator, ssimDenominator, ssimMap);

[0062] Scalar score=Core.mean(ssimMap);

[0063] / / Return the SSIM index

[0064] return score.val[0];

[0065] }

[0066] public static boolean compareImagesWithSSIM(String imagePath1,StringimagePath2){

[0067] String localImagePath1=downloadImage(imagePath1);

[0068] if(StringUtils.isEmpty(localImagePath1)){

[0069] return false;

[0070] }

[0071] String localImagePath2=downloadImage(imagePath2);

[0072] if(StringUtils.isEmpty(localImagePath2)){

[0073] return false;

[0074] }

[0075] Mat image1=Imgcodecs.imread(localImagePath1);

[0076] Mat image2=Imgcodecs.imread(LocalImagePath2);

[0077] / / Delete the downloaded images

[0078] newFile(localImagePath1).delete();

[0079] newFile(LocalImagePath2).delete();

[0080] / / If the images are of different sizes, no comparison is required and they can be directly identified as different images if (image1.size().equals(image2.size()) == false) {

[0081] if(image2.size().equals(getsizeFromUrl(imagePath2)))){

[0082] return true;

[0083] }else{

[0084] return false;

[0085] }

[0086] }

[0087] / / Calculate image similarity

[0088] double similarityScore = calculateImageSimilarityScore(image1, image2); / / If the similarity between two images is higher than a certain threshold, the two images are considered similar

[0089] double threshold=1.0; / / can be adjusted according to actual situation

[0090] if(similarityScore>=threshold){

[0091] return true;

[0092] }else{

[0093]

[0094] Specifically, the present invention adds image validity verification and image size verification on the basis of using the cvtColor and GaussianBlur methods provided by opencv.

[0095] Preferably, the application described in step 1 will pre-process and optimize the image according to the user's parameters.

[0096] Preferably, the image validity check content described in step 2 includes the format, size and content of the image file.

[0097] Preferably, the SSIM method described in step 4 evaluates the similarity between two images by calculating the differences in structure, brightness, contrast, etc. between the two images.

[0098] Preferably, the output comparison result described in step 5 may be in a variety of forms, including text format, proportional scores or visual charts, etc., and users can choose according to their needs and preferences.

[0099] Preferably, the threshold in step 4 is set to be greater than or equal to 1.0, and the closer the similarity score is to 1, the higher the similarity between the two images.

[0100] Preferably, the SSIM described in step 4 refers to structural similarity, which is an indicator for measuring the similarity between two images, and the calculation formula is:

[0101] Preferably, the opencv described in step six is ​​an open source computer vision library, which provides many efficiently implemented computer vision algorithm functions.

[0102] Preferably, the cvtColor described in step 6 is a function used for color space conversion in the opencv library, and the GaussianBlur described in step 6 refers to Gaussian blur, which is a commonly used model in image and signal degradation.

[0103] Compared with the prior art, the present invention has the following beneficial effects:

[0104] The present invention has the following advantages: improving the accuracy and reliability of image similarity comparison. The SSIM comparison method is a high-precision image similarity comparison algorithm that can accurately determine the similarity between two images. By using the SSIM comparison method to perform image similarity comparison, the reliability and accuracy of the algorithm can be greatly improved, and errors and missed detections in practical applications can be avoided; the application range is wide, and it can be used for comparison of various image types. The SSIM comparison method can be applied to various types of images, including grayscale images, color images, natural pictures, engineering pictures, etc., which makes it highly practical and adaptable in various practical applications; it has a wide range of applications in the field of digital media, and can be used in video encoding, image compression, image denoising, etc. The SSIM comparison method has a wide range of applications in digital media processing. Applications: By using the SSIM comparison method, the bit rate of video encoding can be reduced, the efficiency of image compression can be improved, and the adverse effects such as noise and artifacts in the image can be effectively removed; it supports image quality assessment and optimization. In addition to image similarity comparison, the SSIM comparison method can also be used for image quality assessment and optimization. By calculating the SSIM value of the image, the quality of the image can be evaluated, so as to make optimization adjustments to make the image more vivid, natural and realistic; it can be applied to image search and image recognition. The SSIM comparison method can be used in image search and image recognition. By calculating the SSIM value of two images, the degree of similarity between them can be determined, so as to perform accurate search and recognition, which has high application potential in image processing and computer vision. DETAILED DESCRIPTION

[0105] Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in the field without making any creative work shall fall within the scope of protection of the present invention.

[0106] The present invention provides a technical solution: an image comparison test method, the specific steps are as follows:

[0107] Step 1: Image input and processing:

[0108] In the application of the present invention, the user needs to first input the image to be compared and provide comparison parameters;

[0109] Step 2: Image validity check:

[0110] Before comparison, the application will perform image validity verification to ensure that the files being compared are valid and compliant;

[0111] Step 3: Image size determination:

[0112] If size comparison is required, the app will first determine whether the image sizes are the same. If the sizes are different, the app will come to a different conclusion without further comparison;

[0113] Step 4: Use the SSIM method for comparison:

[0114] If the image format and size are checked, the application will use the SSIM (structural similarity) method for comparison. If the similarity between two images is greater than the user-specified threshold, the application will determine that they are similar, otherwise they are considered dissimilar;

[0115] Step 5: Compare the results output and display:

[0116] Finally, the application will output the comparison results and display them to the user;

[0117] Step 6: Code example:

[0118] / / Calculate the similarity between two images

[0119] 1usage

[0120] private static double calculateImagesimilarityScore(Mat imagel, Matimage2){

[0121] / / Convert the original image to a grayscale image

[0122] Mat image1Gray = new Mat();

[0123] Mat image2Gray = new Mat();

[0124] Imgproc.cvtColor(image1, image1Gray, Imgproc.COLOR_BGR2GRAY);

[0125] Imgproc.cvtColor(image2, image2Gray, Imgproc.COLOR_BGR2GRAY);

[0126] / / Define the convolution kernel size of the Gaussian filter

[0127] Size kernelSize=new Size(width: 11, height: 11);

[0128] / / Gaussian filter on grayscale image

[0129] Mat mu1 = new Mat();

[0130] Mat mu2 = new Mat();

[0131] Imgproc.GaussianBlur(image1Gray, mu1, kernelSize, sigmaX: 1.5);

[0132] Imgproc.GaussionBlur(image2Gray, mu2, kernelSize, sigmaX: 1.5);

[0133] / / Calculate the mean and variance of the image

[0134] Mat mu1Square = newNat();

[0135] Mat mu2Square = new Mat();

[0136] Mat mu1mu2 = new Mat();

[0137] Mat sigma1Square=new Mat();

[0138] Mat sigma2Square=new Mat();

[0139] Mat sigma12 = new Hat();

[0140] Core.multiply(mu1, mu1, mu1Square);

[0141] Core.multiply(mu2,mu2,mu2Square);

[0142] Core.multiply(mu1,mu2,mu1mu2);

[0143] Imgproc.GaussianBtur(image1Gray, sigma1Square, kernelSize, sigmax: 1.5);

[0144] Core.multiply(sigma1Square, sigma1Square, sigma1Square);

[0145] Ingproc.GaussianBlur(image2Gray, sigma2Square, kernelSize, sigmaX: 1.5);

[0146] Core.multiply(sigma2Square, sigma2Square, sigma2Square);

[0147] Imgproc.GaussianBLur(mu1mu2, sigma12, kernelSize, sigmaX: 1.5);

[0148] core.multiply(sigma12,sigma12,sigma12);

[0149] / / Calculate the numerator and denominator of SSIM based on the mean and variance of the image

[0150] Mat ssimNumerator=new Mat();

[0151] Mat ssimDenominator1=new Mat();

[0152] Mat ssimDenominator2=new Mat();

[0153] Mat ssimDenominator=new Mat();

[0154] doubte c1=Math.pow(0.01*255, 2);

[0155] double c2=Math.pow(0.03*255, 2);

[0156] Core.addWeighted(mu1mu2, alpha: 2, sigma12, beta: 1, c2, ssimNumerator);

[0157] Core.addWeighted(mu1Square, alpha: 1, mu2Square, beta: 1, c1, ssimDenominator1);

[0158] Core.addWeighted(sigma1Square, alpha: 1, sigma2Square, beta: 1, c1, ssimDenominator2);

[0159] Core.addWeighted(ssimDenominator1, alpha: 1, ssimDenominator2, beta: 1, c2, ssimDenominator);

[0160] / / Take a weighted average of the SSIM numerator and denominator to get the SSIM index

[0161] Mat ssimMap = new Mat();

[0162] Core.divide(ssinNumerator, ssimDenominator, ssimMap);

[0163] Scalar score=Core.mean(ssimMap);

[0164] / / Return the SSIM index

[0165] return score.val[0];

[0166] }

[0167] public static boolean compareImagesWithSSIM(String imagePath1,StringimagePath2){

[0168] String localImagePath1=downloadImage(imagePath1);

[0169] if(StringUtils.isEmpty(localImagePath1)){

[0170] return false;

[0171] }

[0172] String localImagePath2=downloadImage(imagePath2);

[0173] if(StringUtils.isEmpty(localImagePath2)){

[0174] return false;

[0175] }

[0176] Mat image1=Imgcodecs.imread(localImagePath1);

[0177] Mat image2=Imgcodecs.imread(LocalImagePath2);

[0178] / / Delete the downloaded images

[0179] newFile(localImagePath1).delete();

[0180] newFile(LocalImagePath2).delete();

[0181] / / If the images are of different sizes, no comparison is required and they can be directly identified as different images

[0182] if(image1.size().equals(image2.size())==false){

[0183] if(image2.size().equals(getsizeFromUrl(imagePath2)))){

[0184] return true;

[0185] }else{

[0186] return false;

[0187] }

[0188] }

[0189] / / Calculate image similarity

[0190] double similarityScore=calculateImageSimilarityScore(image1, image2);

[0191] / / If the similarity between two images is higher than a certain threshold, the two images are considered similar

[0192] double threshold=1.0; / / can be adjusted according to actual situation

[0193] if(similarityScore>=threshold){

[0194] return true;

[0195] }else{

[0196] return false;

[0197] }

[0198] }

[0199] Specifically, the present invention adds image validity verification and image size verification on the basis of using the cvtColor and GaussianBlur methods provided by opencv.

[0200] The application process of the present invention mainly revolves around three links of image comparison, namely, judging the validity of the image, judging the size of the image and using the SSIM method to judge whether the images are consistent, and adopts a variety of optimization and verification methods. On the basis of the original SSIM algorithm, the algorithm is improved and optimized to ensure the efficiency and accuracy of the comparison. From the verification before image comparison to the optimization of the comparison algorithm, and then to the evaluation of the comparison results, the image comparison process is optimized in all aspects, which not only improves the comparison efficiency and accuracy, but also saves the consumption of computing power and resources. It has broad application fields and promotion prospects.

[0201] Among them, the application in step one will pre-process and optimize the image according to the user's parameters.

[0202] After application preprocessing and optimization, more accurate results can be obtained in subsequent comparisons.

[0203] The image validity check in step 2 includes the format, size and content of the image file.

[0204] If there is a problem with the image data, the corresponding exception handling mechanism can ensure the normal operation of the program and data security.

[0205] Among them, the SSIM method in step 4 evaluates the similarity between two images by calculating the differences in structure, brightness, contrast, etc.

[0206] By using the SSIM comparison method to perform image similarity comparison, the reliability and accuracy of the algorithm can be greatly improved, avoiding errors and missed detections in practical applications. At the same time, the SSIM comparison method can reduce the bit rate of video encoding, improve the efficiency of image compression, and effectively remove adverse effects such as noise and artifacts in the image.

[0207] The output comparison result in step five may be in various forms, including text format, proportional scores, or visual charts, etc. Users can choose according to their needs and preferences.

[0208] Users can choose the form of outputting comparison results according to their needs and preferences, making the result display more intuitive and efficient.

[0209] The threshold in step 4 is set to be greater than or equal to 1.0. The closer the similarity score is to 1, the higher the similarity between the two images.

[0210] Due to the accuracy of computer processing of images, in some cases, the similarity score may be slightly higher than 1. Therefore, setting the similarity score threshold to be greater than or equal to 1.0 can ensure that we can obtain high-quality image comparison results, thereby improving the reliability and accuracy of the algorithm. For cases where the similarity score exceeds 1, we can round the result to 1 or make other adjustments to ensure the accuracy of the comparison results.

[0211] Among them, SSIM in step 4 refers to structural similarity, which is an indicator to measure the similarity between two images. The calculation formula is:

[0212] μ in the formula x is the mean value of x, μ y is the mean value of y, σ x 2 is the variance of x, is the variance of y, σ xy is the covariance of x and y, c1=(k1L) 2 , c2=(k2L) 2 It is a constant used to maintain stability, L is the dynamic range of pixel values, k1=0.01, k2=0.03.

[0213] Among them, opencv in step 6 is an open source computer vision library, which provides many efficiently implemented computer vision algorithm functions.

[0214] The design of OpenCV focuses on efficient computing, with particular emphasis on the development of real-time applications. One of its goals is to provide an easy-to-use computer vision interface to help people quickly build sophisticated visual applications. The OpenCV code is optimized to take full advantage of the performance of modern processors, including multi-core processors and GPU acceleration.

[0215] Among them, cvtColor in step 6 is a function used for color space conversion in the opencv library, and GaussianBlur in step 6 refers to Gaussian blur, which is a commonly used model in image and signal degradation.

[0216] cvtColor is used to convert an image from one color space to another, and GaussianBlur is usually used to reduce image noise and reduce the level of detail.

[0217] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, 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 other elements not explicitly listed, or also includes elements inherent to such process, method, article or device.

[0218] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.

Claims

1. An image comparison test method, characterized in that: The specific steps are as follows: Step 1: Image input and processing: In the application of this method, the user needs to first input the image to be compared and provide comparison parameters; Step 2: Image validity check: Before comparison, the application will perform image validity verification to ensure that the files being compared are valid and compliant; Step 3: Image size determination: If a size comparison is required, the app will first determine whether the image sizes are the same. If the sizes are different, the app will come to a different conclusion without further comparison; Step 4: Use the SSIM method for comparison: If the image format and size are checked, the application will use the SSIM (structural similarity) method for comparison. If the similarity between two images is greater than the user-specified threshold, the application will determine that they are similar, otherwise they are considered dissimilar; Step 5: Compare the results output and display: Finally, the application will output the comparison results and display them to the user; Step 6: Code example: / / Calculate the similarity between two images 1usage private static double calculateImagesimilarityScore(Mat imagel, Matimage2){ / / Convert the original image to a grayscale image Mat image1Gray = new Mat(); Mat image2Gray = new Mat(); Imgproc.cvtColor(image1, image1Gray, Imgproc.COLOR_BGR2GRAY); Imgproc.cvtColor(image2, image2Gray, Imgproc.COLOR_BGR2GRAY); / / Define the convolution kernel size of the Gaussian filter Size kernelSize=new Size(width: 11, height: 11); / / Gaussian filter on grayscale image Mat mu1 = new Mat(); Mat mu2 = new Mat(); Imgproc.GaussianBlur(image1Gray, mu1, kernelSize, sigmaX: 1.5); Imgproc.GaussionBlur(image2Gray, mu2, kernelSize, sigmaX: 1.5); / / Calculate the mean and variance of the image Mat mu1Square = newNat(); Mat mu2Square = new Mat(); Mat mu1mu2 = new Mat(); Mat sigma1Square=new Mat(); Mat sigma2Square=new Mat(); Mat sigma12 = new Hat(); Core.multiply(mu1, mu1, mu1Square); Core.multiply(mu2, mu2, mu2Square); Core.multiply(mu1,mu2,mu1mu2); Imgproc.GaussianBtur(image1Gray, sigma1Square, kernelSize, sigmax: 1.5); Core.multiply(sigma1Square, sigma1Square, sigma1Square); Ingproc.GaussianBlur(image2Gray, sigma2Square, kernelSize, sigmaX: 1.5); Core.multiply(sigma2Square, sigma2Square, sigma2Square); Imgproc.GaussianBLur(mu1mu2, sigma12, kernelSize, sigmaX: 1.5); core.multiply(sigma12, sigma12, sigma12); / / Calculate the numerator and denominator of SSIM based on the mean and variance of the image Mat ssimNumerator=new Mat(); Mat ssimDenominator1=new Mat(); Mat ssimDenominator2=new Mat(); Mat ssimDenominator=new Mat(); doubte c1=Math.pow(0.01*255, 2); double c2=Math.pow(0.03*255, 2); Core.addWeighted(mu1mu2, alpha: 2, sigma12, beta: 1, c2, ssimNumerator); Core.addWeighted(mu1Square, alpha: 1, mu2Square, beta: 1, c1, ssimDenominator1); Core.addWeighted(sigma1Square, alpha: 1, sigma2Square, beta: 1, c1, ssimDenominator2); Core.addWeighted(ssimDenominator1, alpha: 1, ssimDenominator2, beta: 1, c2, ssimDenominator); / / Take a weighted average of the SSIM numerator and denominator to get the SSIM index Mat ssimMap = new Mat(); Core.divide(ssinNumerator, ssimDenominator, ssimMap); Scalar score=Core.mean(ssimMap); / / Return the SSIM index return score.val[0]; } public static boolean compareImagesWithSSIM(String imagePath1,StringimagePath2){ String localImagePath1=downloadImage(imagePath1); if(StringUtils.isEmpty(localImagePath1)){ return false; } String localImagePath2=downloadImage(imagePath2); if(StringUtils.isEmpty(localImagePath2)){ return false; } Mat image1=Imgcodecs.imread(localImagePath1); Mat image2=Imgcodecs.imread(LocalImagePath2); / / Delete the downloaded images newFile(localImagePath1).delete(); newFile(LocalImagePath2).delete(); / / If the images are of different sizes, no comparison is required and they can be directly identified as different images if (image1.size().equals(image2.size()) == false) { if(image2.size().equals(getsizeFromUrl(imagePath2)))){ return true; }else{ return false; } } / / Calculate image similarity double similarityScore = calculateImageSimilarityScore(image1, image2); / / If the similarity between two images is higher than a certain threshold, the two images are considered similar double threshold = 1.0; / / Can be adjusted according to actual situation if(similarityScore>=threshold){ Specifically, this method adds image validity verification and image size verification based on the cvtColor and GaussianBlur methods provided by opencv.

2. The image comparison test method according to claim 1, characterized in that: The application described in step 1 will pre-process and optimize the image according to the user's parameters.

3. The image comparison test method according to claim 1, characterized in that: The image validity check content described in step 2 includes the format, size and content of the image file.

4. The image comparison test method according to claim 1, characterized in that: The SSIM method described in step 4 evaluates the similarity between two images by calculating the differences in structure, brightness, and contrast.

5. The image comparison test method according to claim 1, characterized in that: The output comparison results described in step 5 may be in various forms, including text format, proportional scores, or visual charts, etc. Users can choose according to their needs and preferences.

6. The image comparison test method according to claim 1, characterized in that: The threshold described in step 4 is set to be greater than or equal to 1.

0. The closer the similarity score is to 1, the higher the similarity between the two images.

7. The image comparison test method according to claim 1, characterized in that: The SSIM mentioned in step 4 refers to structural similarity, which is an indicator to measure the similarity between two images. The calculation formula is:

8. The image comparison test method according to claim 1, characterized in that: OpenCV, described in step 6, is an open source computer vision library that provides many efficiently implemented computer vision algorithm functions.

9. The image comparison test method according to claim 1, characterized in that: The cvtColor described in step 6 is a function used for color space conversion in the opencv library. The GaussianBlur described in step 6 refers to Gaussian blur, which is a commonly used model in image and signal degradation.

Citation Information

Cited By

  • Self-adaptive image comparison solution stirring anomaly detection method

    CN122290041A