An image similarity determination method, an electronic device, and a computer-readable storage medium
By considering the brightness, contrast, and differences in brightness between high and low points of an image, a block-based processing method is used to evaluate image similarity. This solves the problem of inaccurate image similarity evaluation in existing technologies and achieves more accurate and efficient evaluation that better reflects human visual perception.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- HONOR DEVICE CO LTD
- Filing Date
- 2024-12-20
- Publication Date
- 2026-06-23
AI Technical Summary
Existing technologies fail to consider the differences between different receptive fields of images when assessing image similarity, resulting in assessment results that do not conform to the human eye's judgment of image differences and fail to accurately reflect the similarity between images.
By considering differences in brightness, contrast, and high/low brightness, a block-based processing method is used to determine image similarity. Combining the similarity of brightness, contrast, and high/low brightness differences reflects the characteristics of the image at different scales, improves the sensitivity to local details, and obtains a more accurate image similarity through weighted summation.
It achieves image similarity assessment that is more in line with human visual perception, improves the accuracy and efficiency of the assessment, maintains the overall style consistency of images under different brightness and contrast, and improves image processing results.
Smart Images

Figure CN122265673A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of image technology, and in particular to an image similarity determination method, an electronic device, and a computer-readable storage medium. Background Technology
[0002] Traditional methods can use parameters such as peak signal-to-noise ratio (PSNR), structural similarity (SSIM), mean squared error (MSE), multi-scale structural similarity index measure (MS-SSIM), and cosine similarity to evaluate the similarity between images.
[0003] While the parameters mentioned above assess image similarity from different perspectives, they all consider the image holistically and fail to account for differences between different receptive fields within the image. Furthermore, none of these parameters accurately reflect the similarity between images and do not conform to the human eye's perception of image differences. Summary of the Invention
[0004] This application provides an image similarity determination method, an electronic device, and a computer-readable storage medium, wherein the obtained image similarity can closely match the human eye's visual perception of image differences.
[0005] To achieve the above objectives, the embodiments of this application adopt the following technical solutions:
[0006] Firstly, embodiments of this application provide an image similarity determination method, which can determine the first image similarity between a first image and a second image based on differences in brightness, contrast, and high / low brightness. Brightness, contrast, and high / low brightness can all reflect the brightness level of an image. When the brightness levels of two images differ significantly, the human eye is more sensitive to these differences, meaning it is easier for the human eye to perceive the differences between the two images, resulting in a lower perceived similarity. Conversely, when the brightness levels of two images are similar, the human eye is less sensitive to these differences, meaning it is less likely to perceive the differences between the two images, resulting in a higher perceived similarity. Therefore, the image similarity trend determined by embodiments of this application—where greater differences in brightness, contrast, or high / low brightness lead to smaller first image similarity and a higher rate of change in first image similarity—aligns with the aforementioned trend of image differences perceived by the human eye under different brightness levels. In other words, the image similarity obtained by embodiments of this application more closely matches the human eye's judgment of image differences under different brightness conditions, demonstrating higher reliability in practical applications. In addition, this application determines the first image similarity from three dimensions: brightness difference, contrast difference, and high and low brightness difference, which is more comprehensive than the dimensions referenced by the prior art. Therefore, the image similarity obtained by this application is more accurate.
[0007] In one embodiment provided in the first aspect, when determining the first image similarity, the electronic device can first perform at least one block processing on the first image and the second image to obtain multiple image block pairs. Each image block pair includes a first image block belonging to the first image and a second image block belonging to the second image, and the first and second image blocks are of the same size and correspond in position. Then, the device can determine the first brightness similarity of each image block pair based on the brightness difference, contrast difference, and high / low brightness difference between the first and second image blocks. Next, it statistically analyzes the first brightness similarity of image block pairs belonging to the same group of images to obtain at least one second brightness similarity. Finally, it performs a weighted summation of the at least one second brightness similarity to obtain the first image similarity. The trend of change in the first brightness similarity is consistent with the trend of change in the first image similarity, except that the first brightness similarity is related to the brightness difference, contrast difference, and high / low brightness difference between the first and second image blocks. In this solution, by performing block processing on the image and obtaining the first brightness similarity of each image block pair, the features of the image at different scales can be captured, improving the sensitivity of the electronic device to local details and making the obtained image similarity more accurate.
[0008] In one embodiment provided in the first aspect, when determining the aforementioned first brightness similarity, the electronic device can determine the first similarity based on the brightness difference between the first image block and the second image block, determine the second similarity based on the contrast difference between the first image block and the second image block, and determine the third similarity based on the high and low brightness difference between the first image block and the second image block. Then, the first similarity, second similarity, and third similarity of each image block pair are summed to obtain the first brightness similarity of each image block pair. Specifically, the greater the brightness difference between the first image block and the second image block, the smaller the first similarity and the greater the rate of change of the first similarity; the greater the contrast difference between the first image block and the second image block, the smaller the second similarity and the greater the rate of change of the second similarity; and the greater the high and low brightness difference between the first image block and the second image block, the smaller the third similarity and the greater the rate of change of the third similarity. Therefore, this application can determine image similarity from three dimensions: brightness difference, contrast difference, and high and low brightness, which is more comprehensive than the dimensions referenced in the prior art, and thus the image similarity obtained by this application is more accurate.
[0009] In one embodiment provided in the first aspect, when determining the first image similarity, the electronic device can further determine a fourth similarity based on the brightness difference between the first and second images, a fifth similarity based on the contrast difference between the first and second images, and a sixth similarity based on the high and low brightness difference between the first and second images. The first image similarity is then determined based on the fourth, fifth, and sixth similarities. Specifically, a greater brightness difference between the first and second images results in a smaller fourth similarity and a greater rate of change in the fourth similarity; a greater contrast difference between the first and second images results in a smaller fifth similarity and a greater rate of change in the fifth similarity; and a greater high and low brightness difference between the first and second images results in a smaller sixth similarity and a greater rate of change in the fifth similarity. In other words, the electronic device can also consider the two images as a whole to determine their similarity. This method requires less computation and can obtain the first image similarity faster than the method that considers local details, thus being more efficient.
[0010] In one embodiment provided in the first aspect, the electronic device can further determine the style similarity between the first image and the second image, and obtain a second image similarity by weighted summation of the first image similarity and the style similarity. The style similarity reflects the similarity of the first image and the second image in terms of global style; therefore, the second image similarity obtained in this embodiment can simultaneously reflect the differences between the first image and the second image in overall style and brightness level, making it more accurate. Furthermore, when applied to business scenarios, this method helps maintain the consistency of the overall style of the two images, improves the visual effect and artistic expression of the images, and achieves superior image processing results.
[0011] In one embodiment provided in the first aspect, when determining the style similarity, the electronic device may first extract a first feature map from the first image and extract a second feature map from the first image, and then determine the style similarity based on the first feature map and the second feature map. Optionally, the style similarity may also be the aforementioned PSNR, SSIM, cosine similarity, etc.
[0012] In one embodiment provided in the first aspect, the first feature map, the second feature map, and the style similarity satisfy the following:
[0013]
[0014] Where gram_loss is the style similarity, xi is the value of the i-th element in the third feature map, the third feature map is the difference between the second and first feature maps, and M is the number of elements in the third feature map.
[0015] In one embodiment provided in the first aspect, the brightness difference between the first image block and the second image block and the first similarity satisfy the following formula:
[0016]
[0017] Where Loss1 is the first similarity, f1(x) is the brightness difference between the first and second image blocks, and f1(x) = r1*(I2-I1) 2 I1 is the average brightness of the first image block, I2 is the average brightness of the second image block, and r1 is a preset first ratio. In practical applications, the rate of change of the first similarity can be adjusted by adjusting r1, and the larger r1 is, the higher the rate of change of the first similarity.
[0018] In one embodiment provided in the first aspect, the contrast difference and the second similarity of the first image block and the second image block satisfy the following formula:
[0019]
[0020] Where Loss2 is the second similarity, f2(x) is the contrast difference between the first and second image patches, and f2(x) = r2*(contrast2-contrast1) 2 Here, contrast1 represents the contrast of the first image block, contrast2 represents the contrast of the second image block, and r2 is a preset second ratio. In practical applications, the rate of change of the second similarity can be adjusted by adjusting r2, and the larger r2 is, the higher the rate of change of the second similarity.
[0021] In one embodiment provided in the first aspect, the brightness difference between the first image block and the second image block and the third similarity satisfy the following formula:
[0022]
[0023] Where Loss3 is the third similarity score, f3(x) is the difference in brightness between the first and second image blocks, and f3(x) = r3*(High_d + Low_d). 2 High_d represents the high brightness difference, Low_d represents the low brightness difference, and r3 is a preset third ratio. The high brightness difference is the difference between the first and second high brightness values, and the low brightness difference is the difference between the first and second low brightness values. The first high brightness value is the average brightness value of the bright pixels in the first image block, the second high brightness value is the average brightness value of the bright pixels in the second image block, and the first low brightness value is the average brightness value of the low brightness pixels in the first and second image blocks. In practical applications, the rate of change of the third similarity can be adjusted by adjusting r3, and the larger r3 is, the higher the rate of change of the third similarity.
[0024] In one embodiment provided in the first aspect, the aforementioned bright pixels are pixels with a brightness value greater than a first threshold, and the low-brightness pixels are pixels with a brightness value less than a second threshold, wherein the second threshold is less than the first threshold.
[0025] Secondly, embodiments of this application provide an electronic device, the electronic device including: a memory and a processor; the processor being coupled to the memory; wherein the memory is used to store computer program code, the computer program code including computer instructions; when the computer instructions are executed by the processor, the electronic device performs the method as described in the first aspect and any of its embodiments.
[0026] Thirdly, embodiments of this application provide a computer-readable storage medium including computer instructions; when the computer instructions are executed on an electronic device, the electronic device causes the electronic device to perform the method as described in the first aspect and any of its embodiments.
[0027] Fourthly, embodiments of this application provide a computer program product, including computer instructions; when the computer instructions are executed on an electronic device, the electronic device causes the electronic device to perform the method as described in the first aspect and any of its embodiments.
[0028] The technical effects of any of the second to fourth aspects can be found in the technical effects of different design methods in the first aspect, and will not be repeated here. Attached Figure Description
[0029] Figure 1A A schematic diagram illustrating the comparison of image similarity is shown;
[0030] Figure 1A A schematic diagram of the hardware structure of an electronic device provided in an embodiment of this application;
[0031] Figure 2 A flowchart illustrating an image similarity determination method provided in an embodiment of this application;
[0032] Figure 3 This is a schematic diagram illustrating the result of block processing provided in an embodiment of this application;
[0033] Figure 4 A similarity graph of 1 is provided for an embodiment of this application;
[0034] Figure 5 A flowchart illustrating another image similarity determination method provided in an embodiment of this application;
[0035] Figure 6 A flowchart illustrating another image similarity determination method provided in this application embodiment;
[0036] Figure 7 This is a schematic diagram of a chip system provided in an embodiment of this application. Detailed Implementation
[0037] Hereinafter, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature. In the description of this embodiment, unless otherwise stated, "a plurality of" means two or more.
[0038] In this application, the terms "exemplary" or "for example" are used to indicate that something is an example, illustration, or description. Any embodiment or design described as "exemplary" or "for example" in this application should not be construed as being better or more advantageous than other embodiments or designs. Specifically, the use of terms such as "exemplary" or "for example" is intended to present the relevant concepts in a specific manner to facilitate understanding.
[0039] This application provides an image similarity determination method that can be applied to scenarios where it is necessary to evaluate the brightness difference between two images.
[0040] For example, in a shooting scenario, an electronic device can determine the image similarity between the captured image (which can be called the captured image) and the target image, and automatically adjust the exposure parameters when the image similarity is less than a threshold, so that the brightness of the newly captured image by the electronic device is close to the brightness of the target image.
[0041] For example, in artificial intelligence (AI) training scenarios, electronic devices can determine the image similarity between the AI-generated image and the target image, and adjust the AI parameters based on the image similarity so that the AI-generated image can meet the brightness standard of the target image.
[0042] For example, in the scenario of quality debugging of shooting equipment, the image similarity between the image captured by the shooting equipment and the target image can be determined, and the potential quality problems of the shooting equipment can be evaluated based on the image similarity.
[0043] It should be noted that the image similarity determination method provided in this application embodiment can also be applied to other scenarios, which will not be elaborated here.
[0044] In related technologies, devices can evaluate the similarity between two images using parameters such as PSNR, SSIM, MSE, MS-SSIM, and cosine similarity. PSNR assesses image similarity based on the error between pixels. SSIM measures image similarity from three aspects: brightness, contrast, and structure. MSE reflects the similarity of outliers in an image. MS-SSIM analyzes the contrast and structure of an image at different resolutions to determine image similarity. Cosine similarity converts the image into vector form and calculates the similarity between two vectors, thus better reflecting the similarity in overall style.
[0045] While the aforementioned parameters take into account that image brightness and contrast affect image similarity, they do not consider that the human eye perceives image differences differently under different brightness and contrast variations.
[0046] Understandably, the human eye perceives image differences according to the following rules: when the brightness levels of two images differ significantly, the human eye is more sensitive to these differences, meaning it is easier to perceive the differences between the two images, and therefore perceives a lower degree of similarity between them. Conversely, when the brightness levels of two images are similar, the human eye is less sensitive to these differences, meaning it is less likely to perceive the differences between them, and therefore perceives a higher degree of similarity between them. Furthermore, these rules are even more pronounced when the field of view (FOV) of the two images is similar.
[0047] For example, Figure 1A This illustrates a comparison of image similarity. For example... Figure 1AAs shown, the image similarity between image 1 and image 2 is 1, and the image similarity between image 1 and image 3 is 2. The brightness levels of image 1 and image 2 are relatively close, while the brightness levels of image 1 and image 3 differ significantly. Therefore, image similarity 1 is greater than image similarity 2.
[0048] Taking SSIM as an example, the formula for calculating SSIM is as follows:
[0049]
[0050] Where, μ x μ y σ represents the mean of the two images (which can be used to reflect the brightness of the images). x σ y C1 and C2 are the standard deviations of the two images (which can be used to reflect the contrast of the images), and are preset constants.
[0051] According to the SSIM calculation formula, it only considers the influence of brightness and contrast of two images on image similarity, without considering the influence of brightness difference and contrast difference between the two images on image similarity. This results in inaccurate image similarity and does not conform to the human eye's judgment of image differences.
[0052] Furthermore, the above methods fail to consider that the brightness of both bright and dark areas in an image also affects image similarity, and they almost entirely consider the image as a whole, neglecting local details. In short, the above methods for evaluating image similarity are inaccurate and do not conform to the human eye's judgment of image differences.
[0053] In this article, for the sake of simplicity, the brightness of the bright areas and the brightness of the dark areas can be simply referred to as: high and low brightness.
[0054] To at least address the aforementioned issues, embodiments of this application provide an image similarity determination method. This method can determine image similarity based on the brightness difference, contrast difference, and high / low brightness difference between a first image and a second image. Furthermore, the greater the brightness difference, contrast difference, or high / low brightness difference, the smaller the image similarity, and the greater the rate of change in image similarity.
[0055] The rate of change of image similarity refers to how quickly image similarity changes as image differences evolve. In other words, the greater the difference in brightness, contrast, or high / low brightness, the faster the image similarity changes; conversely, the smaller the difference in brightness, contrast, or high / low brightness, the slower the image similarity changes.
[0056] It can be seen that the greater the difference in brightness, contrast, or high and low brightness, the smaller the image similarity and the greater the rate of change of image similarity. This makes the trend of image similarity change conform to the pattern of human eye perception of image differences. Therefore, the image similarity obtained by the embodiments of this application is more in line with the human eye's judgment of image differences under different brightness conditions, and shows higher reliability in practical applications.
[0057] The image similarity determination method provided in this application can be applied to electronic devices, such as mobile phones, tablets, desktops, laptops, handheld computers, laptops, ultra-mobile personal computers (UMPCs), netbooks, as well as cellular phones, personal digital assistants (PDAs), augmented reality (AR) / virtual reality (VR) devices, and other devices capable of processing data. This application does not impose any special limitations on the specific form of the electronic device.
[0058] Please see Figure 1B This is a schematic diagram of the hardware structure of an electronic device provided in an embodiment of this application. Figure 1B As shown, the electronic device 100 may include: a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, a headphone jack 170D, a sensor module 180, buttons 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc.
[0059] The processor 110 may include one or more processing units, such as an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural network processing unit (NPU). These different processing units may be independent devices or integrated into one or more processors.
[0060] The controller can be the nerve center and command center of the electronic device 100. The controller can generate operation control signals according to the instruction opcode and timing signals to complete the control of fetching and executing instructions.
[0061] The processor 110 may also include a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. This memory can store instructions or data that the processor 110 has just used or that are used repeatedly. If the processor 110 needs to use the instruction or data again, it can retrieve it directly from the memory.
[0062] In some embodiments, the processor 110 may include one or more interfaces. Interfaces may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.
[0063] It is understood that the interface connection relationships between the modules illustrated in this embodiment are merely illustrative and do not constitute a structural limitation on the electronic device 100. In other embodiments, the electronic device 100 may also employ different interface connection methods or combinations of multiple interface connection methods as described in the above embodiments.
[0064] The external storage interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device. The external memory card communicates with the processor 110 through the external storage interface 120 to perform data storage functions. For example, music, video, and other files can be saved on the external memory card.
[0065] Internal memory 121 can be used to store computer executable program code, which includes instructions. Processor 110 executes various functional applications and data processing of the electronic device by running the instructions stored in internal memory 121.
[0066] The internal memory 121 may include a program storage area and a data storage area. The program storage area may store the operating system, at least one application program required for a function (such as a camera application), etc. The data storage area may store data created during the use of the electronic device (such as image data and image similarity data involved in this solution), etc. Furthermore, the internal memory 121 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, universal flash storage (UFS), etc.
[0067] It is understood that the structure illustrated in this embodiment does not constitute a specific limitation on the electronic device 100. In other embodiments, the electronic device 100 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0068] The following embodiments can all be implemented in electronic devices with the above-described hardware structure.
[0069] Please see Figure 2 This is a flowchart illustrating an image similarity determination method provided in an embodiment of this application. Figure 2 As shown, the image similarity determination method includes at least S201 to S206.
[0070] S201, the electronic device acquires the first image and the second image.
[0071] The first image and the second image are different; the first image can be a pre-set image, and the second image is the image to be compared.
[0072] The second image can vary depending on the application scenario. For example, in a shooting scenario, the second image can be an image captured by an electronic device. In an AI training scenario, the second image can be an image generated by AI using the electronic device, or an AI-generated image received by the electronic device. In a quality calibration scenario, the second image can be an image captured by an electronic device that needs quality calibration.
[0073] It should be noted that the first and second images can adopt color encoding modes such as RGB, YUV, and YCbCr, and this application embodiment does not impose specific restrictions on this.
[0074] S202, the electronic device performs at least one block-segmentation process on the first image and the second image to obtain multiple image block pairs.
[0075] In this embodiment of the application, the electronic device pre-stores segmentation information. The electronic device can perform segmentation processing on the first image and the second image according to the segmentation information. The segmentation information can be used to indicate the number of times the electronic device performs segmentation processing on each image (which can be simply referred to as the number of segmentations) and the number of image blocks obtained in each segmentation processing.
[0076] In one possible implementation, the segmentation information may include N segmentation parameters, where N is the number of segmentations. Each segmentation parameter indicates the number of image blocks obtained by the electronic device performing one segmentation process on the image, where N ≥ 1. For example, a segmentation parameter of 4 indicates that the electronic device can divide the image into 4 image blocks. Another example is a segmentation parameter of 16, which indicates that the electronic device can divide the image into 16 image blocks.
[0077] Optionally, the above-mentioned segmentation information may also carry the segmentation method corresponding to each segmentation parameter. For example, if the segmentation parameter is 4, the corresponding segmentation method can be to divide the image equally in a 2×2 or 4×1 manner. As another example, if the segmentation parameter is 16, the corresponding segmentation method can be to divide the image equally in a 4×4, 8×2, or 16×1 manner.
[0078] In another possible implementation, the block information may include N sets of size parameters, where N is the number of blocks. Each set of size parameters is used to indicate the size of each image block obtained by the electronic device performing one block processing on the image, and N≥1.
[0079] The following text will use the example of block information including N block parameters for illustration.
[0080] In one implementation, the electronic device can perform N block-segmentation processes on both the first and second images based on N block-segmentation parameters, with different block-segmentation parameters used in each process. For example, if the block-segmentation information includes three block-segmentation parameters (4, 16, and 36), the electronic device can perform three block-segmentation processes on both the first and second images. For the first image, the three block-segmentation processes can sequentially divide it into 4, 16, and 36 image blocks; similarly, for the second image, the three block-segmentation processes can sequentially divide it into 4, 16, and 36 image blocks. This processing method involves sequentially performing multiple block-segmentation processes on either the first or second image, eliminating the need for additional storage of the first and second images and thus saving memory resources.
[0081] As another implementation, the electronic device can generate N first images and N second images, and perform block processing on each first image and each second image based on different block parameters. For example, if the block information includes three block parameters of 4, 16, and 36, the electronic device can generate first image 1, first image 2, first image 3, and second image 1, second image 2, and second image 3, dividing first image 1 into 4 image blocks, first image 2 into 16 image blocks, and first image 3 into 36 image blocks, and second image 1 into 4 image blocks, second image 2 into 16 image blocks, and second image 3 into 36 image blocks. This method facilitates the electronic device to perform the block processing of N first images or N second images in parallel, saving processing time and improving efficiency.
[0082] It should be noted that the embodiments of this application do not limit the way the image is segmented, as long as the electronic device uses the same method to divide the first image and the second image into the same number of image blocks.
[0083] In this embodiment of the application, an image block pair includes: image block 1 belonging to the first image, and image block 2 belonging to the second image with the same size and corresponding position as image block 1. It can be understood that the fact that image block 1 and image block 2 have the same size indicates that image block 1 and image block 2 were obtained by the electronic device from dividing the first image and the second image into blocks based on the same block parameters (also known as the same block method). For example, if the electronic device divides both the first image and the second image into 16 image blocks, then image block 1 is one of the 16 image blocks of the first image, and image block 2 is one of the 16 image blocks of the second image.
[0084] The correspondence between image block 1 and image block 2 can be understood as the same position of image block 1 in the first image as the same position of image block 2 in the second image. For example, as... Figure 3As shown, the electronic device divides a first image into four image blocks arranged in a 2×2 pattern; and the electronic device also divides a second image into four image blocks arranged in a 2×2 pattern; wherein image block 301 corresponds to image block 302, and image block 303 corresponds to image block 304. Thus, an image block pair may include image block 301 and image block 302, or alternatively, an image block pair may include image block 303 and image block 304.
[0085] S203, the electronic device determines the similarity of brightness (denoted as similarity 1), contrast (denoted as similarity 2), and high and low brightness (denoted as similarity 3) of each image patch pair.
[0086] In this paper, for ease of understanding, the similarity 1, similarity 2 and similarity 3 of the image patch pair are referred to as the similarity 1, similarity 2 and similarity 3 of image patch 1 and image patch 2.
[0087] In the embodiments of this application, the difference in brightness level between two images can be reflected at least by brightness, contrast, and high / low brightness.
[0088] Thus, similarity 1 reflects the similarity between image patch 1 and image patch 2 in terms of brightness, similarity 2 reflects the similarity between image patch 1 and image patch 2 in terms of contrast, and similarity 3 reflects the similarity between image patch 1 and image patch 2 in terms of high and low brightness. Specifically, the higher the similarity 1, the greater the similarity between image patch 1 and image patch 2 in terms of brightness, meaning the brightness of image patch 2 is closer to that of image patch 1; the higher the similarity 2, the greater the similarity between image patch 1 and image patch 2 in terms of contrast, meaning the contrast of image patch 2 is closer to that of image patch 1; and the higher the similarity 3, the greater the similarity between image patch 1 and image patch 2 in terms of high and low brightness, meaning the high and low brightness of image patch 2 is closer to that of image patch 1.
[0089] Among them, similarity 1 is associated with the brightness difference between image patch 1 and image patch 2, and the greater the brightness difference between image patch 1 and image patch 2, the smaller the similarity 1; similarity 2 is associated with the contrast difference between image patch 1 and image patch 2, and the greater the contrast difference between image patch 1 and image patch 2, the smaller the similarity 2; similarity 3 is associated with the high and low brightness difference between image patch 1 and image patch 2, and the greater the high and low brightness difference between image patch 1 and image patch 2, the smaller the similarity 3.
[0090] Since the calculation of similarity 1, similarity 2 and similarity 3 all involve the brightness value of each pixel in the image block, the process of determining the brightness value of each pixel in the image block will be introduced first below.
[0091] When the first and second images use color encoding modes with a Y component, such as YUV or YCbCr, the Y component of each pixel represents its brightness. Thus, the electronic device can determine the brightness value of each pixel by reading its Y component.
[0092] When the first and second images use RGB color encoding mode, the electronic device can convert the first and second images into grayscale images, where the pixel value of each pixel in the grayscale image is the brightness value of that pixel. Alternatively, the electronic device can convert the RGB format image into YUV, YCbCr, or other formats, and read the Y component of each pixel to determine the brightness value of each pixel.
[0093] In this embodiment, the electronic device can also normalize the brightness value of each pixel. Optionally, the electronic device can map the brightness value of the pixel to the range of [0,1]. This helps to improve the efficiency and accuracy of subsequent processing.
[0094] When determining the similarity 1, the electronic device can first determine the brightness difference between image block 1 and image block 2, and then determine the similarity 1 based on the brightness difference. In this embodiment, the brightness difference between image block 1 and image block 2 can be represented by the difference between brightness value 1 and brightness value 2, wherein brightness value 1 can be used to reflect the brightness level of image block 1, and brightness value 2 can be used to reflect the brightness level of image block 2. As an example, brightness value 1 can be the average brightness value of all pixels in image block 1, and brightness value 2 can be the average brightness value of all pixels in image block 2.
[0095] In this embodiment, the electronic device can first calculate the brightness difference based on brightness value 1 and brightness value 2. In an optional implementation, the brightness difference satisfies formula 1 with respect to brightness value 1 and brightness value 2:
[0096] f1(x)=r1*(I2-I1) 2 Formula 1
[0097] Where f1(x) is the brightness difference, I2 is the brightness value 2, I1 is the brightness value 1, and r1 is the preset first ratio.
[0098] Then, the electronic device calculates a similarity score of 1 based on the brightness difference. The similarity score of 1 and the brightness difference satisfy the following conditions:
[0099] Formula 2:
[0100]
[0101] Loss1 represents a similarity score of 1.
[0102] Combining equations 1 and 2, we can see that the relationship between similarity 1 and brightness difference can be expressed as follows: Figure 4 The curve shown is illustrated. In Figure 4 As the brightness difference changes from 0 to 1, the similarity 1 gradually changes from 1 to 0. This means that the greater the brightness difference between image patch 1 and image patch 2, the smaller the similarity 1.
[0103] according to Figure 4 The curve shown also reveals that as the brightness difference changes from 0 to 1, the rate of change of similarity 1 gradually increases. Understandably, the rate of change of similarity 1 can be used to represent how quickly similarity 1 changes; a larger rate of change indicates that similarity 1 changes faster, and a smaller rate of change indicates that similarity 1 changes slower. In other words, the greater the brightness difference, the greater its impact on similarity 1, which is equivalent to a higher sensitivity to image differences, consistent with the way the human eye perceives image differences. It should be noted that adjusting r1 can change the rate of change of similarity 1; a larger r1 results in a larger rate of change of similarity 1. Therefore, in practical applications, users can adjust r1 to... Figure 4 The curve shown matches the human eye's visual perception of differences in images.
[0104] In one alternative implementation, the process of determining a similarity of 1 by the above-mentioned electronic device can be implemented by the following code:
[0105] Loss1 = 1 - np.clip(r1 * (I2 - I1)) 2 ,0,1)
[0106] Where I2 is the brightness value 2, I1 is the brightness value 1, and np.clip is a function in the Numerical Python (NumPy) database used to limit the values in the array to a specified minimum and maximum value.
[0107] When determining the similarity 2, the electronic device can first determine the contrast difference between image block 1 and image block 2, and then determine the similarity 2 based on the contrast difference. In the embodiments of this application, the contrast difference between image block 1 and image block 2 can be represented by the difference between contrast 1 and contrast 2, where contrast 1 is the contrast of image block 1 and contrast 2 is the contrast of image block 2.
[0108] In this embodiment of the application, the electronic device can first calculate the contrast of image block 1 (i.e., contrast 1) and the contrast of image block 2 (i.e., contrast 2) based on the following formula 3.
[0109] Contrast = (Imax - Imin) / (Imax + Imin) (Formula 3)
[0110] Where contrast is the contrast ratio, Imax is the maximum brightness value, and Imin is the minimum brightness value.
[0111] Thus, the electronic device can calculate contrast 1 based on the maximum and minimum brightness values in image block 1, and contrast 2 based on the maximum and minimum brightness values in image block 2.
[0112] Considering that the contrast calculation using the above formula 3 may result in calculation errors when the brightness of some image blocks is extremely low, this embodiment of the application can add a minimum value (minvalue), such as 0.000001 or 0.0000001, to the denominator of the above formula 3 to increase the distinguishability between the numerator and denominator and reduce the risk of calculation errors. In other words, electronic devices can also calculate contrast using the following formula 4.
[0113] Contrast = (Imax - Imin) / (Imax + Imin + minvalue) (Formula 4)
[0114] After calculating contrast ratio 1 and contrast ratio 2, the electronic device can determine the contrast difference based on contrast ratio 1 and contrast ratio 2. In an optional implementation, the contrast difference satisfies equation 5 with contrast ratio 1 and contrast ratio 2:
[0115] f2(x)=r2*(contrast2-contrast1) 2 Equation 5
[0116] Where f2(x) is the contrast difference, contrast2 is contrast 2, contrast1 is contrast 1, and r2 is a pre-set second ratio.
[0117] Finally, the electronic device can determine the similarity 2 based on the contrast difference. In an optional implementation, the similarity 2 and the contrast difference satisfy equation 6:
[0118]
[0119] Loss2 represents the similarity score of 2.
[0120] It should be noted that the curve showing the change in similarity 2 can be compared with... Figure 4 The curve showing the change in similarity 1 is similar: as the contrast difference changes from 0 to 1, the similarity 2 gradually changes from 1 to 0, which means that the greater the contrast difference between image patch 1 and image patch 2, the smaller the similarity 2.
[0121] Furthermore, as the contrast difference changes from 0 to 1, the rate of change of similarity 2 gradually increases. Understandably, the rate of change of similarity 2 can be used to represent how quickly similarity 2 changes; a larger rate of change indicates that similarity 2 changes faster, and a smaller rate of change indicates that similarity 2 changes slower. In other words, the greater the contrast difference, the greater its impact on similarity 2, which is equivalent to a higher sensitivity to image differences, consistent with the way the human eye perceives image differences. Similarly, adjusting r2 can change the rate of change of similarity 2; a larger r2 results in a larger rate of change of similarity 2.
[0122] In one alternative implementation, the process of determining similarity 2 by the above-mentioned electronic device can be implemented by the following code:
[0123] contrast(img)=(np.max(img)-np.max(min)) / (np.max(img)+np.max(min)+0.000001)
[0124] contrast_error_patch=abs(contrast(I2)-contrast(I1))
[0125] Loss2=1-np.clip(r2*(contrast_error_patch) 2 ,0,1)
[0126] Where contrast(img) represents the image contrast, np.max(img) is the maximum brightness value in the image, np.max(min) is the minimum brightness value in the image, contrast(I2) is the contrast of the second image (i.e., contrast 2), contrast(I1) is the contrast of the first image (i.e., contrast 1), contrast_error_patch is the contrast difference, Loss2 is the similarity 2, and abs is the absolute value function.
[0127] When determining the similarity 3, the electronic device can first determine the brightness difference between image block 1 and image block 2, and then determine the similarity 3 based on this brightness difference. The brightness difference can be determined by high brightness difference and low brightness difference. High brightness difference reflects the difference in brightness level between bright pixels in image block 1 and bright pixels in image block 2, while low brightness difference reflects the difference in brightness level between low brightness pixels in image block 1 and low brightness pixels in image block 2. Bright pixels can be pixels with brightness values greater than a first threshold, and low brightness pixels can be pixels with brightness values less than a second threshold, where the second threshold is less than the first threshold. For example, the first threshold is 0.8, and the second threshold is 0.1. It should be noted that this embodiment does not limit the first and second thresholds; users can set them according to their actual needs.
[0128] As an example, the high brightness difference can be the difference between high brightness value 1 and high brightness value 2, and the low brightness difference can be the difference between low brightness value 1 and low brightness value 2. Here, high brightness value 1 is the average brightness value of the high-brightness pixels in image block 1, high brightness value 2 is the average brightness value of the high-brightness pixels in image block 2, low brightness value 1 is the average brightness value of the low-brightness pixels in image block 1, and low brightness value 2 is the average brightness value of the low-brightness pixels in image block 2. The high brightness difference and low brightness difference can satisfy equations 7 and 8, respectively:
[0129] High_d = |h_light2 - h_light1| * 1 / 2 (Equation 7)
[0130] Low_d = |l_light2-l_light1|*1 / 2 (Equation 8)
[0131] Where High_d represents high brightness difference, Low_d represents low brightness difference, h_light1 represents high brightness value 1, h_light2 represents high brightness value 2, l_light1 represents low brightness value 1, and l_light2 represents low brightness value 2.
[0132] In this embodiment, the electronic device can determine the high / low brightness difference based on the high brightness difference and the low brightness difference. The high / low brightness difference, the high brightness difference, and the low brightness difference satisfy equation 9:
[0133] f3(x) = r3 * [(High_d + Low_d)] 2 Equation 9
[0134] Where f3(x) represents the difference between high and low brightness, and r3 is a pre-set third ratio.
[0135] In this embodiment of the application, the electronic device can determine a similarity level 3 based on the difference between high and low brightness. The similarity level 3 and the difference between high and low brightness satisfy formula 10:
[0136]
[0137] Loss3 represents a similarity score of 3.
[0138] It should be noted that the curve showing the change in similarity level 3 can be compared with... Figure 4 The curve showing the change in similarity 1 is similar: as the difference between high and low brightness changes from 0 to 1, the similarity 3 gradually changes from 1 to 0. This means that the greater the difference between high and low brightness between image block 1 and image block 2, the smaller the similarity 3.
[0139] Furthermore, as the difference in brightness between high and low levels changes from 0 to 1, the rate of change of similarity 3 gradually increases. Understandably, the rate of change of similarity 3 can be used to represent how quickly similarity 3 changes; a larger rate of change indicates that similarity 3 changes faster, and a smaller rate of change indicates that similarity 3 changes slower. In other words, the greater the difference in brightness between high and low levels, the greater its impact on similarity 3, which is equivalent to a higher sensitivity to image differences, consistent with the way the human eye perceives image differences. Similarly, adjusting r3 can change the rate of change of similarity 3; a larger r2 results in a larger rate of change of similarity 3.
[0140] In one alternative implementation, the process of determining similarity 3 by the above-mentioned electronic device can be implemented by the following code:
[0141] Hilight_error_patch=abs[Hilight(I2)-Hilight(I1)]*1 / 2
[0142] Dark_error_patch=abs[Dark(I2)-Dark(I1)]*1 / 2
[0143] Hilight_Dark_error_patch=Hilight_error_patch+Dark_error_patch
[0144] Loss3=1-np.clip(r3*(Hilight_Dark_error_patch) 2 ,0,1)
[0145] Here, Hilight_error_patch represents high brightness difference, Hilight(I2) represents the average brightness value of the bright pixels in image patch 2 (i.e., brightness value 2), Hilight(I1) represents the average brightness value of the bright pixels in image patch 1 (i.e., brightness value 1), Dark_error_patch represents low brightness difference, Dark(I2) represents the average brightness value of the low brightness pixels in image patch 2 (i.e., low brightness value 2), Dark(I1) represents the average brightness value of the low brightness pixels in image patch 1 (i.e., low brightness value 1), Hilight_Dark_error_patch represents high and low brightness difference, and Loss3 represents similarity 3.
[0146] The preceding text describes the process of calculating similarity 1, similarity 2, and similarity 3 based on formulas 1 to 10. However, in other embodiments, the electronic device may also determine similarity 1, similarity 2, and similarity 3 in other ways. For example, the electronic device may be pre-configured with mapping tables 1 to 10, which respectively satisfy the mapping relationships of formulas 1 to 10. In this way, the electronic device can determine similarity 1, similarity 2, and similarity 3 by querying the mapping tables.
[0147] S204, the electronic device obtains the brightness similarity 1 of the image patch pair based on the similarity 1, similarity 2 and similarity 3 of each image patch pair.
[0148] The brightness similarity 1 of the image patch pair is the sum of the similarity 1, similarity 2 and similarity 3 of the image patch pair.
[0149] S205, the electronic device statistically analyzes the brightness similarity 1 of image block pairs belonging to the same group of images to obtain at least one brightness similarity 2.
[0150] Here, an image patch pair belonging to the same group of images refers to an image patch pair where the first image patch comes from the same first image and the second image comes from the same second image. For example, Figure 3 The image block pairs including image block 301 and image block 302, and the image block pairs including image block 303 and image block 304 belong to the same group of images.
[0151] In this embodiment of the application, the electronic device can accumulate the brightness similarity 1 of image block pairs belonging to the same group of images to obtain at least one brightness similarity 2.
[0152] For example, Figure 2 The four image block pairs obtained by dividing the first and second images into blocks belong to the same group of images. The brightness similarity 1 of the four image block pairs can be added together to obtain the brightness similarity 2 of the first and second images. Figure 2The 16 image block pairs obtained by dividing the first and second images into blocks belong to the same group of images. The brightness similarity 1 of these 16 image block pairs can be added together to obtain the brightness similarity 2 of the first and second images. Figure 2 The 36 image block pairs obtained by segmenting the first and second images belong to the same group. Adding the brightness similarity scores (1) of these 36 image block pairs yields the brightness similarity score (2) between the first and second images. In other words, Figure 2 The process shown yields three brightness similarity scores of 2.
[0153] S206, the electronic device obtains the image similarity by weighted summation of at least one brightness similarity 2.
[0154] When the electronic device performs a block-based processing on the first image and the second image, the electronic device can obtain a brightness similarity 2, and the image similarity between the first image and the second image is this brightness similarity 2.
[0155] When the electronic device performs multiple block processing on the first image and the second image, the electronic device can obtain multiple brightness similarity scores 2. The electronic device then performs a weighted summation of the multiple brightness similarity scores 2 to obtain the image similarity score.
[0156] On the one hand, the above embodiments take into account the different sensitivities of the human eye to image differences at different brightness levels. They comprehensively consider the influence of brightness level on image similarity from three aspects: brightness, contrast, and high and low brightness, so that the obtained image similarity is more in line with the human eye's visual perception of image differences and is more accurate.
[0157] On the other hand, the above-mentioned scheme calculates the similarity 1, similarity 2, and similarity 3 independently for each image patch pair, which can capture image features at different scales. This not only improves the sensitivity of electronic devices to local details but also enhances the robustness of the scheme. Therefore, when the image similarity determination method provided by this scheme is applied to different business scenarios, its accuracy can make business processes more reliable.
[0158] The above-mentioned methods primarily consider the similarity of two images in terms of brightness levels, but the overall style of the images also has a certain impact on image similarity. Therefore, this application also provides another image similarity method, which can evaluate the overall style of two images and use the overall style of the two images as an influencing factor on image similarity.
[0159] Please see Figure 5 This is a flowchart illustrating another image similarity determination method provided in an embodiment of this application. Figure 5 As shown, the image similarity determination method provided in this application embodiment is compared to... Figure 2The image similarity determination method shown also includes S306 and S307.
[0160] S306, the electronic device determines the stylistic similarity between the first image and the second image.
[0161] In this embodiment of the application, the electronic device can extract feature map 1 from the first image and feature map 2 from the second image. Figure 2 And based on feature map 1 and features Figure 2 Determine style similarity. The feature map of an image reflects its overall structure and style.
[0162] In one possible design, the image and feature map satisfy equation 11:
[0163] gram = I*I T Equation 11
[0164] Where gram is the feature map, I is the image, and I T This is the transpose of the image. It should be noted that the transpose of the image is obtained by simply swapping the rows and columns.
[0165] Thus, the electronic device can calculate feature map 1 and feature map 2 according to formula 11. Figure 2 .
[0166] After calculating feature map 1 and feature... Figure 2 Then, the electronic device can, according to feature map 1 and feature map 2, perform the following steps: Figure 2 Determine style similarity. In one possible implementation, style similarity, feature map 1, and features... Figure 2 Satisfying equation 12:
[0167]
[0168] Where gram1 is feature map 1, and gram2 is feature map 2. Figure 2 xi∈gram3, where gram3 is the difference between gram2 and gram1, and M is the number of elements in gram3.
[0169] As can be seen, gram loss can effectively capture the style information of an image by modeling the statistical properties of image features.
[0170] To reduce the impact of outliers on image similarity and improve the efficiency of subsequent calculations, electronic devices can first analyze feature map 1 and feature map 2. Figure 2 The normalized result is then used to calculate style similarity.
[0171] In one possible design, the above S306 can be implemented using the following code:
[0172] I1_T = np.transpose(I1)
[0173] gram1 = np.dot(I1, I1_T)
[0174] I2_T = np.transpose(I2)
[0175] gram2 = np.dot(I2, I2_T)
[0176] gram_loss=np.mean[abs(normalization(gram1)-normalization(gram2))]
[0177] Where I1 is the first image, I1_T is the transpose of the first image, I2 is the second image, I2_T is the transpose of the second image, gram1 is feature map 1, and gram2 is feature map 2. Figure 2 gram_loss represents style similarity, np.transpose is the transpose function, np.dot is used to calculate the dot product, np.mean is used to calculate the mean, and normalization is used for normalization.
[0178] In other embodiments, the electronic device may also calculate parameters such as PSNR, SSIM, MSE, MS-SSIM, and cosine similarity of the first and second images as style similarity.
[0179] S307, the electronic device obtains image similarity based on at least one brightness similarity 2 and style similarity.
[0180] In this embodiment, the electronic device can first perform a weighted summation of at least one brightness similarity 2 to obtain a brightness similarity 3, and then perform a weighted summation of brightness similarity 3 and style similarity to obtain an image similarity. Wherein, brightness similarity 3 and style similarity satisfy formula 13:
[0181] final_loss=gram_loss*r4+(1-r4)*final_error_patch equation 13
[0182] Where final_loss is the image similarity, gram_loss is the style similarity, final_error_patch is the brightness similarity 3, and r4 is the pre-set fourth ratio.
[0183] As can be seen, the embodiments of this application determine image similarity by combining local brightness differences and global style information, which can simultaneously reflect the differences between the first image and the second image in terms of overall style and local details. Therefore, when the image similarity determination method provided by the embodiments of this application is applied to business scenarios, it can not only provide more refined adjustments in local detail processing, but also help maintain the overall style consistency of the image, improve the visual effect and artistic expression of the image, and thus achieve a more outstanding image processing effect.
[0184] In one possible implementation, the electronic device may not need to segment the first and second images. This approach considers the overall brightness of the images, requires relatively less computation, and can improve the efficiency of obtaining image similarity.
[0185] Please see Figure 6 This is a flowchart illustrating another image similarity determination method provided in an embodiment of this application. Figure 6 As shown, the method includes:
[0186] S601, the electronic device acquires the first image and the second image.
[0187] For details regarding the first and second images, please refer to S201; they will not be repeated here.
[0188] S602, the electronic device determines the similarity 4, similarity 5 and similarity 6 between the first image and the second image.
[0189] Among them, similarity 4, similarity 5 and similarity 6 can reflect the degree of similarity between the first image and the second image in terms of brightness, contrast and high and low brightness, respectively.
[0190] The process for determining the similarity 4 mentioned above can be referred to in S203 for determining the similarity 1 between image block 1 and image block 2. The process for determining the similarity 5 mentioned above can be referred to in S203 for determining the similarity 2 between image block 1 and image block 2. The process for determining the similarity 5 mentioned above can be referred to in S203 for determining the similarity 3 between image block 1 and image block 2. No specific restrictions are made here.
[0191] S603, the electronic device determines the image similarity based on similarity 4, similarity 5 and similarity 6.
[0192] In this embodiment of the application, the image similarity is the sum of similarity 4, similarity 5 and similarity 6.
[0193] Alternatively, without performing block processing on the first and second images, the electronic device can also determine the style similarity described in S306, and then perform a weighted sum of the style similarity and the result obtained in S603 to obtain the image similarity.
[0194] In summary, the image similarity determination method provided in this application takes into account both local brightness and overall style, and the resulting image similarity is more consistent with the human eye's perception of image differences under different brightness conditions, thus possessing high reliability.
[0195] This application also provides a chip system, such as... Figure 7 As shown, the chip system 700 includes at least one processor 701 and at least one interface circuit 702. The processor 701 and the interface circuit 702 are interconnected via lines. For example, the interface circuit 702 can be used to receive signals from other devices (e.g., the memory of an electronic device). As another example, the interface circuit 702 can be used to send signals to other devices (e.g., the processor 701). Exemplarily, the interface circuit 702 can read instructions stored in memory and send those instructions to the processor 701. When the instructions are executed by the processor 701, the electronic device or server can perform the steps in the above embodiments. Of course, the chip system may also include other discrete components, which are not specifically limited in this application embodiment.
[0196] This embodiment also provides a computer-readable storage medium storing computer instructions that, when executed on an electronic device, cause the electronic device to perform the various functions or steps described in the above method embodiments.
[0197] This embodiment also provides a computer program product that, when run on a computer, causes the computer to perform the various functions or steps in the above method embodiments.
[0198] In addition, embodiments of this application also provide an apparatus, which may specifically be a chip, component or module. The apparatus may include a connected processor and a memory. The memory is used to store computer execution instructions. When the apparatus is running, the processor can execute the computer execution instructions stored in the memory to cause the chip to perform the various functions or steps performed by the mobile phone in the above method embodiments.
[0199] In this embodiment, the electronic device, communication system, computer-readable storage medium, computer program product or chip are all used to execute the corresponding methods provided above. Therefore, the beneficial effects they can achieve can be referred to the beneficial effects in the corresponding methods provided above, and will not be repeated here.
[0200] Through the above description of the embodiments, those skilled in the art can clearly understand that, for the sake of convenience and brevity, only the division of the above functional modules is used as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.
[0201] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another device, or some features may be ignored or not executed. Furthermore, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.
[0202] The unit described as a separate component may or may not be physically separate. The component shown as a unit can be one physical unit or multiple physical units, that is, it can be located in one place or distributed in multiple different places. Some or all of the units can be selected to achieve the purpose of the solution in this embodiment according to actual needs.
[0203] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0204] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solutions of the embodiments of this application, essentially or in other words, the parts that contribute to the prior art, or all or part of the technical solutions, can be embodied in the form of a software product. This software product is stored in a storage medium and includes several instructions to cause a device (which may be a microcontroller, chip, etc.) or processor to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0205] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application and are not intended to limit it. Although this application has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of this application without departing from the spirit and scope of the technical solutions of this application.
Claims
1. A method for determining image similarity, characterized in that, The method includes: Acquire the first image and the second image; The similarity of the first image is determined based on the differences in brightness, contrast, and high and low brightness between the first image and the second image; The greater the difference in brightness, the greater the difference in contrast, or the greater the difference in brightness, the smaller the similarity of the first image, and the greater the rate of change of the similarity of the first image.
2. The method according to claim 1, characterized in that, Determining the similarity of the first image based on the brightness difference, contrast difference, and high / low brightness difference between the first image and the second image includes: The first image and the second image are divided into blocks at least once to obtain multiple image block pairs. Each image block pair includes a first image block and a second image block. The first image block is a partial region of the first image, and the second image block is a partial region of the second image. The first image block and the second image block have the same size and correspond to each other in position. The first brightness similarity of each image block pair is determined based on the brightness difference, contrast difference, and high / low brightness difference between the first image block and the second image block. The greater the brightness difference, contrast difference, or high / low brightness difference between the first image block and the second image block, the smaller the first brightness similarity, and the greater the rate of change of the first brightness similarity. Statistically calculate the first brightness similarity of image patch pairs belonging to the same group of images to obtain at least one second brightness similarity; The first image similarity is obtained by weighted summation of the at least one second brightness similarity.
3. The method according to claim 2, characterized in that, The step of determining the first brightness similarity of each image block pair based on the brightness difference, contrast difference, and high / low brightness difference between the first image block and the second image block includes: A first similarity is determined based on the brightness difference between the first image block and the second image block. The greater the brightness difference between the first image block and the second image block, the smaller the first similarity and the greater the rate of change of the first similarity. The second similarity is determined based on the contrast difference between the first image block and the second image block. The greater the contrast difference between the first image block and the second image block, the smaller the second similarity and the higher the rate of change of the second similarity. A third similarity is determined based on the difference in brightness between the first image block and the second image block. The greater the difference in brightness between the first image block and the second image block, the smaller the third similarity and the greater the rate of change of the third similarity. The first similarity, second similarity, and third similarity of each image patch pair are summed to obtain the first brightness similarity of each image patch pair.
4. The method according to claim 1, characterized in that, Determining the similarity of the first image based on the brightness difference, contrast difference, and high / low brightness difference between the first image and the second image includes: A fourth similarity is determined based on the brightness difference between the first image and the second image. The greater the brightness difference between the first image and the second image, the smaller the fourth similarity and the greater the rate of change of the fourth similarity. The fifth similarity is determined based on the contrast difference between the first image and the second image. The greater the contrast difference between the first image and the second image, the smaller the fifth similarity and the greater the rate of change of the fifth similarity. The sixth similarity is determined based on the difference in brightness between the first image and the second image. The greater the difference in brightness between the first image and the second image, the smaller the sixth similarity and the greater the rate of change of the fifth similarity. The first image similarity is determined based on the fourth similarity, the fifth similarity, and the sixth similarity.
5. The method according to any one of claims 1-4, characterized in that, The method further includes: Determine the style similarity between the first image and the second image; The second image similarity is obtained by weighted summation of the first image similarity and the style similarity.
6. The method according to claim 5, characterized in that, Determining the style similarity between the first image and the second image includes: Extract a first feature map from the first image; Extract the second feature map from the first image; The style similarity is determined based on the first feature map and the second feature map.
7. The method according to claim 6, characterized in that, The first feature map, the second feature map, and the style similarity satisfy the following: Wherein, gram_loss is the style similarity, xi is the value of the i-th element in the third feature map, the third feature map is the difference between the second feature map and the first feature map, and M is the number of elements in the third feature map.
8. The method according to any one of claims 1-7, characterized in that, The brightness difference between the first image block and the second image block and the first similarity satisfy the following formula: Where Loss1 is the first similarity, f1(x) is the brightness difference between the first image patch and the second image patch, and f1(x) = r1*(I2-I1) 2 I1 is the average brightness of the first image block, I2 is the average brightness of the second image block, and r1 is a preset first ratio.
9. The method according to any one of claims 1-7, characterized in that, The contrast difference and the second similarity between the first and second image blocks satisfy the following formula: Where Loss2 is the second similarity, f2(x) is the contrast difference between the first image patch and the second image patch, and f2(x) = r2*(contrast2-contrast1) 2 contrast1 is the contrast of the first image block, contrast2 is the contrast of the second image block, and r2 is a preset second ratio.
10. The method according to any one of claims 1-7, characterized in that, The brightness difference between the first and second image blocks and the third similarity satisfy the following formula: Where Loss3 is the third similarity, f3(x) is the difference in brightness between the first image block and the second image block, and f3(x) = r3*(High_d + Low_d). 2 High_d represents high brightness difference, Low_d represents low brightness difference, and r3 is a preset third ratio. The high brightness difference is the difference between the first high brightness value and the second high brightness value, and the low brightness difference is the difference between the first low brightness value and the second low brightness value. The first high brightness value is the average brightness value of the bright pixels in the first image block, the second high brightness value is the average brightness value of the bright pixels in the second image block, the first low brightness value is the average brightness value of the low brightness pixels in the first image block, and the second low brightness value is the average brightness value of the low brightness pixels in the second image block.
11. The method according to claim 10, characterized in that, The bright pixels are those with a brightness value greater than a first threshold, and the dark pixels are those with a brightness value less than a second threshold, where the second threshold is less than the first threshold.
12. An electronic device, characterized in that, The electronic device includes: a memory and a processor; the processor is coupled to the memory; wherein the memory is used to store computer program code, the computer program code including computer instructions; when the computer instructions are executed by the processor, the electronic device performs the method as described in any one of claims 1-11.
13. A computer-readable storage medium, characterized in that, Includes computer instructions; when the computer instructions are executed on an electronic device, they cause the electronic device to perform the method as described in any one of claims 1-11.