Image processing methods, electronic devices and computer-readable storage media

By generating a binary mask image and adjusting the weights based on brightness and chromaticity data, purple fringing is accurately identified and eliminated, solving the problem of image quality degradation caused by purple fringing and improving the user experience.

CN116721257BActive Publication Date: 2025-10-31HONOR DEVICE CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202210193710.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-02-28
Publication Date
2025-10-31
Estimated Expiration
2042-02-28

AI Technical Summary

Technical Problem

Purple fringing degrades image quality when a camera captures images, impacting user experience, and existing technologies struggle to effectively identify and remove it.

Method used

By acquiring the chromaticity data of the image, a binary mask image is generated using a preset chromaticity range and a preset purple edge size. Purple edge pixels are identified and filtered out, and their weights are adjusted precisely based on the brightness and chromaticity data to eliminate the purple edge.

Benefits of technology

It improves the accuracy of purple fringing recognition and image quality, enhancing the user's visual experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116721257B_ABST
    Figure CN116721257B_ABST
Patent Text Reader

Abstract

This application provides an image processing method, an electronic device, and a computer-readable storage medium, relating to the field of image processing technology. The method includes: acquiring data of an image to be processed, the data of which includes chromaticity data of each pixel in the image; generating a binarized mask image corresponding to the image to be processed based on the chromaticity data, a preset chromaticity range, and a preset purple edge size; the binarized mask image includes a protected area, which refers to a region in the binarized mask image whose size is larger than the preset purple edge size, corresponding to at least one possible purple edge region in the image to be processed; determining purple edge pixels in the image to be processed based on the binarized mask image; purple edge pixels refer to pixels whose chromaticity data belongs to the preset chromaticity range and are located outside the region corresponding to the protected area. The method provided by this application can accurately identify purple edges in an image.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of image processing technology, specifically to an image processing method, an electronic device, and a computer-readable storage medium. Background Technology

[0002] Purple fringing is a common phenomenon in photography. It refers to the appearance of colored patches or edges at the boundary between highlights and shadows when a camera is capturing an image. The formation of purple fringing is related to factors such as chromatic aberration in the camera lens. The presence of purple fringing affects image quality and user experience; therefore, identifying purple fringing in images is a problem that urgently needs to be solved. Summary of the Invention

[0003] This application provides an image processing method, apparatus, chip, electronic device, computer-readable storage medium, and computer program product capable of recognizing purple fringes in images.

[0004] In a first aspect, this application provides an image processing method, which is executed by an electronic device, and the method includes:

[0005] The process involves acquiring data from the image to be processed, including the chromaticity data of each pixel in the image. Based on the chromaticity data, a preset chromaticity range, and a preset purple edge size, a binarized mask image is generated corresponding to the image to be processed. The binarized mask image includes a protected area, which is a region in the binarized mask image whose size is larger than the preset purple edge size, corresponding to at least one possible purple edge region in the image to be processed. A possible purple edge region is a region where the chromaticity data of all pixels within the region belongs to the preset chromaticity range. Purple edge pixels in the image to be processed are determined based on the binarized mask image. Purple edge pixels are pixels whose chromaticity data belongs to the preset chromaticity range and are located outside the region corresponding to the protected area.

[0006] Optionally, the data of the image to be processed can be YUV data, HSV data, RGB data, etc.

[0007] The binarized mask image and the image to be processed have the same size, and the positions of the pixels correspond one-to-one. The identifier value of each pixel in the binarized mask image is a first value or a second value. The first value can be, for example, 1, and the second value can be, for example, 0. The protected area can be the region formed by pixels in the binarized mask image with an identifier value of 1. The binarized mask image includes at least one protected area, and the image to be processed includes at least one possible purple-edge region. Each protected area corresponds to one possible purple-edge region, and the size of each protected area is larger than a preset purple-edge size.

[0008] A preset chromaticity range is used to filter purple pixels. A preset purple edge size is used to filter purple edge regions formed by purple edge pixels. If a pixel's chromaticity data falls within the preset chromaticity range, it indicates that the pixel is a potential purple edge pixel. If the potential purple edge region is less than or equal to the preset purple edge size, it indicates that the potential purple edge region is a true purple edge region. If the potential purple edge region is greater than the preset purple edge size, it indicates that the potential purple edge region is a pseudo-purple edge region. The protected area in the binarized mask image corresponds to the pseudo-purple edge region in the image to be processed.

[0009] Points within the possible purple-edged region are all potential purple-edged pixels. Optionally, in one embodiment, the possible purple-edged region can be the largest contiguous region formed by potential purple-edged pixels.

[0010] Optionally, the preset chromaticity range and preset purple edge size can be obtained through statistical analysis of the chromaticity data of the purple edge pixels in the purple edge sample image. For example, the preset purple edge size can be 5 pixels * 5 pixels.

[0011] The image processing method provided in the first aspect acquires the data of the image to be processed and generates a binarized mask image corresponding to the image to be processed based on the chromaticity data in the data, a preset chromaticity range, and a preset purple edge size. The binarized mask image includes a protected area, which is a region in the image to be processed that corresponds to a possible purple edge region and has a size larger than the preset purple edge size. Since the purple edge region is generally smaller than or equal to the preset size, the protected area does not include the region corresponding to the purple edge region; that is, the protected area only includes the region corresponding to the pseudo-purple edge region. Therefore, the protected area can protect pixels in the pseudo-purple edge region of the image to be processed. Furthermore, based on the binarized mask image, pixels outside the protected area among the possible purple edge pixels in the image to be processed are determined, and purple edge pixels are filtered out. The method provided in this embodiment can accurately determine purple edge pixels, preventing pseudo-purple edge pixels from being identified as real purple edge pixels, improving the accuracy of purple edge recognition, thereby facilitating more accurate subsequent adjustment of the purple edge pixel data to eliminate purple edges, thus improving image quality and enhancing the user's visual experience.

[0012] In conjunction with the first aspect, in some implementations of the first aspect, a binarized mask image corresponding to the image to be processed is generated based on chromaticity data, a preset chromaticity range, and a preset purple edge size. This includes: generating a binarized image corresponding to the image to be processed based on chromaticity data and a preset chromaticity range; the identifier value of pixels in the binarized image whose chromaticity data belongs to the preset chromaticity range is a first value; and performing erosion and dilation processing on the binarized image based on the preset purple edge size to generate a binarized mask image.

[0013] In this implementation, pixels belonging to a preset color range in the image to be processed are filtered out, generating a binary mask image. The binary mask image is then subjected to erosion and dilation processing to generate a binary mask image. Binarization reduces the complexity of image processing, and the erosion and dilation processes enable simple, accurate, and rapid generation of the binary mask image, improving the efficiency and accuracy of identifying pixels with purple edges.

[0014] Combining the first aspect and the above implementation methods, one possible implementation method involves performing erosion and dilation processing on a binarized image based on a preset purple edge size to generate a binarized mask image. This includes: using a structuring element with a preset purple edge size to perform erosion processing on each first region in the binarized image to obtain a corresponding second region, thereby generating a binarized eroded image; wherein, the first region refers to a region where the identifier of all pixels in the region is a first value; and using a structuring element with a preset purple edge size to perform dilation processing on each second region in the binarized eroded image to obtain a corresponding protected area, thereby generating a binarized mask image.

[0015] Optionally, the first region can be the largest continuous region formed by the pixels identified as the first value in the binarized image.

[0016] In this implementation, a structuring element with a preset purple edge size is used to erode each first region in the binarized image, reducing the size of the first region and obtaining a second region. For the region in the binarized image corresponding to the purple edge region, since its size is small (less than or equal to the preset purple edge size), this region is eliminated after erosion, thus generating a binarized eroded image. Then, a structuring element with the preset purple edge size is used to dilate the second region of the binarized eroded image, restoring its edges and obtaining a protected area corresponding to the possible purple edge region in the image to be processed. This allows the generated binarized mask image to protect the false purple edge region in the image to be processed, thereby enabling the filtering of purple edge pixels from regions outside the false purple edge region, preventing false purple edge pixels from being identified as genuine purple edge pixels, and improving the accuracy of purple edge recognition.

[0017] In one possible implementation, the data of the image to be processed also includes the brightness data of each pixel in the image to be processed. The method further includes: determining the target adjustment weight based on the brightness data and chromaticity data of the purple-edged pixels; and adjusting the chromaticity data of the purple-edged pixels according to the target adjustment weight.

[0018] Optionally, the chromaticity data of the purple-edged pixels can be reduced to eliminate the purple fringing and improve image quality.

[0019] In this implementation, a target adjustment weight is determined based on the brightness and chromaticity data of the purple-edged pixels. Then, the chromaticity data of the purple-edged pixels is adjusted according to this target adjustment weight. This ensures that the adjustment of the chromaticity data of the purple-edged pixels considers not only the chromaticity of the pixel but also its brightness, resulting in a more accurate and natural chromaticity and further improving image quality.

[0020] In one possible implementation, determining the target adjustment weight based on the luminance and chrominance data of the purple-edged pixel includes: determining a first target luminance weight based on the luminance data of the purple-edged pixel and pixels within a first preset range surrounding it; the first target luminance weight characterizes the influence of the luminance difference between the purple-edged pixel and pixels within the first preset range on chrominance data adjustment; determining a second target luminance weight based on the luminance data of the purple-edged pixel and pixels within a second preset range surrounding it; the second target luminance weight characterizes the influence of pixels within the second preset range whose luminance data exceeds a preset high-brightness threshold on chrominance data adjustment; determining a target chrominance weight based on the chrominance data of the purple-edged pixel; the target chrominance weight characterizes the influence of the chrominance data of the purple-edged pixel on chrominance data adjustment; and determining a target adjustment weight based on the first target luminance weight, the second target luminance weight, and the target chrominance weight.

[0021] The first target brightness weight is the first brightness weight corresponding to the current purple-edged pixel; the second target brightness weight is the second brightness weight corresponding to the current purple-edged pixel; the target chromaticity weight is the chromaticity weight corresponding to the current purple-edged pixel; and the target adjustment weight is the adjustment weight corresponding to the current purple-edged pixel.

[0022] Optionally, the first brightness weight can be specifically used to characterize the probability that a pixel has a large brightness difference with its surrounding pixels. A large brightness difference refers to a brightness difference greater than a preset value. The larger the first brightness weight, the larger the brightness difference, and the greater the probability that the pixel is a purple-edged pixel. Optionally, the range of the first brightness weight can be [0, 1].

[0023] Optionally, the second brightness weight can be specifically used to characterize the probability that there are a large number (greater than a preset number) of high-brightness pixels around a pixel within a second preset range, that these high-brightness pixels are close to the pixel (at a distance less than a preset distance), and that there is a large difference in brightness (less than a preset threshold) between pixels within the second preset range. High-brightness pixels refer to pixels whose brightness data exceeds a preset brightness threshold. The larger the second brightness weight, the more high-brightness pixels exist around the pixel within the second preset range, the closer these high-brightness pixels are to the pixel, the greater the probability of a large difference in brightness between pixels within the second preset range, and the greater the probability that the pixel is a purple-edged pixel. Optionally, the preset brightness threshold can be a grayscale value; for example, for an image with a grayscale value range of 0 to 255, the preset brightness threshold can be a value between 160 and 240. Optionally, the range of the second brightness weight can be [0, 1].

[0024] Optionally, the chromaticity weight can be specifically used to characterize the probability that a pixel is a possible purple-edged pixel, that is, to characterize the probability that the pixel's chromaticity belongs to a preset chromaticity range. The larger the chromaticity weight, the greater the probability that the pixel is a possible purple-edged pixel, and the greater the probability that the pixel is a purple-edged pixel. Optionally, the range of the chromaticity weight can be [0, 1].

[0025] Optionally, the weight is adjusted to characterize the probability that a pixel is a purple-edged pixel. The larger the adjusted weight, the greater the probability that the pixel is a purple-edged pixel.

[0026] Since purple fringing often appears in edge areas with high contrast between light and dark, brightness difference, bright pixels, and chromaticity range are crucial for its identification and adjustment. The method provided in this implementation fully considers the influence of brightness difference, bright pixels, and chromaticity data itself on eliminating purple fringing when determining the adjustment weights for pixels. This results in a smaller difference in brightness and chromaticity between the adjusted purple-fringed pixels and surrounding pixels, leading to a more natural image and better image quality. Furthermore, the obtained adjustment weights characterize the probability that a pixel is a purple-fringed pixel; a smaller adjustment weight means a lower probability of the pixel being a purple-fringed pixel, resulting in a smaller adjustment force, and vice versa. This allows for more accurate adjustments to chromaticity and brightness. Additionally, in cases where a pixel is misidentified as a purple-fringed pixel, the weight adjustment minimizes the adjustment force for that pixel, thereby reducing the impact of misidentification of purple fringing on image quality.

