Method, system and related equipment for adding light effects to luminous bodies in images

By identifying the luminous objects in the image through preset brightness thresholds and circle detection algorithms, combined with gradient color filling and natural transition processing, it solves the problem of automatically adding light effects in the existing technology and achieves a more realistic image processing effect.

CN116630478BActive Publication Date: 2024-09-03SHENZHEN SHANJIAN INTELLIGENT SCI & TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310639057.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-05-31
Publication Date
2024-09-03
Estimated Expiration
2043-05-31

AI Technical Summary

Technical Problem

The existing technology lacks a method to automatically identify luminous objects in images and automatically add light effects, resulting in unrealistic image processing effects.

Method used

The luminous body and background area are determined by preset brightness thresholds, the circle detection algorithm is used to determine the luminous point set, and the gradient color filling algorithm is used to calculate the filling color. It is combined with the principle of highlight coverage and low brightness for natural transition processing to generate the final light effect image.

Benefits of technology

It realizes the automatic identification of luminous objects in the image and the addition of light effects, making the effect more realistic and natural, simulating the characteristics of natural light.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116630478B
    Figure CN116630478B
Patent Text Reader

Abstract

This invention provides a method, system, and related equipment for adding glow effects to luminous objects in an image. The method includes determining the luminous object pixel region and the background pixel region in the image based on a preset brightness threshold; using a preset circumferential detection algorithm to determine the luminescence of each pixel in the background pixel region surrounding the luminous object pixel region, obtaining a set of pixels that need to emit light; for each pixel in the set of pixels that need to emit light, using a preset gradient color filling algorithm to obtain the fill color for each pixel; color filling of each pixel in the set of pixels that need to emit light to obtain a preliminary glow effect image; and performing natural transition processing on the overlapping areas of the glow in the preliminary glow effect image based on the principle of high brightness covering low brightness to obtain a final glow effect image. This invention achieves automatic identification of luminous objects in images and adds glow effects, which simulate the characteristics of natural light, resulting in a more realistic effect.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of image processing technology, and in particular to a method, system and related equipment for adding light effects to a luminous body in an image. Background Art

[0002] With the rapid development of image processing technology, various ways of processing images have gradually emerged. Among them, a commonly used processing method is special effect processing, for example, beautifying the image, adding special effects, etc. By performing special effect processing on the image, the beauty or interest of the image can be increased. In a specific scenario of adding special effects to an image, a light effect is added to the luminous body in the image. The prior art lacks a method that can automatically identify the luminous object in the image and automatically add light.

[0003] Therefore, the prior art still needs to be improved and developed. Summary of the invention

[0004] The main purpose of the present invention is to solve the technical problems mentioned in the background technology of the prior art.

[0005] A first aspect of the present invention provides a method for adding light effects to a luminous body in an image, the method for adding light effects to a luminous body in an image comprising:

[0006] Determine the luminous body pixel area and the background pixel area in the image according to a preset brightness threshold;

[0007] By using a preset circumference detection algorithm, each pixel point in the background pixel area around the luminous body pixel area is judged to emit light, so as to obtain a set of pixel points that need to emit light;

[0008] For each pixel point in the pixel point set that needs to emit light, a preset gradient color filling algorithm related to the light emission distance is used to calculate and obtain the filling color of each pixel point;

[0009] Filling each pixel point in the pixel point set that needs to emit light with color to obtain a preliminary light special effect image;

[0010] Based on the principle that high brightness covers low brightness, a natural transition process is performed on the light overlapping area in the preliminary light special effect image to obtain a final light special effect image.

[0011] In an optional implementation of the first aspect of the present invention, determining the luminous body pixel area and the background pixel area in the image according to a preset brightness threshold comprises:

[0012] For each pixel in the image, a brightness value of each pixel is obtained by a preset pixel brightness calculation formula based on three primary colors and a weight coefficient;

[0013] For each of the pixels, determining whether the brightness value of the pixel is greater than the brightness threshold;

[0014] Determine in the image all the pixel points whose brightness values ​​are greater than the brightness threshold, and determine whether all the pixel points whose brightness values ​​are greater than the brightness threshold constitute a luminous body;

[0015] The luminous body pixel area and the background pixel area in the image are obtained based on the judgment result.

[0016] In an optional implementation of the first aspect of the present invention, determining in the image all the pixels whose brightness values ​​are greater than the brightness threshold, and determining whether all the pixels whose brightness values ​​are greater than the brightness threshold constitute a luminous body comprises:

[0017] Determine in the image all the pixel points whose brightness values ​​are greater than the brightness threshold;

[0018] Performing clustering detection on all the pixel points whose brightness values ​​are greater than the brightness threshold;

[0019] For each of the pixel points among all the pixel points whose luminance values ​​are greater than the luminance threshold, if the pixel point can form a cluster with the pixel points around the pixel point whose luminance values ​​are greater than the luminance threshold, it is determined that the pixel point belongs to a luminous body pixel point.

[0020] In an optional implementation of the first aspect of the present invention, for each of the pixel points whose brightness values ​​are greater than the brightness threshold, if the pixel point can form a cluster with the pixel points whose brightness values ​​around the pixel point are greater than the brightness threshold, then determining that the pixel point belongs to a light-emitting body pixel point includes:

[0021] For each of the pixel points among all the pixel points whose brightness value is greater than the brightness threshold, generating a moving window of a preset size, and placing the pixel points on each side edge of the moving window in sequence;

