Method and device for detecting purple boundary area of image, storage medium and computer equipment
By using sliding windows and multiple discriminant conditions in the YUV image, multiple purple edge candidate areas are identified and generated, and the most accurate purple edge area is finally obtained through intersection, which solves the problem of low accuracy in detecting purple edge areas in the prior art, and achieves a more accurate and efficient purple edge elimination effect.
Patent Information
- Application Number
- CN202411986675.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-31
- Publication Date
- 2025-04-29
- Estimated Expiration
- 2044-12-31
AI Technical Summary
In the prior art, the accuracy of detecting the purple edge area of the image is not high and complex, and it is easy to cause misidentification due to the subjectivity of the threshold setting and the diversity of the image content.
By using sliding windows and a variety of discriminant conditions in the YUV image, including Y channel value difference, gradient analysis and tone saturation judgment, multiple purple edge candidate areas are identified and generated, and finally the most accurate purple edge area is obtained through intersection.
It improves the accuracy and efficiency of purple edge detection, reduces the possibility of misjudgment, avoids the subjectivity of threshold setting, and achieves more accurate and efficient purple edge elimination.
Smart Images

Figure CN119904478A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing, and in particular to a method, device, storage medium and computer equipment for detecting purple-edge regions in an image. Background Art
[0002] Image quality optimization is a crucial link, among which the elimination of purple fringing is one of the key technologies to improve the visual effect of images. Purple fringing usually occurs at high-contrast edges, especially when using a digital camera to shoot scenes where high-brightness and low-brightness objects are adjacent. Due to the inherent characteristics of the lens dispersion or the sensor's photosensitive elements, unnatural purple edges appear at the edges of the image. This phenomenon not only affects the clarity of the image, but also reduces the overall visual beauty.
[0003] In order to effectively eliminate purple fringing in images, existing technical means mostly focus on processing in the RGB (red, green, blue) color space of the image. As the basis of image processing, the RGB domain provides a way to directly manipulate image color information. A common method for eliminating purple fringing first involves the detection of purple fringing areas. This step is usually achieved by setting specific thresholds for each RGB channel, or by calculating the brightness value based on the RGB channel, and defining potential purple fringing areas based on the threshold of the brightness value, which are recorded as purple fringing candidate areas 1. This method is simple and easy to implement, but the accuracy of the detection results may be limited due to the subjectivity of threshold setting and the diversity of image content.
[0004] Furthermore, in order to enhance the accuracy of purple fringing detection, color judgment is also required. This usually depends on the difference between the R channel and the G channel, or the calculation results of the B channel and the G channel. By analyzing these differences or calculation results, more likely purple fringing candidate regions can be further screened out. The choice of color judgment formula directly affects the accuracy of purple fringing detection, but it also faces the risk of misjudgment, that is, mistakenly identifying non-purple fringing regions as purple fringing.
[0005] After determining the potential purple fringing area, it is necessary to use edge detection operators or statistical pixel variance methods to accurately identify edge information in the image, so as to determine the final purple fringing candidate area 3. The application of edge detection technology can significantly improve the accuracy of purple fringing recognition, but it also increases the complexity of calculation.
[0006] Based on the above steps, the purple fringing region in the image can be accurately locked by taking the intersection of multiple purple fringing candidate regions. Subsequently, an appropriate correction algorithm is used to correct the detected purple fringing to restore the natural transition and color balance of the image.
[0007] However, although the existing purple fringing removal technology has achieved some results, the detection accuracy is still highly dependent on the selection of RGB color judgment formula and the setting of thresholds, which may lead to misidentification in practical applications, that is, misidentifying non-purple fringing areas as purple fringing, thus affecting the efficiency and effect of image processing. Therefore, developing a more accurate and efficient purple fringing removal method is still an urgent problem to be solved in the current image signal processing field. Summary of the invention
[0008] The embodiments of the present application provide a method, device, storage medium and computer equipment for detecting purple fringing areas of images, which can solve the problem of low accuracy and complexity of detecting purple fringing of images in the prior art. The technical solution is as follows:
[0009] In a first aspect, an embodiment of the present application provides a method for detecting a purple-fringed area of an image, the method comprising:
[0010] A sliding window is used to slide in the YUV image to be detected to traverse each pixel point, and if the central pixel point of the sliding window meets the first discrimination condition: the Y channel value is less than the threshold value Yt1 and there is at least one other pixel point in the sliding window whose Y channel value is greater than the threshold value Yt2, the central pixel point is identified as a purple fringing candidate point; and a first purple fringing candidate area is generated according to all the purple fringing pixels in the YUV image that meet the above Y channel discrimination condition;
[0011] For each pixel in the YUV image, if the row adjacent pixel (i-1, j) or the column adjacent pixel (i, j-1) of the current pixel (i, j) is a purple fringing candidate point that satisfies the Y channel discrimination condition, the current pixel (i, j) is identified as a purple fringing candidate point, and the current pixel is added to the first purple fringing candidate area;
[0012] Calculate the Y channel horizontal gradient and the Y channel vertical gradient of the current pixel in the YUV image, determine the edge direction of the current pixel according to the Y channel horizontal gradient, the Y channel vertical gradient and the gradient threshold Gt1, calculate the U channel gradient and the V channel gradient of the current pixel in the edge direction, if the maximum value of the U channel gradient and the V channel gradient is greater than the gradient threshold Gt2, identify the current pixel as a purple fringing candidate point; and generate a second purple fringing candidate area according to all purple fringing pixels in the YUV image that meet the above gradient discrimination conditions;
[0013] Calculating the hue value and color saturation of the current pixel in the YUV image, and if the hue value is within a preset purple-fringe hue range and the color saturation is greater than a saturation threshold, identifying the current pixel as a purple-fringe candidate point; and generating a third purple-fringe candidate region according to all purple-fringe candidate points in the YUV image that meet the above hue and saturation discrimination conditions;
[0014] The first purple fringing candidate region, the second purple fringing candidate region and the third purple fringing candidate region are intersected to obtain a final target purple fringing region.
[0015] In a second aspect, an embodiment of the present application provides a device for detecting a purple-fringed area of an image, the device comprising:
[0016] A brightness discrimination module is configured to use a sliding window to slide in the YUV image to be detected to traverse each pixel point, and if the central pixel point of the sliding window satisfies a first discrimination condition: the Y channel value is less than a threshold value Yt1 and there is at least one other pixel point in the sliding window whose Y channel value is greater than a threshold value Yt2, the central pixel point is identified as a purple fringing candidate point; and a first purple fringing candidate area is generated according to all the purple fringing pixels in the YUV image that meet the above Y channel discrimination condition;
[0017] an adjacent discrimination module, for each pixel in the YUV image, if the row adjacent pixel (i-1, j) or the column adjacent pixel (i, j-1) of the current pixel (i, j) is a purple fringing candidate point that satisfies the Y channel discrimination condition, identifying the current pixel (i, j) as a purple fringing candidate point, and adding the current pixel to the first purple fringing candidate area;
[0018] a gradient discrimination module, for calculating a Y channel horizontal gradient and a Y channel vertical gradient of a current pixel in the YUV image, determining an edge direction of the current pixel according to the Y channel horizontal gradient, the Y channel vertical gradient and a gradient threshold Gt1, calculating a U channel gradient and a V channel gradient of the current pixel in the edge direction, and identifying the current pixel as a purple fringing candidate point if the maximum value of the U channel gradient and the V channel gradient is greater than the gradient threshold Gt2; and generating a second purple fringing candidate region according to all purple fringing pixels in the YUV image that meet the above gradient discrimination conditions;
[0019] A color discrimination module is configured to calculate the hue value and color saturation of a current pixel in the YUV image, and if the hue value is within a preset purple-fringe hue range and the color saturation is greater than a saturation threshold, identify the current pixel as a purple-fringe candidate point; and generate a third purple-fringe candidate region according to all purple-fringe candidate points in the YUV image that meet the above hue and saturation discrimination conditions;
[0020] The merging module is used to obtain a final target purple fringing region by taking the intersection of the first purple fringing candidate region, the second purple fringing candidate region and the third purple fringing candidate region.
[0021] In a third aspect, an embodiment of the present application provides a computer storage medium, wherein the computer storage medium stores a plurality of instructions, wherein the instructions are suitable for being loaded by a processor and executing the above-mentioned method steps.
[0022] In a fourth aspect, an embodiment of the present application provides a computer device, which may include: a processor and a memory; wherein the memory stores a computer program, and the computer program is suitable for being loaded by the processor and executing the above-mentioned method steps.
[0023] The beneficial effects brought about by the technical solutions provided by some embodiments of the present application include at least:
[0024] By judging the difference of Y channel values, the method can preliminarily screen out pixels located at high-contrast edges, which are more likely to belong to the purple-fringed area. By using the relationship between adjacent pixels, the coverage of the candidate purple-fringed area is further expanded, and the sensitivity of detection is improved. By calculating the horizontal and vertical gradients of the Y channel and combining the gradient analysis of the U and V channels, the method can more accurately identify pixels with purple-fringed features, effectively reducing the possibility of misjudgment. Combined with the judgment of hue and saturation, the accuracy of purple-fringed detection is further improved, because the purple-fringed phenomenon is usually accompanied by a specific hue and a high saturation. Compared with the traditional purple-fringed detection method in the RGB color space, the method of the present application is processed in the YUV color space, and the purple-fringed area is identified by objective criteria such as gradient analysis and hue saturation judgment, which reduces the subjectivity and dependence of threshold setting. Each step of the present application is based on basic operations and algorithms of image processing, such as sliding windows, gradient calculations, etc., which can be efficiently executed on modern computers. By taking the intersection of multiple purple-fringed candidate areas to obtain the final target purple-fringed area, the accuracy of detection is guaranteed, unnecessary repeated calculations are avoided, and the overall detection efficiency is improved. By combining multiple discrimination conditions, this method can more accurately identify the purple-fringe area in the image, providing a reliable basis for subsequent purple-fringe correction. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0026] Figure 1It is a flowchart of a method for detecting purple-edge areas of an image provided by an embodiment of the present application;
[0027] Figure 2 is a schematic diagram of a sliding window provided in an embodiment of the present application;
[0028] Figure 3 It is a structural schematic diagram of a device for detecting purple-edge areas of an image provided by the present application;
[0029] Figure 4 It is a structural schematic diagram of a computer device provided by this application. DETAILED DESCRIPTION
[0030] In order to make the objectives, technical solutions and advantages of the present application more clear, the embodiments of the present application will be further described in detail below with reference to the accompanying drawings.
[0031] See also Figure 2 , which is a flow chart of a method for detecting purple-edge regions in an image according to an embodiment of the present application. Figure 2 As shown, the method of the embodiment of the present application may include the following steps:
[0032] S101, use a sliding window to slide in the YUV image to be detected to traverse each pixel point, if the central pixel point of the sliding window meets the first discrimination condition: the Y channel value is less than the threshold Yt1 and there is at least one other pixel point in the sliding window whose Y channel value is greater than the threshold Yt2, identify the central pixel point as a purple fringing candidate point; and generate a first purple fringing candidate area according to all purple fringing pixels in the YUV image that meet the above Y channel discrimination condition.
[0033] Among them, set the size of the sliding window (such as 3×3, 5×5, etc.), for example: Figure 2 The sliding window shown has a sliding serial port size of 3×3. The choice of window size depends on the image resolution and the desired accuracy. Initialize the center position of the window, starting from the upper left corner of the image. Use two layers of loops (usually nested loops) to traverse each pixel of the image. In each loop, the center pixel of the window is updated. For the center pixel of the current window, read its Y channel value and compare it with the preset threshold Yt1. Traverse all pixels in the window to check whether there is at least one pixel with a Y channel value greater than the threshold Yt2. If the Y channel value of the center pixel is less than Yt1 and there is at least one pixel with a Y channel value greater than Yt2 in the window, the center pixel is marked as a purple fringing candidate point. All purple fringing candidate points that meet the above Y channel discrimination conditions are stored in a set or list to form the first purple fringing candidate area.
[0034] S102. For each pixel in the YUV image, if the row adjacent pixel (i-1, j) or the column adjacent pixel (i, j-1) of the current pixel (i, j) is a purple fringing candidate point that meets the Y channel discrimination condition, the current pixel (i, j) is identified as a purple fringing candidate point, and the current pixel is added to the first purple fringing candidate area.
[0035] Wherein, each pixel point (i, j) of the image is checked. The row adjacent pixel points (i-1, j) and the column adjacent pixel points (i, j-1) of the current pixel point are checked. If any of these adjacent pixel points is marked as a purple fringing candidate point (satisfying the Y channel discrimination condition in S101), the current pixel point (i, j) is also marked as a purple fringing candidate point. The newly marked purple fringing candidate point is added to the first purple fringing candidate area.
[0036] S103, calculating the Y channel horizontal gradient and the Y channel vertical gradient of the current pixel in the YUV image, and determining the edge direction of the current pixel according to the Y channel horizontal gradient, the Y channel vertical gradient and the gradient threshold Gt1, calculating the U channel gradient and the V channel gradient of the current pixel in the edge direction, if the maximum value of the U channel gradient and the V channel gradient is greater than the gradient threshold Gt2, identifying the current pixel as a purple fringing candidate point; and generating a second purple fringing candidate area according to all purple fringing pixels in the YUV image that meet the above gradient discrimination conditions.
[0037] Among them, for each pixel point (i, j), the horizontal gradient (Gx) and vertical gradient (Gy) of its Y channel are calculated respectively using the Sobel operator or other gradient calculation methods. The magnitudes of the horizontal gradient (Gx) and vertical gradient (Gy) of the Y channel are compared. Horizontal edge direction: If the horizontal gradient (Gx) of the Y channel is greater than the vertical gradient (Gy) of the Y channel, and the horizontal gradient (Gx) of the Y channel is greater than the preset gradient threshold Gt1, the edge direction of the current pixel point is determined to be horizontal. Vertical edge direction: If the vertical gradient (Gy) of the Y channel is greater than the horizontal gradient (Gx) of the Y channel, and the vertical gradient (Gy) of the Y channel is greater than the preset gradient threshold Gt1, the edge direction of the current pixel point is determined to be vertical. If both gradients are less than or equal to Gt1, or their difference is not enough to clearly determine the edge direction, it can be considered that the pixel point does not meet the edge direction determination condition of the current step, but may still be identified as a purple edge candidate point according to other conditions in subsequent steps.
[0038] According to the determined edge direction (horizontal or vertical), the corresponding direction is selected to calculate the gradients of the U channel and the V channel. For the horizontal edge direction, the U channel gradient (Gu_h) and the V channel gradient (Gv_h) along the horizontal direction (for example, using the difference between adjacent row pixels) can be calculated. For the vertical edge direction, the U channel gradient (Gu_v) and the V channel gradient (Gv_v) along the vertical direction (for example, using the difference between adjacent column pixels) can be calculated. Note: In actual implementation, the above steps may need to be adjusted according to the specific gradient calculation method. For example, if the Sobel operator is used, its horizontal and vertical convolution kernels can be directly applied to calculate the gradients of the U and V channels.
[0039] After determining the edge direction, compare the gradient values of the U channel and the V channel in this direction. If the maximum value of the U channel gradient (Gu) and the V channel gradient (Gv) (the corresponding Gu_h / Gu_v and Gv_h / Gv_v are selected according to the edge direction) is greater than the preset gradient threshold Gt2, the current pixel point is marked as a purple edge candidate point. All purple edge candidate points that meet the above gradient discrimination conditions are stored in a set or list to form a second purple edge candidate area.
[0040] S104, calculating the hue value and color saturation of the current pixel in the YUV image, if the hue value is within a preset purple-fringe hue range and the color saturation is greater than a saturation threshold, identifying the current pixel as a purple-fringe candidate point; and generating a third purple-fringe candidate area based on all purple-fringe candidate points in the YUV image that meet the above hue and saturation discrimination conditions.
[0041] For each pixel (i, j), the YUV to HSV conversion formula is used to calculate its hue value (Hue) and color saturation (Saturation). Check whether the hue value is within the preset purple-fringe hue range (usually a hue range related to purple). Check whether the color saturation is greater than the preset saturation threshold. If the hue value and color saturation of the current pixel meet the above conditions, it is marked as a purple-fringe candidate point. All purple-fringe candidate points that meet the hue and saturation judgment conditions are stored in a set or list to form a third purple-fringe candidate area.
[0042] In some embodiments of the present application, the formula for calculating the hue value is: The formula for calculating color saturation is: Sat(i,j)=abs(V(i,j)-128)+abs(U(i,j)-128).
[0043] S105 , taking the intersection of the first purple fringing candidate region, the second purple fringing candidate region, and the third purple fringing candidate region to obtain a final target purple fringing region.
[0044] The intersection operation is performed on the first purple-fringed candidate region, the second purple-fringed candidate region and the third purple-fringed candidate region to obtain a final target purple-fringed region. The final target purple-fringed region is output, usually in the form of an image or an image mask. Through the above steps, the computer device can accurately identify the purple-fringed region in the YUV image.
[0045] Furthermore, after the target purple-fringed region is detected, purple-fringed correction is performed. All pixels marked as target purple-fringed regions are traversed. This can be achieved by traversing the previously generated list of purple-fringed candidate regions or by directly applying a mask to the image.
[0046] For each pixel traversed, check whether it belongs to the target purple-fringed area. This is usually done by comparing the coordinates of the pixel with the coordinate range of the purple-fringed area. If the pixel belongs to the target purple-fringed area, set the values of its U and V channels to 128. This can be done by directly accessing the YUV data of the image. In the YUV color space, the U and V channels represent chroma and saturation information respectively. Setting them to 128 can neutralize the purple hue because 128 is the midpoint value of the chroma channel. While replacing the U and V channel values, keep the value of the Y channel (brightness) unchanged. This ensures that the corrected image is consistent in brightness. After completing the replacement of the U and V channel values of all purple-fringed pixels, update the image data. This usually means writing the modified YUV data back to the image file or display device. Finally, verify whether the corrected image effectively reduces the purple fringing phenomenon. This can be done by visual inspection or using image quality assessment tools.
[0047] Furthermore, in some embodiments of the present application, for the task of generating the first purple fringing candidate region, the second purple fringing candidate region, and the third purple fringing candidate region, the computer device may implement parallel processing in the following manner:
[0048] 1. Thread parallelism.
[0049] Create threads: Create a separate thread for each candidate region generation task. This can be achieved by using a multithreading library in a programming language (such as std::thread in C++, threading module in Python).
[0050] Task allocation: Assign image data (which may be the entire image or a portion of the image) to each thread and specify the specific candidate region generation task to be performed.
[0051] Synchronization and communication: Ensure synchronization and data consistency between threads, especially when access to shared resources (such as image data or candidate point lists) is required. Access to shared resources can be managed using mutexes or condition variables.
[0052] Result merging: After all threads complete their tasks, the candidate regions generated by each thread are merged into the final candidate region set.
[0053] 2. Task parallelism.
[0054] Use parallel frameworks: Use existing parallel computing frameworks (such as OpenMP, Cilk Plus, Intel TBB, etc.) to parallelize the generation of candidate regions. These frameworks provide high-level parallel programming abstractions, eliminating the need for developers to manually manage threads and synchronization.
[0055] Task division: The image is divided into multiple small blocks, each of which is assigned to a parallel task. Each task is responsible for processing its assigned small block and generating the corresponding candidate region.
[0056] Result collection: The framework is responsible for collecting the results of each task and merging them into the final output.
[0057] 3.GPU acceleration.
[0058] Use CUDA or OpenCL: For large-scale image processing tasks, you can consider using GPU acceleration. By writing CUDA (NVIDIA's parallel computing platform and programming model) or OpenCL (an open standard for heterogeneous platforms) code, the task of generating candidate regions can be offloaded to the GPU for execution.
[0059] Data layout and transfer: Ensure that image data is laid out in a way suitable for GPU processing and transfer data to the GPU efficiently.
[0060] Kernel design: Design one or more GPU kernels for each candidate region generation task, which will process image data in parallel.
[0061] Result return: The results generated on the GPU are returned to the CPU for necessary post-processing.
[0062] The embodiments of the present application specifically include the following beneficial effects:
[0063] By judging the difference of Y channel values, the method can preliminarily screen out pixels located at high-contrast edges, which are more likely to belong to the purple-fringed area. By using the relationship between adjacent pixels, the coverage of the candidate purple-fringed area is further expanded, and the sensitivity of detection is improved. By calculating the horizontal and vertical gradients of the Y channel and combining the gradient analysis of the U and V channels, the method can more accurately identify pixels with purple-fringed features, effectively reducing the possibility of misjudgment. Combined with the judgment of hue and saturation, the accuracy of purple-fringed detection is further improved, because the purple-fringed phenomenon is usually accompanied by a specific hue and a high saturation. Compared with the traditional purple-fringed detection method in the RGB color space, the method of the present application is processed in the YUV color space, and the purple-fringed area is identified by objective criteria such as gradient analysis and hue saturation judgment, which reduces the subjectivity and dependence of threshold setting. Each step of the present application is based on basic operations and algorithms of image processing, such as sliding windows, gradient calculations, etc., which can be efficiently executed on modern computers. By taking the intersection of multiple purple-fringed candidate areas to obtain the final target purple-fringed area, the accuracy of detection is guaranteed, unnecessary repeated calculations are avoided, and the overall detection efficiency is improved. By combining multiple discrimination conditions, this method can more accurately identify the purple-fringe area in the image, providing a reliable basis for subsequent purple-fringe correction.
[0064] The following is an embodiment of the device of the present application, which can be used to execute the embodiment of the method of the present application. For details not disclosed in the embodiment of the device of the present application, please refer to the embodiment of the method of the present application.
[0065] See also Figure 3 , which shows a schematic diagram of the structure of a device for detecting purple-fringed areas of an image provided by an exemplary embodiment of the present application, hereinafter referred to as device 3. The device 3 can be implemented as all or part of a computer device through software, hardware, or a combination of both. The device 3 includes: a brightness discrimination unit 301, an adjacent discrimination unit 302, a gradient discrimination unit 303, a color discrimination unit 304, and a merging unit 305.
[0066] The brightness discrimination module 301 is used to use a sliding window to slide in the YUV image to be detected to traverse each pixel point, and if the central pixel point of the sliding window meets the first discrimination condition: the Y channel value is less than the threshold value Yt1 and there is at least one other pixel point in the sliding window whose Y channel value is greater than the threshold value Yt2, the central pixel point is identified as a purple fringing candidate point; and a first purple fringing candidate area is generated according to all the purple fringing pixels in the YUV image that meet the above Y channel discrimination condition;
[0067] The neighboring discrimination module 302 is configured to, for each pixel in the YUV image, if the row neighboring pixel (i-1, j) or the column neighboring pixel (i, j-1) of the current pixel (i, j) is a purple fringing candidate point that satisfies the Y channel discrimination condition, identify the current pixel (i, j) as a purple fringing candidate point, and add the current pixel to the first purple fringing candidate area;
[0068] The gradient discrimination module 303 is used to calculate the Y channel horizontal gradient and the Y channel vertical gradient of the current pixel in the YUV image, determine the edge direction of the current pixel according to the Y channel horizontal gradient, the Y channel vertical gradient and the gradient threshold Gt1, calculate the U channel gradient and the V channel gradient of the current pixel in the edge direction, and if the maximum value of the U channel gradient and the V channel gradient is greater than the gradient threshold Gt2, identify the current pixel as a purple fringing candidate point; and generate a second purple fringing candidate area according to all purple fringing pixels in the YUV image that meet the above gradient discrimination conditions;
[0069] The color discrimination module 304 is configured to calculate the hue value and color saturation of the current pixel in the YUV image, and if the hue value is within a preset purple-fringe hue range and the color saturation is greater than a saturation threshold, identify the current pixel as a purple-fringe candidate point; and generate a third purple-fringe candidate region according to all the purple-fringe candidate points in the YUV image that meet the above hue and saturation discrimination conditions;
[0070] The merging module 305 is configured to obtain a final target purple fringing region by taking the intersection of the first purple fringing candidate region, the second purple fringing candidate region and the third purple fringing candidate region.
[0071] In one or more possible embodiments, the formula for calculating the hue value is:; the formula for calculating the color saturation is:.
[0072] In one or more possible embodiments, the Sobel operator or the Laplace algorithm is used to calculate the gradient.
[0073] In one or more possible embodiments, the size of the sliding window is 3×3.
[0074] In one or more possible embodiments, the first purple fringing candidate region, the second purple fringing candidate region, and the third purple fringing candidate region are generated in parallel.
[0075] In one or more possible embodiments, determining the edge direction of the current pixel according to the Y channel horizontal gradient, the Y channel vertical gradient and the gradient threshold Gt1 includes:
[0076] If the Y channel horizontal gradient is greater than the Y channel vertical gradient, and the Y channel horizontal gradient is greater than the gradient threshold Gt1, then the edge direction of the current pixel is horizontal; or
[0077] If the Y channel vertical gradient is greater than the Y channel horizontal gradient, and the Y channel vertical gradient is greater than the gradient threshold Gt1, the edge point of the current pixel is in the vertical direction.
[0078] In one or more possible embodiments, it further includes:
[0079] The correction unit is used to replace the U channel value and the V channel value of each purple-fringed pixel in the target purple-fringed area with 128.
[0080] It should be noted that when the device 4 provided in the above embodiment executes the method for detecting the purple-fringed area of an image, 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 is divided into different functional modules to complete all or part of the above functions. In addition, the device for detecting the purple-fringed area of an image provided in the above embodiment and the method embodiment for detecting the purple-fringed area of an image belong to the same concept, and the implementation process thereof is detailed in the method embodiment, which will not be repeated here.
[0081] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0082] The present application also provides a computer storage medium, which can store multiple instructions, and the instructions are suitable for being loaded and executed by a processor as described above. Figure 1 The method steps of the embodiment shown in the figure can be found in the specific implementation process. Figure 1 The specific description of the illustrated embodiment will not be repeated here.
[0083] The present application also provides a computer program product, which stores at least one instruction, and the at least one instruction is loaded and executed by the processor to implement the method for detecting the purple-fringed area of an image as described in the above embodiments.
[0084] See also Figure 4 , which is a schematic diagram of the structure of a computer device according to an embodiment of the present application. Figure 4 As shown, the computer device 400 may include: at least one processor 401 , at least one network interface 404 , a user interface 403 , a memory 405 , and at least one communication bus 402 .
[0085] The communication bus 402 is used to realize the connection and communication between these components.
[0086] The user interface 403 may include a display screen (Display) and a camera (Camera), and the optional user interface 403 may also include a standard wired interface and a wireless interface.
[0087] The network interface 404 may optionally include a standard wired interface or a wireless interface (such as a WI-FI interface).
[0088] Among them, the processor 401 may include one or more processing cores. The processor 401 uses various interfaces and lines to connect various parts within the entire computer device 400, and executes various functions and processes data of the computer device 400 by running or executing instructions, programs, code sets or instruction sets stored in the memory 405, and calling data stored in the memory 405. Optionally, the processor 401 can be implemented in at least one hardware form of digital signal processing (Digital Signal Processing, DSP), field programmable gate array (Field-Programmable Gate Array, FPGA), and programmable logic array (Programmable Logic Array, PLA). The processor 401 can integrate one or a combination of a central processing unit (Central Processing Unit, CPU), a graphics processing unit (Graphics Processing Unit, GPU) and a modem. Among them, the CPU mainly processes the operating system, user interface and application programs; the GPU is responsible for rendering and drawing the content to be displayed on the display screen; the modem is used to process wireless communications. It can be understood that the above-mentioned modem may not be integrated into the processor 401, and it can be implemented separately through a chip.
[0089] Among them, the memory 405 may include a random access memory (Random Access Memory, RAM) and may also include a read-only memory (Read-Only Memory). Optionally, the memory 405 includes a non-transitory computer-readable storage medium. The memory 405 can be used to store instructions, programs, codes, code sets or instruction sets. The memory 405 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as a touch function, a sound playback function, an image playback function, etc.), instructions for implementing the above-mentioned method embodiments, etc.; the data storage area may store data involved in the above-mentioned method embodiments, etc. The memory 405 may optionally be at least one storage device located away from the aforementioned processor 401. As Figure 4 As shown, the memory 405 as a computer storage medium may include an operating system, a network communication module, a user interface module, and an application program.
[0090] exist Figure 4 In the computer device 400 shown in FIG. 1 , the user interface 403 is mainly used to provide an input interface for the user and obtain the data input by the user; and the processor 401 can be used to call the application program stored in the memory 405 and specifically execute the following steps: Figure 2 The specific process can be referred to Figure 1 As shown, no further description is given here.
[0091] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing related hardware through a computer program, and the program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. The storage medium can be a disk, an optical disk, a read-only storage memory, or a random access memory, etc.
[0092] The above disclosure is only the preferred embodiment of the present application, which certainly cannot be used to limit the scope of rights of the present application. Therefore, equivalent changes made according to the claims of the present application are still within the scope covered by the present application.
Claims
1. A method for detecting purple-fringe areas of an image, characterized in that: include: A sliding window is used to slide in the YUV image to be detected to traverse each pixel point, and if the central pixel point of the sliding window meets the first discrimination condition: the Y channel value is less than the threshold value Yt1 and there is at least one other pixel point in the sliding window whose Y channel value is greater than the threshold value Yt2, the central pixel point is identified as a purple fringing candidate point; and a first purple fringing candidate area is generated according to all the purple fringing pixels in the YUV image that meet the above Y channel discrimination condition; For each pixel in the YUV image, if the row adjacent pixel (i-1, j) or the column adjacent pixel (i, j-1) of the current pixel (i, j) is a purple fringing candidate point that satisfies the Y channel discrimination condition, the current pixel (i, j) is identified as a purple fringing candidate point, and the current pixel is added to the first purple fringing candidate area; Calculate the Y channel horizontal gradient and the Y channel vertical gradient of the current pixel in the YUV image, determine the edge direction of the current pixel according to the Y channel horizontal gradient, the Y channel vertical gradient and the gradient threshold Gt1, calculate the U channel gradient and the V channel gradient of the current pixel in the edge direction, if the maximum value of the U channel gradient and the V channel gradient is greater than the gradient threshold Gt2, identify the current pixel as a purple fringing candidate point; and generate a second purple fringing candidate area according to all purple fringing pixels in the YUV image that meet the above gradient discrimination conditions; Calculating the hue value and color saturation of the current pixel in the YUV image, and if the hue value is within a preset purple-fringe hue range and the color saturation is greater than a saturation threshold, identifying the current pixel as a purple-fringe candidate point; and generating a third purple fringing candidate area according to all the purple fringing candidate points in the YUV image that meet the above hue and saturation discrimination conditions; The first purple fringing candidate region, the second purple fringing candidate region and the third purple fringing candidate region are intersected to obtain a final target purple fringing region.
2. The method according to claim 1, characterized in that The formula for calculating the hue value is: The formula for calculating color saturation is: Sat(i,j)=abs(V(i,j)-128)+abs(U(i,j)-128).
3. The method according to claim 1, characterized in that The Sobel operator or Laplace algorithm is used for gradient calculation.
4. The method according to claim 1, characterized in that The size of the sliding window is 3×3.
5. The method according to claim 1, characterized in that A first purple fringing candidate region, a second purple fringing candidate region and a third purple fringing candidate region are generated in parallel.
6. The method according to claim 1, characterized in that The step of determining the edge direction of the current pixel according to the Y channel horizontal gradient, the Y channel vertical gradient, and the gradient threshold Gt1 includes: If the Y channel horizontal gradient is greater than the Y channel vertical gradient, and the Y channel horizontal gradient is greater than the gradient threshold Gt1, then the edge direction of the current pixel is horizontal; or If the Y channel vertical gradient is greater than the Y channel horizontal gradient, and the Y channel vertical gradient is greater than the gradient threshold Gt1, the edge point of the current pixel is in the vertical direction.
7. The method according to claim 1, characterized in that Also includes: The U channel value and the V channel value of each purple-fringed pixel in the target purple-fringed area are replaced with 128.
8. A device for detecting purple-fringe areas of an image, characterized in that: include: A brightness discrimination module is configured to use a sliding window to slide in the YUV image to be detected to traverse each pixel point, and if the central pixel point of the sliding window satisfies a first discrimination condition: the Y channel value is less than a threshold value Yt1 and there is at least one other pixel point in the sliding window whose Y channel value is greater than a threshold value Yt2, the central pixel point is identified as a purple fringing candidate point; and a first purple fringing candidate area is generated according to all the purple fringing pixels in the YUV image that meet the above Y channel discrimination condition; an adjacent discrimination module, for each pixel in the YUV image, if the row adjacent pixel (i-1, j) or the column adjacent pixel (i, j-1) of the current pixel (i, j) is a purple fringing candidate point that satisfies the Y channel discrimination condition, identifying the current pixel (i, j) as a purple fringing candidate point, and adding the current pixel to the first purple fringing candidate area; a gradient discrimination module, for calculating a Y channel horizontal gradient and a Y channel vertical gradient of a current pixel in the YUV image, determining an edge direction of the current pixel according to the Y channel horizontal gradient, the Y channel vertical gradient and a gradient threshold Gt1, calculating a U channel gradient and a V channel gradient of the current pixel in the edge direction, and identifying the current pixel as a purple fringing candidate point if the maximum value of the U channel gradient and the V channel gradient is greater than the gradient threshold Gt2; and generating a second purple fringing candidate region according to all purple fringing pixels in the YUV image that meet the above gradient discrimination conditions; A color discrimination module is used to calculate the hue value and color saturation of the current pixel in the YUV image, and if the hue value is within a preset purple-fringe hue range and the color saturation is greater than a saturation threshold, identify the current pixel as a purple-fringe candidate point; and generating a third purple fringing candidate area according to all the purple fringing candidate points in the YUV image that meet the above hue and saturation discrimination conditions; The merging module is used to obtain a final target purple fringing region by taking the intersection of the first purple fringing candidate region, the second purple fringing candidate region and the third purple fringing candidate region.
9. A computer storage medium, characterized in that The computer storage medium stores a plurality of instructions, and the instructions are suitable for being loaded by a processor and executing the method steps according to any one of claims 1 to 7.
10. A computer device, characterized in that: include: A processor and a memory; wherein the memory stores a computer program, and the computer program is suitable for being loaded by the processor and executing the method steps as claimed in any one of claims 1 to 7.
Citation Information
Patent Citations
Method and device for removing purple edge of image, equipment and medium
CN117635485A
Method and apparatus for cross-component prediction for video coding
WO2023230152A1