[0027] In one possible implementation, determining the first target brightness weight based on the brightness data of the purple-edged pixel and the pixels within a first preset range around the purple-edged pixel includes: determining the brightness gradient of the purple-edged pixel based on the brightness data of the purple-edged pixel and the pixels within the first preset range; and determining the first target brightness weight based on the brightness gradient of the purple-edged pixel.

[0028] In this implementation, the gradient can reflect the brightness difference between the purple-edge pixel and the surrounding pixels. The gradient calculation is simple and convenient, which can quickly determine the brightness weight of the first target and improve the algorithm's running efficiency.

[0029] In one possible implementation, the brightness gradient of the purple-edged pixel can be determined based on the brightness data of pixels along four preset directions. These four preset directions could be, for example, the horizontal and vertical coordinates of the purple-edged pixel, and the diagonal of the region formed by a first preset range. Determining the brightness gradient of the purple-edged pixel using the brightness data from these four preset directions makes the determined gradient more accurate, leading to a more accurate determination of the first target brightness weight. This, in turn, allows for more precise adjustments to the data of the purple-edged pixel, improving the purple-edged removal effect.

[0030] In one possible implementation, determining the first target brightness weight based on the brightness gradient of the purple-edged pixels includes: determining the first target brightness weight corresponding to the brightness gradient of the purple-edged pixels based on the mapping relationship between the brightness gradient and the first brightness weight.

[0031] In this implementation, the first target brightness weight can be determined quickly and easily by mapping the brightness gradient and the first brightness weight, thus improving the algorithm's running efficiency.

[0032] In one possible implementation, determining the second target brightness weight based on the brightness data of the purple-edged pixel and the pixels within a second preset range surrounding the purple-edged pixel includes: dividing the purple-edged pixel and the pixels within the second preset range into multiple brightness blocks; determining the brightness value of each brightness block based on the brightness data of the purple-edged pixel and the pixels within the second preset range; and determining the second target brightness weight based on the brightness value of each brightness block.

[0033] In this implementation, the purple-edge pixels and pixels within a second preset range are divided into multiple brightness blocks. The brightness of these blocks represents the brightness of the individual pixels, thus determining the second target brightness weight. This reduces the impact of noise in the image on brightness determination, improves the accuracy of the second target brightness weight calculation, and ultimately enhances the effect of removing purple edges from the image.

[0034] In one possible implementation, determining the second target brightness weight based on the brightness value of each brightness block includes: determining the brightness distribution parameters of the purple-edged pixels based on the brightness value of each brightness block, the brightness distribution parameters including at least one of the following: the number of high-brightness blocks, the distance between the brightness block containing the purple-edged pixel and the high-brightness blocks, and the brightness difference between brightness blocks; a high-brightness block refers to a brightness block among multiple brightness blocks whose brightness value is greater than a preset high-brightness threshold, and the brightness difference between brightness blocks refers to the difference between the maximum and minimum brightness values ​​among all brightness blocks; and determining the second target brightness weight based on the brightness distribution parameters of the purple-edged pixels.

[0035] In this implementation, the second target brightness weight is determined by the brightness distribution parameters of the purple edge pixels. The brightness distribution parameters include at least one of the following: the number of high brightness blocks, the distance between the brightness block where the purple edge pixel is located and the high brightness block, and the brightness difference between the brightness blocks. These parameters can all characterize the degree of influence of high brightness pixels or high brightness areas on the adjustment of purple edge pixel data. The second target brightness weight determined by the brightness distribution parameters is more accurate.

[0036] In one possible implementation, determining the second target brightness weight based on the brightness distribution parameters of the purple-edged pixels includes: determining the second target brightness weight corresponding to the brightness distribution parameters of the purple-edged pixels based on the mapping relationship between the brightness distribution parameters and the second brightness weight.

[0037] In this implementation, the second target brightness weight can be determined quickly and easily by mapping the brightness distribution parameters and the second brightness weight, thus improving the algorithm's running efficiency.

[0038] In one possible implementation, determining the target chromaticity weight based on the chromaticity data of the purple-edge pixels includes: determining the target chromaticity weight corresponding to the chromaticity data of the purple-edge pixels based on the mapping relationship between chromaticity data and chromaticity weight.

[0039] In this implementation, the target chromaticity weight can be determined quickly and easily by mapping the chromaticity data and chromaticity weight, thus improving the efficiency of the algorithm.

[0040] In one possible implementation, determining the target adjustment weight based on the first target luminance weight, the second target luminance weight, and the target chromaticity weight includes: determining the target adjustment weight based on the product of the first target luminance weight, the second target luminance weight, and the target chromaticity weight.

[0041] In this implementation manner, the target adjustment weight is determined according to the product of the first target brightness weight, the second target brightness weight, and the target chroma weight. The larger the product of the first target brightness weight, the second target brightness weight, and the target chroma weight is, the larger the obtained target adjustment weight is, indicating that the probability that this pixel point is a purple fringing pixel point is higher, and the adjustment strength for the data of the pixel point is greater. On the contrary, the smaller the product is, the smaller the obtained target adjustment weight is, indicating that the probability that this pixel point is a purple fringing pixel point is lower, and the adjustment strength for the pixel point is smaller. This can make the adjustment of the data of purple fringing pixel points more accurate.

[0042] In a possible implementation manner, the method further includes: adjusting the brightness data of the purple fringing pixel points according to the target adjustment weight.

[0043] In this implementation manner, on the basis of adjusting the chroma, the brightness of the purple fringing pixel points is adjusted, so that the brightness difference between the processed purple fringing pixel points and the surrounding pixel points is small, and the obtained image brightness is more balanced and natural, further improving the image quality, thereby improving the user's visual experience. Moreover, the adjustment weight used during brightness adjustment is the same as the weight used during chroma adjustment, so that the adjustment strengths of brightness and chroma are consistent, realizing the adaptive adjustment of brightness with respect to chroma, further improving the image quality, and improving the user's visual experience.

[0044] In a possible implementation manner, adjusting the brightness data of the purple fringing pixel points according to the target adjustment weight includes: determining a brightness adjustment value according to the difference between the brightness data of the purple fringing pixel points and the average brightness data and the target adjustment weight; the average brightness data is the average data of the brightness data of the pixel points within the third preset range around the purple fringing pixel point; determining the target brightness data according to the brightness adjustment value and the brightness data of the purple fringing pixel point, where the target brightness is greater than or equal to the maximum brightness value and less than or equal to the minimum brightness value; the maximum brightness value is the maximum value among the brightness values of multiple brightness blocks obtained by dividing the purple fringing pixel point and the pixel points within the third preset range into multiple brightness blocks, and the minimum brightness value is the minimum value among the brightness values of the multiple brightness blocks; adjusting the brightness data of the purple fringing pixel point to the target brightness data.

[0045] In this implementation manner, the brightness of the purple fringing pixel points is adjusted based on the average brightness data, so that the chroma difference between the adjusted purple fringing pixel points and the pixel points within the third preset range is small, and the chroma of the image is more balanced, improving the image quality. Moreover, the pixel points within the third preset range are divided into multiple brightness blocks, and the brightness of the brightness blocks is used to represent the brightness of the pixel points. This can reduce the influence of noise on brightness calculation, improve the accuracy of target brightness data calculation, and thus further improve the accuracy of brightness adjustment and improve the image quality.

[0046] In one possible implementation, determining the target brightness data based on the brightness adjustment value and the brightness data of the purple-edged pixels includes: determining a reference brightness value based on the brightness adjustment value and the brightness data of the purple-edged pixels; if the reference brightness value is greater than or equal to the minimum brightness value and less than or equal to the maximum brightness value, then the reference brightness value is determined as the target brightness data; if the reference brightness value is greater than the maximum brightness value, then the maximum brightness value is determined as the target brightness data; if the reference brightness value is less than the minimum brightness value, then the minimum brightness value is determined as the target brightness data.

[0047] In this implementation, the final target brightness data is limited to a brightness range, which is determined based on the brightness of pixels surrounding the purple-edged pixels. This ensures that the final adjusted brightness value is neither too high nor too low. This prevents the removed purple-edged portions of the processed image from being too dark or too light, avoiding white edges or black-and-white contrasts, further improving image quality and effect, and ultimately enhancing the user's visual experience.

[0048] In one possible implementation, the data of the image to be processed is YUV data.

[0049] In one possible implementation, the proportion of the Y component of a pixel in the YUV data is higher than the proportion of the UV component. The data acquisition of the image to be processed includes: acquiring the YUV data of each pixel in the image to be processed; acquiring chromaticity data from the YUV data; and downsampling the Y component of each pixel in the image to be processed according to the proportion of the Y, U, and V components in the YUV data and the target sampling ratio to obtain luminance data.

[0050] In this implementation, the Y component of the pixels in the image to be processed is downsampled, which reduces the size of the Y component, saves computation, improves the speed of image processing, and enhances the performance of electronic devices.

[0051] Optionally, the ratio of the Y, U, and V components in the YUV data can be equal to the target sampling ratio. This makes the size of the downsampled Y component the same as the size of the UV component. When traversing the pixel data in subsequent iterations, only one traversal is needed, further saving computation, improving the speed of image processing, and enhancing the performance of electronic devices.

[0052] In one possible implementation, the brightness adjustment value is determined based on the difference between the brightness data of the purple-edged pixels and the average brightness data, and the target adjustment weight. This includes: determining a reference adjustment value based on the product of the difference and the target adjustment weight; determining the adjustment value corresponding to the Y component of the purple-edged pixels using bilinear interpolation based on the reference adjustment value and the target sampling ratio, thus obtaining the brightness adjustment value; and determining the target brightness data based on the brightness adjustment value and the brightness data of the purple-edged pixels, including: determining the target brightness data based on the brightness adjustment value and the Y component of the purple-edged pixels.

[0053] In this implementation, when the brightness data is downsampled, the adjustment value corresponding to the original Y component of the pixel is determined by bilinear interpolation. Based on this adjustment value and the original Y component value, the target brightness data is further calculated. This enables accurate adjustment of the brightness of pixels with purple edges.

[0054] Secondly, this application provides an apparatus included in an electronic device, which has the function of implementing the behaviors of the electronic device in the first aspect and possible implementations thereof. The function can be implemented by hardware or by hardware executing corresponding software. The hardware or software includes one or more modules or units corresponding to the above-described functions. For example, a receiving module or unit, a processing module or unit, etc.

[0055] Thirdly, this application provides an electronic device, which includes a processor, a memory, and an interface; the processor, memory, and interface cooperate with each other to enable the electronic device to execute any one of the methods in the first aspect of the technical solution.

[0056] Fourthly, this application provides a chip including a processor. The processor is used to read and execute a computer program stored in a memory to perform the methods in the first aspect and any possible implementation thereof.

[0057] Optionally, the chip may also include memory, which is connected to the processor via circuitry or wires.

[0058] Alternatively, the chip may also include a communication interface.

[0059] Fifthly, this application provides a computer-readable storage medium storing a computer program, which, when executed by a processor, causes the processor to perform any one of the methods in the first aspect of the technical solution.

[0060] Sixthly, this application provides a computer program product, which includes computer program code that, when executed on an electronic device, causes the electronic device to perform any one of the methods in the first aspect of the technical solution. Attached Figure Description

[0061] Figure 1 This is a schematic diagram of an image exhibiting purple fringing, provided in an embodiment of this application.

[0062] Figure 2 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application;

[0063] Figure 3 This is a software structure block diagram of an electronic device provided in an embodiment of this application;

[0064] Figure 4 This is a schematic flowchart of an example image processing method provided in an embodiment of this application;

[0065] Figure 5 This is an example of a preset chromaticity range diagram provided in an embodiment of this application;

[0066] Figure 6 This is a schematic flowchart of another image processing method provided in an embodiment of this application;

[0067] Figure 7 This is a schematic diagram illustrating an example of generating a binarized mask image provided in an embodiment of this application;

[0068] Figure 8 This is a schematic flowchart of another image processing method provided in the embodiments of this application;

[0069] Figure 9 This is a schematic diagram of a purple-edged pixel and the surrounding pixels within a first preset range provided in an embodiment of this application;

[0070] Figure 10 This is a schematic diagram of the division of brightness blocks provided in an embodiment of this application;

[0071] Figure 11 This is a schematic flowchart of another image processing method provided in the embodiments of this application;

[0072] Figure 12 This is a schematic diagram of the structure of an image processing device provided in an embodiment of this application. Detailed Implementation

[0073] The technical solutions of the embodiments of this application will be described below with reference to the accompanying drawings. In the description of the embodiments of this application, unless otherwise stated, " / " means "or," for example, A / B can mean A or B; "and / or" in this text is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. Furthermore, in the description of the embodiments of this application, "multiple" refers to two or more than two.