[0022] When the pixel points are at each side edge of the moving window, the proportion of the pixel points in the moving window whose brightness value is greater than the brightness threshold to all the pixel points in the moving window is obtained;

[0023] If there are pixels in the moving window on one or more edges whose brightness value is greater than the brightness threshold and the proportion of all pixels in the moving window is greater than a preset threshold, it is determined that the pixel belongs to a light-emitting pixel.

[0024] In an optional implementation of the first aspect of the present invention, the step of performing luminescence judgment on each pixel point of the background pixel area around the luminous body pixel area by a preset circumference detection algorithm to obtain a set of pixel points that need to emit light includes:

[0025] For each pixel point of the background pixel area around the luminous body pixel area, determine whether the pixel point of the luminous body pixel area is within a preset radius with the pixel point as the detection center;

[0026] If the pixel point of the light-emitting body pixel area exists within a preset radius with the pixel point as the detection center, further obtaining the pixel point of the light-emitting body pixel area closest to the detection center within the preset radius;

[0027] Establishing a vector between the pixel point of the luminous body pixel area closest to the detection center within the preset radius and the detection center;

[0028] Calculate the angle of the vector in the origin coordinate system of the detection center;

[0029] If the angle belongs to a preset angle set, the pixel is determined to be a luminous pixel;

[0030] All the luminous pixels are collected to obtain the pixel set that needs to emit light.

[0031] In an optional implementation of the first aspect of the present invention, for each pixel point in the set of pixel points that need to emit light, using a preset gradient color filling algorithm related to the light-emitting distance to calculate the filling color of each pixel point includes:

[0032] For each pixel point in the pixel point set that needs to emit light, obtaining a distance between the pixel point and a pixel point in the light-emitting body pixel region closest to the pixel point;

[0033] Based on the distance, a first saturation coefficient, a second saturation coefficient and a third saturation coefficient corresponding to the pixel point under three gradient filling colors are obtained respectively;

[0034] Obtaining a first gradient fill color based on the first saturation coefficient and a preset first original fill color through power operation;

[0035] Obtaining a second gradient fill color based on the second saturation coefficient and the preset second original fill color through a curve function and a power operation;

[0036] Obtaining a third gradient fill color based on the third saturation coefficient and a preset third original fill color through power operation;

[0037] The filling color of the pixel is obtained by mixing the first gradient filling color, the second gradient filling color and the third gradient filling color.

[0038] In an optional implementation of the first aspect of the present invention, performing natural transition processing on the light overlapping area in the preliminary light special effect image based on the principle of high brightness covering low brightness to obtain the final light special effect image includes:

[0039] Determining the light overlapping pixel points from the pixel points that need to emit light;

[0040] Obtain multiple colors of the light overlapping pixels;

[0041] Determining whether white exists in the plurality of colors;

[0042] If white exists in the multiple colors, white is used as the final filling color of the overlapping pixel points of the light;

[0043] If there is no white among the multiple colors, the gradient difference of the multiple colors in grayscale will be calculated, and then the gradient difference will be substituted into a preset smoothing function to obtain a smoothed color value, and then the color values ​​of the multiple colors and the smoothed color value will be fused to obtain a fused color value, and the color corresponding to the fused color value will be used as the final filling color of the overlapping pixels of the light.

[0044] A second aspect of the present invention provides a system for adding light effects to a luminous body in an image, the system for adding light effects to a luminous body in an image comprising:

[0045] A region distinguishing module, used to determine the luminous body pixel region and the background pixel region in the image according to a preset brightness threshold;

[0046] A light-emitting pixel point determination module is used to determine the light emission of each pixel point in the background pixel area around the light-emitting body pixel area through a preset circumference detection algorithm to obtain a set of pixel points that need to emit light;

[0047] A luminous color calculation module, used for calculating the filling color of each pixel point in the set of pixel points that need to emit light by using a preset gradient color filling algorithm related to the luminous distance;

[0048] A color filling module, used to fill the color of each pixel in the pixel set that needs to emit light, to obtain a preliminary light special effect image;

[0049] The color smoothing module is used to perform natural transition processing on the light overlapping area in the preliminary light special effect image based on the principle that high light covers low light, so as to obtain a final light special effect image.

[0050] A third aspect of the present invention provides a device for adding light effects to a luminous body in an image, the device for adding light effects to a luminous body in an image comprising: a memory and at least one processor, the memory storing instructions, the memory and the at least one processor being interconnected via a line;

[0051] The at least one processor calls the instructions in the memory to enable the device for adding light effects to a luminous body in an image to perform any of the methods for adding light effects to a luminous body in an image as described above.

[0052] A fourth aspect of the present invention provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the method for adding light effects to a light source in an image as described in any one of the above items is implemented.

[0053] Beneficial effects: The present invention provides a method, system and related equipment for adding light effects to a light source in an image. The method includes determining the light source pixel area and the background pixel area in the image according to a preset brightness threshold; judging the light emission of each pixel point in the background pixel area around the light source pixel area by a preset circle detection algorithm to obtain a set of pixels that need to emit light; for each pixel point in the set of pixels that need to emit light, using a preset gradient color filling algorithm to obtain the filling color of each pixel point; color filling of each pixel point in the set of pixels that need to emit light to obtain a preliminary light effect image; based on the principle of high brightness covering low brightness, natural transition processing is performed on the light overlapping area in the preliminary light effect image to obtain the final light effect image. The present invention realizes the automatic recognition of light objects in an image and adds light effects. The light effects simulate the characteristics of natural light and the effect is more realistic. BRIEF DESCRIPTION OF THE DRAWINGS

