Image correction method, device, electronic device, and computer-readable storage medium
By calculating the offset values of pixels in the image and performing correction processing, the problem of image distortion caused by rolling shutter is solved, the visual effect is significantly improved, correction anomalies caused by false detections are avoided, and the image is efficiently corrected.
Patent Information
- Application Number
- CN202110754003.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-07-04
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2041-07-04
AI Technical Summary
Image distortion (such as tilt distortion, wavy distortion, compression and stretching distortion) caused by rolling shutter affects the visual effect, especially in videos, which will reduce the look and feel.
By obtaining the input image and the reference image, the offset value of each pixel is calculated, and the offset value is used to determine whether it is a motion offset or image distortion offset, and corresponding correction processing is performed, including the combination of interpolation algorithm and time domain algorithm. to correct image distortion.
It effectively solves the problem of image distortion, significantly improves the visual effect, avoids correction anomalies caused by false detections, and improves the smoothness and robustness of the image.
Smart Images

Figure CN113658053B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing technology, and in particular to an image correction method, device, electronic equipment, and computer-readable storage medium. Background Art
[0002] The process of camera imaging is as follows: light enters the camera through the lens, and the shutter controls the image sensor to form an image. Among them, the shutter can be divided into rolling shutter and global shutter according to its working mode. The former reads pixels line by line, while the latter reads pixels on the entire sensor in parallel. Usually, the rolling shutter corresponds to the CMOS sensor, and the global shutter corresponds to the CCD sensor. Considering factors such as cost and readout noise, CMOS sensors based on rolling shutter are widely used. However, since this type of image sensor uses a line-by-line exposure method, the exposure time of each row of pixels is not synchronized. When the camera moves, there are moving objects in the imaging scene, or the camera is affected by special internal devices and there is jitter, the camera imaging result will be distorted. This distortion is also called the jello effect. Figure 1 Several common distortion forms are given, such as tilt distortion, wavy distortion, and compression-stretch distortion. As can be seen from the figure, this type of distortion greatly affects the visual effect, especially when presented in a video, it will further reduce the viewing experience. Therefore, it is very necessary to correct this type of distortion, which can greatly improve the visual effect. Summary of the invention
[0003] The present invention provides an image correction method, device, electronic device, and computer-readable storage medium. The method can solve the problem of image distortion and improve the visual effect.
[0004] To solve the above technical problems, the first technical solution provided by the present invention is: to provide an image correction method, including: obtaining an input image and a reference image corresponding to the input image; calculating the offset value of each pixel point in the input image relative to the corresponding pixel point in the reference image; and correcting the input image using the offset value.
[0005] Among them, the step of correcting the input image using the offset value includes: judging whether the offset of the input image is a motion offset or an image distortion offset based on the offset value; in response to the offset of the input image being a motion offset, correcting the offset value and correcting the input image using the corrected offset value; in response to the offset of the input image being an image distortion offset, correcting the input image using the offset value.
[0006] Among them, the step of judging whether the offset of the input image is a motion offset or an image distortion offset based on the offset value includes: calculating a first offset average value of the input image, where the first offset average value is the average value of the offset values of pixels whose offset values are greater than a first threshold; judging whether the offset of the input image is a motion offset or an image distortion offset based on the first offset average value.
[0007] Among them, the step of judging whether the offset of the input image is a motion offset or an image distortion offset based on the first offset average value includes: counting a first number of pixel points in each row of pixels in the input image whose offset value is greater than the first offset average value; and counting a second number of pixel points in each row of pixels in the input image whose offset value is greater than a first set value; and counting a third number of pixel points in each row of pixels in the input image whose offset value is greater than a second set value; wherein the first set value is the sum of the first offset average value and the second threshold value, and the second set value is the sum of the first offset average value and the third threshold value; calculating the ratio of the second number corresponding to each row of pixels to the third set value, the third set value is the sum of the first number and the fourth set value, and the fourth set value is 1; in response to the ratio being not less than the fourth threshold value and not greater than the fifth threshold value, or in response to the third number being not greater than the sixth threshold value, judging that the offset factor is an image distortion offset; in response to the ratio being less than the fourth threshold value and greater than the fifth threshold value, and / or in response to the third number being greater than the sixth threshold value, judging that the offset factor is a motion offset.
[0008] The step of calculating the offset value of each pixel in the input image relative to the corresponding pixel in the reference image includes: using an optical flow calculation method to calculate the offset value of each pixel in the input image relative to the corresponding pixel in the reference image.
[0009] The step of calculating the offset value of each pixel in the input image relative to the corresponding pixel in the reference image using the optical flow calculation method also includes: smoothing the offset value using a guided filtering method.
[0010] The step of smoothing the offset value using a guided filtering method includes: smoothing the offset value based on the input image using a guided filtering method.
[0011] The step of correcting the offset value includes: calculating a second offset average value of the offset values of the pixels in the preset area corresponding to each pixel of the input image, the second offset average value being the corrected offset value.
[0012] The step of correcting the offset value includes: obtaining the difference between the offset value of each pixel point of the input image and the first offset average value; and correcting the offset value using the difference.
[0013] The step of correcting the offset value using the difference includes: shrinking the offset value using the difference to obtain a corrected offset value; wherein the degree of shrinkage is positively correlated with the difference.
[0014] Among them, the step of correcting the offset value using the difference includes: in response to the difference being greater than the fifth set value, shrinking the offset value using a first shrinkage degree to obtain a corrected offset value; in response to the difference being not greater than the fifth set value, shrinking the offset value using a second shrinkage degree to obtain a corrected offset value; wherein the first shrinkage degree is greater than the second shrinkage degree.
[0015] The corrected offset value is calculated using formula (1): DX=dx-dx×dec(1); wherein DX is the corrected offset value, dx is the offset value of the pixel point, and dec is the first contraction degree or the second contraction degree.
[0016] Among them, the step of correcting the input image using the offset value includes: in response to the offset of the input image being a motion offset, using an interpolation algorithm to correct the input image using the corrected offset value; in response to the offset of the input image being an image distortion offset, using an interpolation algorithm to correct the input image using the offset value.
[0017] Among them, the step of correcting the input image using the offset value includes: in response to the offset of the input image being a motion offset, an interpolation algorithm combined with a time domain algorithm is used to correct the input image using the corrected offset value; in response to the offset of the input image being an image distortion offset, an interpolation algorithm combined with a time domain algorithm is used to correct the input image using the offset value.
[0018] The step of acquiring the input image and the reference image corresponding to the input image includes: obtaining the reference image of the current input image based on the current input image and the reference image of the previous input image frame of the current input image.
[0019] Among them, the reference image of the input image is calculated using formula (2): REF=ra×cur+(1-ra)×ref(2); wherein REF is the reference image of the current input image, ra is a weighting coefficient with a value range of (0, 1), cur is the current input image, and ref is the reference image of the previous input frame of the current input image.
[0020] The offset value includes an offset value in a first direction and an offset value in a second direction.
[0021] To solve the above technical problems, the second technical solution provided by the present invention is: to provide an image correction device, including: an acquisition module, used to acquire an input image and a reference image corresponding to the input image; a calculation module, used to calculate the offset value of each pixel point in the input image relative to the corresponding pixel point in the reference image; and a correction module, used to correct the input image using the offset value.
[0022] To solve the above technical problems, the third technical solution provided by the present invention is: to provide an electronic device, comprising: a memory and a processor, wherein the memory stores program instructions, and the processor calls the program instructions from the memory to execute any of the above methods.
[0023] In order to solve the above technical problems, the fourth technical solution provided by the present invention is: providing a computer-readable storage medium storing a program file, and the program file can be executed to implement any of the above methods.
[0024] The beneficial effects of the present invention are different from those of the prior art. The image correction method of the present invention calculates the offset value of each pixel point in the input image relative to the corresponding pixel point in the reference image based on the reference image; then the offset value is used to correct the input image, thereby solving the image distortion problem and improving the visual effect. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for describing the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative work, among which:
[0026] Figure 1 is a schematic diagram of image distortion in the prior art;
[0027] Figure 2 A schematic diagram of a flow chart of an embodiment of an image correction method of the present invention;
[0028] Figure 3 A flowchart of an embodiment for determining whether the offset of an input image is a motion offset or an image distortion offset;
[0029] Figure 4a Schematic diagram of the input image before correction;
[0030] Figure 4b is a schematic diagram of the corrected input image;
[0031] Figure 5 It is a structural schematic diagram of a first embodiment of an image correction device of the present invention;
[0032] Figure 6 is a schematic structural diagram of a second embodiment of an image correction device of the present invention;
[0033] Figure 7 It is a structural schematic diagram of an embodiment of an electronic device of the present invention;
[0034] Figure 8 It is a schematic diagram of the structure of an embodiment of a computer-readable storage medium of the present invention. DETAILED DESCRIPTION
[0035] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0036] See also Figure 2 , is a flow chart of an embodiment of the image correction method of the present invention, which specifically includes:
[0037] Step S11: Acquire an input image and a reference image corresponding to the input image.
[0038] Specifically, an input image is obtained and a reference image corresponding to the input image is calculated. In one embodiment, a reference image of the current input image is obtained based on the current input image and a reference image of an input image of a previous frame of the current input image. For example, the reference image of the input image of the previous frame of the current input image and the current input image are weighted to obtain the reference image of the current input image.
[0039] In a specific embodiment, taking video data as an example, it includes multiple image frames. For a first frame of input image, its corresponding reference image is the first frame of input image. For a second frame of input image, the reference image of the second frame of input image can be calculated using the second frame of input image and the reference image of the first frame of input image. Specifically, the calculation method of calculating the reference image of the input image is as follows:
[0040] REF=ra×cur+(1-ra)×ref(2);
[0041] Wherein, REF is the reference image of the current input image, ra is the weighting coefficient, the value range is (0, 1), cur is the current input image, and ref is the reference image of the previous input image of the current input image. In one embodiment, ra is 0.05.
[0042] It should be noted that the method of the present application can be applied to many different types of images, such as RGB images, or YUV images, etc. Taking YUV images as an example, the input image can be, for example, a brightness channel, and it can be understood that the reference image also corresponds to a brightness channel.
[0043] Step S12: Calculate the offset value of each pixel in the input image relative to the corresponding pixel in the reference image.
[0044] In one embodiment, an optical flow algorithm may be used to calculate the offset value of each pixel in the input image relative to the corresponding pixel in the reference image. The offset value includes an offset value in a first direction and an offset value in a second direction. The first direction is the x direction, and the second direction is the y direction. For example, the optical flow algorithm is used to calculate the offset value dy of each pixel in the input image relative to the corresponding pixel in the reference image in the y direction (column direction), and the offset value dx in the x direction (row direction).
[0045] The optical flow algorithm may be an LK (Lucas-Kanade) optical flow algorithm, or an HS (Horn Schunck) optical flow algorithm, or the like.
[0046] In one embodiment, the offset value is further smoothed using a guided filtering method. This can effectively reduce the correction abnormality problem caused by optical flow false detection. In a specific embodiment, the input image can be used as a guided graph, and the offset value is smoothed based on the guided graph, that is, the input image, using a guided filtering method. This process can reduce the correction abnormality problem caused by optical flow false detection.
[0047] Specifically, after the offset value is calculated, it can be determined based on the offset value whether the offset of the input image is motion offset or image distortion offset.
[0048] Specifically, Figure 1 The several distortion phenomena shown may be caused by two phenomena, one is the distortion caused by target motion offset, and the other is the distortion caused by image distortion offset. In actual application, the distortion caused by target motion offset needs to correct the offset value first, and then use the corrected offset value to correct the input image, while the image distortion offset is directly corrected by the offset value.
[0049] Specifically, Figure 3 As shown, the step of determining whether the offset of the input image is motion offset or image distortion offset based on the offset value specifically includes:
[0050] Step S31: Calculate a first offset average value of the input image, where the first offset average value is the average value of the offset values of pixels whose offset values are greater than a first threshold.
[0051] Specifically, the offset value dx in the x direction (row direction) is used as an example. The absolute value of the offset value of each pixel point can be calculated, denoted as a, and the average value a1 of the offset values of all pixels whose absolute value a is greater than the first threshold th1 is calculated, and the average value a1 is the first offset average value. The processing method of the offset value dy in the y direction (column direction) is the same as the processing method of the offset value dx in the x direction (row direction).
[0052] Step S32: determining whether the offset of the input image is motion offset or image distortion offset based on the first offset average value.
[0053] Specifically, count the first number B1 of pixels in each row of pixels in the input image whose offset value dx is greater than the first offset average value a1; count the second number B2 of pixels in each row of pixels in the input image whose offset value dx is greater than the first set value C1; and count the third number B3 of pixels in each row of pixels in the input image whose offset value dx is greater than the second set value C2. Wherein, the first set value C1 is the sum of the first offset average value a1 and the second threshold value th2, that is, C1=a1+th2; the second set value C2 is the sum of the first offset average value a1 and the third threshold value th3, that is, C2=a1+th3. Calculate the ratio of the second number B2 corresponding to each row of pixels to the third set value C3, the third set value C3 is the sum of the first number B1 and the fourth set value C4, and the fourth set value C4 is 1. That is, calculate B2 / (B1+C4), where C4 is 1, that is, calculate the value N of B2 / (B1+1). In response to the ratio N being less than the fourth threshold th4 and greater than the fifth threshold th5, and / or in response to the third number B3 being greater than the sixth threshold th6, the offset factor is determined to be motion offset. That is, if th5<N<th4, or B3>th6, the offset factor is motion offset. In response to the ratio N being not less than the fourth threshold th4 and not greater than the fifth threshold th5, or in response to the third number B3 being not greater than the sixth threshold th6, the offset factor is determined to be image distortion offset. Specifically, if th4≤N≤th5, or B3≤th6, the offset factor is image distortion offset.
[0054] Specifically, in this embodiment, the judgment is performed row by row. For a row, if it is determined that a moving object is included in the above method, the offset value is first corrected to obtain a corrected offset value, and the position containing the moving object is corrected using the corrected offset value. If it is determined that a moving object is not included in the above method, the position not containing the moving object is corrected using the offset value. In this way, the situation of incorrect correction can be avoided.
[0055] In one embodiment, if the offset is a motion offset, the offset value is corrected to obtain a corrected offset value. Specifically, a second offset average value of the offset values of the pixels in the preset area corresponding to each pixel of the input image is calculated, and the second offset average value is the corrected offset value. The corrected offset value is used to correct the area containing the moving object.
[0056] In another embodiment, the difference between the offset value dx of each pixel of the input image and the first offset average value a1 can also be obtained. Specifically, the difference between the absolute value a of the offset value dx and the first offset average value a1 is calculated. That is, diff=a-a1. The offset value is corrected using the difference to obtain a corrected offset value.
[0057] In a specific embodiment, the offset value dx is shrunk by using the difference value diff to obtain the corrected offset value; wherein the degree of shrinkage is positively correlated with the difference value diff. For example, the larger the difference value diff is, the greater the degree of shrinkage of the offset value dx is, and the smaller the difference value diff is, the smaller the degree of shrinkage of the offset value dx is. Specifically, the difference value diff is compared with the fifth set value, and in response to the difference value diff being greater than the fifth set value, the offset value dx is shrunk by using the first degree of shrinkage to obtain the corrected offset value. In response to the difference value diff being not greater than the fifth set value, the offset value dx is shrunk by using the second degree of shrinkage to obtain the corrected offset value; wherein the first degree of shrinkage is greater than the second degree of shrinkage.
[0058] In a specific embodiment, the seventh threshold th7 can be used to reduce the difference diff to a predetermined range, and the predetermined range can be (0, 1). For example, dec1=diff×th7 is calculated. If dec1 is greater than 1, then dec=1; if dec1 is less than 0, then dec=0; if dec1 is not greater than 1 and not less than 0, then dec=dec1. Specifically:
[0059]
[0060] Among them, dec is the contraction degree, that is, if dec1>1, the first contraction degree dec is 1, if dec1<0, the second contraction degree is 0, otherwise, the contraction degree is dec1.
[0061] In one embodiment, the corrected offset value is calculated using the following formula (1):
[0062] DX = dx - dx × dec (1);
[0063] Among them, DX is the corrected offset value, dx is the offset value of the pixel point, and dec is the first shrinkage degree or the second shrinkage degree.
[0064] The processing method of the offset value dy in the y direction (column direction) is the same as the processing method of the offset value dx in the x direction (row direction). The corrected offset value DY of the offset value dy in the y direction (column direction) can be calculated in the same manner as above, and the details are not repeated here.
[0065] Step S13: Correct the input image using the offset value.
[0066] In one embodiment, in response to the offset of the input image being a motion offset, an interpolation algorithm may be used to correct the input image using the corrected offset value. In response to the offset of the input image being an image distortion offset, an interpolation algorithm may be used to correct the input image using the offset value. The interpolation algorithm may be a bilinear interpolation algorithm. It may also be a bicubic interpolation algorithm.
[0067] Specifically, if the input image of this embodiment is an image of a brightness channel, the three channels YUV of the input image can be corrected separately using an interpolation algorithm. For example, a bilinear interpolation algorithm is selected to calculate and obtain the correction result of each channel. Alternatively, a nearest neighbor or bicubic interpolation algorithm can be selected to calculate and obtain the correction result of each channel, and then the correction is performed.
[0068] In another embodiment, in response to the offset of the input image being a motion offset, an interpolation algorithm combined with a time domain algorithm may be used to correct the input image using the corrected offset value. In response to the offset of the input image being an image distortion offset, an interpolation algorithm combined with a time domain algorithm may be used to correct the input image using the offset value. Combining the time domain algorithm may further optimize the correction result. Specifically, Figure 4a as well as Figure 4b As shown, Figure 4a is the input image before correction, Figure 4b is the corrected input image. As can be seen from the figure, the method of the present application has a good effect on the correction of distorted images. The method of this embodiment can solve the problem of image distortion. Specifically, image distortion includes but is not limited to image distortion caused by rolling shutter.
[0069] In a specific embodiment, the values of the first threshold, the second threshold, the third threshold, the fourth threshold, the fifth threshold, the sixth threshold and the seventh threshold proposed in this application are: 1, 3, 4.5, 0.1, 0, 3, 0.4 respectively.
[0070] In one embodiment, in order to further improve the correction result, the above-mentioned steps S12 and S13 can be implemented multiple times, without specific limitation. Specifically, the present application can use the method of steps S12 and S13 to perform n corrections. The larger the value of n, the more stable the correction result, and the less sensitive to false detection, but the amount of calculation will increase. Therefore, the specific value of n depends on the actual situation. Preferably, n can be set to 2, that is, the above-mentioned steps S12 and S13 are used to perform two corrections. It can be understood that the input of the second correction is the output of the first correction, that is, the image of the second correction is the image after the first correction.
[0071] The image correction method of the present application does not rely on any a priori assumptions, does not require cumbersome and complicated camera or moving object modeling processes, and has strong algorithm generalization capabilities. It can handle both image distortion problems caused by camera motion and image distortion caused by moving objects in the scene. By re-detecting and processing the motion area, the motion area and non-motion area in the output results of the optical flow detection algorithm are distinguished and differentiated, which further improves the visual effect while avoiding correction anomalies. In a variety of ways, the impact of false detection on the correction effect is reduced or minimized, and the robustness is better.
[0072] See also Figure 5 , is a schematic diagram of the structure of an embodiment of the image correction device of the present invention, which specifically includes: an acquisition module 61, a calculation module 62 and a correction module 63.
[0073] The acquisition module 61 is used to acquire the input image and the reference image corresponding to the input image. In a specific embodiment, taking video data as an example, it includes multiple image frames. For the first frame of input image, the corresponding reference image is the first frame of input image. For the second frame of input image, the acquisition module 61 can use the second frame of input image and the reference image of the first frame of input image to calculate the reference image of the second frame of input image. Specifically, the acquisition module 61 calculates the reference image of the input image in the following manner:
[0074] REF=ra×cur+(1-ra)×ref (2);
[0075] Wherein, REF is the reference image of the current input image, ra is the weighting coefficient, the value range is (0, 1), cur is the current input image, and ref is the reference image of the previous input image of the current input image. In one embodiment, ra is 0.05.
[0076] It should be noted that the method of the present application can be applied to many different types of images, such as RGB images, or YUV images, etc. Taking YUV images as an example, the input image can be, for example, a brightness channel, and it can be understood that the reference image also corresponds to a brightness channel.
[0077] The calculation module 62 is used to calculate the offset value of each pixel in the input image relative to the corresponding pixel in the reference image. In one embodiment, the calculation module 62 can use an optical flow algorithm to calculate the offset value of each pixel in the input image relative to the corresponding pixel in the reference image. The offset value includes an offset value in a first direction and an offset value in a second direction. The first direction is the x direction, and the second direction is the y direction. For example, the optical flow algorithm is used to calculate the offset value dx of each pixel in the input image relative to the corresponding pixel in the reference image in the x direction (row direction), and the offset value dy in the y direction (column direction).
[0078] The optical flow algorithm may be an LK (Lucas-Kanade) optical flow algorithm, or an HS (Horn Schunck) optical flow algorithm, or the like.
[0079] In one embodiment, the calculation module 62 further uses a guided filtering method to smooth the offset value. This can effectively reduce the correction abnormality problem caused by optical flow false detection. In a specific embodiment, the input image can be used as a guided graph, and the offset value can be smoothed based on the guided graph, that is, the input image, using a guided filtering method. This process can reduce the correction abnormality problem caused by optical flow false detection.
[0080] The calculation module 62, after calculating the offset value, determines whether the offset of the input image is a motion offset or an image distortion offset based on the offset value. The distortion caused by the target motion offset requires first correcting the offset value, and then using the corrected offset value to correct the input image, while the image distortion offset is directly corrected using the offset value. Specifically, the calculation module 62 counts a first offset average value of the input image, the first offset average value being the average value of the offset values of the pixels whose offset values are greater than the first threshold, and determines whether the offset of the input image is a motion offset or an image distortion offset based on the first offset average value.
[0081] In one embodiment, the calculation module 62 counts the first number B1 of the pixels in each row of the input image whose offset value dx is greater than the first offset average value a1; and counts the second number B2 of the pixels in each row of the input image whose offset value dx is greater than the first set value C1; and counts the third number B3 of the pixels in each row of the input image whose offset value dx is greater than the second set value C2. Wherein, the first set value C1 is the sum of the first offset average value a1 and the second threshold value th2, that is, C1=a1+th2; the second set value C2 is the sum of the first offset average value a1 and the third threshold value th3, that is, C2=a1+th3. The ratio of the second number B2 corresponding to each row of pixels to the third set value C3 is calculated, and the third set value C3 is the sum of the first number B1 and the fourth set value C4, and the fourth set value C4 is 1. That is, B2 / (B1+C4) is calculated, where C4 is 1, that is, the value N of B2 / (B1+1) is calculated. In response to the ratio N being less than the fourth threshold th4 and greater than the fifth threshold th5, and / or in response to the third number B3 being greater than the sixth threshold th6, the offset factor is determined to be motion offset. That is, if th5<N<th4, or B3>th6, the offset factor is motion offset. In response to the ratio N being not less than the fourth threshold th4 and not greater than the fifth threshold th5, or in response to the third number B3 being not greater than the sixth threshold th6, the offset factor is determined to be image distortion offset. Specifically, if th4≤N≤th5, or B3≤th6, the offset factor is image distortion offset.
[0082] Specifically, in this embodiment, the judgment is performed row by row. For a row, if it is determined that a moving object is included in the above method, the offset value is first corrected to obtain a corrected offset value, and the position containing the moving object is corrected using the corrected offset value. If it is determined that a moving object is not included in the above method, the position not containing the moving object is corrected using the offset value. In this way, the situation of incorrect correction can be avoided.
[0083] In one embodiment, if the offset is a motion offset, the offset value is corrected to obtain a corrected offset value. Specifically, the calculation module 62 calculates a second offset average value of the offset values of the pixels in the preset area corresponding to each pixel of the input image, and the second offset average value is the corrected offset value. The corrected offset value is used to correct the area containing the moving object.
[0084] In another embodiment, the calculation module 62 may also obtain the difference between the offset value dx of each pixel of the input image and the first offset average value a1. Specifically, the difference between the absolute value a of the offset value dx and the first offset average value a1 is calculated. That is, diff=a-a1. The offset value is corrected using the difference offset value to obtain a corrected offset value.
[0085] In a specific embodiment, the calculation module 62 shrinks the offset value dx using the difference diff to obtain the corrected offset value; wherein the shrinkage degree is positively correlated with the difference diff. For example, the larger the difference diff is, the greater the shrinkage degree of the offset value dx is, and the smaller the difference diff is, the smaller the shrinkage degree of the offset value dx is. Specifically, the difference diff is compared with the fifth set value, and in response to the difference diff being greater than the fifth set value, the offset value dx is shrunk using the first shrinkage degree to obtain the corrected offset value. In response to the difference diff being not greater than the fifth set value, the offset value dx is shrunk using the second shrinkage degree to obtain the corrected offset value; wherein the first shrinkage degree is greater than the second shrinkage degree.
[0086] In a specific embodiment, the calculation module 62 can use the seventh threshold th7 to reduce the difference to within a predetermined range, and the predetermined range can be (0, 1). For example, dec1=diff×th7 is calculated. If dec1 is greater than 1, then dec=1; if dec1 is less than 0, then dec=0; if dec1 is not greater than 1 and not less than 0, then dec=dec1. Specifically:
[0087]
[0088] Among them, dec is the contraction degree, that is, if dec1>1, the first contraction degree dec is 1, if dec1<0, the second contraction degree is 0, otherwise, the contraction degree is dec1.
[0089] In one embodiment, the calculation module 62 calculates the corrected offset value using the following formula (1):
[0090] DX = dx - dx × dec (1);
[0091] Among them, DX is the corrected offset value, dx is the offset value of the pixel point, and dec is the first shrinkage degree or the second shrinkage degree.
[0092] The processing method of the offset value dy in the y direction (column direction) is the same as the processing method of the offset value dx in the x direction (row direction). The corrected offset value DY of the offset value dy in the y direction (column direction) can be calculated in the same manner as above, and the details are not repeated here.
[0093] The correction module 63 is used to correct the input image using the offset value. In one embodiment, in response to the offset of the input image being a motion offset, the correction module 63 may use an interpolation algorithm to correct the input image using the corrected offset value. In response to the offset of the input image being an image distortion offset, the correction module 63 uses an interpolation algorithm to correct the input image using the offset value. The interpolation algorithm may be a bilinear interpolation algorithm. It may also be a bicubic interpolation algorithm.
[0094] Specifically, if the input image of this embodiment is an image of a brightness channel, the correction module 63 can use an interpolation algorithm to correct the three channels YUV of the input image respectively. For example, a bilinear interpolation algorithm is selected to calculate the correction result of each channel. Alternatively, a nearest neighbor or bicubic interpolation algorithm can be selected to calculate the correction result of each channel, and then the correction is performed.
[0095] In another embodiment, in response to the offset of the input image being a motion offset, the correction module 63 may further use an interpolation algorithm combined with a time domain algorithm to correct the input image using the corrected offset value. In response to the offset of the input image being an image distortion offset, the correction module 63 uses an interpolation algorithm combined with a time domain algorithm to correct the input image using the offset value. Combining the time domain algorithm can further optimize the correction result. Specifically, Figure 4a as well as Figure 4b As shown, Figure 4a is the input image before correction, Figure 4b It is known from the figure that the device of the present application has a good effect on the correction of distorted images.
[0096] In one embodiment, in order to further improve the correction result, the calculation module 62 and the correction module 63 can be set to n. The larger the value of n, the more stable the correction result and the less sensitive to false detection. However, the amount of calculation will be increased. Therefore, the specific value of n depends on the actual situation. Figure 6 As shown, the present application can set two calculation modules 62 and correction modules 63, that is, perform two corrections. It can be understood that during the second correction, the input of the second calculation module 62 is the output of the first correction module 63, that is, the image corrected for the second time is the image corrected for the first time, and the output of the last correction module 63 is the final corrected image.
[0097] The image correction device of the present application does not rely on any a priori assumptions, does not require cumbersome and complicated camera or moving object modeling processes, and has a strong algorithm generalization capability. It can handle both image distortion problems caused by camera motion and image distortion caused by moving objects in the scene. By re-detecting and processing the motion area, the motion area and non-motion area in the output results of the optical flow detection algorithm are distinguished and differentiated, which further improves the visual effect while avoiding correction anomalies. In a variety of ways, the impact of false detection on the correction effect is reduced or minimized, and the robustness is better.
[0098] See also Figure 7 , is a schematic diagram of the structure of an electronic device according to an embodiment of the present invention, the electronic device includes a memory 202 and a processor 201 connected to each other.
[0099] The memory 202 is used to store program instructions for implementing any one of the above methods.
[0100] The processor 201 is used to execute program instructions stored in the memory 202 .
[0101] The processor 201 may also be referred to as a CPU (Central Processing Unit). The processor 201 may be an integrated circuit chip having signal processing capabilities. The processor 201 may also be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0102] The memory 202 can be a memory stick, a TF card, etc., which can store all the information in the electronic device of the device, including the input raw data, computer programs, intermediate operation results and final operation results are all stored in the memory. It stores and retrieves information according to the location specified by the controller. With the memory, the electronic device has a memory function to ensure normal operation. The memory of the electronic device can be divided into main memory (internal memory) and auxiliary memory (external memory) according to its use, and there is also a classification method of dividing it into external memory and internal memory. External memory is usually a magnetic medium or an optical disk, etc., which can store information for a long time. Memory refers to the storage component on the motherboard, which is used to store the data and programs currently being executed, but is only used to temporarily store programs and data. If the power is turned off or the power is cut off, the data will be lost.
[0103] In the several embodiments provided in the present application, it should be understood that the disclosed methods and devices can be implemented in other ways. For example, the device implementation described above is only schematic. For example, the division of modules or units is only a logical function division. There may be other division methods in actual implementation, such as 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 through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0104] 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 present embodiment.
[0105] 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.
[0106] 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, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a system server, or a network device, etc.) or a processor to execute all or part of the steps of the various implementation methods of the present application.
[0107] See also Figure 8, which is a schematic diagram of the structure of the computer-readable storage medium of the present invention. The storage medium of the present application stores a program file 203 that can implement all the above methods, wherein the program file 203 can be stored in the above storage medium in the form of a software product, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor (processor) to execute all or part of the steps of each implementation method of the present application. The aforementioned storage device includes: a U disk, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a disk or an optical disk, etc., which can store program codes, or terminal devices such as computers, servers, mobile phones, and tablets.
[0108] The above are only implementation modes of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. An image correction method, It is characterized in that include: Acquire an input image and a reference image corresponding to the input image; Calculating the offset value of each pixel in the input image relative to the corresponding pixel in the reference image; Correcting the input image using the offset value; Among them, the correcting the input image using the offset value includes: in response to determining that the offset of the input image is a motion offset based on the offset value, correcting the offset value, and correcting the input image using the corrected offset value; in response to determining that the offset of the input image is an image distortion offset based on the offset value, correcting the input image using the offset value.
2. The method according to claim 1, It is characterized in that The step of correcting the input image by using the offset value comprises: It is determined based on the offset value whether the offset of the input image is a motion offset or an image distortion offset.
3. The method according to claim 2, It is characterized in that The step of determining whether the offset of the input image is motion offset or image distortion offset based on the offset value comprises: Counting a first offset average value of the input image, where the first offset average value is an average value of offset values of pixels whose offset values are greater than a first threshold; Based on the first offset average value, it is determined whether the offset of the input image is a motion offset or an image distortion offset.
4. The method according to claim 3, It is characterized in that The step of determining whether the offset of the input image is motion offset or image distortion offset based on the first offset average value comprises: Counting a first number of pixel points in each row of pixel points in the input image whose offset value is greater than the first offset average value; and counting a second number of pixel points in each row of pixel points in the input image whose offset value is greater than a first set value; and counting a third number of pixel points in each row of pixel points in the input image whose offset value is greater than a second set value; wherein the first set value is the sum of the first offset average value and a second threshold value, and the second set value is the sum of the first offset average value and a third threshold value; Calculate the ratio of the second number corresponding to each row of pixels to a third set value, where the third set value is the sum of the first number and a fourth set value, and the fourth set value is 1; In response to the ratio being not less than a fourth threshold and not greater than a fifth threshold, or in response to the third number being not greater than a sixth threshold, determining that the offset factor is an image distortion offset; In response to the ratio being smaller than the fourth threshold and larger than the fifth threshold, and / or in response to the third number being larger than the sixth threshold, it is determined that the offset factor is motion offset.
5. The method according to claim 1, It is characterized in that The step of calculating the offset value of each pixel in the input image relative to the corresponding pixel in the reference image comprises: The optical flow calculation method is used to calculate the offset value of each pixel in the input image relative to the corresponding pixel in the reference image.
6. The method according to claim 5, It is characterized in that The step of calculating the offset value of each pixel in the input image relative to the corresponding pixel in the reference image by using the optical flow calculation method also includes: The offset value is smoothed using a guided filtering method.
7. The method according to claim 6, It is characterized in that The step of smoothing the offset value using the guided filtering method comprises: The offset value is smoothed based on the input image using a guided filtering method.
8. The method according to claim 2, It is characterized in that The step of correcting the offset value comprises: A second offset average value of the offset values of the pixel points in the preset area corresponding to each pixel point of the input image is calculated, and the second offset average value is the corrected offset value.
9. The method according to claim 2, It is characterized in that The step of correcting the offset value comprises: Obtaining a difference between an offset value of each pixel of the input image and a first offset average value; The offset value is corrected using the difference value.
10. The method according to claim 9, It is characterized in that The step of correcting the offset value by using the difference value comprises: The offset value is shrunk using the difference value to obtain the corrected offset value; wherein the degree of shrinkage is positively correlated with the difference value.
11. The method according to claim 10, It is characterized in that The step of correcting the offset value by using the difference value comprises: In response to the difference being greater than a fifth set value, shrinking the offset value using a first shrinkage degree to obtain a corrected offset value; In response to the difference being not greater than the fifth set value, shrinking the offset value using a second shrinkage degree to obtain a corrected offset value; Wherein, the first contraction degree is greater than the second contraction degree.
12. The method according to claim 11, It is characterized in that The corrected offset value is calculated using formula (1): DX = dx - dx × dec (1); Among them, DX is the offset value after correction, dx is the offset value of the pixel point, and dec is the first shrinkage degree or the second shrinkage degree.
13. The method according to claim 1, It is characterized in that The step of correcting the input image by using the offset value comprises: In response to the offset of the input image being a motion offset, correcting the input image using an interpolation algorithm using the corrected offset value; In response to the offset of the input image being an image distortion offset, an interpolation algorithm is used to correct the input image using the offset value.
14. The method according to claim 1, It is characterized in that The step of correcting the input image by using the offset value comprises: In response to the offset of the input image being a motion offset, an interpolation algorithm combined with a time domain algorithm is used to correct the input image using the corrected offset value; In response to the offset of the input image being an image distortion offset, an interpolation algorithm combined with a time domain algorithm is used to correct the input image using the offset value.
15. The method according to claim 1, It is characterized in that The step of acquiring an input image and a reference image corresponding to the input image comprises: A reference image of the current input image is obtained based on the current input image and a reference image of an input image of a previous frame of the current input image.
16. The method according to claim 15, It is characterized in that The reference image of the input image is obtained by using formula (2): REF=ra×cur+(1-ra)×ref (2); Among them, REF is the reference image of the current input image, ra is the weighting coefficient, and the value range is (0, 1), cur is the current input image, and ref is the reference image of the previous input image of the current input image.
17. The method according to claim 2, It is characterized in that The offset value includes an offset value in a first direction and an offset value in a second direction.
18. An image correction device, It is characterized in that include: An acquisition module, used to acquire an input image and a reference image corresponding to the input image; A calculation module, used to calculate the offset value of each pixel in the input image relative to the corresponding pixel in the reference image; A correction module is used to correct the input image using the offset value, specifically, in response to determining that the offset of the input image is a motion offset based on the offset value, correcting the offset value, and correcting the input image using the corrected offset value; in response to determining that the offset of the input image is an image distortion offset based on the offset value, correcting the input image using the offset value.
19. An electronic device, It is characterized in that include: A memory and a processor, wherein the memory stores program instructions, and the processor retrieves the program instructions from the memory to execute the image correction method according to any one of claims 1 to 17.
20. A computer-readable storage medium, It is characterized in that A program file is stored, and the program file can be executed to implement the image correction method according to any one of claims 1 to 17.