[0074] Hereinafter, the terms "first," "second," and "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first," "second," or "third" may explicitly or implicitly include one or more of that feature.

[0075] References to "one embodiment" or "some embodiments" as described in this application specification mean that one or more embodiments of this application include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in still other embodiments," etc., appearing in different parts of this application specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized.

[0076] To better understand the embodiments of this application, the terms or concepts that may be involved in the embodiments are explained below.

[0077] YUV: A color space. Terms like Y'UV, YUV, YCbCr, and YPbPr can all refer to YUV. YUV consists of three components (or channels): Y, U, and V. Y represents luminance (or luma, also known as brightness), which is the grayscale value; U and V (i.e., the UV components) represent chrominance (or chroma), describing the color and saturation of an image and specifying the color of a pixel. When compiling image colors using YUV data, the proportions of the Y, U, and V components in a single pixel determine the type of YUV data, which can be categorized into YUV444, YUV422, and YUV420 data. YUV444 data refers to data sampled in a 4:4:4 ratio, with each Y component corresponding to a set of UV components. YUV422 data refers to data sampled in a 4:2:2 ratio, with every two Y components sharing a set of UV components. YUV420 data refers to data obtained by sampling the Y, U, and V components in a ratio of 4:2:0, with each set of four Y components sharing a single set of UV components.

[0078] HSV: A color space. HSV consists of three components: H, S, and V. H represents hue, also known as hue; S represents saturation; and V represents value, also known as brightness or lightness.

[0079] RGB: A color space. RGB includes three color channels: R, G, and B. R represents the red channel, G represents the green channel, and B represents the blue channel.

[0080] It is understandable that data from different color spaces can be converted to each other. For example, data in the RGB space (i.e., RGB data) can be converted to data in the YUV space (i.e., YUV data) or to data in the HSV space (i.e., HSV data).

[0081] Chromaticity data: Data that characterizes the color and saturation of an image. The specific parameters of chromaticity data differ in different color spaces. For example, chromaticity data in the YUV color space includes U and V components, while chromaticity data in the HSV color space includes H and S components.

[0082] Brightness data: Data that characterizes the brightness of an image, also known as luminance data. The specific parameters of brightness data differ in different color spaces. For example, brightness data in the YUV color space is the Y component, while brightness data in the HSV color space is the V component.

[0083] Image data can include the chromaticity and luminance data of each pixel in the image.

[0084] Purple-edged pixels: Pixels in an image that exhibit a purple edge.

[0085] Purple-edged region: A region in which all pixels are purple-edged is defined as a purple-edged region.

[0086] In one embodiment, the purple-edged region is the largest continuous region formed by purple-edged pixels in the image. Specifically, a purple-edged pixel in the image with no surrounding purple-edged pixels forms a purple-edged region, or the largest region formed by multiple adjacent purple-edged pixels is a purple-edged region.

[0087] False purple-edged pixels: These are pixels in an image that meet the chromaticity requirements of purple-edged pixels but are not actually purple-edged pixels. For example, an image may contain objects with the same or similar chromaticity as purple-edged pixels (such as purple) in addition to purple-edged pixels; the pixels corresponding to these objects are called false purple-edged pixels.

[0088] Pseudo-purple edge region: A region in which all pixels are pseudo-purple edge pixels is defined as a pseudo-purple edge region.

[0089] In one embodiment, the pseudo-purple edge region is the largest continuous region formed by pseudo-purple edge pixels in the image.

[0090] Purple-edged pixels: During image processing, pixels that meet the chromaticity requirements of purple-edged pixels are selected. These pixels may actually be purple-edged pixels or pseudo-purple-edged pixels.

[0091] Purple-edge potential region: The region in which all pixels are potential purple-edge pixels is called the purple-edge potential region.

[0092] In one embodiment, a potential purple-edged region is the largest contiguous region formed by potential purple-edged pixels in the image. Specifically, a potential purple-edged pixel in the image with no surrounding potential purple-edged pixels forms a potential purple-edged region, or the largest region formed by multiple adjacent potential purple-edged pixels is a potential purple-edged region. A potential purple-edged region may actually be a real purple-edged region or a pseudo-purple-edged region.

[0093] Erosion: Consider two images, B and X, where X is the object to be processed, and B is the image used to process X. B is called the structuring element. Translating the structuring element B to point a results in Ba. If Ba is contained within X, then point a is recorded. The set of all points a that satisfy the above condition (Ba obtained after translation to point a is contained within X) is called the result of X being eroded by B. This process is called erosion. Erosion can remove certain parts of an image.

[0094] Dilation: Consider two images, B and X, where X is the object to be processed, and B is the image used to process X. B is called the structuring element. Translating the structuring element B to point a results in Ba. If Ba hits X, point a is recorded. The set of all points a that satisfy the above condition (Ba hits X after translation to point a) is called the result of dilating X by B. This process is called dilation. Dilation adds pixel values ​​to the edges of an image, thus expanding the image's pixel values.

[0095] The image processing method provided in this application will be described below with reference to embodiments.

[0096] Cameras have brought great convenience to people's lives. With the rapid development of electronic technology, cameras are no longer limited to standalone digital cameras; camera functions are increasingly integrated into various electronic devices. For example, mobile phones, tablets, and laptops all have integrated camera modules capable of taking pictures. Whether it's a digital camera or a camera module in various electronic devices, when taking pictures, due to factors such as chromatic aberration in the camera lens, purple fringing may appear in the resulting images, especially in areas with high contrast between the background and foreground. For example, when using a mobile phone's ultra-wide-angle lens to take pictures outdoors in high-contrast lighting conditions, noticeable purple fringing is likely to occur.

[0097] For example, Figure 1 This is a schematic diagram of an image with purple fringing provided in an embodiment of this application. Figure 1The background 101 of the image shown is the sky, which has high brightness, while the foreground object (the large tree) 102 has low brightness. Therefore, a purple fringing 103 appears at the boundary between the foreground object 102 and the background 101, i.e., at the edge of the foreground object 102. It should be noted that the purple fringing is generally purple, blue, or green, etc. Figure 1 The purple border 103 in the image is for illustrative purposes only and does not represent its actual color.

[0098] Purple fringing in images can negatively impact image quality and visual experience. Therefore, this application provides an image processing method for identifying and removing purple fringing in images, thereby improving image quality and enhancing the user's visual experience.

[0099] The image processing method provided in this application can be applied to cameras, as well as to electronic devices such as mobile phones, tablets, wearable devices, in-vehicle devices, augmented reality (AR) / virtual reality (VR) devices, laptops, ultra-mobile personal computers (UMPCs), netbooks, and personal digital assistants (PDAs) that include camera modules and have shooting capabilities. It is used to process data output from a lens (or camera) to remove purple fringing and generate high-quality captured images. Alternatively, the image processing method provided in this application can also be applied to any electronic device capable of processing computer programs to process data of existing images containing purple fringing, remove the purple fringing, and improve the quality of the existing images. This application does not limit the specific type of electronic device or the application scenario of the method. For ease of explanation, the following embodiments illustrate the application of the method to an electronic device containing a camera.

[0100] For example, Figure 2This is a schematic diagram of the structure of an electronic device 100 provided in an embodiment of this application. The electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, a headphone jack 170D, a sensor module 180, buttons 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, a barometric pressure sensor 180C, a magnetic sensor 180D, an accelerometer sensor 180E, a distance sensor 180F, a proximity sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.

[0101] It is understood that the structures illustrated in the embodiments of this application do not constitute a specific limitation on the electronic device 100. In other embodiments of this application, the electronic device 100 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.

[0102] Processor 110 may include one or more processing units, such as: application processor (AP), modem processor, graphics processing unit (GPU), image signal processor (ISP), controller, memory, video codec, digital signal processor (DSP), baseband processor, and / or neural network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.

[0103] The controller can be the nerve center and command center of the electronic device 100. The controller can generate operation control signals according to the instruction opcode and timing signals to complete the control of instruction fetching and execution.

[0104] The processor 110 may also include a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. This memory can store instructions or data that the processor 110 has just used or that are used repeatedly. If the processor 110 needs to use the instruction or data again, it can retrieve it directly from the memory. This avoids repeated accesses, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.

[0105] In some embodiments, the processor 110 may include one or more interfaces. Interfaces may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.

[0106] Electronic device 100 implements display functions through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, connected to the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations and for graphics rendering. Processor 110 may include one or more GPUs, which execute program instructions to generate or modify display information.

[0107] Display screen 194 is used to display images, videos, etc. Display screen 194 includes a display panel. The display panel may be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), a miniature LED, a microLED, a quantum dot light-emitting diode (QLED), etc. In some embodiments, electronic device 100 may include one or N displays 194, where N is a positive integer greater than 1.

[0108] Electronic device 100 can perform shooting functions through ISP, camera 193, video codec, GPU, display 194 and application processor.

[0109] The ISP (Image Signal Processor) is used to process data fed back from the camera 193. For example, when taking a picture, the shutter is opened, and light is transmitted through the lens to the camera's photosensitive element. The light signal is converted into an electrical signal, and the camera's photosensitive element transmits the electrical signal to the ISP for processing, transforming it into an image visible to the naked eye. The ISP can also perform algorithmic optimization of image noise, brightness, and skin tone. The ISP can also optimize parameters such as exposure and color temperature of the shooting scene. In some embodiments, the ISP can be set in the camera 193.

[0110] Camera 193 is used to capture still images or videos. An object is projected onto a photosensitive element by generating an optical image through the lens. The photosensitive element can be a charge-coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the light signal into an electrical signal, which is then passed to an ISP for conversion into a digital image signal. The ISP outputs the digital image signal to a DSP for processing. The DSP converts the digital image signal into image signals in standard RGB, YUV, or other formats. In some embodiments, the electronic device 100 may include one or N cameras 193, where N is a positive integer greater than 1.

[0111] Digital signal processors (DSPs) are used to process digital signals. Besides digital image signals, they can also process other digital signals. For example, when electronic device 100 selects a frequency, the DSP can perform Fourier transforms on the frequency energy.

[0112] An NPU (Neural Processing Unit) is a computational processor for neural networks (NNs). By borrowing the structure of biological neural networks, such as the transmission patterns between neurons in the human brain, it can rapidly process input information and continuously learn on its own. NPUs enable intelligent cognitive applications in electronic devices, such as image recognition, facial recognition, speech recognition, and text understanding.

[0113] The external storage interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 100. The external memory card communicates with the processor 110 through the external storage interface 120 to perform data storage functions. For example, music, video, and other files can be saved on the external memory card.

[0114] Internal memory 121 can be used to store computer executable program code, which includes instructions. Processor 110 executes various functional applications and data processing of electronic device 100 by running the instructions stored in internal memory 121. Internal memory 121 may include a program storage area and a data storage area. The program storage area may store the operating system, at least one application program (APP) required for a function, such as a sound playback function or an image playback function. The data storage area may store data created during the use of electronic device 100 (such as audio data, phonebook, etc.). Furthermore, internal memory 121 may include high-speed random access memory and may also include non-volatile memory, such as at least one disk storage device, flash memory device, universal flash storage (UFS), etc.

[0115] Touch sensor 180K, also known as a "touch panel," can be located on display screen 194. The touch sensor 180K and display screen 194 together form a touchscreen, also known as a "touch screen." Touch sensor 180K detects touch operations applied to or near it. The touch sensor can transmit the detected touch operation to the application processor to determine the type of touch event. Visual output related to the touch operation can be provided through display screen 194. In other embodiments, touch sensor 180K may also be located on the surface of electronic device 100, in a different position than display screen 194.

[0116] The hardware system of electronic device 100 has been described in detail above. The software system of electronic device 100 is described below. The software system can adopt a layered architecture, event-driven architecture, microkernel architecture, microservice architecture, or cloud architecture. This application embodiment takes a layered architecture as an example to exemplarily describe the software system of electronic device 100.

[0117] like Figure 3 As shown, a layered architecture software system is divided into several layers, each with a clear role and division of labor. Layers communicate with each other through software interfaces. In some embodiments, the software system can be divided into five layers, from top to bottom: application layer 210, application framework layer 220, hardware abstraction layer 230, driver layer 240, and hardware layer 250.

[0118] Application layer 210 may include camera and gallery applications, as well as applications such as calendar, call, map, navigation, WLAN, Bluetooth, music, video, and SMS (not shown in the figure).

[0119] Application framework layer 220 provides application access interfaces and programming frameworks for applications in application layer 210.

[0120] For example, the application framework layer 220 includes a camera access interface for providing camera shooting services through camera management and camera devices.

[0121] The camera management section in application framework layer 220 is used to manage cameras. Camera management can obtain camera parameters, such as determining the camera's working status.