[0054] Figure 1 A schematic diagram of an embodiment of a method for adding light effects to a luminous body in an image according to the present invention;

[0055] Figure 2 A schematic diagram of an embodiment of an original image to which a light effect needs to be added according to the present invention;

[0056] Figure 3A schematic diagram of an embodiment of a special effect image after adding a light special effect according to the present invention;

[0057] Figure 4 A schematic diagram of an embodiment of a system for adding light effects to a luminous body in an image according to the present invention;

[0058] Figure 5 The present invention is a schematic diagram of an embodiment of a device for adding light effects to a luminous body in an image. DETAILED DESCRIPTION

[0059] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including" or "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0060] For ease of understanding, the specific process of the embodiment of the present invention is described below. Figure 1 In a first aspect, the present invention provides a method for adding light effects to a luminous body in an image, the method for adding light effects to a luminous body in an image comprising:

[0061] S100. Determine the luminous body pixel area and the background pixel area in the image according to a preset brightness threshold; in the present invention, before adding light effects to the luminous body in the image, it is necessary to first determine the position of the luminous body in the image, and the determination mechanism is based on the brightness of the luminous body being much higher than the brightness of the non-luminous body.

[0062] In an exemplary optional implementation of step S100, determining the luminous body pixel area and the background pixel area in the image according to a preset brightness threshold comprises:

[0063] For each pixel in the image, the brightness value of each pixel is obtained by a preset pixel brightness calculation formula based on three primary colors and a weight coefficient; illustratively, the pixel brightness calculation formula in the present invention is brightness L=0.212f*R+0.715f*G+0.073f*B, R is the red component of the pixel color, G is the green component of the pixel color, and B is the blue component of the pixel color. The present invention calculates the brightness value of each pixel by this formula;

[0064] For each pixel point, determine whether the brightness value of the pixel point is greater than the brightness threshold; in the present invention, the brightness values ​​of each pixel point obtained by calculation, if the brightness value of a pixel point is greater than the preset brightness threshold, then the pixel point has the condition of constituting a luminous body, so before determining the luminous body area, the present invention needs to first find out the pixel points whose brightness value is greater than the preset brightness threshold;

[0065] Determine in the image all the pixel points whose brightness values ​​are greater than the brightness threshold, and judge whether all the pixel points whose brightness values ​​are greater than the brightness threshold constitute a luminous body; after obtaining all the pixel points whose brightness values ​​are greater than the brightness threshold in the image, then judge whether these points can constitute a luminous body, if they can constitute a luminous body, then classify these pixel points that can constitute a luminous body respectively, and the number of luminous bodies that these pixel points can constitute in the image is the number of luminous areas in the image;

[0066] The luminous body pixel area and the background pixel area in the image are obtained based on the judgment result. In the present invention, after the area where the luminous body is located is determined, the area other than the luminous body is called the background pixel area, and the light emitted by the luminous body is formed in the background pixel area.

[0067] In an optional implementation of the present invention, for each of the pixel points among all the pixel points whose brightness values ​​are greater than the brightness threshold, if the pixel point can form a cluster with the pixel points around the pixel point whose brightness values ​​are greater than the brightness threshold, then determining that the pixel point belongs to a light-emitting body pixel point includes:

[0068] For each of the pixel points among all the pixel points whose brightness value is greater than the brightness threshold, a moving window of a preset size is generated, and the pixel points are sequentially placed at the side edges of the moving window; in the present invention, the shape of the moving window may be square or circular, and when the moving window is circular, the side edges of the moving window refer to the left vertex, the right vertex, the upper vertex and the lower vertex of the circle; the preset size here refers to the criterion for forming a minimum luminous body, and when the size of the luminous body is smaller than the preset size, the luminous body is ignored in the present invention because the luminous body is too small;

[0069] When the pixel point is at each side edge of the moving window, the proportion of the pixel points in the moving window whose brightness value is greater than the brightness threshold to all the pixel points in the moving window; in the present invention, the way to judge whether the pixel point is a pixel point of a light source is to judge whether the light-emitting area composed of this pixel point and the surrounding pixel points meets the preset specification (defined by the area of ​​the moving window). In order to facilitate calculation, this judgment process is converted into the judgment of the proportion of pixel points in the present invention;

[0070] If there is one or more edges in the moving window, and the ratio of the pixels whose brightness value is greater than the brightness threshold to all the pixels in the moving window is greater than a preset threshold, the pixel is determined to be a pixel of a light source. In the present invention, when the pixel and the pixels around the pixel whose brightness value is greater than the brightness threshold fill more than 80 percent of the total area of ​​the moving window, in the present invention, such pixels can be considered to constitute pixels of a light source.

[0071] S200, using a preset circumference detection algorithm, the pixel points of the background pixel area around the luminous body pixel area are judged to be luminous, and a set of pixel points that need to be luminous is obtained; in the present invention, after the position of the luminous body pixel area in the image is determined, it is necessary to judge whether each pixel point around the luminous body pixel area belongs to the light area (i.e., whether the pixel point is luminous);

