Image processing method and device
By calculating the directional weight coefficient of the non-shaded pixels in the image on the terminal device and combining edge information to generate a new image with directional soft shadows, the problem that terminal devices in the prior art is difficult to generate directional soft shadows, and the visual effect of the image is improved.
Patent Information
- Application Number
- CN202510510925.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-23
- Publication Date
- 2025-05-23
- Estimated Expiration
- 2045-04-23
AI Technical Summary
It is difficult for the prior art to generate directional soft shadows on terminal devices, and obvious boundaries appear when the soft and hard shadows are fused, affecting the visual effect.
By determining the shadowed area in the image and generating a shadow template, the directional weight coefficient for each non-shading pixel is calculated, and a new image with directional soft shadows is generated in combination with the edge information of the image.
It realizes the generation of directional soft shadow images on terminal devices, solves the problem of soft and hard shadow fusion boundary, improves the softness and reality of the shadows, and makes the image visual effect smoother, smoother and more vivid.
Smart Images

Figure CN120031773A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of display technology, and in particular to an image processing method and device. Background Art
[0002] Soft shadow technology is a technology used in computer graphics to simulate shadow effects in the real world. It simulates the penumbra effect produced when light passes through the edge of an object by calculating the light source, object shape and material. Compared with traditional hard shadows, soft shadow technology can more delicately simulate the gradual diffusion phenomenon produced in the surrounding environment after light is blocked by an object, generating a shadow image with a strong sense of reality. This technology is widely used in film special effects, game rendering and VR / AR, which can significantly enhance the immersion and realism of visual scenes. It is one of the important technologies to enhance the realism of computer graphics.
[0003] In the related art, the common soft shadow processing of 2D images is achieved through methods such as the box-shadow attribute algorithm in CSS (Cascading Style Sheets), but the generated shadow effect is evenly diffused, which makes it difficult to show the directional characteristics of soft shadows in the real physical world, resulting in the lack of realism of the processed shadows. In addition, the diffusion of soft shadows in 2D images usually requires a shadow template, and errors in template segmentation will cause obvious boundaries when soft and hard shadows merge, seriously affecting the final visual effect.
[0004] In addition, since the soft shadow rendering algorithm is complex and consumes huge resources, using it on a terminal device requires the terminal device to have high performance. Limited by the performance of the terminal device, related technologies mostly use hard shadow rendering methods with low resource consumption in terminal devices. Therefore, how to enable the terminal device to flexibly generate directional soft shadows, naturally blend soft and hard shadows, and make the overall visual effect of the shadow smoother and more vivid is a problem that needs to be solved urgently. Summary of the invention
[0005] In view of this, the present disclosure proposes an image processing method and device.
[0006] According to one aspect of the present disclosure, there is provided an image processing method, the method comprising:
[0007] Determine a shadow area in the image, and generate a shadow template corresponding to the image according to the shadow area;
[0008] Determine at least a directional weight coefficient corresponding to each non-shadow pixel in the image according to the shadow template;
[0009] A new image with directional soft shadows is generated according to each of the directional weight coefficients, the edge information of the image and the image.
[0010] In a possible implementation manner, determining at least a directional weight coefficient corresponding to each non-shadow pixel in the image according to the shadow template includes:
[0011] Determine the shortest distance from each non-shadow pixel to the shadow area according to the shadow template, and determine the light source distance from each non-shadow pixel to the light source;
[0012] Determine the actual shadow area corresponding to each of the non-shadow pixels according to the light source distance and shadow area parameters corresponding to each of the non-shadow pixels;
[0013] Determine a directional weight coefficient corresponding to each of the non-shadow pixels according to the nearest distance corresponding to each of the non-shadow pixels and the actual shadow area;
[0014] The directional weight coefficient of each shadow pixel is set to 1 according to the shadow template.
[0015] In a possible implementation manner, generating a new image with directional soft shadows according to each of the directional weight coefficients, the edge information of the image, and the image includes:
[0016] Convert the image from the RGB color space to the YUV color space to obtain the original Y component, the original U component and the original V component corresponding to each pixel in the image;
[0017] According to the directional weight coefficient corresponding to each pixel and the Y eigenvalue, U eigenvalue and V eigenvalue determined based on the shadow area, weighted processing is performed on the original Y component, original U component and original V component corresponding to each pixel to obtain a weighted Y component, weighted U component and weighted V component corresponding to each pixel;
[0018] Performing fuzzy processing on the original Y component and the weighted Y component respectively to obtain a first fuzzy Y component and a second fuzzy Y component;
[0019] Obtain edge information corresponding to each pixel according to the original Y component corresponding to each pixel and the first blurred Y component;
[0020] Determining a target Y component corresponding to each pixel according to the second fuzzy Y component corresponding to each pixel, the edge information and the directional weight coefficient;
[0021] A conversion is performed from the YUV color space to the RGB color space according to the target Y component, the weighted U component and the weighted V component corresponding to each of the pixels, so as to obtain a new image with directional soft shadows.
[0022] In a possible implementation manner, determining the target Y component corresponding to each pixel according to the second fuzzy Y component corresponding to each pixel, the edge information, and the directional weight coefficient includes:
[0023] Determining a soft shadow mask corresponding to each pixel according to a directional weight coefficient corresponding to each pixel;
[0024] The target Y component corresponding to each pixel is determined according to the second fuzzy Y component corresponding to each pixel, the edge information and the soft shadow mask.
[0025] In a possible implementation manner, determining at least a directional weight coefficient corresponding to each non-shadow pixel in the image according to the shadow template includes:
[0026] Determine the shortest distance from each of the non-shadow pixels to the shadow area according to the shadow template, and determine the light source distance from each of the non-shadow pixels to the light source;
[0027] Determine the actual shadow area corresponding to each of the non-shadow pixels according to the light source distance and shadow area parameters corresponding to each of the non-shadow pixels;
[0028] The directional weight coefficient corresponding to each of the non-shadow pixels is determined according to the nearest distance corresponding to each of the non-shadow pixels and the actual shadow area.
[0029] In a possible implementation manner, generating a new image with directional soft shadows according to each of the directional weight coefficients, the edge information of the image, and the image includes:
[0030] Convert the non-shadow pixels of the image from the RGB color space to the YUV color space to obtain the original Y component, the original U component and the original V component corresponding to each of the non-shadow pixels;
[0031] According to the directional weight coefficient corresponding to each of the non-shadow pixels and the Y eigenvalue, U eigenvalue and V eigenvalue determined based on the shadow area, weighted processing is performed on the original Y component, original U component and original V component corresponding to each of the non-shadow pixels to obtain a weighted Y component, weighted U component and weighted V component corresponding to each of the non-shadow pixels;
[0032] Performing fuzzy processing on the original Y component and the weighted Y component respectively to obtain a first fuzzy Y component and a second fuzzy Y component;
[0033] Based on the original Y component and the first blurred Y component corresponding to each of the non-shadow pixels, obtain the edge information corresponding to each of the non-shadow pixels;
[0034] Based on the second blurred Y component, the edge information, and the directional weight coefficient corresponding to each of the non-shadow pixels, determine the target Y component corresponding to each of the non-shadow pixels;
[0035] Perform a conversion from the YUV color space to the RGB color space based on the target Y component, the weighted U component, and the weighted V component corresponding to each of the non-shadow pixels, to obtain the new non-shadow region of the image with directional soft shadows;
[0036] Based on the new non-shadow region and the shadow region, form a new image with directional soft shadows.
[0037] In a possible implementation manner, determining the shadow region in the image and generating a shadow template corresponding to the image includes:
[0038] Determine the shadow region in the image, perform binarization processing on the image according to the shadow region, to obtain the shadow template corresponding to the image, where the value of the shadow pixels in the shadow region of the shadow template is a first value, and the value of the non-shadow pixels in the non-shadow region is a second value.
[0039] According to another aspect of the present disclosure, there is provided an image processing apparatus, the apparatus includes:
[0040] A shadow template generation module, configured to determine the shadow region in the image and generate a shadow template corresponding to the image according to the shadow region;
[0041] A weight coefficient generation module, configured to at least determine the directional weight coefficient corresponding to each non-shadow pixel in the image according to the shadow template;
[0042] An image generation module, configured to generate a new image with directional soft shadows according to each of the directional weight coefficients, the edge information of the image, and the image.
[0043] In a possible implementation manner, the weight coefficient generation module includes:
[0044] A first distance calculation sub-module, configured to determine the closest distance from each non-shadow pixel to the shadow region according to the shadow template, and determine the light source distance from each of the non-shadow pixels to the light source;
[0045] A first area determination submodule, configured to determine an actual shadow area corresponding to each of the non-shadow pixels according to the light source distance and shadow area parameters corresponding to each of the non-shadow pixels;
[0046] A first coefficient determination submodule, configured to determine a directional weight coefficient corresponding to each of the non-shadow pixels according to the nearest distance corresponding to each of the non-shadow pixels and the actual shadow area;
[0047] The second coefficient determination submodule is used to set the directional weight coefficient of each shadow pixel to 1 according to the shadow template.
[0048] In a possible implementation, the image generation module includes:
[0049] A first component determination submodule is used to convert the image from the RGB color space to the YUV color space to obtain the original Y component, the original U component and the original V component corresponding to each pixel in the image;
[0050] A first weighted submodule is used to perform weighted processing on the original Y component, the original U component and the original V component corresponding to each pixel according to the directional weight coefficient corresponding to each pixel and the Y eigenvalue, the U eigenvalue and the V eigenvalue determined based on the shadow area, so as to obtain the weighted Y component, the weighted U component and the weighted V component corresponding to each pixel;
[0051] A first fuzzy processing submodule, used for performing fuzzy processing on the original Y component and the weighted Y component respectively to obtain a first fuzzy Y component and a second fuzzy Y component;
[0052] A first edge information determination submodule, used for obtaining edge information corresponding to each pixel according to the original Y component corresponding to each pixel and the first blurred Y component;
[0053] A first component calculation submodule, configured to determine a target Y component corresponding to each pixel according to the second fuzzy Y component corresponding to each pixel, the edge information and the directional weight coefficient;
[0054] The first image generation submodule is used to convert from the YUV color space to the RGB color space according to the target Y component, the weighted U component and the weighted V component corresponding to each pixel, so as to obtain a new image with directional soft shadows.
[0055] In a possible implementation manner, determining the target Y component corresponding to each pixel according to the second fuzzy Y component corresponding to each pixel, the edge information, and the directional weight coefficient includes:
[0056] Determining a soft shadow mask corresponding to each pixel according to a directional weight coefficient corresponding to each pixel;
[0057] The target Y component corresponding to each pixel is determined according to the second fuzzy Y component corresponding to each pixel, the edge information and the soft shadow mask.
[0058] In a possible implementation, the weight coefficient generating module includes:
[0059] A second distance calculation submodule, used to determine the shortest distance from each of the non-shadow pixels to the shadow area according to the shadow template, and to determine the light source distance from each of the non-shadow pixels to the light source;
[0060] A second area determination submodule, configured to determine an actual shadow area corresponding to each of the non-shadow pixels according to the light source distance and shadow area parameters corresponding to each of the non-shadow pixels;
[0061] The third coefficient determination submodule is used to determine the directional weight coefficient corresponding to each of the non-shadow pixels according to the nearest distance corresponding to each of the non-shadow pixels and the actual shadow area.
[0062] In a possible implementation, the image generation module includes:
[0063] A second component determination submodule is used to convert the non-shadow pixels of the image from the RGB color space to the YUV color space to obtain the original Y component, the original U component and the original V component corresponding to each of the non-shadow pixels;
[0064] A second weighted submodule is used to perform weighted processing on the original Y component, original U component and original V component corresponding to each of the non-shadow pixels according to the directional weight coefficient corresponding to each of the non-shadow pixels and the Y eigenvalue, U eigenvalue and V eigenvalue determined based on the shadow area, so as to obtain the weighted Y component, weighted U component and weighted V component corresponding to each of the non-shadow pixels;
[0065] A second fuzzy processing submodule, used for performing fuzzy processing on the original Y component and the weighted Y component respectively to obtain a first fuzzy Y component and a second fuzzy Y component;
[0066] A second edge information determination submodule, configured to obtain edge information corresponding to each of the non-shadow pixels according to the original Y component corresponding to each of the non-shadow pixels and the first fuzzy Y component;
[0067] A second component calculation submodule, used to determine the target Y component corresponding to each of the non-shadow pixels according to the second fuzzy Y component corresponding to each of the non-shadow pixels, the edge information and the directional weight coefficient;
[0068] A region generation submodule, used for converting from the YUV color space to the RGB color space according to the target Y component, the weighted U component and the weighted V component corresponding to each of the non-shadow pixels, to obtain a new non-shadow region of the image with a directional soft shadow;
[0069] The second image generating submodule is used to form a new image with directional soft shadows according to the new non-shadow area and the shadow area.
[0070] In a possible implementation, the shadow template generating module includes:
[0071] The template generation submodule is used to determine the shadow area in the image, binarize the image according to the shadow area, and obtain a shadow template corresponding to the image, wherein the value of the shadow pixel in the shadow area of the shadow template is a first value, and the value of the non-shadow pixel in the non-shadow area is a second value.
[0072] According to another aspect of the present disclosure, a chip is provided, wherein the chip is used to implement the steps of the above method.
[0073] According to another aspect of the present disclosure, an image processing device is provided, including a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps of the above method.
[0074] According to another aspect of the present disclosure, a non-volatile computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the above method are implemented.
[0075] According to another aspect of the present disclosure, a computer program product is provided, including a computer program, or a non-volatile computer-readable storage medium carrying the computer program, wherein the computer program implements the steps of the above method when executed by a processor.
[0076] The image processing method and device provided by the embodiments of the present disclosure can generate a new image with directional soft shadows after processing an image with shadows after rendering, and the amount of calculation required to generate the directional soft shadows is small, and the method is applicable to various types of terminal devices. The soft shadows in the new image can be better integrated with the original shadows, which solves the boundary problem of the fusion of soft and hard shadows and the jagged problem of the shadow area in the related technology, making the soft shadows in the new image softer and more realistic, and the visual effect of the overall image smoother, more fluid, and more vivid. Moreover, the directionality of the soft shadows in the new image is controllable, which is closer to the directionality of soft shadows in the real physical world, and is applicable to the processing of images in various scenes.
[0077] Further features and aspects of the present disclosure will become apparent from the following detailed description of exemplary embodiments with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0078] The accompanying drawings, which are incorporated in and constitute a part of the specification, illustrate exemplary embodiments, features, and aspects of the disclosure and, together with the description, serve to explain the principles of the disclosure.
[0079] Figure 1 A flowchart of an image processing method according to an embodiment of the present disclosure is shown.
[0080] Figure 2 A flowchart of step S20 in the image processing method according to an embodiment of the present disclosure is shown.
[0081] Figure 3 A flowchart of step S30 in the image processing method according to an embodiment of the present disclosure is shown.
[0082] Figure 4 Another flow chart of step S30 in the image processing method according to an embodiment of the present disclosure is shown.
[0083] Figure 5 A schematic flowchart of an image processing method according to an embodiment of the present disclosure is shown.
[0084] Figure 6 is a block diagram of a device 1900 for image processing according to an exemplary embodiment. DETAILED DESCRIPTION
[0085] Various exemplary embodiments, features and aspects of the present disclosure will be described in detail below with reference to the accompanying drawings. The same reference numerals in the accompanying drawings represent elements with the same or similar functions. Although various aspects of the embodiments are shown in the accompanying drawings, the drawings are not necessarily drawn to scale unless otherwise specified.
[0086] As used herein, the terms "comprises," "including," "having," or variations thereof are open ended and include one or more stated features, integers, elements, steps, parts, or functions, but do not preclude the presence or addition of one or more other features, integers, elements, steps, parts, functions, or groups thereof.
[0087] When an element is referred to as being "connected," "coupled," "responsive," or variations thereof, to another element, it may be directly connected, coupled, or responsive to the other element or intervening elements may be present.
[0088] Although the terms original, second, third, etc. can be used to describe various elements / operations in this article, these elements / operations should not be limited by these terms. These terms are only used to distinguish one element / operation from another element / operation. Therefore, without departing from the teaching content of the present invention, the original element / operation in some embodiments can be referred to as the second element / operation in other embodiments.
[0089] The word “exemplary” is used exclusively herein to mean “serving as an example, example, or illustration.” Any embodiment described herein as “exemplary” is not necessarily to be construed as preferred or advantageous over other embodiments.
[0090] In addition, in order to better illustrate the present disclosure, numerous specific details are given in the following specific embodiments. It should be understood by those skilled in the art that the present disclosure can also be implemented without certain specific details. In some examples, methods, means, components and circuits well known to those skilled in the art are not described in detail in order to highlight the subject matter of the present disclosure.
[0091] Soft shadow technology can generate more realistic shadow images. However, in related technologies, the uniformly diffused shadow effect generated by soft shadow processing of 2D images is difficult to show the directional characteristics of soft shadows in the real physical world, and there will be obvious boundaries when soft and hard shadows merge, which seriously affects the final visual effect. Therefore, in order to make the overall visual effect of the shadow smoother and more vivid, it is necessary to generate directional soft shadows. However, due to the high performance requirements of the terminal device due to the large amount of calculation of the soft shadow rendering algorithm, in order to make the shadow effect rendered by the terminal device better, it is necessary to further reduce the amount of calculation for generating directional soft shadows, so that the terminal device can also generate directional soft shadows, thereby achieving the natural fusion of soft and hard shadows.
[0092] In response to the above problems, the embodiments of the present disclosure provide an image processing method and device, which can generate a new image with directional soft shadows after processing an image with shadows after rendering, and the amount of calculation required to generate the directional soft shadows is small, and the method is applicable to various types of terminal devices. The soft shadows in the new image can be better integrated with the original shadows, which solves the boundary problem of the fusion of soft and hard shadows and the jagged problem of the shadow area in the related technology, making the soft shadows in the new image softer and more realistic, and the overall image visual effect smoother, more fluid, and more vivid. Moreover, the directionality of the soft shadows in the new image is controllable, which is closer to the directionality of soft shadows in the real physical world, and is applicable to the processing of images in various scenes.
[0093] Figure 1 FIG. 1 is a flowchart of an image processing method according to an embodiment of the present disclosure. Figure 1 As shown, the method includes steps S10 to S30. The method can be applied to terminal devices, such as smart phones, tablet computers, laptop computers, virtual reality (VR) devices, augmented reality (AR) devices, etc., which have the resource requirements of the above-mentioned image processing method, and the present disclosure does not limit this.
[0094] Step S10, determining a shadow area in an image, and generating a shadow template corresponding to the image according to the shadow area.
[0095] In this embodiment, the above-mentioned image may be a 2D image and the image may be represented by an RGB color space. The 2D image may be an image that has been rendered, and the image includes shadows formed by hard shadow technology. In step S10, the shadow area where the shadow is located in the image may be determined by brightness analysis, color feature recognition and other methods, and then a shadow template representing the shadow area of the image is generated. Based on the shadow template, it can be determined which positions in the image are shadows and which positions are not shadows. Among them, the hard shadow technology is used to simulate the clear and sharp shadow edges formed when the light is blocked by an object, which can be achieved by shadow mapping, ray tracing and other methods, and the present disclosure does not limit this.
[0096] In a possible implementation, step S10 may include: determining a shadow area in an image, binarizing the image according to the shadow area, and obtaining a shadow template corresponding to the image. The shadow template may be used to mark whether each pixel in the image is a shadow pixel in a shadow area or a non-shadow pixel in a non-shadow area. In the shadow template, each position may respectively mark whether a corresponding pixel in the image belongs to a shadow pixel (or whether it belongs to a non-shadow pixel). The value of each position in the shadow template may be set as needed to distinguish between shadow pixels and non-shadow pixels, and the shadow pixels and non-shadow pixels may be set to a first value and a second value as needed. That is, in the shadow template, the first value of the shadow pixel in the shadow area may be set to x, and the second value of the non-shadow pixel in the non-shadow area may be set to y, so that a shadow template consisting of x and y may be obtained. Wherein, x≠y, x and y may be "0, 1", "0, 255", etc., respectively, and the present disclosure does not limit this.
[0097] Among them, the image can be converted into a shadow template containing only two values through binarization processing, which is convenient for subsequent further processing of the image. The image can be binarized by methods such as the global threshold method, and the present disclosure does not impose any restrictions on this.
[0098] Step S20: determining at least a directional weight coefficient corresponding to each non-shadow pixel in the image according to the shadow template.
[0099] In this embodiment, since a new image with directional soft shadows needs to be generated in the end, and the directional soft shadows are in the non-shadow area of the image, it is necessary to calculate the directional weight coefficient corresponding to each non-shadow pixel in the image in order to generate the new image. The directional weight coefficient of the pixel can be used to characterize the quantitative index of the shadow intensity or blur degree associated with the light source direction of the pixel in the shadow area. The smaller the directional weight coefficient, the closer the pixel (non-shadow pixel) is to the shadow area in the image. When generating directional soft shadows, the participation ratio of the shadow pixel in the shadow area of the image at the pixel is higher, so that the color of the pixel is closer to the color of the shadow pixel in the shadow area.
[0100] Step S30, generating a new image with directional soft shadows according to each of the directional weight coefficients, the edge information of the image and the image.
[0101] In this embodiment, in step S20, the directional weight coefficient corresponding to each pixel (including shadow pixels and non-shadow pixels) in the image can be calculated according to method 1, or the directional weight coefficient corresponding to each non-shadow pixel in the image can be calculated according to method 2, and then step S30 is performed. In view of the different implementation methods of step S20, the implementation process of "performing step S20 according to method 1 and then performing step S30" and the implementation process of "performing step S20 according to method 2 and then performing step S30" are schematically described below through implementation method 1 and implementation method 2.
[0102] Implementation method 1:
[0103] like Figure 2 As shown, step S20 may include steps S201 to S204.
[0104] Step S201, determining the shortest distance from each non-shadow pixel to the shadow area according to the shadow template, and determining the light source distance from each non-shadow pixel to the light source.
[0105] Among them, the shortest distance from each non-shadow pixel to the shadow area can be the shortest distance from the non-shadow pixel to the shadow area, and the shortest distance can be calculated by the distance from the non-shadow pixel to the shadow pixel in the nearest shadow area that is closest to the non-shadow pixel. The shortest distance can be calculated by distance transformation algorithms such as Euclidean Distance Transform (EDT) and Manhattan Distance Transform, and the present disclosure does not impose any restrictions on this.
[0106] Among them, the light source can be an approximate form of any type of light source in 2D space, such as a point light source, a parallel light source (such as a directional light), and the present disclosure does not limit this. In some embodiments, the calculation method of the light source distance may correspond to the type of the light source. For example, if the light source is a point light source, the light source distance from the non-shadow pixel to the light source can be the Euclidean distance between the non-shadow pixel and the light source; if the light source is a parallel light source, the light source distance from the non-shadow pixel to the light source can be the vertical distance or projection distance between the non-shadow pixel and the obstruction. The specific calculation method of the light source distance can be set accordingly according to the direction of the light source and the geometric shape of the obstruction, and the present disclosure does not limit this.
[0107] Step S202: determining the actual shadow area corresponding to each of the non-shadow pixels according to the light source distance and shadow area parameters corresponding to each of the non-shadow pixels.
[0108] In a possible implementation, the actual shadow area corresponding to each non-shadow pixel can be calculated by the following formula 1:
[0109] shadow_size ij =max_shadow_size ij ×ratio ij Formula 1
[0110] Among them, shadow_size ij The actual shadow area corresponding to the non-shadow pixel at position (i, j). max_shadow_size ij is the shadow area parameter corresponding to the non-shadow pixel at position (i, j), which may be a parameter representing the maximum shadow area of the corresponding non-shadow pixel, and is used to control the diffusion range of the shadow. The shadow area parameter corresponding to each non-shadow pixel may be determined based on the light source characteristics (the distance from the light source, the size and intensity of the light source, etc.), object characteristics (the characteristics of the object where the non-shadow pixel is located), scene complexity (the complexity of the scene in the image), and application requirements corresponding to the non-shadow pixel, and the present disclosure does not impose any restrictions on this. ratio ij is the scale factor corresponding to the non-shadow pixel at position (i, j) in the image. ij Used to control the diffusion range of the shadow, which is mainly determined by the distance from the position (i, j) of the non-shadow pixel to the corresponding light source, as well as the size of the light source. The value can be between 0 and 1. When the scale factor is closer to 1, shadow_size ij The larger the value, the larger the shadow diffusion range. The actual shadow area is shadow_size ij The closer the shadow area parameter max_shadow_size is, the ij On the contrary, when the scale factor is close to 0, shadow_size ij The smaller the shadow is, the smaller the shadow diffusion range is. The actual shadow area is shadow_size ij Approaches 0. With the help of the proportional factor ratio ij Adjustment can achieve precise control of the shadow diffusion range, thereby simulating the natural directional change effect of shadows under different light sources.
[0111] Step S203: determining a directional weight coefficient corresponding to each of the non-shadow pixels according to the shortest distance corresponding to each of the non-shadow pixels and the actual shadow area.
[0112] In a possible implementation, the directional weight coefficient corresponding to each non-shadow pixel may be calculated by the following formula 2:
[0113] Formula 2
[0114] Among them, distance_data ij The nearest distance to the non-shadow pixel at position (i, j). shadow_data ij is the directional weight coefficient corresponding to the non-shadow pixel at position (i, j). Among them, through the above calculation, the non-shadow pixel is Figure 5 shadow_data for pixels in the soft shadow area shown ij ∈(0,1), the non-shadow pixels are not in Figure 5 shadow_data for pixels in the soft shadow area shown ij =1.
[0115] Among them, by determining the directional weight coefficient corresponding to each non-shadow pixel, the nearest distance distance_data of each non-shadow pixel point can be ij By the actual shadow area shadow_size ij Normalize to provide directional weight coefficient shadow_data for shadow diffusion ij .in, The larger the shadow_size ij The larger the shadow_data ij The larger the range that can be normalized, the more non-shadow pixels will participate in the generation of soft shadows, thereby achieving directional diffusion. The value of the directional weight coefficient is between 0 and 1. The closer the directional weight coefficient is to 0, the smaller the directional intensity corresponding to the point, and the closer it is to 1, the greater the directional intensity corresponding to the point. The directional weight coefficient can be used to dynamically control the directional intensity of shadow diffusion to simulate the diffusion effect of shadows in the real world. Moreover, through normalization processing, it can be ensured that the shadow edge transition in the final generated new image is natural, avoiding obvious jagged or fault phenomena.
[0116] In a possible implementation, in a complex scene of an image, if the shadow in the image is formed based on multiple light sources, the directional weight coefficient can combine the influence of multiple light sources to generate a more realistic composite shadow effect. In multi-level image processing, the directional weight coefficient can also be dynamically adjusted based on the image resolution to ensure the consistency of shadow diffusion.
[0117] In step S204, the directional weight coefficient of each shadow pixel is set to 1 according to the shadow template. Since the directional soft shadow in the new image with directional soft shadow to be generated is not in the shadow area, the directional weight coefficient of each shadow pixel can be set to 1 in step S204 to protect the shadow area, which can ensure that the original content information of the shadow area in the subsequent step S30 is preserved and will not be lost.
[0118] like Figure 3 As shown, step S30 may include steps S301 to S306.
[0119] Step S301: convert the image from the RGB color space to the YUV color space to obtain the original Y component, the original U component and the original V component corresponding to each pixel in the image.
[0120] In a possible implementation, in the process of converting the image from the RGB color space to the YUV color space, the YUV component corresponding to each pixel can be obtained based on the RGB value of each pixel by the following formula 3-formula 5: Y 原ij =0.299R 原ij +0.587G 原ij +0.114B 原ij Formula 3 U 原ij =-0.14713R 原ij -0.28886G 原ij +0.436B 原ij +128 Formula 4 V 原ij =0.615R 原ij -0.51498G 原ij -0.10001B 原ij +128 Formula 5 Among them, Y 原ij , U 原ij 、V 原ij are the original Y component, original U component, and original V component corresponding to the pixel at position (i, j) in the image, respectively. 原ij , G 原ij , B 原ij It is the value of the R, G, and B channels corresponding to the pixel at position (i, j) in the image.
[0121] Among them, the RGB color space is an additive color model based on the three primary colors of light, R represents red, G represents green, and B represents blue. The YUV color space represents brightness (Y) and chroma (UV) separately. Y represents brightness information, which is used to represent the brightness of the image. U and V represent chroma information. U represents the difference between blue and brightness, and V represents the difference between red and brightness. Through the above conversion formula, image data in the RGB color space can be efficiently converted to brightness components and chroma components in the YUV color space, providing a more flexible and efficient data foundation for subsequent image processing and analysis.
[0122] Step S302, according to the directional weight coefficient corresponding to each pixel and the Y eigenvalue, U eigenvalue and V eigenvalue determined based on the shadow area, weighted processing is performed on the original Y component, original U component and original V component corresponding to each pixel, so as to obtain the weighted Y component, weighted U component and weighted V component corresponding to each pixel.
[0123] Among them, the Y eigenvalue (Y 特 ), U eigenvalue (U 特 ) and V characteristic value (V 特 ) is based on the statistical values corresponding to the components of all shadow pixels in the shadow area to characterize the characteristics of the pixels in the shadow area. Wherein, they can be set to the average values of the Y component, U component and V component of all shadow pixels in the shadow area, or they can be set to the mode of the Y component, U component and V component of all shadow pixels in the shadow area, which is not limited in the present disclosure.
[0124] In a possible implementation, the weighted Y component (Y 加权ij ), weighted U component (U 加权ij ) and the weighted V component (V 加权ij ), can be calculated by the following formula 6-formula 8: Y 加权ij =shadow_data ij ×Y 原ij + (1-shadow_data ij )×Y 特 Formula 6 U 加权ij =shadow_data ij ×U 原ij + (1-shadow_data ij )×U 特 Formula 7 V 加权ij =shadow_data ij ×V原ij + (1-shadow_data ij ) × V 特 Formula 8 Step S303: perform fuzzy processing on the original Y component and the weighted Y component respectively to obtain a first fuzzy Y component and a second fuzzy Y component.
[0125] The original Y component (Y 原ij ) and the weighted Y component (Y 加权ij ) are processed by edge-preserving blur to obtain the first blurred Y component (Y 模糊1-ij ) and the second blurred Y component (Y 模糊2-ij ).
[0126] Step S304: Obtain edge information corresponding to each pixel according to the original Y component corresponding to each pixel and the first blurred Y component.
[0127] The edge information may be a region in the image where pixel intensity (brightness or color) changes significantly. These changes usually correspond to the outline of an object, the boundary of a shape, or the dividing line between different objects.
[0128] In a possible implementation, the edge information corresponding to each pixel may be calculated using the following formula 9:
[0129] Among them, Y 模糊1-ij is the first fuzzy Y component corresponding to the pixel at position (i, j) in the image. The edge information Edge corresponding to the pixel at position (i, j) in the image is calculated by formula 9. ij Afterwards, the edge information of the directional soft shadow in the new image to be generated subsequently can be removed to ensure that the fusion boundary between the shadow area and the directional soft shadow in the new image finally generated can be eliminated (that is, the boundary problem of the fusion of soft and hard shadows is solved).
[0130] Step S305 , determining the target Y component corresponding to each pixel according to the second fuzzy Y component corresponding to each pixel, the edge information and the directional weight coefficient.
[0131] The target Y component (Y 目标ij ):
[0132] Among them, Y 目标ijY is the target Y component corresponding to the pixel at position (i, j). 模糊2-ij The second blurred Y component corresponding to the pixel at position (i, j) in the image. soft_shadow_mask ij is the mask value of the pixel at position (i, j) in the soft shadow mask soft_shadow_mask. The soft_shadow_mask is obtained based on the directional weight coefficient of each pixel and the shadow template. Since the directional weight coefficient of each pixel is between 0 and 1, and the directional weight coefficient for non-shadow pixels should change from 0 to 1 from the boundary of the shadow area to the outside, in order to distinguish between shadow areas and non-shadow areas, the values of each position of the soft shadow mask can be set to 0 or 1. In the soft shadow mask soft_shadow_mask, the original shadow pixel sets the mask value of the shadow pixel to 1 according to the shadow template; the mask value of the pixel with a directional weight coefficient less than 1 in the non-shadow pixel is set to 1; the mask value of the pixel with a directional weight coefficient equal to 1 in the non-shadow pixel is set to 0.
[0133] Step S306, converting from the YUV color space to the RGB color space according to the target Y component, the weighted U component and the weighted V component corresponding to each pixel, to obtain a new image with directional soft shadows.
[0134] Among them, it can be based on the target Y component Y 目标ij , weighted U component U 加权ij and weighted V component V 加权ij The conversion is performed according to the following formula 11 to formula 13 to obtain the RGB channel value of the pixel at each position in the new image. The formed new image includes a directional soft shadow around the original shadow area.
[0135]
[0136] Among them, R 新ij , G 新ij , B 新ij They respectively represent the R channel value, G channel value, and B channel value of the pixel at position (i, j) in the new image.
[0137] Implementation method 2: Step S20 may include: determining the closest distance from each non-shadow pixel to the shadow area according to the shadow template, and determining the light source distance from each non-shadow pixel to the light source; determining the actual shadow area corresponding to each non-shadow pixel according to the light source distance and shadow area parameter corresponding to each non-shadow pixel; determining the directional weight coefficient corresponding to each non-shadow pixel according to the closest distance and the actual shadow area corresponding to each non-shadow pixel. The implementation of step S20 may refer to steps S201 to S203 above, and will not be described in detail to avoid redundancy.
[0138] Then based on the implementation of the above step S20, Figure 4 As shown, step S30 may include steps S401 to S407.
[0139] Step S401, converting the non-shadow pixels of the image from the RGB color space to the YUV color space, and obtaining the original Y component, the original U component and the original V component corresponding to each of the non-shadow pixels.
[0140] Step S402, according to the directional weight coefficient corresponding to each of the non-shadow pixels and the Y eigenvalue, U eigenvalue and V eigenvalue determined based on the shadow area, weighted processing is performed on the original Y component, original U component and original V component corresponding to each of the non-shadow pixels, so as to obtain the weighted Y component, weighted U component and weighted V component corresponding to each of the non-shadow pixels.
[0141] Step S403: perform fuzzy processing on the original Y component and the weighted Y component respectively to obtain a first fuzzy Y component and a second fuzzy Y component.
[0142] Step S404: Obtain edge information corresponding to each of the non-shadow pixels according to the original Y component corresponding to each of the non-shadow pixels and the first blurred Y component.
[0143] Step S405 , determining a target Y component corresponding to each of the non-shadow pixels according to the second fuzzy Y component corresponding to each of the non-shadow pixels, the edge information and the directional weight coefficient.
[0144] Among them, step S401 to step S405 can refer to the implementation method of the above step S301 to step S305, and will not be described in detail to avoid redundancy.
[0145] Step S406, converting from the YUV color space to the RGB color space according to the target Y component, the weighted U component and the weighted V component corresponding to each of the non-shadow pixels, to obtain a new non-shadow area of the image with directional soft shadows. The conversion method is as described in step S306 above, which will not be described in detail to avoid redundancy.
[0146] Step S407: forming a new image with directional soft shadows according to the new non-shadow area and the shadow area. In this way, the new non-shadow area and the shadow area are spliced to obtain a new image with directional soft shadows.
[0147] Thus, through the above implementation method 1 and implementation method 2, as Figure 5 As shown, a new image with directional soft shadows can be generated based on an image that originally includes shadow areas generated by a hard shadow technique.
[0148] The present disclosure also provides an image processing device, the device comprising: A shadow template generation module, used to determine the shadow area in the image and generate a shadow template corresponding to the image according to the shadow area; A weight coefficient generating module, used to determine at least a directional weight coefficient corresponding to each non-shadow pixel in the image according to the shadow template; The image generation module is used to generate a new image with directional soft shadows according to each of the directional weight coefficients, the edge information of the image and the image.
[0149] In a possible implementation, the weight coefficient generating module includes: A first distance calculation submodule, used for determining the shortest distance from each non-shadow pixel to the shadow area according to the shadow template, and determining the light source distance from each non-shadow pixel to the light source; A first area determination submodule, configured to determine an actual shadow area corresponding to each of the non-shadow pixels according to the light source distance and shadow area parameters corresponding to each of the non-shadow pixels; A first coefficient determination submodule, configured to determine a directional weight coefficient corresponding to each of the non-shadow pixels according to the nearest distance corresponding to each of the non-shadow pixels and the actual shadow area; The second coefficient determination submodule is used to set the directional weight coefficient of each shadow pixel to 1 according to the shadow template.
[0150] In a possible implementation, the image generation module includes: A first component determination submodule is used to convert the image from the RGB color space to the YUV color space to obtain the original Y component, the original U component and the original V component corresponding to each pixel in the image; A first weighted submodule is used to perform weighted processing on the original Y component, the original U component and the original V component corresponding to each pixel according to the directional weight coefficient corresponding to each pixel and the Y eigenvalue, the U eigenvalue and the V eigenvalue determined based on the shadow area, so as to obtain the weighted Y component, the weighted U component and the weighted V component corresponding to each pixel; A first fuzzy processing submodule, used for performing fuzzy processing on the original Y component and the weighted Y component respectively to obtain a first fuzzy Y component and a second fuzzy Y component; A first edge information determination submodule, used for obtaining edge information corresponding to each pixel according to the original Y component corresponding to each pixel and the first blurred Y component; A first component calculation submodule, configured to determine a target Y component corresponding to each pixel according to the second fuzzy Y component corresponding to each pixel, the edge information and the directional weight coefficient; The first image generation submodule is used to convert from the YUV color space to the RGB color space according to the target Y component, the weighted U component and the weighted V component corresponding to each pixel, so as to obtain a new image with directional soft shadows.
[0151] In a possible implementation manner, determining the target Y component corresponding to each pixel according to the second fuzzy Y component corresponding to each pixel, the edge information, and the directional weight coefficient includes: Determining a soft shadow mask corresponding to each pixel according to a directional weight coefficient corresponding to each pixel; The target Y component corresponding to each pixel is determined according to the second fuzzy Y component corresponding to each pixel, the edge information and the soft shadow mask.
[0152] In a possible implementation, the weight coefficient generating module includes: A second distance calculation submodule, used to determine the shortest distance from each of the non-shadow pixels to the shadow area according to the shadow template, and to determine the light source distance from each of the non-shadow pixels to the light source; A second area determination submodule, configured to determine an actual shadow area corresponding to each of the non-shadow pixels according to the light source distance and shadow area parameters corresponding to each of the non-shadow pixels; The third coefficient determination submodule is used to determine the directional weight coefficient corresponding to each of the non-shadow pixels according to the nearest distance corresponding to each of the non-shadow pixels and the actual shadow area.
[0153] In a possible implementation, the image generation module includes: A second component determination submodule is used to convert the non-shadow pixels of the image from the RGB color space to the YUV color space to obtain the original Y component, the original U component and the original V component corresponding to each of the non-shadow pixels; A second weighted submodule is used to perform weighted processing on the original Y component, original U component and original V component corresponding to each of the non-shadow pixels according to the directional weight coefficient corresponding to each of the non-shadow pixels and the Y eigenvalue, U eigenvalue and V eigenvalue determined based on the shadow area, so as to obtain the weighted Y component, weighted U component and weighted V component corresponding to each of the non-shadow pixels; A second fuzzy processing submodule is used to perform fuzzy processing on the original Y component and the weighted Y component respectively to obtain a first fuzzy Y component and a second fuzzy Y component; A second edge information determination submodule, configured to obtain edge information corresponding to each of the non-shadow pixels according to the original Y component corresponding to each of the non-shadow pixels and the first fuzzy Y component; A second component calculation submodule, used to determine the target Y component corresponding to each of the non-shadow pixels according to the second fuzzy Y component corresponding to each of the non-shadow pixels, the edge information and the directional weight coefficient; A region generation submodule, used for converting from the YUV color space to the RGB color space according to the target Y component, the weighted U component and the weighted V component corresponding to each of the non-shadow pixels, to obtain a new non-shadow region of the image with a directional soft shadow; The second image generation submodule is used to form a new image with directional soft shadows according to the new non-shadow area and the shadow area.
[0154] In a possible implementation, the shadow template generating module includes: The template generation submodule is used to determine the shadow area in the image, binarize the image according to the shadow area, and obtain a shadow template corresponding to the image, wherein the value of the shadow pixel in the shadow area of the shadow template is a first value, and the value of the non-shadow pixel in the non-shadow area is a second value.
[0155] In some embodiments, the functions or modules included in the device provided by the embodiments of the present disclosure can be used to execute the method described in the above method embodiments. The specific implementation can refer to the description of the above method embodiments, and for the sake of brevity, it will not be repeated here.
[0156] It should be noted that although the above embodiments are used as examples to introduce the image processing method and device, those skilled in the art will appreciate that the present disclosure should not be limited thereto. In fact, users can flexibly set each step and module according to personal preferences and / or actual application scenarios, as long as the technical solution of the present disclosure is sufficient.
[0157] The embodiment of the present disclosure further provides an image processing device, including a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps of the above method.
[0158] The embodiment of the present disclosure also provides a chip, which is used to implement the steps of the above method. In some embodiments, the chip can be an integrated circuit chip, including but not limited to a central processing unit (CPU), a graphics processing unit (GPU), a main processor (AP, Application Processor) in terminal devices such as mobile phones, a field-programmable gate array (FPGA) with related similar functions, an application-specific integrated circuit (ASIC), and other chips, which are not limited by the present disclosure.
[0159] The embodiment of the present disclosure further provides a non-volatile computer-readable storage medium having a computer program stored thereon, and the computer program implements the steps of the above method when executed by a processor.
[0160] The embodiments of the present disclosure further provide a computer program product, including a computer program, or a non-volatile computer-readable storage medium carrying the computer program, wherein the steps of the above method are implemented when the computer program is executed by a processor.
[0161] Figure 6 1 is a block diagram of an apparatus 1900 for image processing according to an exemplary embodiment. For example, the apparatus 1900 may be provided as a terminal device. Figure 6 , the apparatus 1900 includes a processing component 1922, which further includes one or more processors, and a memory resource represented by a memory 1932 for storing instructions, such as an application, that can be executed by the processing component 1922. The application stored in the memory 1932 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 1922 is configured to execute instructions to perform the above method.
[0162] The device 1900 may also include a power supply component 1926 configured to perform power management of the device 1900, a wired or wireless network interface 1950 configured to connect the device 1900 to a network, and an input / output interface 1958 (I / O interface). The device 1900 may operate based on an operating system stored in the memory 1932, such as Windows Server 2000. TM , MacOS X TM , Unix TM , Linux TM , FreeBSD TM or similar.
[0163] In an exemplary embodiment, a non-volatile computer-readable storage medium is also provided, such as a memory 1932 including computer program instructions, which can be executed by the processing component 1922 of the device 1900 to perform the above method.
[0164] A computer-readable storage medium may be a tangible device that can hold and store programs / instructions used by an instruction execution device. A computer-readable storage medium may be, for example, but not limited to, an electrical storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination of the above. More specific examples (a non-exhaustive list) of computer-readable storage media include: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a static random access memory (SRAM), a portable compact disk read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, such as a punch card or a raised structure in a groove on which instructions are stored, and any suitable combination of the above. The computer-readable storage medium used herein is not to be interpreted as a transient signal itself, such as a radio wave or other freely propagating electromagnetic wave, an electromagnetic wave propagating through a waveguide or other transmission medium (e.g., a light pulse through a fiber optic cable), or an electrical signal transmitted through a wire.
[0165] The computer program (or computer-readable program instructions) described herein can be downloaded from a computer-readable storage medium to each computing / processing device, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network may include copper transmission cables, optical fiber transmission, wireless transmission, routers, firewalls, switches, gateway computers, and / or edge servers. The network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in the computer-readable storage medium in each computing / processing device.
[0166] The computer program (or computer program instructions) used to perform the operation of the present disclosure may be an assembly instruction, an instruction set architecture (ISA) instruction, a machine instruction, a machine-dependent instruction, a microcode, a firmware instruction, a state setting data, or a source code or an object code written in any combination of one or more programming languages, including object-oriented programming languages, such as Smalltalk, C++, etc., and conventional procedural programming languages, such as "C" language or similar programming languages. The computer-readable program instructions may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer, partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., using an Internet service provider to connect through the Internet). In some embodiments, by using the state information of the computer-readable program instructions to personalize an electronic circuit, such as a programmable logic circuit, a field programmable gate array (FPGA), or a programmable logic array (PLA), the electronic circuit may execute the computer-readable program instructions, thereby implementing various aspects of the present disclosure.
[0167] Various aspects of the present disclosure are described herein with reference to flowcharts and / or block diagrams of methods, devices (systems) and computer program products according to embodiments of the present disclosure. It should be understood that each box in the flowchart and / or block diagram and the combination of boxes in the flowchart and / or block diagram can be implemented by computer-readable program instructions.
[0168] These computer-readable program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, thereby producing a machine, so that when these instructions are executed by the processor of the computer or other programmable data processing device, a device that implements the functions / actions specified in one or more boxes in the flowchart and / or block diagram is generated. These computer-readable program instructions can also be stored in a computer-readable storage medium, and these instructions cause the computer, programmable data processing device, and / or other equipment to work in a specific manner, so that the computer-readable medium storing the instructions includes a manufactured product, which includes instructions for implementing various aspects of the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0169] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device so that a series of operating steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to implement the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0170] The flow chart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system, method and computer program product according to multiple embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a part of a module, program segment or instruction, and a part of the module, program segment or instruction includes one or more executable instructions for realizing the specified logical function. In some alternative implementations, the function marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two continuous square boxes can actually be executed substantially in parallel, and they can sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs the specified function or action, or can be implemented with a combination of special hardware and computer instructions.
[0171] The embodiments of the present disclosure have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The selection of terms used herein is intended to best explain the principles of the embodiments, practical applications, or technical improvements in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.
Claims
1. An image processing method, characterized in that: The method comprises: Determine a shadow area in the image, and generate a shadow template corresponding to the image according to the shadow area; Determine at least a directional weight coefficient corresponding to each non-shadow pixel in the image according to the shadow template; A new image with directional soft shadows is generated according to each of the directional weight coefficients, the edge information of the image and the image.
2. The method according to claim 1, characterized in that The step of at least determining a directional weight coefficient corresponding to each non-shadow pixel in the image according to the shadow template comprises: Determine the shortest distance from each non-shadow pixel to the shadow area according to the shadow template, and determine the light source distance from each non-shadow pixel to the light source; Determine the actual shadow area corresponding to each of the non-shadow pixels according to the light source distance and shadow area parameters corresponding to each of the non-shadow pixels; Determine a directional weight coefficient corresponding to each of the non-shadow pixels according to the nearest distance corresponding to each of the non-shadow pixels and the actual shadow area; The directional weight coefficient of each shadow pixel is set to 1 according to the shadow template.
3. The method according to claim 2, characterized in that Generating a new image with directional soft shadows according to each of the directional weight coefficients, the edge information of the image and the image, including: Convert the image from the RGB color space to the YUV color space to obtain the original Y component, the original U component and the original V component corresponding to each pixel in the image; According to the directional weight coefficient corresponding to each pixel and the Y eigenvalue, U eigenvalue and V eigenvalue determined based on the shadow area, weighted processing is performed on the original Y component, original U component and original V component corresponding to each pixel to obtain a weighted Y component, weighted U component and weighted V component corresponding to each pixel; Performing fuzzy processing on the original Y component and the weighted Y component respectively to obtain a first fuzzy Y component and a second fuzzy Y component; Obtain edge information corresponding to each pixel according to the original Y component corresponding to each pixel and the first blurred Y component; Determining a target Y component corresponding to each pixel according to the second fuzzy Y component corresponding to each pixel, the edge information and the directional weight coefficient; A conversion is performed from the YUV color space to the RGB color space according to the target Y component, the weighted U component and the weighted V component corresponding to each of the pixels, so as to obtain a new image with directional soft shadows.
4. The method according to claim 3, characterized in that Determining a target Y component corresponding to each pixel according to the second fuzzy Y component corresponding to each pixel, the edge information, and the directional weight coefficient, including: Determining a soft shadow mask corresponding to each pixel according to a directional weight coefficient corresponding to each pixel; The target Y component corresponding to each pixel is determined according to the second fuzzy Y component corresponding to each pixel, the edge information and the soft shadow mask.
5. The method according to claim 1, characterized in that The step of at least determining a directional weight coefficient corresponding to each non-shadow pixel in the image according to the shadow template comprises: Determine the shortest distance from each of the non-shadow pixels to the shadow area according to the shadow template, and determine the light source distance from each of the non-shadow pixels to the light source; Determine the actual shadow area corresponding to each of the non-shadow pixels according to the light source distance and shadow area parameters corresponding to each of the non-shadow pixels; The directional weight coefficient corresponding to each of the non-shadow pixels is determined according to the nearest distance corresponding to each of the non-shadow pixels and the actual shadow area.
6. The method according to claim 5, characterized in that Generating a new image with directional soft shadows according to each of the directional weight coefficients, the edge information of the image and the image, including: Convert the non-shadow pixels of the image from the RGB color space to the YUV color space to obtain the original Y component, the original U component and the original V component corresponding to each of the non-shadow pixels; According to the directional weight coefficient corresponding to each of the non-shadow pixels and the Y eigenvalue, U eigenvalue and V eigenvalue determined based on the shadow area, weighted processing is performed on the original Y component, original U component and original V component corresponding to each of the non-shadow pixels to obtain a weighted Y component, weighted U component and weighted V component corresponding to each of the non-shadow pixels; Performing fuzzy processing on the original Y component and the weighted Y component respectively to obtain a first fuzzy Y component and a second fuzzy Y component; Obtain edge information corresponding to each of the non-shadow pixels according to the original Y component corresponding to each of the non-shadow pixels and the first blurred Y component; Determining a target Y component corresponding to each of the non-shadow pixels according to the second fuzzy Y component corresponding to each of the non-shadow pixels, the edge information, and the directional weight coefficient; Converting from the YUV color space to the RGB color space according to the target Y component, the weighted U component, and the weighted V component corresponding to each of the non-shadow pixels to obtain a new non-shadow area of the image with a directional soft shadow; A new image with directional soft shadows is formed according to the new non-shadow area and the shadow area.
7. The method according to claim 1, characterized in that Determining a shadow area in an image and generating a shadow template corresponding to the image according to the shadow area includes: A shadow area in an image is determined, and the image is binarized according to the shadow area to obtain a shadow template corresponding to the image, wherein the value of the shadow pixel in the shadow area of the shadow template is a first value, and the value of the non-shadow pixel in the non-shadow area is a second value.
8. An image processing device, characterized in that: The device includes: A shadow template generation module, used to determine the shadow area in the image, and generate a shadow template corresponding to the image according to the shadow area; A weight coefficient generating module, used to determine at least a directional weight coefficient corresponding to each non-shadow pixel in the image according to the shadow template; The image generation module is used to generate a new image with directional soft shadows according to each of the directional weight coefficients, the edge information of the image and the image.
9. An image processing device, comprising a memory, a processor and a computer program stored in the memory, characterized in that: The processor executes the computer program to implement the steps of the method according to any one of claims 1 to 7.
10. A non-volatile computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
11. A chip, characterized in that: The chip is used to implement the method described in any one of claims 1 to 7.
Citation Information
Patent Citations
Real-time soft shadow rendering method for point light sources
CN102768765A
Method and device for treating shadow in video image
CN103971347A
Real-time soft shadow realization method based on image screen space
CN104103089A
Method for approximately drawing soft shadow of three-dimensional scene
CN104346831A
Direct3D 11-based 3D graphics rendering engine
CN106056661A