[0122] The camera devices in the application framework layer 220 are used to provide data access interfaces between different camera devices and camera management.

[0123] The hardware abstraction layer 230 is used to abstract hardware. For example, the hardware abstraction layer 230 may include a camera hardware abstraction layer and hardware device abstraction layers of other devices (not shown in the figure); the camera hardware abstraction layer may include camera device 1, camera device 2, etc.; the camera hardware abstraction layer can be connected to a camera algorithm library, and the camera hardware abstraction layer can call algorithms in the camera algorithm library.

[0124] The driver layer 240 is used to provide drivers for different hardware devices. For example, the driver layer may include camera device drivers, digital signal processor drivers, and graphics processor drivers.

[0125] Hardware layer 250 may include cameras, image signal processors, digital signal processors, graphics processors, and other hardware devices.

[0126] The following example, using a photographing scenario as an example, illustrates the workflow of the software system of the electronic device 100.

[0127] When a user taps the touch sensor 180K, the camera app is activated and accesses various camera devices in the camera hardware abstraction layer via the camera access interface. For example, after determining the current zoom level, the camera hardware abstraction layer can send a command to the camera device driver to invoke the camera.

[0128] The camera algorithm library can load algorithms corresponding to the image processing methods provided in the embodiments of this application.

[0129] When the camera at the hardware layer is invoked, it acquires raw image data and sends it to the image signal processor for preliminary processing such as registration and decoding to generate initial image data. The initial image data can be, for example, YUV data. The image signal processor then returns the processed initial image data to the hardware abstraction layer via the camera device driver. The processed data is then processed using the algorithm corresponding to the method provided in this embodiment of the camera algorithm library to obtain the captured image.

[0130] The captured images are sent back to the camera application for display and storage via the camera hardware abstraction layer and camera access interface.

[0131] For ease of understanding, the following embodiments of this application will be described using the following methods: Figure 2 and Figure 3 Taking the electronic device with the structure shown as an example, and in conjunction with the accompanying drawings, the image processing method provided in the embodiments of this application will be specifically described.

[0132] Figure 4 This is a schematic flowchart of an image processing method provided in an embodiment of this application. The method can be achieved through the above... Figure 3 The camera algorithm library implementation is shown below. Figure 4 As shown, the method includes:

[0133] S410. Obtain the data of the image to be processed. The data of the image to be processed may include the chromaticity data and luminance data of the pixels of the image to be processed.

[0134] The image data to be processed refers to the image data for which purple fringing needs to be identified and removed. The image to be processed is a color image. The image data to be processed can be HSV data or YUV data.

[0135] The image data to be processed can be the initial image data directly obtained from the image signal processor, or it can be image data obtained after processing the initial image data. Taking YUV data as an example, the image signal processor can decode the original image data to obtain the initial YUV420 image data. This reduces the sampling of UV components, saves computation, increases the speed of image processing, and improves the performance of electronic devices. In this case, the Y component of the initial YUV420 image data can also be downsampled by 1 / 4 to obtain the image data to be processed. Downsampling the Y component reduces its size to be the same as the size of the UV components. This means that only one traversal is needed when traversing the pixel data subsequently, further saving computation, increasing the speed of image processing, and improving the performance of electronic devices. Of course, the initial image data can also be YUV422 data, in which case the Y component of the YUV422 data can be downsampled by 1 / 2 to obtain the image data to be processed.

[0136] S420. Generate a binarized mask image corresponding to the image to be processed based on the chromaticity data of the pixels in the image to be processed, the preset chromaticity range, and the preset purple edge size.

[0137] A binarized mask image, also known as a binary mask image, has the same size (i.e., pixel values) as the image to be processed, and the pixel positions correspond one-to-one. Each pixel in the binarized mask image is identified by either a first value or a second value. The first value can be 1, and the second value can be 0. 1 indicates that the pixel belongs to a protected area, and 0 indicates that the pixel is outside the protected area. The protected area refers to the region in the binarized mask image that corresponds to a possible purple-edge region in the image to be processed, and its size is larger than a preset purple-edge size.

[0138] The preset chromaticity range, also known as the range of chromaticity requirements for purple fringing, is a pre-set range of chromaticity data used to filter pixels that may have purple fringing. If the chromaticity of a pixel falls within the preset chromaticity range, it means that the pixel is a potential pixel for purple fringing; if the chromaticity does not fall within the preset chromaticity range, it means that the pixel is not a potential pixel for purple fringing, that is, the pixel is neither a pixel with purple fringing nor a pixel with pseudo-purple fringing.

[0139] A preset chromaticity range can be obtained by collecting and analyzing the chromaticity data of purple-edged pixels in various purple-edged sample images. The preset chromaticity range can be pre-stored in memory. It can be represented by parameter values ​​or by images. Taking YUV data as an example, the preset chromaticity range can be represented by the values ​​of the U and Y components, by two-dimensional coordinates defined by the U and V components, or by a preset chromaticity range diagram corresponding to the two-dimensional coordinates.

[0140] For example, Figure 5 This is an example of a preset chromaticity range diagram provided in an embodiment of this application. The horizontal axis represents the U component, the vertical axis represents the V component, and the area enclosed by the curves represents the preset chromaticity range. If the coordinates defined by the UV components of a pixel fall within this area, then the pixel is considered a potential purple-edge pixel (e.g., ...). Figure 5 The pixel corresponding to the point inside the curve; the coordinates defined by the UV components are outside this area, indicating that the pixel is not a possible purple-edge pixel (e.g., ...). Figure 5 (The pixel corresponding to point 501, which is outside the curve).

[0141] One or more potential purple-edge regions can be identified based on the possible pixels of the purple edge.

[0142] The preset purple edge size is a pre-defined range of dimensions used to filter purple edge regions. It can be understood that purple edge regions in the image being processed are generally located at the edges of objects, and compared to pseudo-purple edge regions, they are generally narrower or shorter, i.e., smaller in size. Therefore, the preset purple edge size allows for the differentiation between genuine and pseudo-purple edge regions from the possible purple edge regions. If the size of a possible purple edge region is larger than the preset purple edge size, it is considered a pseudo-purple edge region; if it is smaller than or equal to the preset purple edge size, it is considered a genuine purple edge region. Optionally, the preset purple edge size can be, for example, 5 pixels * 5 pixels.

[0143] In the binarized mask image, regions whose size is larger than a preset purple edge size are defined as protected areas within the area corresponding to the pseudo-purple edge region in the image to be processed. In other words, the protected area is the region in the binarized mask image that corresponds to the pseudo-purple edge region in the image to be processed. The protected area is used to protect the pseudo-purple edge pixels within the pseudo-purple edge region in the image to be processed, thereby filtering out the purple edge pixels.

[0144] S430. Determine the purple-edge pixels in the image to be processed based on the binarized mask image.

[0145] Specifically, a binarized mask image is used as a mask to filter out potential purple-edged pixels in the image to be processed that are located outside the area corresponding to the protected zone. In this way, the protected zone can protect pseudo-purple-edged pixels in the pseudo-purple-edged area, thereby filtering out purple-edged pixels in the image to be processed.

[0146] S440, Adjust the data of the purple-edged pixels.

[0147] In one embodiment, the chromaticity data of the purple-edged pixels can be reduced to eliminate the purple fringing and improve image quality.

[0148] In another embodiment, in addition to reducing the chromaticity data of the purple-edged pixels, the brightness data can be further adjusted to make the brightness of the purple-edged pixels more uniform after removing the purple edges, thereby further improving the image quality.

[0149] In this embodiment, data of the image to be processed is acquired, and a binarized mask image corresponding to the image to be processed is generated based on the chromaticity data in the data, a preset chromaticity range, and a preset purple edge size. The binarized mask image includes a protected area, which is a region in the image to be processed that corresponds to a possible purple edge region and has a size larger than the preset purple edge size. Since the purple edge region is generally smaller than or equal to the preset size, the protected area does not include the region corresponding to the purple edge region; that is, the protected area only includes the region corresponding to the pseudo-purple edge region. Therefore, the protected area can protect pixels in the pseudo-purple edge region of the image to be processed. Furthermore, pixels outside the protected area among the possible purple edge pixels in the image to be processed are determined based on the binarized mask image, and purple edge pixels are filtered out. The method provided in this embodiment can accurately determine purple edge pixels, prevent pseudo-purple edge pixels from being identified as real purple edge pixels, improve the accuracy of purple edge recognition, and thus more accurately adjust the data of purple edge pixels to eliminate purple edges, thereby improving image quality and enhancing the user's visual experience.

[0150] The following, in conjunction with the accompanying drawings, provides a more detailed explanation of the specific process of generating a binarized mask image corresponding to the image to be processed based on the chromaticity data of the pixels in the image to be processed, the preset chromaticity range, and the preset purple edge size.

[0151] For example, Figure 6 This is a schematic flowchart illustrating another example of an image processing method provided in an embodiment of this application. For example... Figure 6 As shown, the method includes:

[0152] S421. Based on the chromaticity data of the pixels in the image to be processed and the preset chromaticity range, generate a binarized image corresponding to the image to be processed. In the binarized image, the pixel value of the chromaticity data belonging to the preset chromaticity range is 1.

[0153] Specifically, firstly, a template image with the same size as the image to be processed and whose pixel positions correspond one-to-one is created. Then, using the chromaticity data belonging to a preset chromaticity range as a filtering condition, the chromaticity data of each pixel in the image to be processed is traversed to filter out pixels that meet the filtering condition, i.e., pixels with possible purple edges in the image to be processed. In the template image, the identifier value of pixels corresponding to pixels with possible purple edges (i.e., pixels that meet the filtering condition) is set to 1, and the identifier value of pixels corresponding to pixels without possible purple edges (i.e., pixels that do not meet the filtering condition) is set to 0. This yields a binarized image corresponding to the image to be processed. The region where all pixels have an identifier value of 1 is defined as the first region. In one embodiment, the first region is the largest continuous region formed by pixels with an identifier value of 1 in the binarized image. The first region is also the region corresponding to the possible purple edge region in the image to be processed.

[0154] For example, Figure 7 This is a schematic diagram illustrating an example of generating a binary mask image, provided as an embodiment. Figure 7 As shown, with Figure 1 The image shown is an example of the image to be processed, where it is assumed that... Figure 1 The color at position 104 is purple, which is similar to the color of the purple edge at position 103. That is... Figure 1 104 of these locations are pseudo-purple edge areas. Figure 1 The CCP includes three pseudo-purple-bordered regions. Figure 1 The 103rd location is a purple-edged area. (Regarding...) Figure 1 The image shown is processed to generate a binarized image as follows. Figure 7 As shown in Figure (a). Figure 7 In Figure (a), the pixel corresponding to the white dot has a value of 1, meaning that the pixel is a possible purple-edge pixel, while the pixel corresponding to the black dot has a value of 0, meaning that the pixel is a possible non-purple-edge pixel. The white area is also known as the first area. Figure 7 The first region in Figure (a) consists of four regions: 701a, 702a, 703a, and 704a. Among them, 701a, 702a, and 703a correspond to the pseudo-purple edge region, and 704a corresponds to the purple edge region.

[0155] S422. Using a structuring element with a preset purple edge size, perform erosion processing on each first region in the binarized image to obtain the corresponding second region, and generate a binarized eroded image.

[0156] Using an image with a preset purple border size as a structuring element, erosion processing is applied to each first region in the binarized image to remove the edge portions of the first regions. As described in the above embodiment, the purple border regions are generally narrow and small in size. Therefore, through erosion processing, the portion in the binarized image corresponding to the purple border region will be completely eliminated, and the identifier value will become 0.

[0157] See also Figure 7 ,right Figure 7 The binarized eroded image obtained by eroding the image in (a) is shown below. Figure 7 As shown in Figure (b) above. Compare Figure 7 As can be seen from Figures (a) and (b), after corrosion treatment, Figure 7 In Figure (a), the ranges of the first regions 701a, 702a, and 703a are reduced (see the white dotted line in the figure for comparison), and the following are obtained respectively. Figure 7 The second region 701b, 702b, and 703b in Figure (b). Figure 7 In Figure (a), the first region 704a is eliminated and turns black.

[0158] S423. Using a structuring element with a preset purple edge size, dilate each second region in the binarized erosion image to obtain the corresponding protected area, and generate a binarized mask image.

