Image processing method and device, electronic equipment and storage medium
Patent Information
- Application Number
- CN202210946297.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-08
- Publication Date
- 2026-09-25
- Estimated Expiration
- 2042-08-08
AI Technical Summary
[0004]本发明提供一种图像处理方法、装置、电子设备和存储介质,用以解决现有技术中图像亮度调整时限制较大的问题,实现图像亮度调整效果的优化
[0022]本发明提供的一种图像处理方法、装置、电子设备和存储介质,不断更新输入灰度与输出灰度之间的映射函数,采用映射函数对待处理图像进行处理,通过待处理图像的处理效果来确定映射函数对待处理图像来说是否最优,直到找到最优的目标映射函数。本方案中映射函数并不局限于Gamma函数、非完全Beta函数或其他标准函数,而是通过多次迭代确定对输入灰度来说合适的输出灰度,以及它们之间的映射函数,能够尽可能多的覆盖图像的各种灰度,对图像的适应性更好,能够提高图像调整的效果。尤其对于灰度变化复杂的图像来说,优化效果更加显著。
Smart Images

Figure CN117593229B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing technology, and more particularly to an image processing method, apparatus, electronic device, and storage medium. Background Technology
[0002] When a camera captures an image, it typically adjusts the exposure based on the average brightness of different parts of the image. This can result in overexposure or underexposure, causing not every part of the image to be clearly visible, which is detrimental to target recognition or detection. Therefore, before image recognition, it is necessary to adjust the image to increase contrast and make the target clearer.
[0003] Currently, most image adjustments are made using Gamma transform, which uses the Gamma function, also known as the power-law function, to map and transform the brightness of an image. Alternatively, a partial Beta function can be used. However, both the Gamma function and the partial Beta function are limited by their curve shape and cannot flexibly adapt to all brightness conditions of an image, resulting in adjustments that are far from optimal. Summary of the Invention
[0004] This invention provides an image processing method, apparatus, electronic device, and storage medium to solve the problem of significant limitations in image brightness adjustment in the prior art, and to optimize the image brightness adjustment effect.
[0005] This invention provides an image processing method, comprising: obtaining an initial mapping function corresponding to an image to be processed, the initial mapping function being used to characterize the correspondence between the input grayscale and the output grayscale of the image to be processed; updating the initial mapping function to obtain a mapping function; adjusting the input grayscale of the image to be processed based on the mapping function to obtain a target image; if the image quality parameters of the target image do not meet a preset condition, continuing to update the mapping function until the image quality parameters of the target image meet the preset condition; and using the finally obtained target image as the processing result of the image to be processed.
[0006] According to one embodiment of the present invention, the step of continuing to update the mapping function until the image quality parameters of the target image meet the preset conditions when the image quality parameters of the target image do not meet the preset conditions includes: extracting k search starting points from the initial mapping function, where k is a positive integer; entering an iteration step, the iteration step including: updating the search starting points to obtain the updated k points, and determining the mapping function corresponding to the updated k points; when the image quality parameters do not meet the preset conditions, using the updated k points as search starting points and entering the iteration step again; when the image quality parameters meet the preset conditions, ending the iteration step and using the mapping function at the end of the iteration step as the target mapping function.
[0007] According to one embodiment of the present invention, when the image quality parameters do not meet the preset conditions, the step of using the updated k points as the search starting point and then entering the iteration step includes: when the image quality parameters do not meet the preset conditions, obtaining temperature parameters and reducing the temperature parameters based on a simulated annealing algorithm; and when the reduced temperature parameters are not less than a first preset value, using the updated k points as the search starting point and then entering the iteration step.
[0008] According to one embodiment of the present invention, the method further includes: if the reduced temperature parameter is less than the first preset value, increasing k and resetting the temperature parameter; based on the increased k value, re-extracting the search starting point in the initial mapping function and entering the iteration step.
[0009] According to one embodiment of the present invention, the method further includes: determining a confidence level when identifying the target image, and determining that the image quality parameters of the target image meet the preset conditions when the confidence level is greater than a second preset value.
[0010] According to one embodiment of the present invention, the method further includes: determining the confidence level when identifying the image to be processed and the confidence level when identifying the target image; discarding the updated k points and proceeding to the iteration step when the confidence level of the target image is not greater than the confidence level of the image to be processed; and retaining the updated k points when the confidence level of the target image is greater than the confidence level of the image to be processed.
[0011] According to one embodiment of the present invention, the method further includes: determining a grayscale histogram of the target image, and determining that the image quality parameters of the target image satisfy the preset condition when the distance between the grayscale histogram and the target grayscale histogram is less than a third preset value.
[0012] The present invention also provides an image processing apparatus, comprising: an initial mapping module for obtaining an initial mapping function corresponding to an image to be processed, the initial mapping function being used to characterize the correspondence between the input grayscale and the output grayscale of the image to be processed; a mapping update module for updating the initial mapping function to obtain a mapping function; an adjustment determination module for adjusting the input grayscale of the image to be processed based on the mapping function to obtain a target image; an iteration module for continuing to update the mapping function when the image quality parameters of the target image do not meet a preset condition, until the image quality parameters of the target image meet the preset condition; an iteration end module for ending the iteration step when the mapping function meets the preset condition, and taking the mapping function at the end of the iteration step as the target mapping function; and an image processing module for taking the finally obtained target image as the processing result of the image to be processed.
[0013] In one embodiment of the present invention, the iteration module specifically includes: an extraction module, used to extract k search starting points from the initial mapping function, where k is a positive integer; an update module, used to enter an iteration step, the iteration step including: updating the search starting points to obtain the updated k points, and determining the mapping function corresponding to the updated k points; a loop module, used to, when the image quality parameters do not meet the preset conditions, use the updated k points as search starting points and then enter the iteration step again; and an exit iteration module, used to, when the image quality parameters meet the preset conditions, end the iteration step and use the mapping function at the end of the iteration step as the target mapping function.
[0014] In one embodiment of the present invention, the loop module specifically includes: an annealing module, used to obtain temperature parameters when the image quality parameters do not meet preset conditions, and reduce the temperature parameters based on a simulated annealing algorithm; and a search point update module, used to take the updated k points as the search starting point and then enter the iteration step when the reduced temperature parameters are not less than the first preset value.
[0015] In one embodiment of the present invention, the image processing apparatus further includes: an quantity increasing module, configured to increase k and reset the temperature parameter when the reduced temperature parameter is less than the first preset value; and a re-extraction module, configured to re-extract the search starting point in the initial mapping function based on the increased k value and enter the iteration step.
[0016] In one embodiment of the present invention, the image processing apparatus further includes: a confidence level acquisition module, configured to determine the confidence level when recognizing the target image, and when the confidence level is greater than a second preset value, determine that the image quality parameters of the target image meet the preset conditions.
[0017] In one embodiment of the present invention, the image processing apparatus further includes: a confidence determination module, configured to determine the confidence level when recognizing the image to be processed and the confidence level when recognizing the target image; a discard module, configured to discard the updated k points and proceed to the iteration step when the confidence level of the target image is not greater than the confidence level of the image to be processed; and a retention module, configured to retain the updated k points when the confidence level of the target image is greater than the confidence level of the image to be processed.
[0018] In one embodiment of the present invention, the image processing apparatus further includes: a grayscale determination module, configured to determine the grayscale histogram of the target image, and when the distance between the grayscale histogram and the target grayscale histogram is less than a third preset value, determine that the image quality parameters of the target image meet the preset condition.
[0019] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the image processing method described above.
[0020] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the image processing method as described above.
[0021] The present invention also provides a computer program product, including a computer program that, when executed by a processor, implements the image processing method as described above.
[0022] This invention provides an image processing method, apparatus, electronic device, and storage medium that continuously updates the mapping function between input and output gray levels. The mapping function is used to process the image to be processed, and the optimality of the mapping function for the image is determined by the processing effect, until the optimal target mapping function is found. In this scheme, the mapping function is not limited to the Gamma function, the incomplete Beta function, or other standard functions. Instead, it determines a suitable output gray level for the input gray level and the mapping function between them through multiple iterations. This allows for wider coverage of various gray levels in the image, resulting in better image adaptability and improved image adjustment effects. The optimization effect is particularly significant for images with complex gray level variations. Attached Figure Description
[0023] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0024] Figure 1 This is one of the flowcharts illustrating the image processing method provided in this embodiment of the invention;
[0025] Figure 2 This is a second schematic flowchart of the image processing method provided in this embodiment of the invention.
[0026] Figure 3A This is one of the schematic diagrams of the mapping function in the image processing method provided in this embodiment of the invention;
[0027] Figure 3B This is the second schematic diagram of the mapping function curve in the image processing method provided in this embodiment of the invention;
[0028] Figure 4 This is the third flowchart illustrating the image processing method provided in this embodiment of the invention;
[0029] Figure 5A This is one of the schematic diagrams illustrating the effect of the image processing method provided in the embodiments of the present invention;
[0030] Figure 5B This is the second schematic diagram illustrating the effect of the image processing method provided in this embodiment of the invention;
[0031] Figure 6 This is a schematic diagram of the image processing apparatus provided in an embodiment of the present invention;
[0032] Figure 7 This is a schematic diagram of the structure of the electronic device provided in an embodiment of the present invention. Detailed Implementation
[0033] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.
[0034] The grayscale mentioned in this invention refers to a parameter used to represent brightness levels. Each grayscale object can have 0 to 255 gray levels, representing brightness from dark to light, from black to white.
[0035] The gray-level histogram mentioned refers to a function of gray-level distribution, which is a statistical representation of the gray-level distribution in an image. In other words, it counts the frequency of occurrence of all pixels in an image according to their gray levels.
[0036] The image processing method of the present invention will now be described with reference to the accompanying drawings. Exemplary examples show that this image processing method can be applied to mobile phones, tablet computers, laptops, handheld computers, augmented reality (AR) / virtual reality (VR) devices, robots, wearable devices, and also to various electronic devices such as servers and personal computers (PCs). The present invention does not specifically limit these applications.
[0037] like Figure 1 As shown, the image processing method may include the following steps:
[0038] Step 10: Obtain the initial mapping function corresponding to the image to be processed. The initial mapping function is used to characterize the correspondence between the input grayscale and the output grayscale of the image to be processed.
[0039] Step 20: Update the initial mapping function to obtain the mapping function.
[0040] Step 30: Adjust the input grayscale of the image to be processed based on the mapping function to obtain the target image.
[0041] Step 40: If the image quality parameters of the target image do not meet the preset conditions, continue to update the mapping function until the image quality parameters of the target image meet the preset conditions.
[0042] Step 50: Use the final target image as the processing result of the image to be processed.
[0043] The image to be processed is the image that actually needs brightness adjustment or enhancement. The initial mapping function is a pre-set initial correspondence between the input grayscale and the output grayscale. The input grayscale is the actual grayscale of the image to be processed, and the initial mapping function can be used to determine the output grayscale corresponding to the input grayscale. For example, initially, the input grayscale and the output grayscale can be the same. If the input grayscale is denoted as r and the output grayscale as s, then the initial mapping function can be: s = r. That is, initially, the grayscale mapping is the same before and after the transformation.
[0044] Image quality parameters refer to the quality of the target image obtained after grayscale adjustment of the image to be processed. Starting from the input grayscale, a search is performed. Each time a new mapping function is found, it is used to adjust the grayscale of the image to be processed, resulting in the transformed target image. The image quality parameters of the target image are used to evaluate whether the searched mapping function is suitable for the image to be processed. Through multiple iterations, the mapping function is continuously updated, gradually searching for the optimal mapping function for the image to be processed, thus maximizing the optimization of the brightness adjustment effect and obtaining the best processing result for the image to be processed.
[0045] Specifically, the process of updating the initial mapping function is as follows: Figure 2 As shown:
[0046] In step 21, k search starting points are extracted from the initial mapping function, where k is a positive integer.
[0047] After determining the initial mapping function, k points can be extracted from it, where k can be any positive integer greater than 0. These k points are used as the search starting points for subsequent iterative steps. For example, the search starting points can be extracted uniformly, that is, the range of the initial mapping function is evenly divided into k-1 segments, and the endpoints of each segment are extracted to obtain k search starting points. If the input and output grayscale values range from [0, 255], then k points can be extracted uniformly from 0 to 255. Alternatively, the grayscale range can be normalized to between 0 and 1, thus extracting k points uniformly from 0 to 1. Normalizing the grayscale facilitates calculation; subsequent steps will use a grayscale value of [0, 1] as an example.
[0048] In any case, points (0, 0) and (1, 1) are known points regardless of the specific conditions. Therefore, when selecting points, only those points other than these two can be extracted. An initial value for k can be preset, such as 3 or 4; this implementation does not limit this. For example, when k is 4 and the grayscale value is [0, 1], the extraction search starting points can be (0.2, 0.2), (0.4, 0.4), (0.6, 0.6), and (0.8, 0.8). Combining the two known points mentioned above, six points can be obtained on the initial mapping function.
[0049] Understandably, the initial mapping function is a monotonically increasing function, and the extracted k search starting points increase sequentially. For example, s i Let be the output grayscale value of the i-th point among k search starting points, then s i Less than s i+1 .
[0050] Step 22: Proceed to the iteration step, which includes: updating the search starting point, obtaining the updated k points, and determining the mapping function corresponding to the updated k points.
[0051] In this embodiment, step 22 is an iterative step, that is, a step that needs to be executed iteratively. Each time it is executed, the parameters in this step are updated, namely the above k points and the corresponding mapping function.
[0052] Updating the search starting point refers to performing a random search around the original search starting point, changing the output grayscale value of the search starting point, causing a small fluctuation in the search starting point. For example, for the search starting point (r1, s1), a random number RAND is generated, and then the following algorithm is executed:
[0053] s1=s1+R*RAND (1)
[0054] The random number RAND can be generated using various random number generation algorithms, such as the mid-square method. This implementation does not impose any special limitations on this method. It is understood that the grayscale value ranges from 0 to 1, therefore the values of s1 before and after the update should satisfy this range. To fix the updated value of s1 within this range, the range of the random number RAND is (-min(s...). i ),1-max(s i )), s i Let s be the values of the k search points from the previous iteration, where 1 ≤ i ≤ k. Setting the random number RAND within this range ensures that the updated s1, whether greater or less than the original s1, will always be between 0 and 1, preventing overflow. R can be a constant, and R is less than or equal to 1. With each iteration, the value of R decreases; for example, R is 1 in the first iteration, then successively reduced to 0.9, 0.8, 0.7, etc. By gradually decreasing the coefficient R, the updates to s at the starting point of the search gradually converge, accelerating the search for the optimal solution. It can be understood that the points on the mapping function are the solutions to the mapping function.
[0055] The original s1 can be randomly updated to another value that is larger or smaller than it using the above formula (2). Since the input grayscale is the actual grayscale value of the image, updating the output grayscale will not affect the search starting point. It should be noted that the updated k points also need to satisfy the condition of increasing, that is, the updated s1... i+1 It needs to be greater than the updated s i If the updated points according to formula (2) above do not meet the condition, they can be updated again to ensure the monotonically increasing property of the mapping function.
[0056] After updating each search starting point, we obtain k updated points. These k points are then used as the solution to the mapping function, allowing us to determine the corresponding mapping function.
[0057] In this embodiment, the mapping function between the input and output can be determined by polynomial fitting. The polynomial can be determined through practical verification and induction, and can fit various curves. For example, the mapping function can be a power-law polynomial, specifically represented as follows:
[0058]
[0059] Each term in this polynomial is a power-law function. Where c i Let i be the coefficients of the mapping function, i∈[1,k+1], r is the input gray level, and f(r) is the output gray level. γ1, γ2, ..., γ k+1 These are constants set based on practical experience and can be integers or non-integers. For example, when k is 4, γ1 = 0.1, γ2 = 0.4, γ3 = 1, γ4 = 5, and γ5 = 10 can be set. Understandably, the terms in a linear combination of terms in a mapping function can be linearly independent.
[0060] The mapping function described above is a polynomial with respect to k search starting points and two known points (0, 0) and (1, 1). Since the term corresponding to the known point (0, 0) is 0, the mapping function is actually expressed as a polynomial of order k+1.
[0061] The corresponding polynomial, i.e., the mapping function, can be solved based on the updated k points. For example, when k = 4, the mapping function is a 5th-order polynomial, and the updated 4 points can be substituted into the following formula (3):
[0062]
[0063] In the matrix When the rank is 5, the solution to this non-homogeneous system of equations is... It is unique. That is, if the updated k points are not repeated, the unique solution to the above equation can be obtained, that is, the corresponding mapping function can be obtained.
[0064] In this embodiment, by limiting the monotonically increasing nature of the solution, the monotonically increasing nature of the mapping function can be guaranteed. Under a monotonically increasing mapping function, the larger the input gray level, the larger the output gray level, which can ensure that no abnormal phenomena such as brightness reversal occur before and after image processing, and the brightness of the originally brighter areas will always be higher than or equal to that of the originally darker areas after processing.
[0065] In this embodiment, each sub-term of the mapping function is taken as a power-law function. It can be understood that the sub-terms of the mapping function can also be other forms of functions, such as incomplete beta functions, logarithmic functions, etc. This embodiment does not make any special limitations on this.
[0066] In step 23, when the image quality parameters do not meet the preset conditions, the updated k points are used as the search starting point, and the iteration step is then entered.
[0067] In each iteration of step 22 above, the mapping function corresponding to k points can be solved. The image to be processed is then transformed using the mapping function, and it is determined whether the image quality parameters of the resulting target image meet preset conditions. If the image quality parameters do not meet the preset conditions, the updated k points are used as the search starting point, and the iteration process continues. If the image quality parameters meet the preset conditions, step 24 is executed: when the image quality parameters meet the preset conditions, the iteration process ends, and the mapping function at the end of the iteration process is used as the target mapping function.
[0068] In this embodiment, the adjusted image quality is used as the basis for determining whether the mapping function meets preset conditions. If the image quality meets the requirements, the mapping function can effectively adjust the image to be processed. For example, the iteratively obtained mapping function is used to perform a mapping transformation on the image to be processed, resulting in the processed target image. Then, it is determined whether the image quality parameters of the processed target image meet the preset conditions. These image quality parameters may include root mean square error, structural similarity, etc., but this embodiment is not limited to these.
[0069] For example, the confidence level is determined when recognizing the target image. The target image can generally be used for specific recognition tasks, such as face recognition, license plate recognition, and classification recognition; this embodiment does not impose any special limitations on this. The recognition task can use a convolutional neural network model or other recognition algorithms to recognize the image. When recognizing the target image, the recognition algorithm can provide the confidence level of the target image. The higher the confidence level, the greater the recognition accuracy of the target image. In this embodiment, a confidence level greater than a specific preset value (i.e., a second preset value) is used as a preset condition. When the confidence level of the target image is greater than this second preset value, the mapping function used to obtain the target image is the final target mapping function, and the iteration step is exited.
[0070] If the confidence level of the target image is not greater than the second preset value, it indicates that the processing effect on the target image is not optimal. Therefore, the current k points are used as the new search starting point, and the iteration process is restarted to continue searching for the next solution. Then, the next obtained solution is used to process the image again. This process is repeated multiple times until a solution is found that makes the confidence level of the processed target image greater than the second preset value.
[0071] For example, before determining whether the confidence level of the target image is greater than the second preset value, it can be verified whether the processing effect of the target image is better than that of the image to be processed. If the processing effect of the target image is better than that of the image to be processed, then the solution found in this iteration is better than the previous solution. Even if the confidence level of the target image is not greater than the second preset value in this case, it is still beneficial to the convergence of the search process.
[0072] Specifically, the confidence level for identifying the image to be processed is determined. If the confidence level of the target image is not greater than that of the image to be processed, the updated k points are discarded, and the iteration step is repeated. That is, the search starting point before the update is used for the next iteration. If the confidence level of the target image is not greater than that of the image to be processed, it means that the current solution has not played a role in optimizing the image recognition accuracy, and the current solution can be discarded.
[0073] If the confidence score of the target image is greater than that of the image to be processed, it means that the current mapping function can improve the image recognition accuracy by adjusting the image to be processed, and the updated k points are retained. Then, it is determined whether the confidence score of the target image is greater than the second preset value. If the confidence score of the target image is not greater than the second preset value, then the currently retained k points are the optimal solution.
[0074] In short, the k points that perform better than the previous solution are retained, and these k points are used as the new search starting point for the next iteration. The k points that perform worse than the previous solution are discarded, and the search starting point for the next iteration is still the previous solution. Accepting only solutions that improve the recognition effect of the processed image each time speeds up the search for the optimal solution and improves search efficiency, until an optimal solution is found that satisfies a confidence level greater than a second preset value, meaning the image quality parameters of the target image meet the preset conditions.
[0075] In the above embodiments, the image quality parameter is the confidence level of the image. For example, the image quality parameter may also include the grayscale histogram of the image. Specifically, the image to be processed is acquired, and the grayscale of the image to be processed is adjusted using a mapping function to obtain the target image. Then, the grayscale histogram of the target image is determined. When the distance between the grayscale histogram of the target image and the grayscale histogram is less than a set threshold (i.e., a third preset value), it can be determined that the image quality parameter meets the preset condition, and the iteration ends.
[0076] The target grayscale histogram is a pre-set grayscale histogram based on actual needs. Users can set an ideal grayscale histogram as the target grayscale histogram according to the requirements of the actual recognition task.
[0077] In each iteration, the obtained mapping function is used to process the image to be processed, resulting in the processed target image. If the gray-level histogram of the target image is closer to the target gray-level histogram than the gray-level histogram of the image to be processed, then the k points of this iteration are retained. Then, it is determined whether the distance between the gray-level histogram of the target image and the target gray-level histogram is less than a third preset value. If the distance between the gray-level histogram of the target image and the target gray-level histogram is less than the third preset value, the current k points are the final solution. If the gray-level histogram of the target image is not closer to the target gray-level histogram than the gray-level histogram of the image to be processed, then the k points of this iteration are discarded, and the iteration restarts from the previous search starting point.
[0078] Calculate the difference between the frequency of each gray level in the target image and the frequency of each gray level in the target gray-level histogram. Then, sum the differences for each gray level. The result is the distance between the gray-level histogram of the target image and the target gray-level histogram. Similarly, the distance between the gray-level histogram of the image to be processed and the target gray-level histogram can be obtained. Then, compare the distance between the image to be processed and the distance between the target image to determine how close they are to the target gray-level histogram.
[0079] Furthermore, different distance calculation methods can be used to determine the distance between grayscale histograms depending on the actual distance metric. For example, the Euclidean distance algorithm can be used to calculate the sum of the squares of the differences between each gray level in the grayscale histograms, and then take the square root to obtain the distance between the grayscale histograms.
[0080] For example, this embodiment can employ simulated annealing during the search for the optimal solution. Simulated annealing is an optimization algorithm based on hill climbing, aiming to find the global optimum of a problem, and can transform the problem into finding the global pole of a function. For any continuous function on a closed interval, a global pole exists. Therefore, the mapping function in this embodiment can be applied to simulated annealing. Using simulated annealing can improve the probability of finding the global pole by overcoming local poles while maintaining time complexity.
[0081] Specifically, a temperature parameter T and an annealing rule are preset. The annealing rule is the rule for updating the temperature parameter. For example, the initial temperature parameter T is 1, and after each iteration, the temperature parameter T is reduced to half of its original value. After obtaining the mapping function through iteration, if the image quality parameters of the target image processed by the mapping function do not meet the preset conditions, the current temperature parameter is obtained, and then the current temperature parameter is reduced based on the simulated annealing algorithm. When the reduced temperature parameter is not less than a preset threshold, the updated k points are used as the search starting point, and iteration is performed again. For example, this threshold is recorded as the first preset value. This first preset value can be set according to the actual situation, for example, it can be 0.2, 0.1, 0.005, etc., and this embodiment does not make any special limitation on it.
[0082] For example, the temperature parameter T is set to 0 when it is lower than a first preset value. After each iteration, it can be checked whether the temperature parameter T is currently 0. If it is not 0, the iteration can continue; if it is 0, the iteration exits.
[0083] For example, if the image quality parameter does not meet the preset conditions, and the reduced temperature parameter is less than the first preset value, the value of k can be increased, and the temperature parameter can be reset. Then, based on the increased k value, the search starting point is extracted again from the initial mapping function, and the next iteration begins. For example, if k is initially 4, it can be increased to 5. Then, 5 points are uniformly extracted from the initial mapping function as the search starting point for iteration. Simultaneously, the temperature parameter is also reset to its initial value, which can be 1.
[0084] Understandably, the more search points there are, the more accurate the resulting mapping function will be. For example... Figure 3A and Figure 3B As shown, Figure 3A The middle line represents the mapping function curve 1 obtained when there are fewer search points. Figure 3B The middle figure shows the mapping function curve 2 obtained when there are relatively more search points. It can be seen that mapping curve 2 has more points than mapping curve 1. The mapping function can be divided into multiple segments from these points, and each segment can have a different mapping transformation method. The more k values there are, the more segments there are, the more accurate the mapping, and the less smooth the function curve. k can be up to 254, and with the addition of 0 and 255, each gray level will have a corresponding mapping method. To avoid overfitting, the number of k values can be limited, for example, k cannot exceed 50, 100, 150, etc. The specific range of k values can be set according to the actual situation, and this implementation method is not limited to this.
[0085] The mapping function of this invention is not limited to a certain standard function, and its function curve is also different from that of the standard function. This greatly reduces the restrictions on the function form, thereby increasing the probability of approximating the optimal solution.
[0086] Continue to refer to Figure 2 In step 24, at the end of the iteration, the current mapping function is used as the target mapping function. Then, step 50 is executed: the final target image is used as the processing result of the image to be processed. That is, the target image whose image quality parameters meet the preset conditions is the final processing result.
[0087] For each image to be processed, the image itself can be used during the iteration process to verify the processing effect of the mapping function, obtaining the target image with the optimal processing effect for the image itself, which is then used as the final processing result. This processing result can be used for image recognition, object detection, and other processing tasks. Compared to directly using the original image to be processed for these tasks, the processed result after adjusting the image to be processed can improve the performance of image recognition, object detection, and other processing tasks, such as achieving higher recognition accuracy.
[0088] For example, depending on the specific image processing task, the image to be processed can be segmented to identify the target region. Then, a target mapping function can be used to adjust the target region, which can reduce the amount of data processed and improve processing speed. For instance, when performing face recognition, the face in the image to be processed can be located first to obtain the coordinates of the face region. Then, based on the coordinates of the face region, a target mapping function can be used to adjust the face region, which can increase the contrast of the face region and make the facial features more prominent, thereby improving the accuracy of face recognition.
[0089] In the above embodiments, while searching for the optimal solution, the number of iterations is controlled by the simulated annealing algorithm, which reduces the time complexity of the search process and improves search efficiency; at the same time, it also ensures the possibility of finding the global optimum. Furthermore, determining whether the solution is optimal based on the image processing results has practical significance for image processing and can improve image recognition accuracy. In addition, the mapping function in this embodiment is not limited to a single functional form; by using multiple points to perform relatively independent transformations on each grayscale segment, it gets closer to the global optimum.
[0090] like Figure 4 As shown, the image processing method of the present invention may further include the following steps:
[0091] In step 31, points are uniformly selected on s = r according to the value of k. s = r is a curve with a slope of 1, where s is the output gray level and r is the input gray level. k points are uniformly extracted on this curve. In step 32, vertical perturbation is applied to these k points to generate a new set of k points. Applying vertical perturbation means changing the s value of the points while keeping the r value unchanged. The updated points for each point can be obtained using the above formula (1). For example, the R coefficient in formula (1) can be set as the temperature parameter T. The initial value of the temperature parameter T can be 1. In step 33, based on the set of k points and the points (0,0) and (1,1), a polynomial f of order k+1 is obtained. This polynomial f is the mapping function corresponding to the set of k points. In step 34, f is used to perform a mapping transformation on the image to be processed to obtain the target image, and the gray level histograms of the image to be processed and the target image are determined. In step 35, it is determined whether the target image is better than the image to be processed. If the grayscale histogram of the target image is closer to the target grayscale histogram, it can be determined that the grayscale histogram of the target image is superior to that of the image to be processed. If the target image is superior to the image to be processed, proceed to step 36; otherwise, return to step 32. In step 36, retain the group of k points while reducing the temperature parameter. Annealing can be performed according to a pre-set annealing rule, for example, T = T / 2, reducing the temperature parameter to half of its original value. Then, proceed to step 37 to determine if the adjustment effect meets the requirements. If the distance between the grayscale histogram of the target image and the target grayscale histogram is less than the third preset value, it can be determined that the adjustment effect on the image (i.e., the target image) meets the requirements. If the distance between the grayscale histogram of the target image and the target grayscale histogram is not less than the third preset value, the adjustment effect does not meet the requirements. If the adjustment effect meets the requirements, the iteration ends, and the mapping function f at this time is the target mapping function.
[0092] If the adjustment effect does not meet the requirements, proceed to step 38: determine if the temperature parameter is less than a specific threshold. If the temperature parameter is less than the specific threshold, proceed to step 39. Alternatively, in step 37, it can also be determined whether the temperature parameter is 0. For example, in each iteration, the temperature parameter is reduced to half of its original value. When the reduced temperature parameter is less than a specific threshold, such as 0.1 or 0.05, the temperature parameter is set to 0. If the temperature parameter is not less than the specific threshold or is not equal to 0, return to step 32, update the k points retained in step 35, obtain the updated k points again, and continue iterating. In step 39, increase the value of k, reset the temperature parameter to the initial value, and then return to step 31. For example, k increases by 1 each time, i.e., k = k + 1, and the temperature parameter is also reset to 1. In the next iteration, extract k points evenly on the curve s = r again and enter the iteration again. If the adjustment effect still does not meet the requirements in this iteration, the value of k can be increased again. As the number of extracted points increases, regardless of how the threshold of the temperature parameter changes, the effect closest to the optimal solution can eventually be achieved. Considering the impact of the number of points on time complexity and curve smoothness, we can limit the maximum value of k so that k can only increase to this maximum value.
[0093] It is necessary to understand that Figure 4 The implementation details of each step have been described in detail in the above implementation methods, and will not be repeated here to avoid repetition.
[0094] Through the above Figure 4 After obtaining the optimal target mapping function through the iterative process, this target mapping function can be used to adjust the brightness of the image to be processed. Compared with the commonly used Gamma transform, which uses a uniform Gamma curve to map all gray levels, it is obviously not suitable for adjusting every gray level. In this invention, the target mapping function can determine the corresponding mapping method for each gray level, which can adapt to complex images and improve the accuracy of image brightness adjustment. For example, as... Figure 5A and Figure 5B As shown, the face portion in Image 1 is an image adjusted using Gamma transformation, while the face portion in Image 2 is an image with brightness adjusted using the target mapping function obtained iteratively in the above embodiments of the present invention. The brightness contrast of the face portion in Image 2 is more pronounced, and the facial features are clearer. For face recognition tasks, Image 2 is easier to extract features from and easier to recognize.
[0095] Furthermore, the present invention also provides an image processing apparatus capable of performing the above-described image processing method. The image processing apparatus provided by the present invention will now be described, and the image processing apparatus described below can be referred to in correspondence with the image processing method described above.
[0096] like Figure 6 As shown, the image processing device 50 may include an initial mapping module 51, used to obtain an initial mapping function corresponding to the image to be processed, wherein the initial mapping function is used to characterize the correspondence between the input grayscale and the output grayscale of the image to be processed; a mapping update module 52, used to update the initial mapping function to obtain a mapping function; an adjustment determination module 53, used to adjust the input grayscale of the image to be processed based on the mapping function to obtain a target image; an iteration module 54, used to continue updating the mapping function if the image quality parameters of the target image do not meet the preset conditions, until the image quality parameters of the target image meet the preset conditions; and an image processing module 55, used to use the finally obtained target image as the processing result of the image to be processed.
[0097] In one embodiment of the present invention, the iteration module 54 specifically includes: an extraction module, used to extract k search starting points from the initial mapping function, where k is a positive integer; an update module, used to enter an iteration step, the iteration step including: updating the search starting points to obtain the updated k points, and determining the mapping function corresponding to the updated k points; a loop module, used to take the updated k points as search starting points and then enter the iteration step again when the image quality parameters do not meet the preset conditions; and an exit iteration module, used to end the iteration step when the image quality parameters meet the preset conditions, and take the mapping function at the end of the iteration step as the target mapping function.
[0098] In one embodiment of the present invention, the loop module specifically includes: an annealing module, used to obtain temperature parameters when the image quality parameters do not meet preset conditions, and reduce the temperature parameters based on a simulated annealing algorithm; and a search point update module, used to take the updated k points as the search starting point and then enter the iteration step when the reduced temperature parameters are not less than the first preset value.
[0099] In one embodiment of the present invention, the image processing device 50 further includes: an quantity increasing module, configured to increase k and reset the temperature parameter when the reduced temperature parameter is less than the first preset value; and a re-extraction module, configured to re-extract the search starting point in the initial mapping function based on the increased k value and enter the iteration step.
[0100] In one embodiment of the present invention, the image processing apparatus 50 further includes: a confidence level acquisition module, configured to determine the confidence level when recognizing the target image, and when the confidence level is greater than a second preset value, determine that the image quality parameters of the target image meet the preset condition.
[0101] In one embodiment of the present invention, the image processing apparatus 50 further includes: a confidence determination module, configured to determine the confidence level when recognizing the image to be processed and the confidence level when recognizing the target image; a discard module, configured to discard the updated k points and proceed to the iteration step when the confidence level of the target image is not greater than the confidence level of the image to be processed; and a retention module, configured to retain the updated k points when the confidence level of the target image is greater than the confidence level of the image to be processed.
[0102] In one embodiment of the present invention, the image processing device 50 further includes: a grayscale determination module, configured to determine the grayscale histogram of the target image, and when the distance between the grayscale histogram and the target grayscale histogram is less than a third preset value, determine that the image quality parameters of the target image meet the preset conditions.
[0103] Figure 7 This is a schematic diagram of the structure of the electronic device provided in the embodiment of the present invention, such as... Figure 7 As shown, the electronic device may include a processor 610, a communications interface 620, a memory 630, and a communication bus 640, wherein the processor 610, communications interface 620, and memory 630 communicate with each other via the communication bus 640. The processor 610 can call logical instructions in the memory 630 to execute an image processing method. This method includes: obtaining an initial mapping function corresponding to the image to be processed, the initial mapping function being used to characterize the correspondence between the input grayscale and output grayscale of the image to be processed; updating the initial mapping function to obtain a mapping function; adjusting the input grayscale of the image to be processed based on the mapping function to obtain a target image; if the image quality parameters of the target image do not meet preset conditions, continuing to update the mapping function until the image quality parameters of the target image meet the preset conditions; and using the finally obtained target image as the processing result of the image to be processed.
[0104] Furthermore, the logical instructions in the aforementioned memory 630 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, essentially, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. 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.
[0105] On the other hand, the present invention also provides a computer program product, which includes a computer program that can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the image processing methods provided by the above methods. The method includes: obtaining an initial mapping function corresponding to the image to be processed, the initial mapping function being used to characterize the correspondence between the input grayscale and the output grayscale of the image to be processed; updating the initial mapping function to obtain a mapping function; adjusting the input grayscale of the image to be processed based on the mapping function to obtain a target image; if the image quality parameters of the target image do not meet the preset conditions, continuing to update the mapping function until the image quality parameters of the target image meet the preset conditions; and using the finally obtained target image as the processing result of the image to be processed.
[0106] In another aspect, the present invention also provides a non-transitory computer-readable storage medium storing a computer program thereon. When executed by a processor, the computer program implements the image processing methods provided by the above methods. The method includes: obtaining an initial mapping function corresponding to an image to be processed, the initial mapping function being used to characterize the correspondence between the input grayscale and the output grayscale of the image to be processed; updating the initial mapping function to obtain a mapping function; adjusting the input grayscale of the image to be processed based on the mapping function to obtain a target image; if the image quality parameters of the target image do not meet a preset condition, continuing to update the mapping function until the image quality parameters of the target image meet the preset condition; and using the finally obtained target image as the processing result of the image to be processed.
[0107] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0108] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0109] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. An image processing method, characterized in that, include: Obtain the initial mapping function corresponding to the image to be processed, wherein the initial mapping function is used to characterize the correspondence between the input gray level and the output gray level of the image to be processed; The initial mapping function is updated to obtain the new mapping function; The input grayscale of the image to be processed is adjusted based on the mapping function to obtain the target image; If the image quality parameters of the target image do not meet the preset conditions, the mapping function continues to be updated until the image quality parameters of the target image meet the preset conditions. The final target image is used as the processing result of the image to be processed; The step of updating the initial mapping function to obtain the mapping function includes: extracting k search starting points from the monotonically increasing initial mapping function, where k is a positive integer, and the output grayscale of the k search starting points increases sequentially along the direction of increasing input grayscale; iteratively randomly perturbing the output grayscale of each search starting point to obtain updated k points; wherein, the perturbation range of the iterative random perturbation is determined according to the output grayscale boundary of the k points obtained in the previous iteration, so that the perturbed output grayscale is within a preset grayscale range; the perturbation amplitude of the iterative random perturbation decreases as the number of iterations increases; and determining the mapping function based on the updated k points when the updated k points satisfy the condition of monotonically increasing output grayscale.
2. The image processing method according to claim 1, characterized in that, The step of continuing to update the mapping function when the image quality parameters of the target image do not meet the preset conditions, until the image quality parameters of the target image meet the preset conditions, includes: Extract k search starting points from the initial mapping function, where k is a positive integer; The process proceeds to the iteration step, which includes: updating the search starting point to obtain the updated k points, and determining the mapping function corresponding to the updated k points; When the image quality parameters do not meet the preset conditions, the updated k points are used as the search starting point, and the iteration step is then entered. When the image quality parameters meet the preset conditions, the iteration step ends, and the mapping function at the end of the iteration step is taken as the target mapping function.
3. The image processing method according to claim 2, characterized in that, When the image quality parameters do not meet the preset conditions, the updated k points are used as the search starting point, and the iteration step is then initiated, including: When the image quality parameters do not meet the preset conditions, the temperature parameters are obtained, and the temperature parameters are reduced based on the simulated annealing algorithm; If the reduced temperature parameter is not less than the first preset value, the updated k points are used as the search starting point, and then the iteration step is entered.
4. The image processing method according to claim 3, characterized in that, The method further includes: If the reduced temperature parameter is less than the first preset value, increase k and reset the temperature parameter; Based on the increased value of k, the search starting point is extracted again from the initial mapping function, and the iteration step is then initiated.
5. The image processing method according to claim 1, characterized in that, The method further includes: Determine the confidence level when identifying the target image, and when the confidence level is greater than a second preset value, determine that the image quality parameters of the target image meet the preset conditions.
6. The image processing method according to claim 2, characterized in that, The method further includes: Determine the confidence level when recognizing the image to be processed and the confidence level when recognizing the target image; When the confidence level of the target image is not greater than the confidence level of the image to be processed, the updated k points are discarded, and the iteration step is initiated. When the confidence level of the target image is greater than the confidence level of the image to be processed, the updated k points are retained.
7. The image processing method according to claim 1, characterized in that, The method further includes: The grayscale histogram of the target image is determined. When the distance between the grayscale histogram and the target grayscale histogram is less than a third preset value, the image quality parameters of the target image are determined to meet the preset conditions.
8. An image processing apparatus, characterized in that, To implement the image processing method according to any one of claims 1 to 7, comprising: An initial mapping module is used to obtain an initial mapping function corresponding to the image to be processed. The initial mapping function is used to characterize the correspondence between the input grayscale and the output grayscale of the image to be processed. The mapping update module is used to update the initial mapping function to obtain the mapping function; The adjustment and determination module is used to adjust the input grayscale of the image to be processed based on the mapping function to obtain the target image; An iterative module is used to continue updating the mapping function when the image quality parameters of the target image do not meet the preset conditions, until the image quality parameters of the target image meet the preset conditions; The image processing module is used to take the final target image as the processing result of the image to be processed.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the image processing method as described in any one of claims 1 to 7.
10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the image processing method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Automatic SAR image segmentation method based on graph division particle swarm optimization
CN107220985A
Image brightness adjustment method and device, storage medium and electronic device
CN110120021A