[0072] In an optional implementation of step S200, the step of determining the light emission of each pixel point in the background pixel area around the light-emitting body pixel area by using a preset circumference detection algorithm to obtain a set of pixel points that need to emit light includes:

[0073] For each pixel point of the background pixel area around the luminous body pixel area, determine whether the pixel point of the luminous body pixel area is within a preset radius with the pixel point as the detection center; in the present invention, the purpose of this step is to determine whether the pixel point falls within the luminous range of the luminous body pixel area;

[0074] If there is a pixel of the light-emitting pixel region within the preset radius range centered on the pixel, further obtain the pixel of the light-emitting pixel region that is closest to the detection center within the preset radius range; in this step, when it is determined whether the pixel falls within the light-emitting range of the light-emitting pixel region, the next step of determining whether the pixel emits light is performed. In the present invention, in order to make the light effect more beautiful, the light effect of the light-emitting body in the image is configured to form a "cross" shape. To form a "cross" shape, in addition to the condition that the pixel is within the light-emitting range, it is also necessary to determine whether the angle between the pixel and the light-emitting body is appropriate. In the present invention, the light-emitting angle model assumes that the shape of the light-emitting body is circular, and the angle between the pixel and the center of the light-emitting body can be obtained by calculating the angle between the pixel and the closest light-emitting point on the edge of the light-emitting body;

[0075] Establish a vector between the pixel of the light-emitting pixel region that is closest to the detection center within the preset radius range and the detection center; calculate the included angle of the vector in the origin coordinate system of the detection center; in the present invention, the X and Y axes of the origin coordinate system of the detection center are vertical and horizontal respectively, and this included angle can be the included angle formed with the X axis or the Y axis. When the X axis or the Y axis is selected, the subsequent corresponding set of included angles is different;

[0076] If the included angle belongs to a preset set of included angles, determine that the pixel is a light-emitting pixel; in the present invention, an exemplary set of included angles is 0°, 45°, and 135°. When the calculated included angle belongs to one of these three angles, determine that this pixel is a pixel of the "cross" shaped light;

[0077] Collect all the light-emitting pixels to obtain the set of pixels that need to emit light. In the present invention, after obtaining the pixels of the "cross" shaped light one by one, the set of pixels that need to emit light is summarized.

[0078] S300. For each pixel in the set of pixels that need to emit light, use a preset gradient color filling algorithm related to the light-emitting distance to calculate the filling color of each pixel; in the present invention, the filling of the color of the light-emitting pixel is processed in a way similar to the superposition of three-color gradients, and the gradient process is interpolated using a relevant curve function. Here, the light-emitting distance refers to the distance between each pixel and the edge pixel of the light-emitting body. The farther the light-emitting distance, the darker the filling color (such as black), and the closer the light-emitting distance, the brighter the filling color (such as white);

[0079] In an optional implementation manner of step S300, the step of using a preset gradient color filling algorithm related to the light-emitting distance to calculate the filling color of each pixel in the set of pixels that need to emit light includes:

[0080] For each pixel point in the pixel point set that needs to emit light, obtain the distance between the pixel point and the pixel point of the light-emitting body pixel area closest to the pixel point; calculate the first saturation coefficient, the second saturation coefficient and the third saturation coefficient corresponding to the pixel point under three gradient fill colors based on the distance; obtain the first gradient fill color based on the first saturation coefficient and the preset first original fill color and through power operation; obtain the second gradient fill color based on the second saturation coefficient and the preset second original fill color and through curve function and power operation; obtain the third gradient fill color based on the third saturation coefficient and the preset third original fill color and through power operation; obtain the fill color of the pixel point by mixing the first gradient fill color, the second gradient fill color and the third gradient fill color.

[0081] Exemplarily, the relevant formulas used in the gradient color filling algorithm of the present invention are as follows:

[0082] float lightRatio = 0.0f;

[0083] float middleRatio = 0.0f;

[0084] float shadowRatio=0.0f;

[0085] if(forwardDir){

[0086] lightRatio=

[0087] mix(0.0f, getNewValue(clamp(1.0f-(distance) / (topTotalDistanceLight), 0.0f, 1.0f)), step(distance, topTotalDistanceLight));

[0088] middleRatio=

[0089] mix(0.0f, getNewValue(clamp(1.0f-(distance) / (topTotalDistanceMiddle),

[0090] 0.0f, 1.0f)), step(distance, topTotalDistanceMiddle));

[0091] shadowRatio=

[0092] mix(0.0f,getNewValue(clamp(1.0f-(distance) / (topTotalDistanceShadow),0.0f,1.0f)),step(distance,topTotalDistanceShadow));

[0093] }

[0094] else{

[0095] lightRatio=

[0096] mix(0.0f,getNewValue(clamp(1.0f-(distance) / (bottomTotalDistanceLight),0.0f,1.0f)),step(distance,bottomTotalDistanceLight));

[0097] middleRatio=

[0098] mix(0.0f,getNewValue(clamp(1.0f-(distance) / (bottomTotalDistanceMiddle),0.0f,1.0f)),step(distance,bottomTotalDistanceMiddle));

[0099] shadowRatio=

[0100] mix(0.0,getNewValue(clamp(1.0f-(distance) / (bottomTotalDistanceShadow),0.0f,1.0f)),step(distance,bottomTotalDistanceShadow));

[0101] }