[0159] The structuring element used in the dilation process remains the preset purple edge size. Therefore, through dilation, the second region in the binarized eroded image is restored (the pixel's identifier value changes from 0 to 1) to its original size in the binarized image, that is, restored to the size corresponding to the pseudo-purple edge region. Since the part corresponding to the purple edge region is eliminated during the erosion process and cannot be restored after dilation, the binarized mask image obtained after dilation only includes the region corresponding to the pseudo-purple edge region, i.e., the protected area.

[0160] After the above erosion and dilation processes, the resulting binarized mask image includes only the protected area corresponding to the pseudo-purple edge region, but not the region corresponding to the purple edge region. This protects the pseudo-purple edge pixels and allows the purple edge pixels to be filtered out.

[0161] See also Figure 7 ,right Figure 7 The binarized mask image obtained by dilating image (b) can be shown as follows. Figure 7 As shown in Figure (c) above. Compare Figure 7 As can be seen from Figures (a), (b), and (c), after the dilation process, Figure 7 Edge restoration of the second region 701b, 702b, and 703b in Figure (b) yields the following results: Figure 7Protected areas 701c, 702c and 703c in Figure (c). Figure 7 Protected areas 701c, 702c, and 703c in Figure (c) are... Figure 7 In Figure (a), 701c, 702c, and 703c are the same. Furthermore, Figure 7 Map (c) only includes protected areas 701c, 702c, and 703c, and does not include... Figure 7 704a in Figure (a).

[0162] The method provided in this embodiment can generate binary mask images simply, accurately, and quickly, improving the efficiency and accuracy of determining purple-edge pixels.

[0163] Optionally, when adjusting the data of purple-edged pixels, the calculation and adjustment can be performed one by one. For ease of explanation, in the following embodiments, the purple-edged pixel that is currently being calculated and adjusted, or undergoing other processing, is referred to as the current purple-edged pixel.

[0164] There are several methods to adjust the data of purple-edged pixels. In one embodiment, the target chromaticity data corresponding to the current purple-edged pixel's chromaticity data can be determined based on a pre-established mapping relationship between chromaticity data and target chromaticity data. The chromaticity data of the purple-edged pixel can then be adjusted to the target chromaticity data, thereby removing the purple edge from the image to be processed.

[0165] In another embodiment, the data of the purple-edged pixels can be adjusted based on luminance and chrominance data to remove the purple edge. Specifically, adjustment weights can be determined based on the luminance and chrominance data of the purple-edged pixels, and then the data of the purple-edged pixels can be adjusted according to these weights. This ensures that the adjustment of the purple-edged pixels considers not only the chrominance of the pixel but also its luminance, resulting in more accurate and natural chrominance and further improving image quality.

[0166] The following is combined Figures 8 to 10 The above-described scheme for adjusting the data of purple-edged pixels based on luminance and chrominance data will be further explained in detail. The following embodiments use the adjustment process for the current purple-edged pixel as an example; the process can be repeated for other purple-edged pixels without further elaboration.

[0167] 1) Determine the adjustment weights based on the current luminance and chrominance data of the purple-edged pixels.

[0168] like Figure 8 As shown, determining the adjustment weights based on the current luminance and chrominance data of the purple-edged pixels can be achieved by following these steps:

[0169] S441. Determine the first brightness weight w1 of the current purple-edge pixel based on the brightness data of the current purple-edge pixel and the pixels within the first preset range around the current purple-edge pixel.

[0170] It is understandable that each pixel can determine its first brightness weight w1 based on its brightness data and the brightness data of pixels within a first preset range around it.

[0171] The first luminance weight w1 is used to characterize the influence of the luminance difference (hereinafter referred to as luminance difference) between a pixel and pixels within a first preset range on the chromaticity data adjustment of that pixel. The larger the first luminance weight w1, the greater the influence of the luminance difference on the chromaticity data adjustment of that pixel. The range of the first luminance weight w1 can be [0, 1].

[0172] In a specific embodiment, the first brightness weight w1 is used to characterize the probability that a pixel has a large brightness difference with its surrounding pixels. A large brightness difference means that the brightness difference is greater than a certain preset value. The larger the first brightness weight w1, the larger the brightness difference. A first brightness weight w1 of 0 indicates that the pixel has no brightness difference with its surrounding pixels within a first preset range. A first brightness weight w1 of 1 indicates that the pixel has a large brightness difference with its surrounding pixels within the first preset range. The larger the brightness difference, the greater the probability that the pixel is a purple-edged pixel.

[0173] The size of the first preset range can be determined according to actual needs. For example, Figure 9 This is a schematic diagram illustrating an example of a purple-edged pixel and surrounding pixels within a first preset range, provided as an embodiment of this application. Figure 9 As shown, each circle in the diagram represents a pixel. The black-filled circle in the center represents the current purple-edged pixel. The pixels within the first preset range include pixels within a 13-pixel*13-pixel area centered on the current purple-edged pixel, as shown by the white-filled pixels in the diagram.

[0174] In one embodiment, the first brightness weight w1 can be determined by the brightness gradient of a pixel. Specifically, for the current purple-edged pixel, the first brightness weight w1 can be determined by the brightness gradient of the current purple-edged pixel within a first preset range. Specifically, the brightness gradient of the current purple-edged pixel can be determined based on the brightness data of pixels in multiple preset directions where the current purple-edged pixel is located.

[0175] Optionally, in one possible implementation, the brightness gradient of the current purple-edged pixel can be determined based on the brightness data of the pixels in the horizontal and vertical coordinate directions where the current purple-edged pixel is located.

[0176] Alternatively, in another possible implementation, the brightness gradient of the current purple-edged pixel can be determined based on the brightness data of pixels in four preset directions where the current purple-edged pixel is located. These four preset directions could be, for example, the horizontal and vertical coordinate directions of the purple-edged pixel, and the diagonal direction of the region formed by the first preset range.

[0177] Please continue reading Figure 9 For example, it can be based on such Figure 9 The brightness gradient of the current purple-edged pixel is determined by the brightness data of pixels along four preset directions indicated by four straight lines. Specifically, the brightness gradient of the current purple-edged pixel in these four preset directions is calculated separately, resulting in four candidate gradient values. Then, the largest of the four candidate gradient values ​​is determined as the brightness gradient of the current purple-edged pixel. The larger the brightness gradient, the greater the brightness difference between the current purple-edged pixel and its surrounding pixels. In this implementation, the brightness gradient of the current purple-edged pixel is determined by the brightness data of pixels along four preset directions, making the determined brightness gradient more accurate. This, in turn, makes the subsequent determination of the first brightness weight w1 of the current purple-edged pixel more accurate, leading to more accurate adjustments to the data of the current purple-edged pixel and improving the purple-edged removal effect.

[0178] Optionally, after determining the brightness gradient of the current purple-edged pixel, the first brightness weight w1 corresponding to the current purple-edged pixel can be determined according to the first mapping relationship. The first mapping relationship is a pre-set correspondence between the brightness gradient and the first brightness weight w1. Optionally, the first mapping relationship can be, for example, a lookup table of brightness gradient and first brightness weight w1.

[0179] S442. Determine the second brightness weight w2 of the current purple-edge pixel based on the brightness data of the current purple-edge pixel and the pixels within the second preset range around the current purple-edge pixel.

[0180] It is understandable that each pixel can determine its second brightness weight w2 based on its brightness data and the brightness data of pixels within a second preset range around it.

[0181] The second brightness weight w2 characterizes the influence of high-brightness pixels within a second preset range on the chroma data adjustment of that pixel. High-brightness pixels refer to pixels whose brightness data exceeds a preset brightness threshold. Optionally, the preset brightness threshold can be a grayscale value; for example, for an image with a grayscale value range of 0 to 255, the preset brightness threshold can be a value between 160 and 240. The larger the second brightness weight w2, the greater the influence of high-brightness pixels within the second preset range on the chroma data adjustment of that pixel. The range of the second brightness weight w2 can be [0, 1].

[0182] In a specific embodiment, the second brightness weight w2 is specifically used to characterize the probability that there are a large number (greater than a preset number) of high-brightness pixels within a second preset range around the pixel, that these high-brightness pixels are close to the pixel (at a distance less than a preset distance), and that there is a large difference in brightness (less than a preset threshold) among the pixels within the second preset range. A larger second brightness weight w2 indicates a greater probability that there are a large number of high-brightness pixels within the second preset range around the pixel, that these high-brightness pixels are close to the pixel, and that there is a large difference in brightness among the pixels within the second preset range. A second brightness weight w2 of 0 indicates that there are no high-brightness pixels around the pixel, or that the high-brightness pixels are far from the pixel, or that there is no large difference in brightness within the second preset range. A second brightness weight w2 of 1 indicates that there are a large number of high-brightness pixels around the pixel, that these high-brightness pixels are close to the pixel, and that there is a large difference in brightness within the second preset range. A larger second brightness weight w2 indicates a greater probability that the pixel is a purple-edged pixel.

[0183] The size of the second preset range can be determined according to actual needs. The second preset range can be the same as or different from the first preset range. When the second preset range is the same as the first preset range, the first brightness weight w1 and the second brightness weight w2 corresponding to a certain pixel can be determined by the same set of brightness data, thereby reducing the amount of computation and improving computational efficiency.

[0184] In one embodiment, pixels within a second preset range can be divided into multiple brightness blocks, and the brightness of each brightness block can represent the brightness of a single pixel, thereby determining the second brightness weight w2. This reduces the impact of noise in the image on brightness determination, improves the accuracy of the second brightness weight w2 calculation, and thus enhances the effect of removing purple fringing from the image. The specific implementation steps are as follows:

[0185] a. Divide the current purple-edged pixel and the pixels within a second preset range around the current purple-edged pixel into multiple brightness blocks.

[0186] The number of pixels in each brightness block and the shape of the brightness block can be set according to requirements.

[0187] For example, Figure 10 This is a schematic diagram illustrating the division of a brightness block according to an embodiment of this application. Taking the second preset range being the same as the first preset range as an example, it can be... Figure 9The pixels shown are divided into 2-pixel x 2-pixel blocks, meaning each luminance block contains 4 pixels. During division, if a luminance block located at the edge of a region within a first preset range cannot meet the 2-pixel x 2-pixel size requirement, then that luminance block can contain fewer than 4 pixels. The division result can be as follows... Figure 10 As shown in the figure. Among them, the brightness block where the current purple-edged pixel is located is brightness block 1001.

[0188] b. Determine the brightness value of each brightness block based on the brightness data of the current purple-edged pixel and the pixels within a second preset range surrounding the current purple-edged pixel.

[0189] Optionally, the chromaticity data of the pixels in each luminance block can be averaged to obtain the luminance value of that luminance block. By averaging, the influence of the luminance of a single pixel on the luminance value of the luminance block can be reduced, thereby reducing the impact of noise in the image on the luminance calculation and improving the accuracy of the calculation of the second luminance weight w2.

[0190] c. Determine the brightness distribution parameters of the current purple-edge pixel based on the brightness values ​​of each brightness block. The brightness distribution parameters include at least one of the following: the number of high brightness blocks, the distance between the high brightness blocks and the brightness block where the current purple-edge pixel is located, and the brightness difference between brightness blocks. A high brightness block refers to a brightness block whose brightness value is greater than a preset high brightness threshold. The brightness difference between brightness blocks refers to the difference between the maximum and minimum brightness values ​​among all brightness blocks.

[0191] Specifically, based on the brightness value of each brightness block, the number and location of high-brightness blocks with brightness values ​​greater than a preset high-brightness threshold can be determined, along with the maximum and minimum brightness values. The location of the high-brightness blocks can be represented using coordinates. For example, the brightness block containing the current purple-edged pixel can be defined as the zero point of a coordinate system. Each brightness block corresponds to a coordinate value in this system, and the coordinate value of the high-brightness block is its location. Then, based on the coordinates of the high-brightness block, the distance between that high-brightness block and the brightness block containing the current purple-edged pixel can be determined. Finally, the difference between the maximum and minimum brightness values ​​is calculated to obtain the brightness difference of the brightness blocks.

[0192] d. Determine the second brightness weight w2 based on the brightness distribution parameters of the current purple-edged pixels.

[0193] The second luminance weight w2 can be determined based on one of the luminance distribution parameters, or it can be determined based on multiple luminance distribution parameters.

[0194] Optionally, the second luminance weight w2 corresponding to the current purple-edged pixel can be determined based on the second mapping relationship. The second mapping relationship is the correspondence between pre-set luminance distribution parameters and the second luminance weight w2.

[0195] Optionally, when determining the second luminance weight w2 based on multiple luminance distribution parameters, the second mapping relationship may include the correspondence between each parameter and the sub-weight. Based on this correspondence, the sub-weight corresponding to each parameter is determined. Then, operations such as multiplication of multiple sub-weights can be performed to obtain the final second luminance weight w2.

[0196] In this implementation, the second brightness weight is determined by the brightness distribution parameters of the purple-edge pixels. The brightness distribution parameters include at least one of the following: the number of high-brightness blocks, the distance between the brightness block where the purple-edge pixel is located and the high-brightness block, and the brightness difference between the brightness blocks. These parameters can all characterize the degree of influence of high-brightness pixels or high-brightness regions on the purple-edge pixels. The second brightness weight determined by the brightness distribution parameters is more accurate.

