Image processing method and system based on histogram matching

By using dynamic programming algorithms and SSIM in image processing, combined with the cumulative distribution probability density function, the color distortion and overcorrection problems caused by the histogram matching algorithm are solved, and effective white balance adjustment and visual quality improvement of the image are achieved.

CN119583779APending Publication Date: 2025-03-07DONGFENG OFF ROAD VEHICLE CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411532804.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-30
Publication Date
2025-03-07

AI Technical Summary

Technical Problem

When the existing histogram matching algorithms nonlinearly map images, they are prone to color distortion or overcorrection, and it is difficult to effectively realize the white balance adjustment of the image. At the same time, the changes to the source image information are too obvious.

Method used

Dynamic programming algorithm is used for histogram matching, combining the cumulative distribution probability density function (CDF) and structural similarity index (SSIM) to maintain the linearity of the image, realize effective white balance adjustment of the image, and reduce color distortion and over-correction.

Benefits of technology

Through the combination of dynamic programming algorithms and SSIM, the histogram of the image can be better adjusted, the contrast and brightness distribution of the image can be improved, the color distortion is reduced, the visual quality of the image can be improved, and the performance can be better when processed under a monochromatic light source.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119583779A_ABST
    Figure CN119583779A_ABST
Patent Text Reader

Abstract

The invention belongs to the technical field of image processing, and particularly discloses an image processing method and system based on histogram matching. Comprising the following steps: separating an original image into RGB channels, and respectively calculating histograms of the channels; calculating the cumulative distribution probability density of each channel according to the histogram of each channel; selecting the channel with the maximum energy as a standard channel, matching histograms of other channels to a standard histogram, obtaining a mapping curve of each channel, and obtaining a gain curve of each channel according to the mapping curve of each channel; calculating the gain of each channel according to the sigma principle and the gain curve of each channel; and respectively adjusting the RGB channels by using the calculated gains to obtain an image after white balance processing. According to the method, the linearity of the image is kept while histogram matching is carried out, so that effective white balance adjustment of the image is realized, and excessive change of source image information is avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of image processing, and more specifically, relates to an image processing method and system based on histogram matching. Background Art

[0002] The automatic white balance (AWB) algorithm is an image processing technique that is mainly used to adjust the color temperature of an image so that white or gray objects look realistic and natural under different light sources. This technique is essential to maintain image consistency and color accuracy under various lighting conditions, especially in digital cameras, smartphone cameras, and image processing software.

[0003] The existing automatic white balance algorithm is mainly the Gray World Algorithm. The basic steps of the Gray World Algorithm are as follows: Calculate the average value of the red (R), green (G) and blue (B) channels in the image. Calculate the adjustment coefficient based on the average value of each channel so that the adjusted average value tends to neutral gray. Usually, the green channel is selected as a reference here because the human eye is most sensitive to green. Use the adjustment coefficient calculated above to adjust the color of each pixel in the image to achieve white balance. If a certain color in the image is dominant (for example, there is a lot of blue sky or green plants in the captured image), the Gray World Algorithm may not be able to correctly restore the white balance. Furthermore, compared with the Gray World Algorithm, the histogram matching algorithm has improved the visual quality and color performance of the image to a certain extent. The basic steps of the histogram matching algorithm are as follows: Calculate the histograms of the original image and the target image, and convert the histograms of the original image and the target image into a cumulative distribution function (CDF). The CDF represents the cumulative probability of each pixel value. By comparing the cumulative distribution functions of the histograms of the original image and the target image, a mapping relationship between pixel values ​​is established. Using the established mapping relationship, each pixel value of the original image is mapped to generate a new image that has been color corrected or enhanced. When the histogram matching algorithm processes images with large grayscale jumps or uneven target radiation, it often cannot maintain the information of the source image well due to the nonlinear mapping of the image grayscale, resulting in the loss of the original linearity of the source image. In addition, this type of algorithm may also cause color distortion or over-correction when processing complex images.

[0004] Based on the above defects and shortcomings, there is an urgent need in this field to propose an image processing method based on histogram matching to solve the problem that the existing histogram matching algorithm performs nonlinear mapping on the original image, resulting in color distortion or over-correction, thereby achieving effective white balance adjustment of the image while avoiding excessive changes to the source image information. Summary of the invention