[0102] vec4 colorOne=lightColor*pow(middleRatio,20.0f);

[0103] vec4 colorTwo=middleColor*(sin(PI*0.875f*(1.0f-middleRatio)+0.125*PI)*1.0f)*pow(middleRatio, 1.1f)*mix(0.0f, 1.0f, step(floatOffset, middleRatio));

[0104] vec4 colorThree=shadowColor*pow(shadowRatio, 1.0f);

[0105] vec4 resultColor=colorOne+colorTwo+colorThree.

[0106] Among them, lightColor (such as white, red), middleColor (such as a color between white and black), and shadowColor (such as black, gray) are three original filling colors, colorOne, colorTwo, and colorThree are the corresponding gradient intermediate processing colors, lightRatio, middleRatio, and shadowRatio correspond to the saturation coefficients of the three original filling colors, PI is Π=3.1415926f, floatOffset is the floating point calculation error, sin, pow, and mix are corresponding mathematical functions and graphics functions.

[0107] S400, color filling is performed on each of the pixel points in the set of pixel points that need to emit light, so as to obtain a preliminary light special effect image; in the present invention, after the filling color of each of the pixel points in the set of pixel points that need to emit light is calculated in step S300, the color of each of the pixel points in the set of pixel points that need to emit light is changed to the filling color according to the filling color. In the present invention, if a pixel point needs to be changed to more than one color, the color will not be filled in the supplement first, and the color of these pixel points will be changed after the final filling color is obtained after calculation in the subsequent step S500;

[0108] S500 , based on the principle of high brightness covering low brightness, a natural transition process is performed on the light overlapping area in the preliminary light special effect image to obtain a final light special effect image.

[0109] In an optional implementation of the first aspect of the present invention, performing natural transition processing on the light overlapping area in the preliminary light special effect image based on the principle of high brightness covering low brightness to obtain the final light special effect image includes:

[0110] Determine overlapping light pixels from the pixel points that need to emit light; obtain multiple colors of the overlapping light pixels; determine whether white exists in the multiple colors; if white exists in the multiple colors, use white as the final fill color of the overlapping light pixels; if white does not exist in the multiple colors, calculate the gradient difference of the multiple colors in grayscale, then substitute the gradient difference into a preset smoothing function to obtain a smoothed color value, then fuse the color values ​​of the multiple colors and the smoothed color value to obtain a fused color value, and use the color corresponding to the fused color value as the final fill color of the overlapping light pixels.

[0111] Exemplarily, the formula for naturally transitioning the colors of pixels in the overlapping light regions of the present invention is as follows:

[0112] float grayOne=getGray(colorOne);

[0113] float grayTwo=getGray(colorTwo);

[0114] if(isWhiteColor(colorOne)||isWhiteColor(colorTwo)){

[0115] glFragColor = vec4(1.0f);}

[0116] else{glFragColor=mix(colorOne, colorTwo, smoothstep(-1.0f, 1.0f, grayTwo-grayOne));

[0117] }

[0118] Related explanation: function smoothstep: y = x*x*(3-2*x), where the independent variable x = color brightness gradient. Based on this gradient difference, the two colors are smoothly blended, that is, each color occupies a certain proportion, and this proportion is remapped by the current function.

[0119] Simply put, the principle of the technical solution of the present invention is to first separate the light source and the background texture of the original image (picture or video) according to the preset "brightness threshold" parameter, and then obtain the pixel points around the light source that need to form the light effect through the circle detection algorithm, and then use the gradient color filling algorithm to obtain the color of each pixel point that needs to form the light effect, and then combine the physical principles of natural lighting (when multiple light sources overlap, high-brightness light covers low-brightness light) to naturally mix the overlapping parts of the multiple light sources. The color filling of the light effect of the present invention combines the laws of real natural light sources and performs a three-color gradient superposition process. In addition, each color component needs to be reasonably constrained by a curve function, rather than a linear relationship. The light effect of the light source formed is more realistic and natural. An exemplary original image before adding light effects and the effect image after adding special effects of the present invention are shown in the figure. Figure 2 and Figure 3 shown.

[0120] See also Figure 4 A second aspect of the present invention provides a system for adding light effects to a luminous body in an image, the system for adding light effects to a luminous body in an image comprising:

[0121] A region distinguishing module 10, for determining a light source pixel region and a background pixel region in an image according to a preset brightness threshold;

[0122] The luminous pixel point determination module 20 is used to determine the luminescence of each pixel point in the background pixel area around the luminous body pixel area by using a preset circumference detection algorithm to obtain a set of pixel points that need to be illuminated;

[0123] The luminous color calculation module 30 is used to calculate the filling color of each pixel point in the pixel point set that needs to emit light by using a preset gradient color filling algorithm related to the luminous distance;

[0124] A color filling module 40 is used to fill the color of each pixel in the pixel set that needs to emit light, so as to obtain a preliminary light effect image;

[0125] The color smoothing module 50 is used to perform natural transition processing on the light overlapping area in the preliminary light special effect image based on the principle of high brightness covering low brightness, so as to obtain a final light special effect image.

[0126] In an optional implementation of the second aspect of the present invention, the region distinguishing module 10 includes:

[0127] A brightness calculation unit, configured to obtain a brightness value of each pixel in the image by using a preset pixel brightness calculation formula based on three primary colors and a weight coefficient;

