A method, system and related device for image shadow correction
By dividing areas in the image and using gray surface images for linear or cosine compensation correction, the problems of information distortion, high computational complexity and insufficient adaptability of the shadow correction algorithm in the prior art are solved, and efficient and accurate shadow correction is achieved. Effect, suitable for a variety of application scenarios.
Patent Information
- Application Number
- CN202411178889.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-27
- Publication Date
- 2025-01-03
- Estimated Expiration
- 2044-08-27
AI Technical Summary
In the prior art, shadow correction algorithms may cause image information to be distorted when removing shadows, high computational complexity, difficult to meet real-time application requirements, and insufficient versatility and adaptability, and are only suitable for shadow processing of specific types and scenes.
By dividing rectangular areas and concentric circle areas, using first-order and second-order gray surface images for linear or cosine compensation correction, combining preset parameters and brightness threshold judgment, flexibly adjust the compensation mode to adapt to the shadow distribution of different types and scenes, directly in The original color space is compensated to avoid deviations introduced by color space conversion.
Reduces calculation complexity and processing time, improves adaptability to different types of shadows and scenes, ensures efficient and accurate shadow correction effect, avoids color deviation and distortion in color space conversion, and is suitable for a wider range of application scenarios .
Smart Images

Figure CN118691516B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of image shadow correction, and in particular to a method, system and related device for image shadow correction. Background Art
[0002] Due to uneven lighting, tilted camera shooting angle and other reasons, shadows often appear in images, which will affect the image quality and subsequent image processing tasks. In order to improve this problem, it is necessary to perform shadow correction on the image. Image shadow correction is a key technology in the field of computer vision and image processing, and has been widely used in medical imaging, remote sensing images, video surveillance and other fields.
[0003] Some shadow correction algorithms in the prior art require color space conversion when removing shadows, which may cause image information distortion and affect image quality. Some other shadow correction algorithms have significant effects, but they have high computational complexity and long processing time, making it difficult to meet the needs of real-time application scenarios. Moreover, these shadow correction algorithms often only work well for specific types of shadows and specific scenes, and perform poorly for different scenes or different types of shadows, and lack versatility and adaptability. Summary of the invention
[0004] The present application provides a method, system and related devices for image shadow correction, which are used to flexibly adjust the compensation mode according to different shadow distribution conditions, and ensure efficient and accurate shadow correction effects in a wider range of application scenarios.
[0005] The first aspect of the present application provides a method for image shading correction, comprising: the method comprises compensating and correcting the image to be corrected by way one or / and way two;
[0006] The first method includes:
[0007] Acquire the image to be corrected, divide the image to be corrected into at least four rectangular areas, and calculate the brightness level of each rectangular area;
[0008] Determine whether a difference in brightness levels between two adjacent rectangular areas among the at least four rectangular areas exceeds a preset threshold;
[0009] If yes, taking the origin of the image to be corrected as the center and combining the first preset parameters to construct a first-order first gray curved surface image, and performing linear compensation correction on the image to be corrected according to the first gray curved surface image;
[0010] The second method includes:
[0011] Acquire the image to be corrected, and determine a correction reference point of the image to be corrected;
[0012] Dividing the image to be corrected into a plurality of concentric circle areas, and calculating the brightness level of each concentric circle area;
[0013] Determining whether the brightness levels of the plurality of concentric circle areas show a trend of gradually decreasing from the center to the periphery;
[0014] If yes, taking the correction reference point as the center and combining with the second preset parameters, construct a second-order second gray curved surface image, and perform linear compensation correction on the image to be corrected according to the second gray curved surface image;
[0015] If not, a second-order third gray surface image is constructed with the correction reference point as the center in combination with the camera principal axis distance parameter and the third preset parameter, and cosine compensation correction is performed on the image to be corrected according to the third gray surface image.
[0016] Optionally, performing linear compensation correction on the image to be corrected according to the second gray curved surface image includes:
[0017] Performing a linear transformation on the second gray surface image by using a first target formula;
[0018] The second gray surface image after linear transformation is multiplied by the image to be corrected to obtain an output image after linear compensation correction.
[0019] Optionally, the first target formula is:
[0020] v' = v * (Ratio_2-Ratio_1) / Max+ Ratio_1;
[0021] Wherein, v is the second gray surface image, Ratio_1 and Ratio_2 are linear compensation coefficients, Max is the maximum grayscale value of the second gray surface image, and v' is the second gray surface image after linear transformation.
[0022] Optionally, performing cosine compensation correction on the image to be corrected according to the third gray curved surface image includes:
[0023] Performing cosine transformation on the third gray surface image by using a second target formula;
[0024] The third gray curved surface image after cosine transformation is multiplied by the image to be corrected to obtain an output image after cosine compensation correction.
[0025] Optionally, the second target formula is:
[0026] ;
[0027] Wherein, v is the third gray curved surface image, level is a positive integer greater than 1, and v' is the third gray curved surface image after linear transformation.
[0028] Optionally, determining a correction reference point of the image to be corrected includes:
[0029] Converting the image to be corrected into a grayscale image, and calculating a brightness histogram and a cumulative histogram of the grayscale image;
[0030] Determining a brightness threshold according to the cumulative histogram, and determining a bright area in the grayscale image based on the brightness threshold;
[0031] A correction reference point of the image to be corrected is determined according to the center of gravity of the bright area.
[0032] Optionally, determining a correction reference point of the image to be corrected according to the center of gravity of the bright area includes:
[0033] Counting the number of the bright areas, and calculating the grayscale average value of each bright area;
[0034] Performing weighted processing on each of the bright areas according to the grayscale average value;
[0035] The correction reference point of the image to be corrected is determined according to the center of gravity of all the bright areas after weighted processing.
[0036] A second aspect of the present application provides a system for image shading correction, comprising: a first compensation correction unit and / or a second compensation correction unit, wherein the first compensation correction unit and the second compensation correction unit are used to acquire an image to be corrected and perform compensation correction on the image to be corrected;
[0037] The first compensation correction unit comprises:
[0038] A first division module, used for dividing the image to be corrected into at least four rectangular areas, and calculating the brightness level of each rectangular area;
[0039] A first judging module, configured to judge whether a difference in brightness levels between two adjacent rectangular areas in the at least four rectangular areas exceeds a preset threshold;
[0040] A first correction module, configured to, when the judgment result of the first judgment module is yes, construct a first-order first gray curved surface image with the origin of the image to be corrected as the center and in combination with a first preset parameter, and perform linear compensation correction on the image to be corrected according to the first gray curved surface image;
[0041] The second compensation correction unit comprises:
[0042] A determination module, used to determine a correction reference point of the image to be corrected;
[0043] A second division module is used to divide the image to be corrected into a plurality of concentric circle areas and calculate the brightness level of each concentric circle area;
[0044] The second judging module is used to judge whether the brightness levels of the plurality of concentric circle areas show a trend of gradually decreasing from the center to the surrounding areas;
[0045] A second correction module, configured to construct a second-order second gray surface image with the correction reference point as the center and in combination with a second preset parameter when the judgment result of the second judgment module is yes, and perform linear compensation correction on the image to be corrected according to the second gray surface image;
[0046] The third correction module is used to construct a second-order third gray surface image with the correction reference point as the center and in combination with the camera main axis distance parameter and the third preset parameter when the judgment result of the second judgment module is no, and perform cosine compensation correction on the image to be corrected according to the third gray surface image.
[0047] Optionally, the second correction module is specifically used for:
[0048] Performing a linear transformation on the second gray surface image by using a first target formula;
[0049] The second gray surface image after linear transformation is multiplied by the image to be corrected to obtain an output image after linear compensation correction.
[0050] Optionally, the first target formula is:
[0051] v' = v * (Ratio_2-Ratio_1) / Max+ Ratio_1;
[0052] Wherein, v is the second gray surface image, Ratio_1 and Ratio_2 are linear compensation coefficients, Max is the maximum grayscale value of the second gray surface image, and v' is the second gray surface image after linear transformation.
[0053] Optionally, the third correction module is specifically used for:
[0054] Performing cosine transformation on the third gray surface image by using a second target formula;
[0055] The third gray curved surface image after cosine transformation is multiplied by the image to be corrected to obtain an output image after cosine compensation correction.
[0056] Optionally, the second target formula is:
[0057] ;
[0058] Wherein, v is the third gray curved surface image, level is a positive integer greater than 1, and v' is the third gray curved surface image after linear transformation.
[0059] Optionally, the second acquisition module is specifically used to:
[0060] Converting the image to be corrected into a grayscale image, and calculating a brightness histogram and a cumulative histogram of the grayscale image;
[0061] Determining a brightness threshold according to the cumulative histogram, and determining a bright area in the grayscale image based on the brightness threshold;
[0062] A correction reference point of the image to be corrected is determined according to the center of gravity of the bright area.
[0063] Optionally, the second acquisition module is further configured to:
[0064] Counting the number of the bright areas, and calculating the grayscale average value of each bright area;
[0065] Performing weighted processing on each of the bright areas according to the grayscale average value;
[0066] The correction reference point of the image to be corrected is determined according to the center of gravity of all the bright areas after weighted processing.
[0067] A third aspect of the present application provides a device for image shading correction, the device comprising:
[0068] Processor, memory, input-output unit, and bus;
[0069] The processor is connected to the memory, the input and output unit, and the bus;
[0070] The memory stores a program, and the processor calls the program to execute the first aspect and any optional image shading correction method in the first aspect.
[0071] A fourth aspect of the present application provides a computer-readable storage medium, on which a program is stored. When the program is executed on a computer, the method for image shading correction in the first aspect and any optional method in the first aspect is executed.
[0072] It can be seen from the above technical solutions that this application has the following advantages:
[0073] By dividing the rectangular area and the concentric circle area, and using the gray surface image for linear or cosine compensation correction, the computational complexity and processing time are reduced, which can meet the needs of real-time applications. In addition, this method judges the brightness level difference of the rectangular area in method one, and judges the brightness level trend according to the concentric circle area in method two, and selects different first-order or second-order gray surface images for linear or cosine multi-mode shadow correction compensation, thereby improving the adaptability to different types of shadows and various scenes, and can flexibly adjust the compensation mode according to different shadow distribution conditions, which can ensure efficient and accurate shadow correction effects in a wider range of application scenarios. Moreover, the present application directly performs compensation correction through the gray surface in the original color space, which effectively avoids the color deviation and distortion problems that may be introduced during the color space conversion process, and ensures the authenticity of the image and the complete retention of details.
[0074] Especially in the scenario of display panel defect detection, the camera can more easily capture mura-type defects by shooting at a side view angle, but it will cause uneven image brightness. At this time, the image shadow correction method provided by the present application is particularly suitable. It can reasonably and efficiently correct the shadow according to the actual situation of the image, and adaptively select different correction modes for the shadows caused by different shooting situations, while ensuring the algorithm rhythm to maximize the image quality and detection effect. BRIEF DESCRIPTION OF THE DRAWINGS
[0075] In order to more clearly illustrate the technical solution in the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0076] Figure 1 A schematic diagram of an embodiment of a method for image shadow correction provided in this application;
[0077] Figure 2 This is a schematic diagram of the compensation effect before and after of the first method provided in the present application;
[0078] Figure 3 This is a schematic diagram of an embodiment of the second method of image shadow correction in the method provided by the present application;
[0079] Figure 4 A schematic diagram of a correction reference point in the method provided in this application;
[0080] Figure 5 This is a schematic diagram of the linear correction compensation effect before and after the second method provided in the present application;
[0081] Figure 6This is a schematic diagram of the cosine correction compensation effect before and after the second method provided in the present application;
[0082] Figure 7 A schematic diagram of the structure of an embodiment of the image shadow correction system provided by the present application;
[0083] Figure 8 A schematic diagram of the physical structure of an embodiment of the image shadow correction device provided in the present application. DETAILED DESCRIPTION
[0084] The present application provides a method, system and related devices for image shadow correction, which are used to flexibly adjust the compensation mode according to different shadow distribution conditions, and ensure efficient and accurate shadow correction effects in a wider range of application scenarios.
[0085] It should be noted that the image shadow correction method provided in this application can be applied to a terminal or a server. For example, the terminal can be a smart phone or a computer, a tablet computer, a smart TV, a smart watch, a portable computer terminal, or a fixed terminal such as a desktop computer. For the convenience of explanation, this application uses a terminal as an example for the execution subject.
[0086] See also Figure 1 , Figure 1 An embodiment of the method for image shading correction provided by the present application includes obtaining an image to be corrected, and directly using method one, or directly using method two, and performing compensation correction on the image to be corrected by combining method one with method two. The following is a specific description:
[0087] Method 1:
[0088] 101. Divide the image to be corrected into at least four rectangular areas, and calculate the brightness level of each rectangular area;
[0089] First, obtain the image to be corrected and divide it into at least four rectangular areas. Then calculate the brightness level of each rectangular area respectively. The brightness level can be the sum of the brightness in the rectangular area or the average brightness in the rectangular area. The specific details are not limited here. When the brightness level is the sum of the brightness, extract the brightness value of each pixel in the rectangular area, and then add up the brightness values of all pixels in the area to get the sum of the brightness of the rectangular area. By calculating the brightness levels of these rectangular areas, the brightness distribution of the image in the horizontal and vertical directions can be understood, thereby providing data support for subsequent shadow correction.
[0090] The size and number of rectangular regions can be flexibly adjusted according to specific application requirements to adapt to different image scenes and brightness changes. These rectangular regions can be divided as follows: upper left region, upper right region, lower left region, and lower right region to obtain the most basic brightness distribution information. The entire image to be corrected can also be divided into more detailed grids, such as dividing the image into 3x2 or 4x3 grids, and the brightness level of each rectangular region can be calculated and analyzed separately.
[0091] 102. Determine whether a difference in brightness levels between two adjacent rectangular areas among at least four rectangular areas exceeds a preset threshold;
[0092] In the process of image shadow correction, by comparing the brightness level difference between two adjacent rectangular areas, it can be determined whether there is a shadow. If the brightness difference between two adjacent rectangular areas exceeds a preset threshold, it indicates that there is a significant brightness unevenness between these areas, that is, there may be a shadow. The preset threshold is a percentage threshold of the brightness difference. For example, the preset threshold can be set to 10%. If the brightness level difference between two adjacent rectangular areas exceeds 10%, for example, the brightness level difference between the upper left area and the upper right area exceeds 10%, then it means that there is a significant brightness unevenness between the upper left area and the upper right area, and it is necessary to perform the subsequent step 103 to perform shadow correction.
[0093] 103. Taking the origin of the image to be corrected as the center and combining the first preset parameters, construct a first-order first gray curved surface image, and perform linear compensation correction on the image to be corrected according to the first gray curved surface image;
[0094] If it is confirmed that the difference in brightness between two adjacent rectangular areas exceeds a preset threshold, that is, there is a shadow, the terminal takes the origin of the image to be corrected as the center and combines the first preset parameters to construct a first-order first gray surface image to perform linear compensation correction on the image to be corrected. The first-order first gray surface image is generated by the following formula:
[0095] ImageSurface(r,c) = Alpha(r - Row) +Beta(c - Column) +Gamma;
[0096] The first preset parameter r and c represent the row and column index parameters of the image respectively. is the offset, which determines the reference level of the grayscale value of the entire first gray surface image. The average grayscale value of the image can be normalized to 0-1 to obtain the reference level. Row and Column are the reference points for defining the first gray surface image to be created, and the image origin is selected by default.
[0097] Alpha and Beta are the first-order coefficients in the vertical and horizontal directions respectively. When the first-order first gray surface image is used to perform linear compensation correction on the image to be corrected, the settings of the parameters Alpha and Beta can be divided into two cases: up and down compensation and left and right compensation:
[0098] If the difference in brightness between two adjacent rectangular areas in the vertical direction exceeds a preset threshold, the up-down compensation correction is applied. The parameter Beta in the first gray surface image is a first-order coefficient in the horizontal direction, which indicates the slope parameter in the row direction and determines the tilt of the image in the row direction. It is set to 0 in the up-down compensation correction mode. The parameter Alpha is a first-order coefficient in the vertical direction, which indicates the slope parameter in the column direction. In the up-down compensation correction mode, the average grayscale difference between the upper and lower parts of the image and the whole, Mean_top_diff and Mean_bottom_diff, need to be calculated respectively, and then the absolute value of the difference between Mean_top_diff and Mean_bottom_diff, diff1, is calculated. The value of Alpha can be obtained by normalizing diff1 from the image grayscale interval to between 0 and 1.
[0099] If the difference in brightness between two adjacent rectangular areas in the horizontal direction exceeds a preset threshold, left-right compensation correction is applied. The parameter Alpha in the first gray surface image is a first-order coefficient in the vertical direction, indicating the slope parameter in the row direction, which determines the degree of inclination of the image in the row direction. It is set to 0 in the left-right compensation correction mode. The parameter Beta is a first-order coefficient in the horizontal direction, indicating the slope parameter in the column direction. In the left-right compensation correction mode, the average grayscale difference Mean_left_diff and Mean_right_diff between the left and right parts of the image and the whole need to be calculated respectively, and then the absolute value diff2 of the difference between Mean_left_diff and Mean_right_diff is calculated. The value of Beta can be obtained by normalizing diff2 from the image grayscale interval to between 0 and 1.
[0100] Specifically, when the image to be corrected is linearly compensated by the first gray surface image, the first gray surface image needs to be linearly transformed to obtain a compensation image, which can correct the shadow or uneven brightness in the image to be corrected. The compensated image is multiplied by the image to be corrected to obtain the corrected output image. Figure 2 , Figure 2 (2a) is the image to be corrected, which has uneven brightness on the left and right sides. Figure 2 (2b) is the compensated image obtained by linearly transforming the first gray surface image generated around the reference point. Figure 2 (2c) in the figure is the rectified output image.
[0101] It should be noted that, when determining whether the difference in brightness levels of two adjacent rectangular areas among the at least four rectangular areas exceeds a preset threshold in step 102, if the difference in brightness levels of all rectangular areas does not exceed the preset threshold, it means that there is no obvious brightness unevenness in the image. At this time, according to actual needs and application scenarios, there are two processing methods:
[0102] 1. End the process: If the brightness uniformity of the image meets the requirements, the process can be ended directly, indicating that the image has no obvious brightness unevenness and no further processing is required. This situation is suitable for application scenarios that do not require high brightness uniformity.
[0103] 2. Execution mode 2 (subsequent steps 104 to 108) performs more complex shadow judgment and compensation correction. This situation is suitable for application scenarios with higher requirements for brightness uniformity.
[0104] Method 2:
[0105] 104. Determine a correction reference point of the image to be corrected;
[0106] The terminal obtains the image to be corrected and determines a correction reference point in the image to be corrected. The correction reference point may be the center point of brightness distribution in the image or other specific position, such as the geometric center or brightness center of the image, which is not specifically limited here.
[0107] 105. Divide the image to be corrected into a plurality of concentric circle areas, and calculate the brightness level of each concentric circle area;
[0108] The terminal divides the image to be corrected into several concentric circle areas. When dividing the concentric circle areas, the center point of the image can be used as the center of the circle, and the correction reference point can be used as the center of the circle. The specific details are not limited here. After determining the center of the circle, several concentric circle areas are divided around the center of the circle. The number and radius of the rings can be set according to needs. The radius of each concentric circle area can be set to a fixed value or a gradually increasing value. In each concentric circle area, the brightness level of all pixels in the area is calculated. The brightness level can be the mean or sum of the brightness.
[0109] 106. Determine whether the brightness levels of several concentric circle areas tend to decrease gradually from the center to the surrounding areas;
[0110] The terminal analyzes whether the brightness level change from the center to the outside shows a gradually decreasing trend based on the brightness levels of the concentric circle areas, that is, analyzes whether the brightness of the image to be corrected gradually decreases from the center to the surrounding areas. If the brightness level change from the center to the outside shows a gradually decreasing trend, it means that the brightness attenuation of the image is relatively uniform. In this case, the linear compensation correction mode is applicable, and step 107 is executed. If the brightness level change from the center to the outside does not show a gradually decreasing trend, it means that the brightness attenuation of the image is uneven. In this case, the cosine compensation correction mode is applicable, and step 108 is executed.
[0111] In addition, the judgment of whether the brightness center of the image to be corrected is close to the geometric center can be added to further determine whether to use the linear compensation correction mode or the cosine compensation correction mode. First, calculate the brightness center of the image to be corrected. The brightness center is the center of gravity of the brightness value in the image, that is, the center point of the brightness distribution, which can be obtained by calculating the weighted average position of the brightness of all pixels in the image to be corrected. The geometric center of the image to be corrected is the geometric midpoint of the image, that is, the center position of the image. For a rectangular image, the geometric center is located at the midpoint of the width and height of the image. If the brightness center of the image is close to the geometric center, it means that the light source is irradiated vertically, the image brightness distribution is relatively uniform, and the linear compensation correction mode is suitable. If there is a significant deviation between the brightness center and the geometric center, it means that the light source or shooting angle causes uneven brightness distribution, and the cosine compensation correction mode is suitable.
[0112] 107. Taking the correction reference point as the center and combining with the second preset parameters, construct a second-order second gray surface image, and perform linear compensation correction on the image to be corrected according to the second gray surface image;
[0113] If it is confirmed that the brightness levels of several concentric circle areas tend to decrease from the center to the surrounding areas, that is, the image brightness decreases linearly from the center to the surrounding areas, then the linear compensation correction mode is selected. This linear compensation correction mode is suitable for situations where the image brightness center is close to the image geometric center, which may exist in application scenarios where the light source is irradiated from top to bottom. In the linear compensation correction mode, the terminal takes the correction reference point as the center and constructs a second-order second gray surface image in combination with the second preset parameters to perform linear compensation correction on the image to be corrected. The second-order second gray surface image is generated by the following formula:
[0114] ;
[0115] The r and c in the second preset parameter represent the row and column index parameters of the image respectively, and Gamma is the offset, which determines the reference level of the grayscale value of the entire first gray surface image. The Gamma value can be obtained by normalizing the average grayscale value of the image to 0-1. The parameters Delta and Epsilon represent the first-order coefficients in the row and column directions respectively, which determine the linear change of the grayscale value in the row and column directions. First, the average grayscale differences between the upper and lower parts and the left and right parts of the image and the whole are calculated respectively, and the absolute values of the differences between Mean_top_diff and Mean_bottom_diff, diff3, and the absolute values of the differences between Mean_left_diff and Mean_right_diff, diff4, are calculated. The values of Delta and Epsilon can be obtained by normalizing diff3 and diff4 from the image grayscale interval to between 0-1. Zeta is the zero-order coefficient, and the parameters Row and Column represent the correction reference point.
[0116] After obtaining the second gray curved surface image, the terminal performs linear compensation correction on the image to be corrected according to the second gray curved surface image.
[0117] 108. Taking the correction reference point as the center, a second-order third gray surface image is constructed in combination with the camera principal axis distance parameter and the third preset parameter, and cosine compensation correction is performed on the image to be corrected according to the third gray surface image.
[0118] If it is confirmed that the brightness levels of several concentric circle areas do not show a trend of gradually decreasing from the center to the surrounding areas, that is, the image brightness change presents a nonlinear distribution, then select the cosine compensation correction mode. This cosine compensation mode is suitable for scenes where the image brightness center and the image geometric center are somewhat deviated, which may exist in application scenarios caused by skewed shooting angles or complex lighting methods. In the cosine compensation correction mode, the terminal takes the correction reference point as the center, combines the camera main axis distance parameter and the third preset parameter to construct a second-order third gray surface image to perform cosine compensation correction on the image to be corrected. The second-order third gray surface image is generated by the following formula:
[0119] ;
[0120] Wherein, Distance is the main axis distance parameter of the camera, and the unit is image pixel. The meanings of other third preset parameters such as r, c, Gamma, Delta, Epsilon, Zeta, Row, Column, etc. are consistent with those in the linear correction compensation mode in step 107.
[0121] After obtaining the third gray surface image, the terminal performs cosine compensation correction on the image to be corrected according to the third gray surface image. The principal axis distance parameter has a direct impact on the brightness distribution of the image. By combining the principal axis distance parameter of the camera during cosine compensation correction, the brightness distribution in the actual image can be more accurately simulated, thereby achieving more accurate compensation correction.
[0122] In addition, in some specific application scenarios, such as the scenario of display panel defect detection, the camera's shooting angle is fixed, so the position and shape of the shadows presented in the image to be corrected are also relatively fixed. At this time, different correction modes can be directly selected for shadow compensation correction without judgment. Specifically, for scenes where the camera's shooting angle of view is offset in the vertical / horizontal direction or the lighting is uneven up and down / left and right, the up and down / left and right compensation mode in step 103 can be used directly. For scenes where the image is more complex and unevenly lit due to an incorrect shooting angle or complex lighting method, the linear compensation mode of step 107 or the cosine compensation mode of step 108 can be used directly. That is, a fixed correction mode can be selected in a fixed shooting scene, so that each image to be corrected can be quickly processed, fixed shadows can be eliminated, and the accuracy and reliability of defect detection can be ensured.
[0123] In this embodiment, by dividing the rectangular area and the concentric circle area, and using the gray surface image for linear or cosine compensation correction, the computational complexity and processing time are reduced, and the needs of real-time applications can be met. In addition, this method judges the brightness level difference of the rectangular area in method one, and judges the brightness level trend according to the concentric circle area in method two, and selects different first-order or second-order gray surface images for linear or cosine multi-mode shadow correction compensation, thereby improving the adaptability to different types of shadows and various scenes, and can flexibly adjust the compensation mode according to different shadow distribution conditions, and can ensure efficient and accurate shadow correction effects in a wider range of application scenarios. Moreover, the present application directly performs compensation correction through the gray surface in the original color space, effectively avoiding the color deviation and distortion problems that may be introduced during the color space conversion process, and ensuring the authenticity of the image and the complete retention of details.
[0124] Especially in the scenario of display panel defect detection, the camera can more easily capture mura-type defects by shooting at a side view angle, but it will cause uneven image brightness. At this time, the image shadow correction method provided by the present application is particularly suitable. It can reasonably and efficiently correct the shadow according to the actual situation of the image, and adaptively select different correction modes for the shadows caused by different shooting situations, while ensuring the algorithm rhythm to maximize the image quality and detection effect.
[0125] The following is a detailed description of the linear compensation correction and cosine compensation correction in method 2. Figure 3 , Figure 3This is an embodiment of the second method of image shadow correction provided by the present application, the method comprising:
[0126] 301. Convert the image to be corrected into a grayscale image, and calculate a brightness histogram and a cumulative histogram of the grayscale image;
[0127] The terminal obtains the image to be corrected and converts the color image I_input into a grayscale image I_gray to simplify subsequent processing. The terminal counts the frequency of each grayscale level (0-255) in the grayscale image to obtain a brightness histogram H. Based on the brightness histogram H, the cumulative histogram C is calculated, where C(i) represents the sum of the number of pixels with grayscale values i and below. It should be noted that before calculating the brightness histogram and cumulative histogram of the grayscale image, the grayscale image needs to be preprocessed to reduce image noise, such as performing Gaussian filtering on the grayscale image.
[0128] 302. Determine a brightness threshold according to the cumulative histogram, and determine a bright area in the grayscale image based on the brightness threshold;
[0129] The terminal determines a brightness threshold according to the cumulative histogram, for example, finds the brightness threshold of the first 25% of pixels according to the cumulative histogram C, and uses the brightness threshold as a binarization threshold to binarize the grayscale image I_gray, thereby obtaining a bright region Region.
[0130] 303. Determine a correction reference point of the image to be corrected according to the center of gravity of the bright area;
[0131] The terminal calculates the centroid of the bright region Region, which refers to the average position of all pixels in the bright region, and uses the centroid of the bright region Region as the correction reference point of the image to be corrected. Figure 4 , Figure 4 (4a) is the image to be corrected. Figure 4 (4b) is a schematic diagram of the bright area. Figure 4 (4c) is the determined correction reference point.
[0132] In some specific embodiments, if there are multiple bright areas, the correction reference point can be further corrected, and the terminal specifically performs the following steps: counting the number of bright areas and calculating the grayscale average of each bright area; performing weighted processing on each bright area according to the grayscale average; and determining the correction reference point of the image to be corrected according to the center of gravity of all the bright areas after weighted processing.
[0133] That is, the terminal first determines the number of all lit areas, and for each lit area, calculates its grayscale average. According to the grayscale average of each lit area, it is weighted, and the larger the weight, the greater the brightness contribution of the area. Then the center of gravity of all lit areas after weighted processing is calculated, and the weighted center of gravity is used as the final correction reference point of the image to be corrected.
[0134] 304. Divide the image to be corrected into a plurality of concentric circle areas, and calculate the brightness level of each concentric circle area;
[0135] 305. Determine whether the brightness levels of a plurality of concentric circle areas show a trend of gradually decreasing from the center to the periphery;
[0136] In this embodiment, steps 304 to 305 are similar to steps 105 to 106 in the above embodiment, and are not described again here.
[0137] 306. Taking the correction reference point as the center and combining the second preset parameters, construct a second-order second gray surface image;
[0138] In this embodiment, the process of constructing the second-order second gray surface image in combination with the second preset parameters in step 306 is similar to step 107 and will not be described again here.
[0139] 307. Performing a linear transformation on the second gray surface image using the first target formula;
[0140] In the linear compensation correction mode, it is necessary to perform a linear transformation on the second gray surface image in combination with the first target formula, that is, to adjust the brightness distribution of the second gray surface image and construct a compensation image that conforms to the actual brightness distribution, so as to achieve brightness uniformity and eliminate shadows when correcting and compensating the image to be corrected. Through linear transformation, the brightness gradient of each area in the second gray surface image can be adjusted to the reverse gradient of the actual brightness distribution of the image to be corrected, so as to perform appropriate brightness compensation on the shadow area and eliminate shadows. The first target formula is specifically:
[0141] v' = v * (Ratio_2-Ratio_1) / Max+ Ratio_1;
[0142] Among them, Ratio_1 and Ratio_2 are the compensation coefficients of the linear transformation, among which Ratio_1 is used to set the lower limit of the grayscale value after the linear transformation, which determines the minimum brightness level of the transformed image. In the first target formula, Ratio_1 plays a translation role, so that the entire grayscale value moves up or down to a new reference point. Ratio_2 is used to set the upper limit of the grayscale value after the linear transformation, which determines the maximum brightness level of the transformed image. In the first target formula, Ratio_2 plays a stretching role, stretching the grayscale value proportionally to a new range. Max is the maximum grayscale value of the second gray surface image v, and v' is the second gray surface image after the linear transformation, that is, the compensated image. It should be noted that in method one, the first gray surface image can also be linearly transformed according to the first target formula, but the settings of Ratio_1 and Ratio_2 are different.
[0143] See also Figure 5 , Figure 5 The image in (5a) is to be corrected, and the brightness level gradually decreases from the center to the periphery. Figure 5 (5b) is the second gray surface image after linear transformation, and the brightness level gradually increases from the center to the periphery to achieve the purpose of shadow compensation correction.
[0144] 308. Multiply the second gray surface image after linear transformation by the image to be corrected to obtain an output image after linear compensation correction;
[0145] When performing linear compensation correction, by multiplying the second gray surface image after linear transformation with the image to be corrected, the brightness distribution of the image to be corrected can be effectively adjusted to achieve brightness balance and shadow elimination, and finally obtain the output image after compensation correction. Figure 5 , Figure 5 (5c) is the output image after linear compensation correction.
[0146] 309. Taking the correction reference point as the center, a second-order third gray surface image is constructed in combination with the camera principal axis distance parameter and the third preset parameter;
[0147] In this embodiment, the process of constructing the second-order third gray surface image by combining the camera principal axis distance parameter and the third preset parameter in step 309 is similar to step 108 and will not be repeated here.
[0148] 310. Perform cosine transform on the third gray surface image using the second target formula;
[0149] In the cosine compensation correction mode, it is necessary to perform a cosine transform on the third gray surface image in combination with the second target formula. The cosine transform can nonlinearly adjust the brightness distribution of the third gray surface image to adapt to complex brightness changes. The cosine transform includes an inverse tangent operation and a cosine operation. The inverse tangent operation maps the original grayscale value to a new range so that the brightness value is more evenly distributed under nonlinear changes. These values are further adjusted by the cosine operation to make the brightness distribution more continuous and consistent with the changes in actual complex scenes. Compared with linear transformation, the cosine transform can better adapt to the situation where the brightness changes nonlinearly, thereby more effectively eliminating complex shadows. The second target formula is:
[0150] ;
[0151] The meaning of the second target formula is to perform an inverse tangent operation on the third gray surface image v, and then take the inverse of the level power result of the cosine transform, where level is an open parameter that can be adjusted according to the subsequent correction effect to flexibly control the compensation intensity. A lower level value makes the transformation smoother and is suitable for a small range of brightness changes. A higher level value makes the transformation more drastic and is suitable for a large range of brightness changes.
[0152] See also Figure 6 , Figure 6 (6a) is the image to be corrected, and there is a nonlinear distribution of brightness changes. Figure 6 (6b) is the third gray surface image after cosine transform.
[0153] 311. Multiply the third gray surface image after cosine transformation with the image to be corrected to obtain an output image after cosine compensation correction.
[0154] When performing cosine compensation correction, by multiplying the third gray surface image after cosine transformation with the image to be corrected, the brightness distribution of the image to be corrected can be effectively adjusted to achieve brightness balance and shadow elimination, and finally obtain the compensated and corrected output image. Figure 6 , Figure 6 (6c) is the output image after cosine compensation correction.
[0155] In this embodiment, for the linear transformation correction mode and the cosine transformation mode, the correction reference point can be adaptively generated, which can effectively reduce the influence of noise, adapt to different brightness distributions, and ensure the accuracy and robustness of the correction process. Based on the correction reference point, a gray surface image for correction compensation is accurately and quickly generated. By performing linear transformation or cosine transformation on the gray surface image, it is suitable for different types of shadow situations, and the real-time and adaptability of image processing are also ensured, which can significantly improve the overall quality of the image and meet various practical application requirements.
[0156] The following is a detailed description of the image shadow correction system provided by this application. Figure 7 , Figure 7 An embodiment of the system for image shading correction provided by the present application includes:
[0157] A first compensating correction unit 71 and / or a second compensating correction unit 72, wherein the first compensating correction unit 71 and the second compensating correction unit 72 are used to obtain an image to be corrected and perform compensating correction on the image to be corrected;
[0158] The first compensation correction unit 71 includes:
[0159] A first division module 711 is used to divide the image to be corrected into at least four rectangular areas and calculate the brightness level of each rectangular area;
[0160] A first judging module 712, configured to judge whether a difference in brightness levels between two adjacent rectangular areas within at least four rectangular areas exceeds a preset threshold;
[0161] A first correction module 713 is used for, when the judgment result of the first judgment module 712 is yes, taking the origin of the image to be corrected as the center and combining the first preset parameters to construct a first-order first gray surface image, and performing linear compensation correction on the image to be corrected according to the first gray surface image;
[0162] The second compensation correction unit 72 includes:
[0163] A determination module 721 is used to determine a correction reference point of the image to be corrected;
[0164] The second division module 722 is used to divide the image to be corrected into a plurality of concentric circle areas and calculate the brightness level of each concentric circle area;
[0165] The second judgment module 723 is used to judge whether the brightness levels of a plurality of concentric circle areas show a trend of gradually decreasing from the center to the surrounding areas;
[0166] The second correction module 724 is used for constructing a second-order second gray surface image with the correction reference point as the center and combining the second preset parameters when the judgment result of the second judgment module 723 is yes, and performing linear compensation correction on the image to be corrected according to the second gray surface image;
[0167] The third correction module 725 is used to construct a second-order third gray surface image centered on the correction reference point in combination with the camera main axis distance parameter and the third preset parameter when the judgment result of the second judgment module 723 is no, and perform cosine compensation correction on the image to be corrected according to the third gray surface image.
[0168] Optionally, the second correction module 724 is specifically used for:
[0169] Performing a linear transformation on the second gray surface image by using the first target formula;
[0170] The second gray surface image after linear transformation is multiplied by the image to be corrected to obtain an output image after linear compensation correction.
[0171] Optionally, the first target formula is:
[0172] v' = v * (Ratio_2-Ratio_1) / Max+ Ratio_1;
[0173] Wherein, v is the second gray surface image, Ratio_1 and Ratio_2 are linear compensation coefficients, Max is the maximum gray value of the second gray surface image, and v' is the second gray surface image after linear transformation.
[0174] Optionally, the third correction module 725 is specifically used for:
[0175] Performing cosine transformation on the third gray surface image by using the second target formula;
[0176] The third gray surface image after cosine transformation is multiplied by the image to be corrected to obtain an output image after cosine compensation correction.
[0177] Optionally, the second target formula is:
[0178] ;
[0179] Wherein, v is the third gray surface image, level is a positive integer greater than 1, and v' is the third gray surface image after linear transformation.
[0180] Optionally, the determination module 721 is specifically used for:
[0181] Convert the image to be corrected into a grayscale image, and calculate the brightness histogram and cumulative histogram of the grayscale image;
[0182] Determine a brightness threshold according to the cumulative histogram, and determine a bright area in the grayscale image based on the brightness threshold;
[0183] The correction reference point of the image to be corrected is determined according to the center of gravity of the bright area.
[0184] Optionally, the determination module 721 is further configured to:
[0185] Count the number of bright areas and calculate the average grayscale value of each bright area;
[0186] Each bright area is weighted according to the grayscale average value;
[0187] The correction reference point of the image to be corrected is determined according to the centroid of all the bright areas after weighted processing.
[0188] In this embodiment, the functions of each unit are the same as those described above. Figure 1 or Figure 3 The steps in the method embodiment shown correspond to each other and will not be repeated here.
[0189] This application also provides, see Figure 8 , Figure 8 An embodiment of the device for image shadow correction provided by the present application includes:
[0190] Processor 801, memory 802, input and output unit 803, bus 804;
[0191] The processor 801 is connected to the memory 802, the input and output unit 803 and the bus 804;
[0192] The memory 802 stores a program, and the processor 801 calls the program to execute any of the above image shading correction methods.
[0193] The present application also relates to a computer-readable storage medium, on which a program is stored. When the program is run on a computer, the computer executes any of the above-mentioned methods for image shading correction.
[0194] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0195] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0196] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0197] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0198] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, read-only memory), random access memory (RAM, random access memory), disk or optical disk, etc. Various media that can store program codes.
Claims
1. A method for image shadow correction, characterized in that: The method comprises acquiring an image to be corrected, and performing compensation correction on the image to be corrected by way one or / and way two; The first method includes: Dividing the image to be corrected into at least four rectangular areas, and calculating the brightness level of each rectangular area; Determine whether a difference in brightness levels between two adjacent rectangular areas in a vertical direction or a horizontal direction of the at least four rectangular areas exceeds a preset threshold; If so, taking the origin of the image to be corrected as the center and combining the first preset parameters to construct a first-order first gray curved surface image, and performing linear compensation correction on the image to be corrected according to the first gray curved surface image, wherein the linear compensation correction includes up and down compensation correction related to the vertical direction and left and right compensation correction related to the horizontal direction; The first gray surface image is generated by the following formula: ImageSurface(r,c) = Alpha(r - Row) +Beta(c - Column) +Gamma; Among them, r and c in the first preset parameter represent row and column index parameters of the image respectively. is the offset, Row and Column are the reference points of the first gray surface image, Beta is the first-order coefficient in the horizontal direction, and Alpha is the first-order coefficient in the vertical direction; The second method includes: Determining a correction reference point of the image to be corrected; Dividing the image to be corrected into a plurality of concentric circle areas, and calculating the brightness level of each concentric circle area; Determining whether the brightness levels of the plurality of concentric circle areas show a trend of gradually decreasing from the center to the periphery; If yes, taking the correction reference point as the center and combining with the second preset parameters, construct a second-order second gray curved surface image, and perform linear compensation correction on the image to be corrected according to the second gray curved surface image; If not, taking the correction reference point as the center, combining the camera principal axis distance parameter and the third preset parameter to construct a second-order third gray surface image, and performing cosine compensation correction on the image to be corrected according to the third gray surface image; The second gray surface image is generated by the following formula: ; Among them, r and c in the second preset parameters represent the row and column index parameters of the image respectively, Gamma is the offset, parameters Delta and Epsilon represent the first-order coefficients in the row and column directions respectively, Zeta is the zero-order coefficient, and parameters Row and Column represent the correction reference points; The third gray surface image is generated by the following formula: ; Among them, Distance in the third preset parameter is the main axis distance parameter of the camera, r and c represent the row and column index parameters of the image respectively, Gamma is the offset, parameters Delta and Epsilon represent the first-order coefficients in the row and column directions respectively, Zeta is the zero-order coefficient, and parameters Row and Column represent the correction reference points.
2. The method according to claim 1, characterized in that The performing linear compensation correction on the image to be corrected according to the second gray curved surface image comprises: Performing a linear transformation on the second gray surface image by using a first target formula; The second gray surface image after linear transformation is multiplied by the image to be corrected to obtain an output image after linear compensation correction.
3. The method according to claim 2, characterized in that The first target formula is: v' = v * (Ratio_2-Ratio_1) / Max+ Ratio_1; Wherein, v is the second gray surface image, Ratio_1 and Ratio_2 are linear compensation coefficients, Max is the maximum grayscale value of the second gray surface image, and v' is the second gray surface image after linear transformation.
4. The method according to claim 1, characterized in that: The performing cosine compensation correction on the image to be corrected according to the third gray curved surface image comprises: Performing cosine transformation on the third gray surface image by using a second target formula; The third gray curved surface image after cosine transformation is multiplied by the image to be corrected to obtain an output image after cosine compensation correction.
5. The method according to claim 4, characterized in that The second objective formula is: ; Wherein, v is the third gray curved surface image, level is a positive integer greater than 1, and v' is the third gray curved surface image after linear transformation.
6. The method according to claim 1, characterized in that The step of determining a correction reference point of the image to be corrected comprises: Converting the image to be corrected into a grayscale image, and calculating a brightness histogram and a cumulative histogram of the grayscale image; Determining a brightness threshold according to the cumulative histogram, and determining a bright area in the grayscale image based on the brightness threshold; A correction reference point of the image to be corrected is determined according to the center of gravity of the bright area.
7. The method according to claim 6, characterized in that The step of determining the correction reference point of the image to be corrected according to the center of gravity of the bright area comprises: Counting the number of the bright areas, and calculating the grayscale average value of each bright area; Performing weighted processing on each of the bright areas according to the grayscale average value; The correction reference point of the image to be corrected is determined according to the center of gravity of all the bright areas after weighted processing.
8. A system for image shading correction, characterized in that: The system comprises: a first compensation correction unit and / or a second compensation correction unit, wherein the first compensation correction unit and the second compensation correction unit are used to acquire an image to be corrected and perform compensation correction on the image to be corrected; The first compensation correction unit comprises: A first division module, used for dividing the image to be corrected into at least four rectangular areas, and calculating the brightness level of each rectangular area; A first judging module, configured to judge whether a difference in brightness levels between two adjacent rectangular areas in a vertical direction or a horizontal direction of the at least four rectangular areas exceeds a preset threshold; A first correction module, configured to, when the judgment result of the first judgment module is yes, construct a first-order first gray curved surface image with the origin of the image to be corrected as the center and in combination with a first preset parameter, and perform linear compensation correction on the image to be corrected according to the first gray curved surface image, wherein the linear compensation correction includes an up-and-down compensation correction related to the vertical direction and a left-and-right compensation correction related to the horizontal direction; The first gray surface image is generated by the following formula: ImageSurface(r,c) = Alpha(r - Row) +Beta(c - Column) +Gamma; Among them, r and c in the first preset parameter represent row and column index parameters of the image respectively. is the offset, Row and Column are the reference points of the first gray surface image, Beta is the first-order coefficient in the horizontal direction, and Alpha is the first-order coefficient in the vertical direction; The second compensation correction unit comprises: A determination module, used to determine a correction reference point of the image to be corrected; A second division module is used to divide the image to be corrected into a plurality of concentric circle areas and calculate the brightness level of each concentric circle area; The second judging module is used to judge whether the brightness levels of the plurality of concentric circle areas show a trend of gradually decreasing from the center to the surrounding areas; A second correction module, configured to construct a second-order second gray surface image with the correction reference point as the center and in combination with a second preset parameter when the judgment result of the second judgment module is yes, and perform linear compensation correction on the image to be corrected according to the second gray surface image; a third correction module, configured to, when the judgment result of the second judgment module is negative, construct a second-order third gray surface image with the correction reference point as the center, in combination with the camera principal axis distance parameter and the third preset parameter, and perform cosine compensation correction on the image to be corrected according to the third gray surface image; The second gray surface image is generated by the following formula: ; Among them, r and c in the second preset parameters represent the row and column index parameters of the image respectively, Gamma is the offset, parameters Delta and Epsilon represent the first-order coefficients in the row and column directions respectively, Zeta is the zero-order coefficient, and parameters Row and Column represent the correction reference points; The third gray surface image is generated by the following formula: ; Among them, Distance in the third preset parameter is the main axis distance parameter of the camera, r and c represent the row and column index parameters of the image respectively, Gamma is the offset, parameters Delta and Epsilon represent the first-order coefficients in the row and column directions respectively, Zeta is the zero-order coefficient, and parameters Row and Column represent the correction reference points.
9. A device for image shadow correction, characterized in that: The device comprises: Processor, memory, input-output unit, and bus; The processor is connected to the memory, the input and output unit, and the bus; The memory stores a program, and the processor calls the program to execute the method according to any one of claims 1 to 7.
10. A computer-readable storage medium having a program stored thereon, wherein the program, when executed on a computer, performs the method according to any one of claims 1 to 7.