[0005] In view of the above defects or improvement needs of the prior art, the present invention provides an image processing method based on histogram matching, which performs histogram matching by using a dynamic programming algorithm, introduces a structural similarity index (SSIM) as an evaluation index, and combines the cumulative distribution probability density function (CDF) and the dynamic programming algorithm. While performing histogram matching, the linearity of the image is maintained, thereby achieving effective white balance adjustment of the image while avoiding excessive changes to the source image information. When processing images with large grayscale jumps or uneven target radiation under a monochromatic light source, better results can be achieved, reducing the problems of color distortion and over-correction.

[0006] To achieve the above object, according to one aspect of the present invention, a method and system for image processing based on histogram matching are proposed, comprising the following steps:

[0007] Step 1: Separate the original image into three channels, RGB, and calculate the histogram of each channel;

[0008] Step 2: Calculate the cumulative distribution probability density of each channel according to the histogram of each channel;

[0009] Step 3: Select the channel with the largest energy as the standard channel, match the histograms of other channels to the standard histogram, obtain the mapping curves of each channel, and obtain the gain curves of each channel according to the mapping curves of each channel;

[0010] Step 4: Calculate the gain of each channel according to the sigma principle and the gain curve of each channel;

[0011] Step 5: Use the calculated gains to adjust the three channels of RGB respectively to obtain a white balanced image.

[0012] As a further preferred embodiment, step two specifically includes the following steps: normalizing the histogram of each channel to obtain the probability density, and obtaining the cumulative distribution probability density function of each channel by accumulating the probability density functions: Sr, Sg and Sb, wherein Sr is the cumulative distribution probability density function of the R channel, Sg is the cumulative distribution probability density function of the G channel, and Sb is the cumulative distribution probability density function of the B channel.

[0013] As further preferred, the cumulative distribution probability density function of each channel includes:

[0014] The cumulative distribution probability density function of the G channel is:

[0015] The cumulative distribution probability density function of the R channel is:

[0016] The cumulative distribution probability density function of channel B is:

[0017] Among them, pr(i), pb(i), pg(i) are the normalized histogram values, and k is the grayscale level.

[0018] As a further preferred embodiment, in step three, the sum of the grayscale values ​​of the histogram of each channel is counted, the channel with the largest sum of grayscale values ​​is used as the standard channel, and the histogram with the largest sum of grayscale values ​​is used as the standard histogram.

[0019] As further preferred, in step 3, obtaining the mapping curve of each channel includes:

[0020] (301) Let dp[i][j] denote the minimum cost when the first i elements of histogram H are matched to the first j elements of histogram G;

[0021] (302) Initialize the dp array, where dp[0][j] and dp[i][0] represent the state when a histogram is empty;

[0022] (303) Construct the state transition equation for histogram matching:

[0023] dp[i][j]=min(dp[i-1][j],dp[i][j-1],dp[i-1][j-1]+cost(Sr(i),Sg(j),Sb(k)))where cost(Sr(i),Sg(j),Sb(k)) is the cost of matching the i-th element of the source image histogram to the j-th element of the target image histogram;

[0024] (304) According to the state transfer equation, starting from dp[1][1], gradually fill the dp table until dp[m][n], where m and n are the lengths of the histograms of the source image and the target image, respectively;

[0025] (305) Calculate the mapping curve of each channel according to the filled dp table;

[0026] (306) According to the calculated mapping curve, the pixel value of each channel is adjusted to match the histogram of the target image.

[0027] As a further preferred embodiment, in step (304), the following calculation model is used to solve the state transfer equation:

[0028]

[0029] In the process of calculating the state transfer equation, the boundary conditions include:

[0030] dp[0][j] = 0 for all j, indicating that the minimum cost of matching the first 0 elements of the source image histogram to the first j elements of the target image histogram is 0;

[0031] dp[i][0]=0 for all i, indicating that the minimum cost when the first i elements of the source image histogram are matched to the first 0 elements of the target image histogram is 0.

[0032] As a further preferred method, the method further includes using a structural similarity index to evaluate the image after histogram matching:

[0033] SSIMw(x,y)=w l ·l w (x,y)+w c ·c w (x,y)+w s ·s w (x,y)

[0034] Among them, l w (x,y) is the brightness comparison, c w (x,y) is the contrast comparison, s w (x,y) is the structural comparison, w l 、w c 、w s is the weight coefficient.

[0035] According to another aspect of the present invention, there is also provided an image processing system based on histogram matching, comprising:

[0036] The first main control module is used to separate the original image into three channels of RGB and calculate the histogram of each channel respectively;

[0037] The second main control module is used to calculate the cumulative distribution probability density of each channel according to the histogram of each channel;

[0038] The third main control module is used to select the channel with the largest energy as the standard channel, match the histograms of other channels to the standard histogram, obtain the mapping curves of each channel, and obtain the gain curves of each channel according to the mapping curves of each channel;

[0039] The fourth main control module is used to calculate the gain of each channel according to the sigma principle and the gain curve of each channel;

[0040] The fifth main control module is used to use the calculated gains to adjust the three channels of RGB respectively to obtain an image after white balance processing.

[0041] According to another aspect of the present invention, there is also provided an electronic device, comprising:

[0042] At least one processor, at least one memory and a communication interface; wherein,

[0043] The processor, memory and communication interface communicate with each other;

[0044] The memory stores program instructions that can be executed by the processor, and the processor calls the program instructions to execute an image processing method based on histogram matching in any of the above embodiments or a combination of multiple embodiments.

[0045] According to another aspect of the present invention, a non-transitory computer-readable storage medium stores computer instructions, and the computer instructions enable the computer to execute an image processing method based on histogram matching according to any embodiment or a combination of multiple embodiments described above.

[0046] In general, the above technical solution conceived by the present invention has the following technical advantages compared with the prior art:

[0047] 1. The present invention can effectively adjust the histogram of the source image to match the histogram of the target image by using a dynamic programming algorithm for histogram matching. This adjustment can improve the contrast and brightness distribution of the image, making the details of the image clearer. In addition, by introducing the structural similarity index (SSIM) as an evaluation indicator, it can ensure that the images maintain a high visual similarity after processing, thereby improving the visual quality of the image.

[0048] 2. The present invention can accurately calculate the gain curve of each channel by combining the cumulative distribution probability density function (CDF) and the dynamic programming algorithm, and calculate the gain of each channel accordingly. This method can not only adjust the overall brightness and contrast of the image, but also make separate adjustments for each color channel, thereby achieving more accurate white balance processing.

[0049] 3. The method of calculating gain through a mapping curve within a certain range of the present invention avoids direct mapping and changes to the linearity of the original image. When processing images with large grayscale jumps or uneven target radiation under a monochromatic light source, better results can be achieved, reducing the problems of color distortion and over-correction.

[0050] 4. The present invention calculates the mean of the gain curve based on the sigma principle. By filtering out data points with large deviations, it can ensure that the selected data points more accurately reflect the central trend of the gain curve and are more representative, thereby ensuring that the calculated gain is more accurate.

[0051] 5. The method provided by the present invention has low computational complexity while maintaining a high processing effect, and is suitable for real-time image processing scenarios. In the canon data set, the ΔE2000 value is 10% lower than that of the grayscale world method, and under monochromatic light sources, the ΔE2000 value is 80% lower than that of the grayscale world algorithm. BRIEF DESCRIPTION OF THE DRAWINGS

[0052] Figure 1 is a flow chart of an image processing method based on histogram matching involved in an embodiment of the present invention;

[0053] Figure 2 (a) is the mapping curve obtained by taking the G channel as the standard channel; Figure 2 (b) in the figure is the gain curve obtained by taking the G channel as the standard channel. DETAILED DESCRIPTION

[0054] In order to make the purpose, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention. In addition, the technical features involved in the various embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.

[0055] like Figure 1 As shown, an image processing method based on histogram matching provided by an embodiment of the present invention includes the following steps:

[0056] S1. Separate the original image into three channels of RGB and calculate the histogram of each channel respectively.

[0057] S2. Calculate the cumulative distribution probability density of each channel according to the histogram of each channel.

[0058] Specifically, the histogram of each channel is normalized to obtain the probability density, and the cumulative distribution probability density function of each channel is obtained by accumulating the probability density functions: Sr, Sg and Sb, where Sr is the cumulative distribution probability density function of the R channel, Sg is the cumulative distribution probability density function of the G channel, and Sb is the cumulative distribution probability density function of the B channel.

[0059] S3. Select the channel with the largest energy as the standard channel.

[0060] Specifically, the sum of the grayscale values ​​of the histogram of each channel is counted, the channel with the largest sum of grayscale values ​​is used as the standard channel, and the histogram with the largest sum of grayscale values ​​is used as the standard histogram.