[0128] A brightness judgment unit, configured to judge, for each pixel point, whether the brightness value of the pixel point is greater than the brightness threshold;

[0129] a luminous body judging unit, used for determining in the image all the pixel points whose brightness values ​​are greater than the brightness threshold, and judging whether all the pixel points whose brightness values ​​are greater than the brightness threshold constitute luminous bodies;

[0130] The area division unit is used to obtain the luminous body pixel area and the background pixel area in the image based on the judgment result.

[0131] In an optional implementation of the second aspect of the present invention, the luminous body judgment unit includes:

[0132] A target pixel point acquisition subunit, used to determine in the image all the pixels whose brightness values ​​are greater than the brightness threshold;

[0133] a clumping detection subunit, configured to perform clumping detection on all the pixel points whose brightness values ​​are greater than the brightness threshold;

[0134] A determination subunit is used to determine, for each of the pixel points among all the pixel points whose luminance values ​​are greater than the luminance threshold, that the pixel point belongs to a luminous body pixel point if the pixel point can form a cluster with the pixel points around the pixel point whose luminance values ​​are greater than the luminance threshold.

[0135] In an optional implementation of the second aspect of the present invention, the determination subunit includes:

[0136] A first window generation subunit is used to generate a moving window of a preset size for each of the pixel points among all the pixel points whose brightness value is greater than the brightness threshold, and sequentially place the pixel points on each side edge of the moving window;

[0137] A second ratio acquisition subunit is used to acquire the ratio of the pixel points whose brightness value in the moving window is greater than the brightness threshold to all the pixel points in the moving window when the pixel points are at the side edges of the moving window;

[0138] The third subunit is used to determine that if there are one or more edges on the moving window and the proportion of the pixels whose brightness value is greater than the brightness threshold in the moving window is greater than a preset threshold, then the pixel points are determined to be luminous body pixels.

[0139] In an optional implementation of the second aspect of the present invention, the luminous pixel point determination module includes:

[0140] A pixel point detection unit is used to determine, for each pixel point of the background pixel area around the luminous body pixel area, whether the pixel point of the luminous body pixel area exists within a preset radius with the pixel point as the detection center;

[0141] A nearest luminous body pixel point acquisition unit, used for further acquiring the pixel point of the luminous body pixel area closest to the detection center within the preset radius if the pixel point of the luminous body pixel area exists within the preset radius with the pixel point as the detection center;

[0142] A vector construction unit, used to establish a vector between the pixel point of the luminous body pixel area closest to the detection center within the preset radius and the detection center;

[0143] An angle calculation unit, used for calculating the angle of the vector in the origin coordinate system of the detection center;

[0144] a luminous pixel point determination unit, configured to determine that the pixel point is a luminous pixel point if the angle belongs to a preset angle set;

[0145] The luminous pixel point aggregation unit is used to collect all the luminous pixel points to obtain the pixel point set that needs to emit light.

[0146] In an optional implementation of the second aspect of the present invention, the luminous color calculation module includes:

[0147] A distance acquisition unit, configured to acquire, for each pixel point in the pixel point set that needs to emit light, a distance between the pixel point and a pixel point in a pixel area of ​​the light emitter closest to the pixel point;

[0148] A saturation coefficient calculation unit, used for calculating, based on the distance, a first saturation coefficient, a second saturation coefficient and a third saturation coefficient corresponding to the pixel point under three gradient fill colors respectively;

[0149] A first gradient filling color calculation unit, configured to obtain a first gradient filling color through power operation based on the first saturation coefficient and a preset first original filling color;

[0150] A second gradient fill color calculation unit, configured to obtain a second gradient fill color based on the second saturation coefficient and a preset second original fill color by using a curve function and a power operation;

[0151] A third gradient filling color calculation unit, used for obtaining a third gradient filling color through power operation based on the third saturation coefficient and a preset third original filling color;

[0152] A color mixing unit is used to obtain the filling color of the pixel point by mixing the first gradient filling color, the second gradient filling color and the third gradient filling color.

[0153] In an optional implementation of the second aspect of the present invention, the color smoothing module includes:

[0154] A light overlapping pixel point acquisition unit, used for determining light overlapping pixel points from the pixel points that need to emit light;

[0155] A color acquisition unit, used for acquiring a plurality of colors of the overlapping pixel points of the light;

[0156] A color judgment unit, used for judging whether there is white in the multiple colors;

[0157] A first color determination unit, configured to use white as the final filling color of the light overlapping pixel points if white exists in the multiple colors;

[0158] The second color determination unit is used to calculate the gradient difference of the multiple colors in grayscale if there is no white among the multiple colors, and then substitute the gradient difference into a preset smoothing function to obtain a smoothed color value, and then fuse the color values ​​of the multiple colors and the smoothed color value to obtain a fused color value, and use the color corresponding to the fused color value as the final filling color of the overlapping pixel points of the light.

[0159] Figure 5 It is a schematic diagram of the structure of a device for adding light effects to a luminous body in an image provided by an embodiment of the present invention. The device for adding light effects to a luminous body in an image may have relatively large differences due to different configurations or performances, and may include one or more processors 60 (central processing units, CPU) (for example, one or more processors) and a memory 70, and one or more storage media 80 for storing applications or data (for example, one or more mass storage devices). Among them, the memory and the storage medium may be temporary storage or permanent storage. The program stored in the storage medium may include one or more modules (not shown in the figure), and each module may include a series of instruction operations in the device for adding light effects to a luminous body in an image. Furthermore, the processor may be configured to communicate with the storage medium and execute a series of instruction operations in the storage medium on the vehicle-mounted central control.

