A color image purple fringing correction method, device and computer storage medium
By performing pixel classification marking on digital camera images and correcting in local windows, the problem of purple edge phenomenon under high contrast and large backlight is solved, and the image is better restored.
Patent Information
- Application Number
- CN202011076671.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-10-10
- Publication Date
- 2025-01-14
- Estimated Expiration
- 2040-10-10
AI Technical Summary
In high contrast and large backlight scenarios, images captured by digital cameras are prone to purple edges, and the prior art is difficult to effectively remove, affecting the image restoration effect.
By sorting the pixels according to the color information and edge information of each pixel of the input image, the pixels marked as purple edges are corrected using other pixels in the local window, which specifically includes calculating edge intensity, swelling processing and traversing the image to correct, using pre- Set the threshold value and formula to update the pixel value to reduce the purple edge phenomenon.
In the high contrast large backlight scenario, the original color of the pixel is effectively restored, the quality of the image is improved, and the occurrence of purple edges is reduced.
Smart Images

Figure CN114331857B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image and video processing, and in particular to a method and device for correcting purple fringing of a color image and a computer storage medium. Background Art
[0002] In high-contrast and backlit scenes, purple fringing is prone to occur in images taken with digital cameras. This purple fringing is not real purple fringing, but is caused by optical diffraction at the edge of still objects in high-contrast and backlit scenes, plus the inherent defects of the CCD sensor of the digital camera during color interpolation. How to remove the purple fringing of images and restore the images better is a problem that needs to be solved urgently. Summary of the invention
[0003] In view of this, the present invention provides a color image purple fringing correction method, device, computer storage medium and terminal device, which are used to solve the deficiencies of the prior art.
[0004] In order to achieve the above object, the present invention adopts the following technical scheme:
[0005] The embodiment of the present invention provides a method for correcting purple fringing of a color image, comprising:
[0006] According to the color information and edge information of each pixel of the input image, the pixels are classified and marked as purple-edge pixels, white pixels and other pixels;
[0007] Traverse the image from left to right and from top to bottom, and use other pixels in the local window to correct the pixels marked as purple-fringe pixels;
[0008] The image is traversed from right to left and from bottom to top, and the pixels marked as purple-fringe pixels are corrected using other pixels in the local window.
[0009] Furthermore, the “classifying and marking pixels as purple-edge pixels, white pixels, and other pixels according to the color information and edge information of each pixel of the input image” specifically includes:
[0010] The edge strength of each pixel is calculated using the green component of the color image; the edge strength of each pixel is equal to the difference between the strongest edge strength and the weakest edge strength in the four directions of 0°, 90°, 45°, and 135°;
[0011] According to the color information and boundary information of the pixel, two binary images are used to mark "purple pixels" and "non-purple pixels", "white pixels" and "non-white pixels" respectively; among them, when the input pixel meets , the pixel is marked as a "purple edge pixel". When , the pixel is marked as a "white pixel"; where R(i,j), G(i,j), and B(i,j) are red, green, and blue components respectively; th1, th2, thd, thL, and th3 are preset threshold values respectively.
[0012] Dilate the binary image with purple-fringe pixels marked.
[0013] Furthermore, the “sequentially traversing the image and correcting the pixels marked as purple-edge pixels using other pixels in the local window” specifically includes:
[0014] Enter pixel values in a preset order;
[0015] When the input pixel is judged to be a purple-fringed pixel, the number of other pixels in the local window is counted;
[0016] When the number of other pixels is not zero, the color information of other pixels in the local window is counted;
[0017] Correct the color of the current point and update the value of the binary image corresponding to the purple-edge pixel;
[0018] Output the corresponding pixel value.
[0019] Furthermore, the number of other pixels in the local window is calculated by taking (i, j) as the center and calculating the number of other pixels in the (2m+1)*(2n+1) window S. n , the calculation formula is as follows:
[0020]
[0021] The color information of other pixels in the statistical local window adopts the following formula:
[0022]
[0023]
[0024]
[0025] Correcting the color of the current point and updating the value of the corresponding purple-edge pixel binary image specifically include:
[0026] Using expressions Calculate the average difference Dr(i,j) between the red component and the green component and the average difference Db(i,j) between the blue component and the green component of other pixels in the local window;
[0027] Using expressions Correct the red component and blue component of the current point according to the average difference;
[0028] After correcting the current purple fringing, modify the corresponding mark of the current point, and change its purple pixel mark to a non-purple fringed pixel mark.
[0029] The embodiment of the present invention further provides a color image purple fringing correction device, comprising:
[0030] A marking module, used for classifying and marking pixels as purple-edge pixels, white pixels, and other pixels according to color information and edge information of each pixel of the input image;
[0031] A first correction module is used to traverse the image from left to right and from top to bottom, and use other pixels in the local window to correct the pixels marked as purple-fringed pixels;
[0032] The second correction module is used to traverse the image from right to left and from bottom to top, and correct the pixels marked as purple-edge pixels by using other pixels in the local window.
[0033] Furthermore, the marking module is specifically used to calculate the edge strength of each pixel point with the green component of the color image; wherein the edge strength of each pixel point is equal to the difference between the strongest edge strength and the weakest edge strength in the four directions of 0°, 90°, 45°, and 135°; and two binary images are used to mark "purple pixels" and "non-purple pixels", "white pixels" and "non-white pixels" respectively according to the color information and boundary information of the pixels; wherein, when the input pixel point satisfies , the pixel is marked as a "purple edge pixel". When , the pixel is marked as a "white pixel"; where R(i,j), G(i,j), and B(i,j) are red, green, and blue components respectively; th1, th2, thd, thL, and th3 are preset threshold values respectively.
[0034] Dilate the binary image with purple-fringe pixels marked.
[0035] Furthermore, the first correction module and the second correction module are specifically used for
[0036] Enter pixel values in a preset order;
[0037] When the input pixel is judged to be a purple-fringed pixel, the number of other pixels in the local window is counted;
[0038] When the number of other pixels is not zero, the color information of other pixels in the local window is counted;
[0039] Correct the color of the current point and update the value of the binary image corresponding to the purple-edge pixel;
[0040] Output the corresponding pixel value.
[0041] Furthermore, the number of other pixels in the local window is calculated by taking (i, j) as the center and calculating the number of other pixels in the (2m+1)*(2n+1) window S. n , the calculation formula is as follows:
[0042]
[0043] The color information of other pixels in the statistical local window adopts the following formula:
[0044]
[0045]
[0046]
[0047] Correcting the color of the current point and updating the value of the corresponding purple-edge pixel binary image specifically include:
[0048] Using expressions Calculate the average difference Dr(i,j) between the red component and the green component and the average difference Db(i,j) between the blue component and the green component of other pixels in the local window;
[0049] Using expressions Correct the red component and blue component of the current point according to the average difference;
[0050] After correcting the current purple fringing, modify the corresponding mark of the current point, and change its purple pixel mark to a non-purple fringed pixel mark.
[0051] The embodiment of the present invention further provides a computer storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned method for correcting purple fringing of a color image are implemented.
[0052] An embodiment of the present invention further provides a terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above-mentioned method for correcting purple fringing of color images when executing the computer program.
[0053] The color image purple fringing correction method provided by the present invention can better restore the original color of the pixel in a high-contrast and high-backlight scenario. BRIEF DESCRIPTION OF THE DRAWINGS
[0054] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0055] Figure 1 It is a flow chart of the method for correcting purple fringing of a color image provided by the present invention;
[0056] Figure 2 It is a flow chart of classifying and marking each pixel of an input image provided by the present invention;
[0057] Figure 3 It is a specific flow chart of correcting purple-fringe pixels provided by the present invention;
[0058] Figure 4 It is a schematic diagram of the four convolution kernels for calculating edge strength;
[0059] Figure 5 It is a schematic diagram of a color image purple fringing correction device provided in Embodiment 2 of the present invention. DETAILED DESCRIPTION
[0060] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0061] Figure 1 The figure is a flow chart of a method for correcting purple fringing of a color image provided by an embodiment of the present invention. The method comprises the following steps:
[0062] S101 , classifying and marking each pixel into purple-edge pixels, white pixels, and other pixels according to color information and edge information of each pixel of an input image.
[0063] Each pixel of the input image is classified and marked. According to the color information and edge information of each pixel of the input image, the pixel is classified and marked as purple-edge pixel, white pixel and other pixel.
[0064] See also Figure 2 In the first embodiment of the present invention, S101 may specifically include the following steps:
[0065] S1011. Calculate the edge strength of each pixel using the green component of the color image.
[0066] The specific method of calculating the edge strength of each pixel using the green component of the color image is as follows: First, Figure 3 The four 5*5 convolution kernel templates are shown, which are used to calculate the edge strength in the directions of 0°, 90°, 45°, and 135°, respectively, denoted as D0, D90, D45, and D135. The edge strength of each pixel is expressed by formula (1), which is the difference between the strongest edge strength and the weakest edge strength in the four directions.
[0067] D=max{D0,D90,D45,D135}-min{D0,D90,D45,D135} (1)
[0068] S1012. Mark “purple pixel” and “non-purple pixel”, and “white pixel” and “non-white pixel” using two binary images according to the color information and boundary information of the pixel.
[0069] Specifically, when the input pixel satisfies condition 1 shown in formula (2), the pixel is marked as a "purple-edge pixel", and when the input pixel satisfies condition 2 shown in formula (3), the pixel is marked as a "white pixel". As shown in formula (4). p A pixel point of 1 represents a "purple-edge pixel", and a pixel point of 0 represents a "non-purple-edge pixel". The binary image f w A pixel value of 1 represents a "white pixel" and a pixel value of 0 represents a "non-white pixel".
[0070] Condition 1:
[0071] Condition 2:
[0072]
[0073]
[0074] In this embodiment, th1=25, th2=25, thd=15, thL=128, and th3=50.
[0075] S1013: Perform dilation processing on the binary image marked with purple-fringe pixels.
[0076] S102: traverse the image from left to right and from top to bottom, and use other pixels in the local window to correct the pixels marked as purple-fringe pixels.
[0077] See also Figure 4 In the first embodiment of the present invention, S102 may specifically include the following steps:
[0078] S1021: Input pixel values in order from left to right and from top to bottom;
[0079] S1022: Determine whether the input pixel is a "purple-edge pixel", if so, proceed to S1023, if not, proceed to S1027;
[0080] If the current pixel I(i,j) is a "purple edge pixel", that is, f p (i,j)=1 and f w If (i, j) = 0, the process proceeds to S1023 to correct the point; otherwise, the process proceeds to S1027 to directly output the current pixel.
[0081] S1023: Count the number of “other pixels” in the local window;
[0082] Among them, pixels that are neither "purple-edge pixels" nor "white pixels" are defined as "other pixels". Centered at (i, j), count the number of "other pixels" in the (2m+1)*(2n+1) window S n , as shown in formula (5),
[0083]
[0084] S1024: Determine whether the number of "other pixels" is 0, if so, proceed to S1027, if not, proceed to S1025;
[0085] S1025: Counting the color information of “other pixels” in the local window;
[0086] Count the sum of the R, G, and B components of "other pixels" in the local window S R ,S G ,S B As shown in formulas (6)(7)(8).
[0087]
[0088]
[0089]
[0090] S1026: Correct the color of the current point and update the value of the binary image corresponding to the purple-edge pixel;
[0091] Furthermore, the purple-fringed pixels are corrected. First, as shown in formula (9), the average difference Dr(i, j) between the red component and the green component and the average difference Db(i, j) between the blue component and the green component of the "other pixels" in the local window are calculated, and then the current point is corrected according to the average difference, as shown in formula (10). After correcting the current purple fringing, the corresponding mark of the current point is modified, and its "purple pixel" mark is changed to "non-purple fringed pixel" mark, and the matrix f is updated as shown in formula (11) p The value of (i,j).
[0092]
[0093]
[0094] f p (i,j)=0 (11)
[0095] S1027: Output pixels.
[0096] S103: traverse the image from right to left and from bottom to top, and use other pixels in the local window to correct the pixels marked as purple-fringe pixels.
[0097] After the image is corrected once, there are still some "purple-edge pixels". Traverse the image from right to left and from bottom to top, and correct the pixels that are still marked as purple-edge pixels. The difference between this step and S102 is the order of traversing the image, and the rest is the same.
[0098] The above color image purple fringing correction method can better restore the original color of the pixel.
[0099] Figure 4 FIG. 1 is a schematic diagram of a color image purple fringing correction device provided by an embodiment of the present invention, comprising:
[0100] A marking module 11 is used to classify and mark each pixel as a purple-edge pixel, a white pixel, or other pixels according to the color information and edge information of each pixel of the input image;
[0101] A first correction module 12 is used to traverse the image from left to right and from top to bottom, and correct the pixels marked as purple-fringed pixels using other pixels in the local window;
[0102] The second correction module 13 is used to traverse the image from right to left and from bottom to top, and correct the pixels marked as purple-fringe pixels using other pixels in the local window.
[0103] Furthermore, the marking module is specifically used to calculate the edge strength of each pixel point with the green component of the color image; wherein the edge strength of each pixel point is equal to the difference between the strongest edge strength and the weakest edge strength in the four directions of 0°, 90°, 45°, and 135°; and two binary images are used to mark "purple pixels" and "non-purple pixels", "white pixels" and "non-white pixels" respectively according to the color information and boundary information of the pixels; wherein, when the input pixel point satisfies , the pixel is marked as a "purple edge pixel". When , the pixel is marked as a "white pixel"; where R(i,j), G(i,j), and B(i,j) are red, green, and blue components respectively; th1, th2, thd, thL, and th3 are preset threshold values respectively.
[0104] Dilate the binary image with purple-fringe pixels marked.
[0105] Further, the first correction module and the second correction module are specifically used for:
[0106] Enter pixel values in a preset order;
[0107] When the input pixel is judged to be a purple-fringed pixel, the number of other pixels in the local window is counted;
[0108] When the number of other pixels is not zero, the color information of other pixels in the local window is counted;
[0109] Correct the color of the current point and update the value of the binary image corresponding to the purple-edge pixel;
[0110] Output the corresponding pixel value.
[0111] Furthermore, the number of other pixels in the local window is calculated by taking (i, j) as the center and calculating the number of other pixels in the (2m+1)*(2n+1) window S. n , the calculation formula is as follows:
[0112]
[0113] The color information of other pixels in the statistical local window adopts the following formula:
[0114]
[0115]
[0116]
[0117] Correcting the color of the current point and updating the value of the corresponding purple-edge pixel binary image specifically include:
[0118] Using expressions Calculate the average difference Dr(i,j) between the red component and the green component and the average difference Db(i,j) between the blue component and the green component of other pixels in the local window;
[0119] Using expressions Correct the red component and blue component of the current point according to the average difference;
[0120] After correcting the current purple fringing, modify the corresponding mark of the current point, and change its purple pixel mark to a non-purple fringed pixel mark.
[0121] It should be noted that: when the color image purple fringing correction device provided in the above embodiment performs correction, only the division of the above program modules is used as an example. In actual application, the above processing can be assigned to different program modules as needed, that is, the internal structure of the device is divided into different program modules to complete all or part of the above-described processing. In addition, the color image purple fringing correction device provided in the above embodiment and the color image purple fringing correction method embodiment belong to the same concept, and the specific implementation process is detailed in the method embodiment, and the beneficial effects are the same as the method embodiment, which will not be repeated here.
[0122] The embodiment of the present invention also provides a computer storage medium, which is a computer-readable storage medium, on which a computer program is stored, and the computer program can be executed by a processor of a computer device to complete the steps of the above-mentioned color image purple fringing correction method. The computer-readable storage medium can be a magnetic random access memory (FRAM, ferromagnetic random access memory), a read-only memory (ROM, Read Only Memory), a programmable read-only memory (PROM, Programmable Read-Only Memory), an erasable programmable read-only memory (EPROM, Erasable Programmable Read-Only Memory), an electrically erasable programmable read-only memory (EEPROM, Electrically Erasable Programmable Read-Only Memory), a flash memory (Flash Memory), a magnetic surface memory, an optical disk, or a read-only optical disk (CD-ROM, Compact Disc Read-Only Memory) and other memories.
[0123] An embodiment of the present invention further provides a terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above-mentioned method for correcting purple fringing of color images when executing the computer program.
[0124] In the several embodiments provided by the present invention, it should be understood that the disclosed methods and intelligent devices can be implemented in other ways. The device embodiments described above are only schematic. For example, the division of the 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 can be integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed can be through some interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.
[0125] The units described above as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place or 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.
[0126] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.
Claims
1. A method for correcting purple fringing of a color image, characterized in that: include: According to the color information and edge information of each pixel of the input image, the pixels are classified and marked as purple-edge pixels, white pixels and other pixels; specifically, the edge strength of each pixel is calculated by the green component of the color image; wherein the edge strength of each pixel is equal to the difference between the strongest edge strength and the weakest edge strength in the four directions of 0°, 90°, 45° and 135°; according to the color information and edge information of the pixel, "purple pixel" and "non-purple pixel", "white pixel" and "non-white pixel" are marked respectively with two binary images; wherein, when the input pixel satisfies , the pixel is marked as a "purple edge pixel". When , the pixel is marked as a "white pixel"; where R(i,j), G(i,j), B(i,j) are the red, green and blue components respectively, and D(i,j) is the edge strength of the pixel; th1, th2, thd, thL, th3 are the preset threshold values respectively; the binary image marked with purple-edge pixels is dilated; Traverse the image from left to right and from top to bottom, and use other pixels in the local window to correct the pixels marked as purple-fringe pixels; The image is traversed from right to left and from bottom to top, and the pixels marked as purple-fringed pixels are corrected using other pixels in the local window; specifically, the red and blue components in the purple-fringed pixels are corrected according to the number of other pixels and the average difference between the blue and red components and the green component respectively.
2. The method according to claim 1, characterized in that The “sequentially traversing the image and correcting the pixels marked as purple-edge pixels using other pixels in the local window” specifically includes: Enter pixel values in a preset order; When the input pixel is judged to be a purple-fringed pixel, the number of other pixels in the local window is counted; When the number of other pixels is not zero, the color information of other pixels in the local window is counted; Correct the color of the current point and update the value of the binary image corresponding to the purple-edge pixel; Output the corresponding pixel value.
3. The method according to claim 2, characterized in that The number of other pixels in the local window is counted by taking (i, j) as the center and counting the number of other pixels in the (2m+1)*(2n+1) window S. n , the calculation formula is as follows: The color information of other pixels in the statistical local window adopts the following formula: Correcting the color of the current point and updating the value of the corresponding purple-edge pixel binary image specifically include: Using expressions Calculate the average difference Dr(i,j) between the red component and the green component and the average difference Db(i,j) between the blue component and the green component of other pixels in the local window; Using expressions Correct the red component and blue component of the current point according to the average difference; After correcting the current purple fringing, modify the corresponding mark of the current point, and change its purple pixel mark to a non-purple fringed pixel mark.
4. A color image purple fringing correction device, characterized in that: include: The marking module is used to classify and mark pixels as purple-edge pixels, white pixels and other pixels according to the color information and edge information of each pixel of the input image; specifically, the edge strength of each pixel is calculated based on the green component of the color image; wherein the edge strength of each pixel is equal to the difference between the strongest edge strength and the weakest edge strength in the four directions of 0°, 90°, 45° and 135°; according to the color information and boundary information of the pixel, two binary images are used to mark "purple pixels" and "non-purple pixels", "white pixels" and "non-white pixels" respectively; wherein, when the input pixel satisfies , the pixel is marked as a "purple edge pixel". When , the pixel is marked as a "white pixel"; where R(i,j), G(i,j), B(i,j) are the red, green and blue components respectively, and D(i,j) is the edge strength of the pixel; th1, th2, thd, thL, th3 are the preset threshold values respectively; the binary image marked with purple-edge pixels is dilated; A first correction module is used to traverse the image from left to right and from top to bottom, and use other pixels in the local window to correct the pixels marked as purple-fringed pixels; The second correction module is used to traverse the image from right to left and from bottom to top, and correct the pixels marked as purple-edge pixels using other pixels in the local window; The first correction module and the second correction module both correct the red component and the blue component in the purple-fringe pixel according to the number of other pixels and the average difference between the blue component and the red component and the green component respectively.
5. The device according to claim 4, characterized in that The first correction module and the second correction module are specifically used for Enter pixel values in a preset order; When the input pixel is judged to be a purple-fringed pixel, the number of other pixels in the local window is counted; When the number of other pixels is not zero, the color information of other pixels in the local window is counted; Correct the color of the current point and update the value of the binary image corresponding to the purple-edge pixel; Output the corresponding pixel value.
6. The device according to claim 5, characterized in that The number of other pixels in the local window is counted by taking (i, j) as the center and counting the number of other pixels in the (2m+1)*(2n+1) window S. n , the calculation formula is as follows: The color information of other pixels in the statistical local window adopts the following formula: Correcting the color of the current point and updating the value of the corresponding purple-edge pixel binary image specifically include: Using expressions Calculate the average difference Dr(i,j) between the red component and the green component and the average difference Db(i,j) between the blue component and the green component of other pixels in the local window; Using expressions Correct the red component and blue component of the current point according to the average difference; After correcting the current purple fringing, modify the corresponding mark of the current point, and change its purple pixel mark to a non-purple fringed pixel mark.
7. A computer storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method for correcting purple fringing of a color image according to any one of claims 1 to 3 is implemented.
8. A terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method for correcting purple fringing of a color image according to any one of claims 1 to 3 is implemented.
Citation Information
Patent Citations
Image processing method and device
CN105389786A
Image purple fringe eliminating system, method, computer-readable storage medium, and photographing device
US20200128221A1