[0197] S443. Determine the chromaticity weight w3 of the current purple-edge pixel based on its chromaticity data.

[0198] It can be understood that each pixel can have its chromaticity weight w3 determined based on its chromaticity data. The chromaticity weight w3 is used to characterize the degree of influence of the pixel's chromaticity data itself on the adjustment of its chromaticity data. Optionally, the range of the chromaticity weight w3 can be [0, 1].

[0199] In a specific embodiment, the chromaticity weight w3 is used to characterize the probability that a pixel is a potential purple-edged pixel, that is, the probability that the pixel's chromaticity falls within a preset chromaticity range. The larger the chromaticity weight w3, the greater the probability that the pixel is a purple-edged pixel, meaning the closer the pixel's chromaticity data is to the preset chromaticity range. A chromaticity weight of 0 indicates that the pixel is not a potential purple-edged pixel. A chromaticity weight w3 of 1 indicates that the pixel is a potential purple-edged pixel. A larger chromaticity weight w3 also indicates a greater probability that the pixel is a purple-edged pixel.

[0200] Optionally, the chromaticity weight w3 corresponding to the current purple-edged pixel can be determined based on the third mapping relationship. The third mapping relationship is a pre-set correspondence between chromaticity data and chromaticity weight w3.

[0201] S444. Determine the adjustment weight W of the current purple edge pixel based on the first luminance weight w1, the second luminance weight w2, and the chromaticity weight w3.

[0202] Optionally, the adjustment weight corresponding to the current purple-edge pixel can be determined according to the first brightness weight w1, the second brightness weight w2, and the chromaticity weight w3 of the current purple-edge pixel, based on a preset product calculation formula.

[0203] Let's take the preset product calculation formula W = w1 * w2 * w3 as an example. The larger the product of the first luminance weight w1, the second luminance weight w3, and the chromaticity weight w3, the greater the probability that the pixel is a purple-edged pixel, and the greater the adjustment of the pixel's data. Conversely, the smaller the product, the lower the probability that the pixel is a purple-edged pixel, and the smaller the adjustment of the pixel.

[0204] In this implementation, a first luminance weight and a second luminance weight are determined based on the luminance data of the purple-edged pixel and the pixels surrounding it, respectively. A chromaticity weight is then determined based on the chromaticity data of the purple-edged pixel. Finally, the adjustment weight corresponding to the purple-edged pixel is determined based on the first luminance weight, the second luminance weight, and the chromaticity weight. As described in the previous embodiment, purple edges often appear in edge areas with large contrast between light and dark areas. Therefore, luminance difference, bright pixels, and chromaticity range are crucial for the identification and adjustment of purple edges. The method provided in this implementation fully considers the influence of luminance difference, bright pixels, and the chromaticity data itself on eliminating purple edges when determining the adjustment weights. This results in a smaller difference in luminance and chromaticity between the adjusted purple-edged pixel and its surrounding pixels, leading to a more natural image effect and better image quality. Furthermore, the obtained adjustment weights characterize the probability that a pixel is a purple-edged pixel. The smaller the adjustment weight, the lower the probability that the pixel is a purple-edged pixel, and the smaller the adjustment force, and vice versa. This makes the adjustment of chromaticity and luminance more accurate. Furthermore, when a pixel is misidentified as a purple-edged pixel, the adjustment weights are adjusted to minimize the impact on image quality caused by this misidentification. For example, if a non-purple-edged pixel is misidentified, but at least one of its first luminance weight, second luminance weight, and chromaticity weight is calculated to be 0, the resulting adjustment weight is 0. Therefore, when adjusting the data of this pixel, the adjustment is minimized, or no adjustment is made at all, thus improving the accuracy of data adjustment and reducing the impact of purple-edged misidentification on image quality.

[0205] 2) Adjust the data of the purple-edged pixels according to the adjustment weights.

[0206] like Figure 8 As shown, adjusting the data of the purple-edged pixels according to the adjustment weights can be achieved by following these steps:

[0207] S445. Determine the target chromaticity data based on the chromaticity data of the current purple-edge pixels and the adjusted weight W.

[0208] The target chromaticity data refers to the target value for adjusting the chromaticity of the current purple-edged pixel. Optionally, the target chromaticity data of the current purple-edged pixel can be determined based on its chromaticity data and the adjustment weight determined in step S444. The target chromaticity data can be less than or equal to the chromaticity data of the current purple-edged pixel, that is, reducing the chromaticity data of the current purple-edged pixel. Reducing the chromaticity data darkens the color of the pixel, thereby eliminating the purple edge.

[0209] Taking the image data to be processed as YUV data as an example, the chromaticity data consists of UV components. In a specific embodiment, the target chromaticity data may include target U component values ​​and target V component values. The target U component values ​​and target V component values ​​can then be determined according to the following formula:

[0210] Target U component value = current U component value * (1-W);

[0211] Target V component value = current V component value * (1 - W).

[0212] Based on the determination process of the adjustment weight W in the above embodiments, the larger the adjustment weight W, the greater the reduction in the chromaticity data of the pixel. Conversely, the smaller the adjustment weight W, the smaller the reduction in the chromaticity of the pixel. When the first luminance weight w1, the second luminance weight w3, and the chromaticity weight w3 are all 1, the adjustment weight W is 1, and the target U component value and the target V component value are both 0. That is, the chromaticity data of the pixel is reduced to 0. When any one of the first luminance weight w1, the second luminance weight w3, and the chromaticity weight w3 is 0, the adjustment weight W is 0, the target U component value is equal to the current U component value, and the target V component value is equal to the current V component value, that is, the chromaticity data of the pixel is not adjusted.

[0213] Therefore, the above process adjusts the chromaticity data of the purple-edged pixels according to the adjustment weight, which can eliminate the purple edge. After the adjustment, the chromaticity difference between the purple-edged pixels and the surrounding pixels is smaller, resulting in a more balanced and natural image chromaticity, which can improve image quality and thus enhance the user's visual experience.

[0214] S446. Adjust the chromaticity data of the current purple-edged pixels to the target chromaticity data.

[0215] That is, adjust the current U component value to the target U component value, and adjust the current V component value to the target V component value.

[0216] S447. Determine the target brightness data based on the current brightness data of the purple-edged pixels and the adjusted weight W.

[0217] Optionally, the difference between the current brightness data and the average brightness data of the current purple-edge pixel can be calculated first, and then the product of this difference and the adjustment weight can be calculated to obtain the brightness adjustment value. The target brightness value can then be calculated based on the brightness adjustment value and the current brightness data of the current purple-edge pixel.

[0218] The average brightness data is the average brightness data of pixels within a third preset range surrounding the current purple-edged pixel. This third preset range can be defined as needed. In one embodiment, the third preset range can be the same as the second preset range described above. The average brightness data can be calculated using the methods described in steps a, b, and c of step S442 in the above embodiment, calculating the average brightness value of each brightness block, and using this average value as the average brightness data. This reduces the impact of noise on brightness calculation, improves the accuracy of target brightness data calculation, thereby improving the accuracy of brightness adjustment and image quality.

[0219] Continuing with the example of using YUV data for the image to be processed, in a specific embodiment, the average brightness data can be the average Y component value, and the target brightness data can be the target Y component value. Then, the target Y component value can be determined according to the following formula:

[0220] Target Y component value = (Average Y component value - Current Y component value) * W + Current Y component value. Where (Average Y component value - Current Y component value) * W is the brightness adjustment value mentioned above.

[0221] As can be seen from the formula, depending on the relationship between the current Y component value and the average Y component value, the brightness adjustment value may be positive, negative, or zero. In other words, the brightness adjustment may increase, decrease, or remain unchanged. Specifically, referring to the determination process of the adjustment weight W in the above embodiments, the larger the adjustment weight W, the greater the adjustment of the pixel's brightness data. Conversely, the smaller the adjustment weight W, the smaller the adjustment of the pixel's brightness. When the first brightness weight w1, the second brightness weight w3, and the chromaticity weight w3 are all 1, the adjustment weight W is 1, and the brightness adjustment value is the difference between the average Y component and the current Y component. That is, the brightness of the pixel is adjusted to the average brightness. When any one of the first brightness weight w1, the second brightness weight w3, and the chromaticity weight w3 is 0, the adjustment weight W is 0, the brightness adjustment value is 0, the target Y component value is equal to the current Y component value, meaning that the brightness data of the pixel is not adjusted.

[0222] It can be seen that in the above process, on the basis of adjusting the chromaticity, the brightness of the purple fringing pixel points is adjusted, so that the brightness difference between the processed purple fringing pixel points and the surrounding pixel points is small, and the brightness of the obtained image is more balanced and natural, further improving the image quality and thus enhancing the user's visual experience. Moreover, the adjustment weight used during brightness adjustment is the same as the weight used during chromaticity adjustment, which makes the adjustment intensity of brightness and chromaticity consistent, realizes the adaptive adjustment of brightness with chromaticity, further improves the image quality, and enhances the user's visual experience.

[0223] It should be noted that when the brightness data is the downsampled brightness data (i.e., the data obtained by downsampling according to the method in step S410 in the above embodiment), in the calculation formula of the above target Y component value, each Y component value is the downsampled Y component value. In this case, the brightness adjustment value needs to be calculated through interpolation processing. Specifically, the calculation process of the target Y component value in this case can be as follows: First, calculate the difference between the average downsampled Y component value and the current downsampled Y component value to obtain the reference adjustment value. Among them, the average downsampled Y component value refers to the average brightness data determined according to the downsampled Y component values. The current downsampled Y component value refers to the Y component value after downsampling of the current pixel point. Then, according to the reference adjustment value and the downsampling ratio, the bilinear interpolation method is used to calculate the adjustment value corresponding to the Y component before downsampling (i.e., the original Y component), and this value is used as the final brightness adjustment value. Then, the target Y component value is determined according to the final brightness adjustment value and the Y component value before downsampling. In short, when the obtained brightness data is the downsampled Y component data, it is necessary to determine the reference adjustment value through the downsampled Y component, and then, after interpolation processing according to the downsampling ratio, obtain the adjustment value corresponding to the Y component before downsampling; furthermore, the final target Y component value is determined according to the Y component before downsampling and the adjustment value corresponding to the Y component before downsampling.

[0224] The adjustment value corresponding to the original Y component of the pixel point is determined by the bilinear interpolation method, and according to this adjustment value and the original Y component value, the target Y component value is further calculated. This can accurately adjust the brightness of the purple fringing pixel points.

[0225] On the other hand, during the brightness adjustment process, the brightness adjustment range can be further limited. Optionally, in a specific embodiment, it can be limited that the target brightness data belongs to a brightness interval, and the brightness interval can be determined according to the brightness situation of the pixel points in the above third preset range. Continuing to take the case where the third preset range is the same as the second preset range as an example, the brightness interval can determine the maximum brightness value and the minimum brightness value through steps a, b, and c in step S442 in the above embodiment. The maximum brightness value is used as the upper limit of the brightness interval, and the minimum brightness value is used as the lower limit of the brightness interval.

[0226] Based on the calculation formula for the target Y component value described above, the target Y component value can be further defined as belonging to the aforementioned brightness range, i.e., the target Y component value ∈ [minimum brightness value, maximum brightness value]. Specifically, after calculating the target Y component value using the aforementioned calculation formula, if the value belongs to the brightness range, the calculated target Y component value is taken as the final target Y component value; if the value is greater than the upper limit of the brightness range, the upper limit of the brightness range (i.e., the maximum brightness value) is taken as the final target Y component value; if the value is less than the lower limit of the brightness range, the lower limit of the brightness range (i.e., the minimum brightness value) is taken as the final target Y component value.

[0227] In this implementation, the final target Y component value is limited to a brightness range, which is determined based on the brightness of pixels surrounding the purple-edged pixels. This ensures that the final adjusted brightness value is neither too high nor too low. This prevents the removed purple-edged portions of the processed image from being too dark or too light, resulting in white edges or black-and-white contrasts, thus improving the quality and effect of the obtained image and ultimately enhancing the user's visual experience.

[0228] S448. Adjust the brightness data of the current purple-edge pixels to the target brightness data.

[0229] That is, adjust the current Y component value to the target Y component value.

[0230] It should be noted that the implementation methods and execution order of the steps in the above embodiments are merely examples and do not limit the image processing method provided in this embodiment. For example, in some embodiments, the method provided in this embodiment can also be implemented according to the following process. The following process is illustrated using YUV420 data of the image to be processed as an example. (Reference) Figure 11 The method may include:

[0231] S1101. Obtain the YUV420 data of the image to be processed.