[0160] The device for adding light effects to a light source in an image of the present invention may also include one or more power supplies 90, one or more wired or wireless network interfaces 100, one or more input and output interfaces 110, and / or one or more operating systems, such as Windows Server, Mac OS X, Unix, Linux, FreeBSD, etc. It will be appreciated by those skilled in the art that Figure 5 The structure of the device for adding light effects to a luminous body in an image shown does not constitute a limitation on the device for adding light effects to a luminous body in an image, and may include more or fewer components than shown in the figure, or a combination of certain components, or a different arrangement of components.

[0161] The present invention also provides a computer-readable storage medium, which may be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium. Instructions are stored in the computer-readable storage medium. When the instructions are executed on a computer, the computer executes the steps of the method for adding light effects to a light source in an image.

[0162] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the system or system or unit described above can refer to the corresponding process in the aforementioned method embodiment and will not be repeated here.

[0163] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program codes.

[0164] As described above, the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features thereof may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for adding light effects to a luminous body in an image, characterized in that: The method for adding a light effect to a luminous body in an image comprises: Determine the luminous body pixel area and the background pixel area in the image according to a preset brightness threshold; By using a preset circumference detection algorithm, each pixel point in the background pixel area around the luminous body pixel area is judged to emit light, so as to obtain a set of pixel points that need to emit light; For each pixel point in the pixel point set that needs to emit light, a preset gradient color filling algorithm related to the light emission distance is used to calculate and obtain the filling color of each pixel point; Filling each pixel point in the pixel point set that needs to emit light with color to obtain a preliminary light special effect image; Based on the principle that high brightness covers low brightness, a natural transition process is performed on the light overlapping area in the preliminary light special effect image to obtain a final light special effect image; The step of judging the emission of each pixel point in the background pixel area around the luminous body pixel area by using a preset circumference detection algorithm to obtain a set of pixel points that need to emit light includes: For each pixel point of the background pixel area around the luminous body pixel area, determine whether the pixel point of the luminous body pixel area is within a preset radius with the pixel point as the detection center; If the pixel point of the light-emitting body pixel area exists within a preset radius with the pixel point as the detection center, further obtaining the pixel point of the light-emitting body pixel area closest to the detection center within the preset radius; Establishing a vector between the pixel point of the luminous body pixel area closest to the detection center within the preset radius and the detection center; Calculate the angle of the vector in the origin coordinate system of the detection center; If the angle belongs to a preset angle set, determining that the pixel is a luminous pixel; Collect all the luminous pixels to obtain the pixel set that needs to emit light; For each pixel point in the set of pixel points that need to emit light, using a preset gradient color filling algorithm related to the light emission distance, calculating and obtaining the filling color of each pixel point includes: For each pixel point in the pixel point set that needs to emit light, obtaining a distance between the pixel point and a pixel point in the light-emitting body pixel region closest to the pixel point; Based on the distance, a first saturation coefficient, a second saturation coefficient and a third saturation coefficient corresponding to the pixel point under three gradient filling colors are obtained respectively; Obtaining a first gradient fill color based on the first saturation coefficient and a preset first original fill color through power operation; Obtaining a second gradient fill color based on the second saturation coefficient and the preset second original fill color through a curve function and a power operation; Obtaining a third gradient fill color based on the third saturation coefficient and a preset third original fill color through power operation; The filling color of the pixel point is obtained by mixing the first gradient filling color, the second gradient filling color and the third gradient filling color; The naturally transitioning the light overlapping area in the preliminary light special effect image based on the principle of high light covering low light to obtain the final light special effect image comprises: Determining the light overlapping pixel points from the pixel points that need to emit light; Obtain multiple colors of the light overlapping pixels; Determining whether white exists in the plurality of colors; If white exists in the multiple colors, white is used as the final filling color of the overlapping pixel points of the light; If there is no white among the multiple colors, the gradient difference of the multiple colors in grayscale will be calculated, and then the gradient difference will be substituted into a preset smoothing function to obtain a smoothed color value, and then the color values ​​of the multiple colors and the smoothed color value will be fused to obtain a fused color value, and the color corresponding to the fused color value will be used as the final filling color of the overlapping pixels of the light.

2. The method for adding light effects to a luminous body in an image according to claim 1, characterized in that: The step of determining the luminous body pixel area and the background pixel area in the image according to the preset brightness threshold comprises: For each pixel in the image, a brightness value of each pixel is obtained by a preset pixel brightness calculation formula based on three primary colors and a weight coefficient; For each of the pixel points, determining whether the brightness value of the pixel point is greater than the brightness threshold; Determine in the image all the pixel points whose brightness values ​​are greater than the brightness threshold, and determine whether all the pixel points whose brightness values ​​are greater than the brightness threshold constitute a luminous body; The luminous body pixel area and the background pixel area in the image are obtained based on the judgment result.