[0061] S4. Match the histograms of other channels to the standard histogram so that the shapes and center positions of the histograms of each channel are as consistent as possible. Specifically, the cumulative distribution function of other channels is substituted into the inverse function of the cumulative distribution function of the standard channel to obtain the mapping curve of each channel. For example:

[0062] Taking the G channel as the standard channel, the cumulative distribution function of the G channel is:

[0063] The cumulative distribution function of the R channel is

[0064] The mapping curve of the R channel to the G channel is: r =G -1 (Sr).

[0065] More specifically, in an optional embodiment of the present invention, a dynamic programming algorithm is used to find the optimal mapping curve. The histogram of the source image is matched to the histogram of the target image. This process involves the calculation and matching of the cumulative distribution probability density function (CDF) of each channel. The following are the detailed steps of the histogram matching scheme combined with the cumulative distribution probability density function:

[0066] (1) Calculate the cumulative distribution probability density function (CDF) of each channel:

[0067] For each channel (for example, R, G, B channels), its histogram needs to be calculated first, and then the CDF is calculated by accumulating the values ​​of the histogram. CDF is expressed as Sr(k), Sg(k), Sb(k), which correspond to the cumulative distribution probability density functions of the R, G, and B channels, respectively. Specifically:

[0068] The cumulative distribution probability density function of the G channel is:

[0069] The cumulative distribution probability density function of the R channel is:

[0070] The cumulative distribution probability density function of channel B is:

[0071] Among them, pr(i), pb(i), pg(i) are the normalized histogram values, and k is the grayscale level.

[0072] (2) Select the standard channel:

[0073] Selecting the channel with the largest energy as the standard channel can be achieved by comparing the sum of the grayscale values ​​of the histogram of each channel.

[0074] (3) Histogram matching:

[0075] Use dynamic programming to find the optimal mapping curve. Define the state variable dp[i][j] to represent the minimum cost when the first i elements of the source image histogram match the first j elements of the target image histogram.

[0076] (4) Initialization and boundary conditions:

[0077] dp[0][j] = 0 for all j, indicating that the minimum cost of matching the first 0 elements of the source image histogram to the first j elements of the target image histogram is 0;

[0078] dp[i][0]=0 for all i, indicating that the minimum cost when the first i elements of the source image histogram are matched to the first 0 elements of the target image histogram is 0.

[0079] (5) Construct the state transfer equation:

[0080] For i>0 and j>0, the state transition equation is:

[0081] dp[i][j]=min(dp[i-1][j],dp[i][j-1],dp[i-1][j-1]+cost(Sr(i),Sg(j),Sb(k))),

[0082] Among them, cost(Sr(i),Sg(j),Sb(k)) is the cost of matching the i-th element of the source image histogram to the j-th element of the target image histogram

[0083] (6) Fill in the p table:

[0084] According to the state transfer equation, starting from dp[1][1], the dp table is gradually filled until dp[m][n], where m and n are the lengths of the histograms of the source image and the target image, respectively;

[0085] (7) Reconstruct the optimal solution:

[0086] The optimal mapping curve can be reconstructed through the values ​​in the dp table, starting from dp[m][n], backtracking to dp[0][0], and selecting the decision that results in the minimum cost at each step.

[0087] (8) Adjustment of mapping curve:

[0088] Using the calculated mapping curve, the pixel values ​​of each channel are adjusted to match the histogram of the target image.

[0089] The following calculation model is used to solve the state transfer equation:

[0090]

[0091] S5. Divide the mapping curve of each channel by the mapping curve of the standard channel to obtain the gain curve of each channel. The gain curve can be determined by the slope of the mapping curve. If the mapping curve is linear, the gain is the inverse of the slope. If the mapping curve is nonlinear, the gain can be approximated by the local slope of the curve. Figure 2 The mapping curve and gain curve are obtained by taking the G channel as the standard channel, where: Figure 2 In (a), the red curve is the mapping curve of the R channel, the green curve is the mapping curve of the G channel, and the blue curve is the mapping curve of the B channel. Figure 2 In (b), the red curve is the gain curve of the R channel, the green curve is the gain curve of the G channel, and the blue curve is the gain curve of the B channel. It can be seen that the gain of the standard channel (G channel) is 1.