[0232] S1102. Based on the YUV420 data, the Y component of each pixel in the image to be processed is downsampled by 1 / 4 to obtain the downsampled Y component and UV component of each pixel.

[0233] S1103. For each pixel in the image to be processed, calculate the brightness gradient of the pixel based on the downsampled Y component of the pixel and the surrounding pixels within a first preset range, and determine the first brightness weight w1 of the pixel based on the brightness gradient and the first mapping relationship.

[0234] In this way, the first brightness weight w1 of each pixel in the image to be processed can be obtained.

[0235] S1104. For each pixel in the image to be processed, determine the brightness distribution parameters based on the downsampled Y components of the pixel and the surrounding pixels within a first preset range, and determine the second brightness weight w2 based on the brightness distribution parameters.

[0236] Specifically, it may include the following processes:

[0237] a. Divide the pixels within a second preset range around the pixel into multiple brightness blocks;

[0238] b. Calculate the brightness value of each brightness block based on the downsampled Y component of the pixel and the surrounding pixels within a second preset range;

[0239] c. Count the brightness values ​​of these brightness blocks that are greater than the preset high brightness threshold, and identify the high brightness blocks;

[0240] d. Determine the number of high-brightness blocks and the distance between the high-brightness blocks and the brightness block where the current pixel is located;

[0241] e. Calculate the difference between the maximum and minimum brightness values ​​among these brightness blocks to obtain the brightness difference of the brightness blocks;

[0242] f. Determine the second brightness weight w2 of the pixel based on the number of high brightness blocks, the distance between the high brightness blocks and the brightness block where the current pixel is located, the brightness difference between the brightness blocks, and the second mapping relationship.

[0243] In this way, the second brightness weight w2 of each pixel in the image to be processed can be obtained.

[0244] It should be noted that when the first preset range and the second preset range are the same, the first brightness weight w1 and the second brightness weight w2 can be obtained by one traversal according to the above steps S1103 and S1104, which saves computation and improves algorithm efficiency.

[0245] S1105. For each pixel in the image to be processed, compare the UV component of the pixel with the preset UV component range (i.e., the preset chromaticity range mentioned above) to determine the chromaticity weight w3 of the pixel.

[0246] In a specific embodiment, for a certain pixel, the angle between the direction of the vector determined by the UV component of the pixel and a preset direction can be determined according to a preset angle weight mapping relationship to obtain the weight corresponding to the angle, thus obtaining the first sub-weight; then, the weight corresponding to the amplitude can be determined according to the amplitude of the vector determined by the UV component of the pixel and a preset amplitude weight mapping relationship to obtain the second sub-weight; the first sub-weight and the second sub-weight are multiplied to obtain the chromaticity weight w3 of the pixel.

[0247] In this way, the chromaticity weight w3 of each pixel in the image to be processed can be obtained.

[0248] It is understandable that after performing the above steps S1101 to S1105, the first brightness weight w1, the second brightness weight w2 and the third brightness weight w3 of each pixel can be saved.

[0249] S1106. Based on the chromaticity weight w3 of each pixel in the image to be processed obtained in step S1105 above, generate a binarized mask image corresponding to the image to be processed.

[0250] Specifically, a template image with the same size as the image to be processed and whose pixels correspond one-to-one is generated. In the template image, the identifier value of the pixel corresponding to the pixel with a chromaticity weight w3 of 1 in the image to be processed is set to 1 to obtain the first region; the identifier value of the pixel corresponding to the pixel with a chromaticity weight w3 less than 1 is set to 0; thus generating a binarized image; each first region in the binarized image is eroded using a structuring element with a preset purple edge size to obtain the corresponding second region, thus generating a binarized eroded image; each second region in the binarized eroded image is dilated to obtain the corresponding protected area, thus generating a binarized mask image.

[0251] S1107. Using the binarized mask image as a mask, traverse the position and chromaticity weight w3 of each pixel in the image to be processed, and determine whether each pixel is located outside the area corresponding to the protected area in the binarized mask image in the image to be processed, and whether the chromaticity weight w3 is 1.

[0252] If the pixel is located outside the protected area in the binary mask image in the image to be processed, and the chromaticity weight w3 of the pixel is 1, then the pixel is determined to be a purple edge pixel, and steps S1108 to S1110 are executed.

[0253] If the pixel is located in the protected area in the binary mask image, or if the pixel's chromaticity weight w3 is less than 1, then the pixel is determined not to be a purple-edged pixel, and no processing is performed on the pixel.

[0254] S1108. Determine the adjustment weight W of the pixel based on the first luminance weight w1, the second luminance weight w2, and the chromaticity weight w3.

[0255] S1109. Reduce the UV component of the pixel according to the adjusted weight W.

[0256] S1110. Adaptively adjust the Y component of the pixel according to the adjustment weight W.

[0257] When adaptively adjusting the Y component, the process described in the above embodiment is followed to determine the adjustment value corresponding to the downsampled Y component of the pixel, and based on the adjustment value corresponding to the downsampled component, the adjustment value corresponding to the Y component of the pixel is determined based on the bilinear interpolation method, and then the Y component of the pixel is adjusted according to the adjustment value corresponding to the Y component.

[0258] The specific implementation methods of each step in this embodiment are the same as those in the above embodiments, and will not be repeated here. In this embodiment, before determining whether a pixel is a purple-edged pixel, the first luminance weight w1, the second luminance weight w2, and the chromaticity weight w3 of each pixel in the image to be processed are obtained in advance. Then, the chromaticity weight w3 is used to determine whether the pixel is a purple-edged pixel. If it is a purple-edged pixel, the adjustment weight W of the pixel is determined by the product of the three weights. Then, the purple-edged pixel is processed according to the adjustment weight W to eliminate the purple edge. In this way, for images to be processed with the same or similar size, the time required to remove the purple edge by executing the method of this application is basically the same, thereby making the image processing time highly controllable and improving the stability of the electronic device's shooting function.

[0259] The foregoing has detailed examples of image processing methods provided in the embodiments of this application. It is understood that, in order to achieve the above functions, the electronic device includes hardware and / or software modules corresponding to the execution of each function. Those skilled in the art should readily recognize that, based on the units and algorithm steps of the examples described in conjunction with the embodiments disclosed herein, this application can be implemented in hardware or a combination of hardware and computer software. Whether a function is executed in hardware or by computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application in conjunction with the embodiments, but such implementation should not be considered beyond the scope of this application.

[0260] This application embodiment can divide the electronic device into functional modules according to the above method example. For example, each function can be divided into a separate functional module, such as a detection unit, a processing unit, a display unit, etc., or two or more functions can be integrated into one module. The integrated module can be implemented in hardware or as a software functional module. It should be noted that the module division in this application embodiment is illustrative and only represents one logical functional division. In actual implementation, there may be other division methods.

[0261] It should be noted that all relevant content of each step involved in the above method embodiments can be referenced from the functional description of the corresponding functional module, and will not be repeated here.

[0262] The electronic device provided in this embodiment is used to execute the above-described image processing method, and therefore can achieve the same effect as the above-described implementation method.

[0263] When using integrated units, the electronic device may further include a processing module, a storage module, and a communication module. The processing module is used to control and manage the operation of the electronic device. The storage module supports the execution of stored program code and data. The communication module supports communication between the electronic device and other devices.

[0264] The processing module can be a processor or a controller. It can implement or execute various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. The processor can also be a combination of functions that implement computing capabilities, such as a combination of one or more microprocessors, a combination of digital signal processing (DSP) and a microprocessor, etc. The storage module can be a memory. The communication module can specifically be a radio frequency circuit, a Bluetooth chip, a Wi-Fi chip, or other devices that interact with other electronic devices.

[0265] In one embodiment, when the processing module is a processor and the storage module is a memory, the electronic device involved in this embodiment can be a device having... Figure 2 The device with the structure shown.

[0266] For example, such as Figure 12 As shown in the figure, this application embodiment also provides an image processing apparatus, which includes:

[0267] The acquisition module 1201 is used to acquire the data of the image to be processed, which includes the chromaticity data of each pixel in the image to be processed;

[0268] The image generation module 1202 is used to generate a binarized mask image corresponding to the image to be processed based on chromaticity data, a preset chromaticity range, and a preset purple edge size. The binarized mask image includes a protected area, which refers to the area in the binarized mask image whose size is larger than the preset purple edge size, corresponding to at least one possible purple edge area in the image to be processed. The possible purple edge area refers to the area where the chromaticity data of all pixels in the area belongs to the preset chromaticity range.

[0269] The recognition module 1203 is used to determine the purple-edged pixels in the image to be processed based on the binarized mask image; the purple-edged pixels refer to pixels whose chromaticity data belongs to a preset chromaticity range and is located outside the area corresponding to the protected area.

[0270] In one embodiment, the image generation module 1202 is specifically used to generate a binarized image corresponding to the image to be processed based on chromaticity data and a preset chromaticity range; the identifier value of the pixel points whose chromaticity data belongs to the preset chromaticity range in the binarized image is a first value; based on the preset purple edge size, erosion processing and dilation processing are performed on the binarized image to generate a binarized mask image.

[0271] In one embodiment, the image generation module 1202 is specifically used to perform erosion processing on each first region in the binarized image using a structuring element with a preset purple edge size to obtain a corresponding second region, thereby generating a binarized eroded image; wherein, the first region refers to the region where the identifier of all pixels in the region is a first value; and to perform dilation processing on each second region in the binarized eroded image using a structuring element with a preset purple edge size to obtain a corresponding protected area, thereby generating a binarized mask image.

[0272] In one embodiment, the data of the image to be processed further includes the brightness data of each pixel in the image to be processed. The device further includes a weight determination module 1204 and a data adjustment module 1205. The weight determination module 1204 is used to determine the target adjustment weight based on the brightness data and chromaticity data of the purple-edged pixels. The data adjustment module 1205 is used to adjust the chromaticity data of the purple-edged pixels based on the target adjustment weight.

[0273] In one embodiment, the weight determination module 1204 is specifically used to determine a first target brightness weight based on the brightness data of the purple-edged pixel and pixels within a first preset range surrounding the purple-edged pixel; the first target brightness weight is used to characterize the influence of the brightness difference between the purple-edged pixel and pixels within the first preset range on chromaticity data adjustment; determine a second target brightness weight based on the brightness data of the purple-edged pixel and pixels within a second preset range surrounding the purple-edged pixel; the second target brightness weight is used to characterize the influence of pixels within the second preset range whose brightness data exceeds a preset high-brightness threshold on chromaticity data adjustment; determine a target chromaticity weight based on the chromaticity data of the purple-edged pixel; the target chromaticity weight is used to characterize the influence of the chromaticity data of the purple-edged pixel on chromaticity data adjustment; and determine a target adjustment weight based on the first target brightness weight, the second target brightness weight, and the target chromaticity weight.

[0274] In one embodiment, the weight determination module 1204 is specifically used to determine the brightness gradient of the purple-edged pixel based on the brightness data of the purple-edged pixel and the pixels within a first preset range; and to determine the first target brightness weight based on the brightness gradient of the purple-edged pixel.

[0275] In one embodiment, the weight determination module 1204 is specifically used to determine the first target brightness weight corresponding to the brightness gradient of the purple-edged pixel based on the mapping relationship between the brightness gradient and the first brightness weight.

[0276] In one embodiment, the weight determination module 1204 is specifically used to divide the purple-edged pixels and the pixels within the second preset range into multiple brightness blocks; determine the brightness value of each brightness block based on the brightness data of the purple-edged pixels and the pixels within the second preset range; and determine the second target brightness weight based on the brightness value of each brightness block.

[0277] In one embodiment, the weight determination module 1204 is specifically used to determine the brightness distribution parameters of the purple-edged pixels based on the brightness values ​​of each brightness block. The brightness distribution parameters include at least one of the following: the number of high-brightness blocks, the distance between the brightness block containing the purple-edged pixel and the high-brightness block, and the brightness difference between brightness blocks. A high-brightness block refers to a brightness block among multiple brightness blocks whose brightness value is greater than a preset high-brightness threshold. The brightness difference between brightness blocks refers to the difference between the maximum and minimum brightness values ​​among all brightness blocks. The second target brightness weight is determined based on the brightness distribution parameters of the purple-edged pixels.

[0278] In one embodiment, the weight determination module 1204 is specifically used to determine the second target brightness weight corresponding to the brightness distribution parameter of the purple edge pixel based on the mapping relationship between the brightness distribution parameter and the second brightness weight.

[0279] In one embodiment, the weight determination module 1204 is specifically used to determine the target chromaticity weight corresponding to the chromaticity data of the purple-edged pixel based on the mapping relationship between chromaticity data and chromaticity weight.

[0280] In one embodiment, the weight determination module 1204 is specifically used to determine the target adjustment weight based on the product of the first target brightness weight, the second target brightness weight, and the target chromaticity weight.