3. The method for adding light effects to a luminous body in an image according to claim 2, characterized in that: The determining in the image all the pixels whose brightness values ​​are greater than the brightness threshold, and judging whether all the pixels whose brightness values ​​are greater than the brightness threshold constitute a luminous body comprises: Determine in the image all the pixel points whose brightness values ​​are greater than the brightness threshold; Performing clustering detection on all the pixel points whose brightness values ​​are greater than the brightness threshold; For each of the pixel points among all the pixel points whose luminance values ​​are greater than the luminance threshold, if the pixel point can form a cluster with the pixel points around the pixel point whose luminance values ​​are greater than the luminance threshold, it is determined that the pixel point belongs to a luminous body pixel point.

4. The method for adding light effects to a luminous body in an image according to claim 3, characterized in that: For each of the pixel points among all the pixel points whose brightness values ​​are greater than the brightness threshold, if the pixel point can form a cluster with the pixel points around the pixel point whose brightness values ​​are greater than the brightness threshold, determining that the pixel point belongs to a luminous body pixel point includes: For each of the pixel points among all the pixel points whose brightness value is greater than the brightness threshold, generating a moving window of a preset size, and placing the pixel points on each side edge of the moving window in sequence; When obtaining the pixel points at each side edge of the moving window, the proportion of the pixel points in the moving window whose brightness value is greater than the brightness threshold to all the pixel points in the moving window; If there are pixels in the moving window on one or more edges whose brightness value is greater than the brightness threshold and the proportion of all pixels in the moving window is greater than a preset threshold, it is determined that the pixel belongs to a light-emitting pixel.

5. A system for adding light effects to a luminous body in an image, characterized in that: The system for adding a light effect to a luminous body in an image comprises: A region distinguishing module, used to determine the luminous body pixel region and the background pixel region in the image according to a preset brightness threshold; A light-emitting pixel point determination module is used to determine the light emission of each pixel point in the background pixel area around the light-emitting body pixel area through a preset circumference detection algorithm to obtain a set of pixel points that need to emit light; A luminous color calculation module, used for calculating the filling color of each pixel point in the set of pixel points that need to emit light by using a preset gradient color filling algorithm related to the luminous distance; A color filling module, used to fill the color of each pixel in the pixel set that needs to emit light, to obtain a preliminary light special effect image; A color smoothing module is used to perform natural transition processing on the light overlapping area in the preliminary light special effect image based on the principle that high light covers low light, so as to obtain a final light special effect image; The luminous pixel point determination module includes: A pixel point detection unit is used to determine, for each pixel point of the background pixel area around the luminous body pixel area, whether the pixel point of the luminous body pixel area exists within a preset radius with the pixel point as the detection center; A nearest luminous body pixel point acquisition unit, used for further acquiring the pixel point of the luminous body pixel area closest to the detection center within the preset radius if the pixel point of the luminous body pixel area exists within the preset radius with the pixel point as the detection center; A vector construction unit, used to establish a vector between the pixel point of the luminous body pixel area closest to the detection center within the preset radius and the detection center; An angle calculation unit, used for calculating the angle of the vector in the origin coordinate system of the detection center; a luminous pixel point determination unit, configured to determine that the pixel point is a luminous pixel point if the angle belongs to a preset angle set; A luminous pixel point aggregation unit, used for collecting all the luminous pixel points to obtain the pixel point set that needs to emit light; The luminous color calculation module includes: A distance acquisition unit, configured to acquire, for each pixel point in the pixel point set that needs to emit light, a distance between the pixel point and a pixel point in a pixel area of ​​the light emitter closest to the pixel point; A saturation coefficient calculation unit, used for calculating, based on the distance, a first saturation coefficient, a second saturation coefficient and a third saturation coefficient corresponding to the pixel point under three gradient fill colors respectively; A first gradient filling color calculation unit, configured to obtain a first gradient filling color through power operation based on the first saturation coefficient and a preset first original filling color; A second gradient fill color calculation unit, configured to obtain a second gradient fill color based on the second saturation coefficient and a preset second original fill color by using a curve function and a power operation; A third gradient filling color calculation unit, used for obtaining a third gradient filling color through power operation based on the third saturation coefficient and a preset third original filling color; a color mixing unit, configured to obtain the filling color of the pixel by mixing the first gradient filling color, the second gradient filling color and the third gradient filling color; The color smoothing module comprises: A light overlapping pixel point acquisition unit, used for determining light overlapping pixel points from the pixel points that need to emit light; A color acquisition unit, used for acquiring a plurality of colors of the overlapping pixel points of the light; A color judgment unit, used for judging whether there is white in the multiple colors; A first color determination unit, configured to use white as the final filling color of the light overlapping pixel points if white exists in the multiple colors; The second color determination unit is used to calculate the gradient difference of the multiple colors in grayscale if there is no white among the multiple colors, and then substitute the gradient difference into a preset smoothing function to obtain a smoothed color value, and then fuse the color values ​​of the multiple colors and the smoothed color value to obtain a fused color value, and use the color corresponding to the fused color value as the final filling color of the overlapping pixel points of the light.

6. A device for adding light effects to a luminous body in an image, characterized in that: The device for adding light effects to a luminous body in an image comprises: a memory and at least one processor, the memory stores instructions, and the memory and the at least one processor are interconnected via a line; The at least one processor calls the instructions in the memory to enable the device for adding a light effect to a luminous body in an image to perform the method for adding a light effect to a luminous body in an image as described in any one of claims 1-4.

7. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method for adding light effects to a luminous body in an image according to any one of claims 1 to 4 is implemented.