[0092] S6. Calculate the gain of each channel according to the sigma principle and the gain curve of each channel. Specifically, the Sigma principle states that for a normal distribution, approximately 68% of the data is within ±1 standard deviation (σ) of the mean. According to the sigma principle, take the 68 percent of the median above and below the median of each gain curve, calculate the mean of the part as the gain of the channel, and thus obtain the gain of each channel, where the gain of the standard channel is 1. Let Gr, Gb, Gg be the gain curves of the R, G, and B channels, μr, μg, and μb be the means of the gain curves of each channel, and σr, σg, and σb be the standard deviations of the gain curves of each channel. Then the gain G of each channel can be calculated as:

[0093]

[0094] In addition, in this step, brightness, contrast and structure information are taken into account, and it is closer to the visual perception of the human eye. The structural similarity index (SSIM) is used to evaluate the quality of the image after histogram matching, and the contrast and brightness distribution of the image are evaluated by histogram comparison. Specifically:

[0095] (1) Constructing brightness comparison model:

[0096]

[0097] Where μx and μy are the average brightness of the two images, respectively, and C1 is a constant to avoid the denominator being zero. The weight coefficient wl can be introduced to adjust the importance of brightness comparison.

[0098] (2) Constructing a contrast comparison model:

[0099]

[0100] Where σx and σy are the standard deviations of the two images, respectively, and C2 is a constant. The weight coefficient wc can be introduced to adjust the importance of contrast comparison.

[0101] (3) Constructing a structural comparison model:

[0102]

[0103] Among them, σxy is the covariance of the two images, C3 is a constant. The weight coefficient ws can be introduced to adjust the importance of structure comparison.

[0104] (3) Use the structural similarity index to evaluate the image after histogram matching:

[0105] SSIMw(x,y)=w l ·l w (x,y)+w c ·c w (x,y)+w s ·s w (x,y)

[0106] Among them, l w (x,y) is the brightness comparison, c w (x,y) is the contrast comparison, s w (x,y) is the structural comparison, w l 、w c 、w s is the weight coefficient.

[0107] Through the above method, the optimal mapping curve can be found to achieve histogram matching.

[0108] S7, using the calculated gain to adjust the three channels of RGB respectively to obtain a white-balanced image. Specifically, the grayscale value of each channel is multiplied by the gain of the corresponding channel to obtain the three adjusted channels, and the adjusted three channels of RGB are re-merged to obtain a white-balanced image.

[0109] Based on any of the above embodiments or a combination of multiple embodiments, according to another aspect of the present invention, there is also provided an image processing system based on histogram matching, which is used to execute the above method, including: a first main control module, used to separate the original image into three channels of RGB, and calculate the histogram of each channel respectively; a second main control module, used to calculate the cumulative distribution probability density of each channel according to the histogram of each channel; a third main control module, used to select the channel with the largest energy as the standard channel, match the histograms of other channels to the standard histogram, obtain the mapping curve of each channel, and obtain the gain curve of each channel according to the mapping curve of each channel; a fourth main control module, used to calculate the gain of each channel according to the sigma principle and the gain curve of each channel; a fifth main control module, used to use the calculated gains to adjust the three channels of RGB respectively to obtain an image after white balance processing.

[0110] The method of the embodiment of the present invention is implemented by relying on electronic devices, so it is necessary to introduce the relevant electronic devices. For this purpose, an embodiment of the present invention provides an electronic device, which includes: at least one processor, a communication interface, at least one memory, and a communication bus, wherein at least one processor, a communication interface, and at least one memory communicate with each other through the communication bus. At least one processor can call the logic instructions in at least one memory to execute all or part of the steps of the method provided by the aforementioned method embodiments.

[0111] In addition, the logic instructions in the at least one memory mentioned above can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on this understanding, the technical solution of the present invention can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each method embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0112] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.

[0113] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.

[0114] It will be easily understood by those skilled in the art that the above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.

Claims

1. An image processing method based on histogram matching, characterized in that: The following steps are involved: Step 1: Separate the original image into three channels, RGB, and calculate the histogram of each channel; Step 2: Calculate the cumulative distribution probability density of each channel according to the histogram of each channel; Step 3: Select the channel with the largest energy as the standard channel, match the histograms of other channels to the standard histogram, obtain the mapping curves of each channel, and obtain the gain curves of each channel according to the mapping curves of each channel; Step 4: Calculate the gain of each channel according to the sigma principle and the gain curve of each channel; Step 5: Use the calculated gains to adjust the three channels of RGB respectively to obtain a white balanced image.