[0281] In one embodiment, the data adjustment module 1205 is further configured to adjust the brightness data of the purple-edged pixels according to the target adjustment weight.

[0282] In one embodiment, the data adjustment module 1205 is specifically used to determine a brightness adjustment value based on the difference between the brightness data of the purple-edged pixel and the average brightness data and the target adjustment weight; the average brightness data is the average brightness data of pixels within a third preset range surrounding the purple-edged pixel; the target brightness data is determined based on the brightness adjustment value and the brightness data of the purple-edged pixel, wherein the target brightness is greater than or equal to the maximum brightness value and less than or equal to the minimum brightness value; the maximum brightness value is the maximum value among the brightness values ​​of the multiple brightness blocks divided into multiple brightness blocks of the purple-edged pixel and the pixels within the third preset range, and the minimum brightness value is the minimum value among the brightness values ​​of the multiple brightness blocks; the brightness data of the purple-edged pixel is adjusted to the target brightness data.

[0283] In one embodiment, the data adjustment module 1205 is specifically used to determine a reference brightness value based on the brightness adjustment value and the brightness data of the purple-edge pixels; if the reference brightness value is greater than or equal to the minimum brightness value and less than or equal to the maximum brightness value, then the reference brightness value is determined as the target brightness data; if the reference brightness value is greater than the maximum brightness value, then the maximum brightness value is determined as the target brightness data; if the reference brightness value is less than the minimum brightness value, then the minimum brightness value is determined as the target brightness data.

[0284] In one embodiment, the data of the image to be processed is YUV data.

[0285] In one embodiment, the proportion of the Y component of a pixel in the YUV data is higher than the proportion of the UV component. The data acquisition module 1201 is specifically used to acquire the YUV data of each pixel in the image to be processed; acquire chromaticity data from the YUV data; and downsample the Y component of each pixel in the image to be processed according to the proportion of the Y, U and V components in the YUV data and the target sampling ratio to obtain luminance data.

[0286] In one embodiment, the data adjustment module 1205 is specifically used to determine a reference adjustment value based on the product of the difference and the target adjustment weight; determine the adjustment value corresponding to the Y component of the purple-edged pixel using bilinear interpolation based on the reference adjustment value and the target sampling ratio to obtain the brightness adjustment value; and determine the target brightness data based on the brightness adjustment value and the Y component of the purple-edged pixel.

[0287] This application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, causes the processor to perform the image processing method of any of the above embodiments.

[0288] This application also provides a computer program product that, when run on a computer, causes the computer to perform the aforementioned steps to implement the image processing method described above.

[0289] In addition, embodiments of this application also provide an apparatus, which may specifically be a chip, component, or module. The apparatus may include a connected processor and a memory; wherein the memory is used to store computer execution instructions, and when the apparatus is running, the processor may execute the computer execution instructions stored in the memory to cause the chip to execute the image processing methods in the above-described method embodiments.

[0290] In this embodiment, the electronic device, computer-readable storage medium, computer program product or chip are all used to execute the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can be referred to the beneficial effects of the corresponding methods provided above, and will not be repeated here.

[0291] Through the above description of the embodiments, those skilled in the art will understand that, for the sake of convenience and brevity, only the division of the above functional modules is used as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.

[0292] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another apparatus, or some features may be ignored or not executed. Furthermore, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.

[0293] The units described as separate components may or may not be physically separate. A component shown as a unit can be one or more physical units; that is, it can be located in one place or distributed in multiple different locations. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0294] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0295] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solutions of the embodiments of this application, in essence, or the parts that contribute to the prior art, or all or part of the technical solutions, can be embodied in the form of a software product. This software product is stored in a storage medium and includes several instructions to cause a device (which may be a microcontroller, chip, etc.) or processor to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0296] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. An image processing method, said method being executed by an electronic device, characterized in that, The method includes: Acquire data of the image to be processed, wherein the data of the image to be processed includes the chromaticity data of each pixel in the image to be processed; Based on the chromaticity data, the preset chromaticity range, and the preset purple edge size, a binarized mask image corresponding to the image to be processed is generated. The binarized mask image includes a protected area, which is a region in the binarized mask image that corresponds to at least one possible purple edge region in the image to be processed, and whose size is larger than the preset purple edge size. The possible purple edge region is a region where the chromaticity data of all pixels within the region belongs to the preset chromaticity range. The identifier value of the pixels within the protected area is a first value, and the identifier value of the pixels outside the protected area is a second value. The purple-edged pixels in the image to be processed are determined based on the binarized mask image; the purple-edged pixels refer to pixels whose chromaticity data belongs to the preset chromaticity range and are located outside the area corresponding to the protected area.

2. The method according to claim 1, characterized in that, The step of generating a binarized mask image corresponding to the image to be processed based on the chromaticity data, a preset chromaticity range, and a preset purple fringing size includes: Based on the chromaticity data and the preset chromaticity range, a binarized image corresponding to the image to be processed is generated; the identifier value of the pixels in the binarized image whose chromaticity data belongs to the preset chromaticity range is the first value; Based on the preset purple edge size, the binarized image is subjected to erosion and dilation processing to generate the binarized mask image.

3. The method according to claim 2, characterized in that, The step of generating the binary mask image by performing erosion and dilation processing on the binary image based on the preset purple edge size includes: Using the structuring element with the preset purple edge size, each first region in the binarized image is eroded to obtain the corresponding second region, thus generating a binarized eroded image; wherein, the first region refers to the region where the identifier of all pixels in the region is the first value. The binary erosion image is generated by performing dilation processing on each of the second regions in the binary erosion image using the structuring element with the preset purple edge size.

4. The method according to any one of claims 1 to 3, characterized in that, The data of the image to be processed also includes the brightness data of each pixel in the image to be processed, and the method further includes: The target adjustment weight is determined based on the brightness and chromaticity data of the purple-edged pixels. The chromaticity data of the purple-edged pixels are adjusted according to the target adjustment weight.

5. The method according to claim 4, characterized in that, The step of determining the target adjustment weight based on the luminance and chromaticity data of the purple-edged pixels includes: A first target brightness weight is determined based on the brightness data of the purple-edged pixel and the pixels within a first preset range surrounding the purple-edged pixel; the first target brightness weight is used to characterize the degree of influence of the brightness difference between the purple-edged pixel and the pixels within the first preset range on the chromaticity data adjustment. A second target brightness weight is determined based on the brightness data of the purple-edged pixel and the pixels within a second preset range surrounding the purple-edged pixel; the second target brightness weight is used to characterize the degree of influence of pixels whose brightness data exceeds a preset high-brightness threshold on the chroma data adjustment within the second preset range; The target chromaticity weight is determined based on the chromaticity data of the purple-edged pixels; the target chromaticity weight is used to characterize the degree of influence of the chromaticity data of the purple-edged pixels on the chromaticity data adjustment. The target adjustment weight is determined based on the first target brightness weight, the second target brightness weight, and the target chromaticity weight.

6. The method according to claim 5, characterized in that, The step of determining the first target brightness weight based on the brightness data of the purple-edged pixel and the pixels within a first preset range surrounding the purple-edged pixel includes: The brightness gradient of the purple-edged pixel is determined based on the brightness data of the purple-edged pixel and the pixels within the first preset range; The first target brightness weight is determined based on the brightness gradient of the purple-edged pixels.

7. The method according to claim 6, characterized in that, Determining the first target brightness weight based on the brightness gradient of the purple-edged pixels includes: Based on the mapping relationship between the brightness gradient and the first brightness weight, the first target brightness weight corresponding to the brightness gradient of the purple-edged pixel is determined.

8. The method according to claim 5, characterized in that, The step of determining the second target brightness weight based on the brightness data of the purple-edged pixel and the pixels within a second preset range surrounding the purple-edged pixel includes: The purple-edged pixels and the pixels within the second preset range are divided into multiple brightness blocks; The brightness value of each brightness block is determined based on the brightness data of the purple-edged pixels and the pixels within the second preset range; The second target brightness weight is determined based on the brightness value of each brightness block.

9. The method according to claim 8, characterized in that, Determining the second target brightness weight based on the brightness values ​​of each of the brightness blocks includes: The brightness distribution parameters of the purple-edged pixel are determined based on the brightness values ​​of each brightness block. The brightness distribution parameters include at least one of the following: the number of high-brightness blocks, the distance between the brightness block containing the purple-edged pixel and the high-brightness block, and the brightness difference between the brightness blocks. The high-brightness block refers to the brightness block among the plurality of brightness blocks whose brightness value is greater than the preset high-brightness threshold. The brightness difference between the brightness blocks refers to the difference between the maximum brightness value and the minimum brightness value among all the brightness values ​​of the brightness blocks. The second target brightness weight is determined based on the brightness distribution parameters of the purple-edged pixels.

10. The method according to claim 9, characterized in that, Determining the second target brightness weight based on the brightness distribution parameters of the purple-edged pixels includes: Based on the mapping relationship between the brightness distribution parameters and the second brightness weight, the second target brightness weight corresponding to the brightness distribution parameters of the purple-edged pixels is determined.

11. The method according to any one of claims 5 to 10, characterized in that, The step of determining the target chromaticity weight based on the chromaticity data of the purple-edged pixels includes: Based on the mapping relationship between chromaticity data and chromaticity weights, the target chromaticity weight corresponding to the chromaticity data of the purple-edged pixel is determined.

12. The method according to any one of claims 5 to 10, characterized in that, Determining the target adjustment weight based on the first target luminance weight, the second target luminance weight, and the target chromaticity weight includes: The target adjustment weight is determined by multiplying the first target luminance weight, the second target luminance weight, and the target chromaticity weight.

13. The method according to claim 4, characterized in that, The method further includes: The brightness data of the purple-edged pixels is adjusted according to the target adjustment weight.

14. The method according to claim 13, characterized in that, The step of adjusting the brightness data of the purple-edged pixels according to the target adjustment weight includes: The brightness adjustment value is determined based on the difference between the brightness data of the purple-edged pixel and the average brightness data, and the target adjustment weight; the average brightness data is the average brightness data of pixels within a third preset range surrounding the purple-edged pixel. The target brightness data is determined based on the brightness adjustment value and the brightness data of the purple-edged pixels. The target brightness is greater than or equal to the maximum brightness value and less than or equal to the minimum brightness value. The maximum brightness value is the maximum value among the brightness values ​​of the multiple brightness blocks divided into the purple-edged pixels and the pixels within the third preset range. The minimum brightness value is the minimum value among the brightness values ​​of the multiple brightness blocks. Adjust the brightness data of the purple-edged pixels to the target brightness data.

15. The method according to claim 14, characterized in that, The step of determining the target brightness data based on the brightness adjustment value and the brightness data of the purple-edged pixels includes: A reference brightness value is determined based on the brightness adjustment value and the brightness data of the purple-edge pixels; If the reference brightness value is greater than or equal to the minimum brightness value and less than or equal to the maximum brightness value, then the reference brightness value is determined as the target brightness data; If the reference brightness value is greater than the maximum brightness value, then the maximum brightness value is determined as the target brightness data; If the reference brightness value is less than the minimum brightness value, then the minimum brightness value is determined as the target brightness data.

16. The method according to claim 14 or 15, characterized in that, The data of the image to be processed is YUV data.

17. The method according to claim 16, characterized in that, In the YUV data, the proportion of the Y component of a pixel is higher than the proportion of the UV component. The process of acquiring the data for the image to be processed includes: Obtain the YUV data of each pixel in the image to be processed; Obtain the chromaticity data from the YUV data; Based on the proportions of the Y, U, and V components in the YUV data, the Y component of each pixel in the image to be processed is downsampled according to the target sampling ratio to obtain the brightness data.

18. The method according to claim 17, characterized in that, The step of determining the brightness adjustment value based on the difference between the brightness data of the purple-edged pixels and the average brightness data, and the target adjustment weight, includes: A reference adjustment value is determined by multiplying the difference by the target adjustment weight; Based on the reference adjustment value and the target sampling ratio, the adjustment value corresponding to the Y component of the purple-edged pixel is determined by bilinear interpolation to obtain the brightness adjustment value; The step of determining the target brightness data based on the brightness adjustment value and the brightness data of the purple-edged pixels includes: The target brightness data is determined based on the brightness adjustment value and the Y component of the purple-edged pixel.

19. An electronic device, characterized in that, include: Processor, memory, and interface; The processor, the memory, and the interface cooperate with each other to enable the electronic device to perform the method as described in any one of claims 1 to 18.

20. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, causes the processor to perform the method of any one of claims 1 to 18.

Citation Information

Patent Citations

  • Image processing method, device and apparatus

    CN109191406A

  • Image purple edge elimination device and method

    CN111080559A

  • Automatic removal of purple fringing from images

    US20070153341A1