2. The image processing method based on histogram matching according to claim 1, characterized in that: Step 2 specifically includes the following steps: normalize the histogram of each channel to obtain the probability density, and obtain the cumulative distribution probability density function of each channel by accumulating the probability density function: Sr, Sg and Sb, where Sr is the cumulative distribution probability density function of the R channel, Sg is the cumulative distribution probability density function of the G channel, and Sb is the cumulative distribution probability density function of the B channel.

3. The image processing method based on histogram matching according to claim 2, characterized in that: The cumulative distribution probability density function of each channel includes: The cumulative distribution probability density function of the G channel is: The cumulative distribution probability density function of the R channel is: The cumulative distribution probability density function of channel B is: Among them, pr(i), pb(i), pg(i) are the normalized histogram values, and k is the grayscale level.

4. The image processing method based on histogram matching according to claim 1, characterized in that: In step three, the sum of the grayscale values ​​of the histogram of each channel is counted, the channel with the largest sum of grayscale values ​​is taken as the standard channel, and the histogram with the largest sum of grayscale values ​​is taken as the standard histogram.

5. The image processing method based on histogram matching according to claim 1, characterized in that: In step 3, obtaining the mapping curve of each channel includes: (301) Let dp[i][j] denote the minimum cost when the first i elements of histogram H are matched to the first j elements of histogram G; (302) Initialize the dp array, where dp[0][j] and dp[i][0] represent the state when a histogram is empty; (303) Construct the state transition equation for histogram matching: dp[i][j]=min(dp[i-1][j],dp[i][j-1],dp[i-1][j-1]+cost(Sr(i),Sg(j),Sb(k)))where cost(Sr(i),Sg(j),Sb(k)) is the cost of matching the i-th element of the source image histogram to the j-th element of the target image histogram; (304) According to the state transfer equation, starting from dp[1][1], gradually fill the dp table until dp[m][n], where m and n are the lengths of the histograms of the source image and the target image, respectively; (305) Calculate the mapping curve of each channel according to the filled dp table; (306) According to the calculated mapping curve, the pixel value of each channel is adjusted to match the histogram of the target image.

6. The image processing method based on histogram matching according to claim 5, characterized in that: In step (304), the following calculation model is used to solve the state transfer equation: In the process of calculating the state transfer equation, the boundary conditions include: dp[0][j] = 0 for all j, indicating that the minimum cost of matching the first 0 elements of the source image histogram to the first j elements of the target image histogram is 0; dp[i][0]=0 for all i, indicating that the minimum cost when the first i elements of the source image histogram are matched to the first 0 elements of the target image histogram is 0.

7. The image processing method based on histogram matching according to claim 5, characterized in that: It also includes the evaluation of images after histogram matching using a structural similarity index: SSIMw(x,y)=w l ·l w (x,y)+w c ·c w (x,y)+w s ·s w (x,y) Among them, l w (x,y) is the brightness comparison, c w (x,y) is the contrast comparison, s w (x,y) is the structural comparison, w l 、w c 、w s is the weight coefficient.

8. An image processing system based on histogram matching, characterized in that: include: The first main control module is used to separate the original image into three channels of RGB and calculate the histogram of each channel respectively; The second main control module is used to calculate the cumulative distribution probability density of each channel according to the histogram of each channel; The third main control module is used to select the channel with the largest energy as the standard channel, match the histograms of other channels to the standard histogram, obtain the mapping curves of each channel, and obtain the gain curves of each channel according to the mapping curves of each channel; The fourth main control module is used to calculate the gain of each channel according to the sigma principle and the gain curve of each channel; The fifth main control module is used to use the calculated gains to adjust the three channels of RGB respectively to obtain an image after white balance processing.

9. An electronic device, characterized in that: include: At least one processor, at least one memory and a communication interface; wherein, The processor, memory and communication interface communicate with each other; The memory stores program instructions that can be executed by the processor, and the processor calls the program instructions to execute the image processing method based on histogram matching as described in any one of claims 1 to 7.

10. A non-transitory computer-readable storage medium, characterized in that: The non-transitory computer-readable storage medium stores computer instructions, and the computer instructions enable the computer to execute the image processing method based on histogram matching as described in any one of claims 1 to 7.