An image processing method and apparatus

By determining the shadow area and template on the terminal device, calculating the directional weight coefficient of non-shading pixels, and generating directional soft shadows with edge information, the soft and hard shadow fusion boundary and jagging problems are solved, and efficient soft shadow rendering with small calculations is achieved.

CN120031773BActive Publication Date: 2025-07-22CHIPONE TECHNOLOGY (BEIJING) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510510925.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-04-23
Publication Date
2025-07-22
Estimated Expiration
2045-04-23

AI Technical Summary

Technical Problem

The prior art is difficult to generate directional soft shadows on terminal devices, resulting in obvious boundary and jagging problems when soft and hard shadows are fusion, and the soft shadow rendering algorithm is computationally large and consumes too much resources.

Method used

By determining the shadowed area and shadow template in the image, the directional weight coefficient of non-shaded pixels is calculated, and a new image with directional soft shadow is generated based on edge information, and YUV color space conversion and weighting are used to reduce the calculation amount.

Benefits of technology

The soft shadows and the original shadows in the generated new image are better blended, with stronger softness and reality, and the overall visual effect is smoother and smoother, suitable for various terminal devices.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120031773B_ABST
    Figure CN120031773B_ABST
Patent Text Reader

Abstract

The present disclosure relates to the field of display technologies, and particularly to an image processing method and apparatus. The method includes: determining a shadow area in an image, and generating a shadow template corresponding to the image according to the shadow area; determining at least a directional weight coefficient corresponding to each non-shadow pixel in the image according to the shadow template; generating a new image with directional soft shadows according to the respective directional weight coefficients, edge information of the image, and the image. The amount of calculation is small and it is applicable to various types of terminal devices. The soft shadows in the new image can be better fused with the original shadows, solving the boundary problem of the fusion of hard and soft shadows and the jagged problem in the shadow area in the related art, making the soft shadows in the new image more soft and realistic, and the visual effect of the overall image smoother, more fluent, and more vivid. Moreover, the directionality of the soft shadows in the new image is controllable and is closer to the directionality of the soft shadows in the real physical world, and is applicable to the processing of images in various scenarios.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of display technologies, and in particular, to an image processing method and apparatus. Background Art

[0002] Soft shadow technology is a technology in computer graphics used to simulate the shadow effect in the real world. By calculating the light source, object shape, and material, it simulates the penumbra effect generated when light passes through the edge of an object. Compared with traditional hard shadows, soft shadow technology can more delicately simulate the gradual diffusion phenomenon generated in the surrounding environment after light is blocked by an object, generating a shadow image with strong realism. This technology is widely used in fields such as movie special effects, game rendering, and VR / AR, which can significantly enhance the immersion and vividness of visual scenes and is one of the important technologies to enhance the realism of computer graphics.

[0003] In related technologies, the common soft shadow processing of 2D images is achieved through methods such as the box-shadow property algorithm in CSS (Cascading Style Sheets), but the generated shadow effect is uniformly diffused, making it difficult to display the directional characteristics of soft shadows in the real physical world, resulting in the processed shadows still lacking realism. Moreover, soft shadow diffusion for 2D images usually requires a shadow template, and errors in template segmentation will cause obvious boundaries when soft and hard shadows are fused, seriously affecting the final visual effect.

[0004] In addition, due to the complex operation and huge resource consumption of soft shadow rendering algorithms, using them on terminal devices requires the terminal devices to have high performance. Limited by the performance of terminal devices, related technologies mostly adopt hard shadow rendering methods with low resource consumption in terminal devices. Therefore, how to enable terminal devices to also flexibly generate directional soft shadows, naturally fuse soft and hard shadows, and make the overall visual effect of shadows smoother and more vivid is an urgent problem to be solved currently. Summary of the Invention

[0005] In view of this, the present disclosure provides an image processing method and apparatus.

[0006] According to one aspect of the present disclosure, an image processing method is provided, and the method includes:

[0007] Determine the shadow area in the image, and generate a shadow template corresponding to the image according to the shadow area;

[0008] Determine at least the directional weight coefficient corresponding to each non-shadow pixel in the image according to the shadow template;

[0009] Generate a new image with directional soft shadows based on each of the directional weight coefficients, the edge information of the image, and the image.

[0010] In a possible implementation, the determining the 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 non-shadow pixel according to the light source distance and the shadow area parameter corresponding to each non-shadow pixel;

[0013] Determine the directional weight coefficient corresponding to each non-shadow pixel according to the shortest distance and the actual shadow area corresponding to each non-shadow pixel;

[0014] Set the directional weight coefficient of each shadow pixel to 1 according to the shadow template.

[0015] In a possible implementation, generating a new image with directional soft shadows based on 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, original U component, and original V component corresponding to each pixel in the image;

[0017] Perform weighted processing on the original Y component, original U component, and original V component corresponding to each pixel respectively 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 to obtain the weighted Y component, weighted U component, and weighted V component corresponding to each pixel;

[0018] Perform blur processing on the original Y component and the weighted Y component respectively to obtain a first blurred Y component and a second blurred Y component;

[0019] Obtain the edge information corresponding to each pixel according to the original Y component and the first blurred Y component corresponding to each pixel;

[0020] Determine the target Y component corresponding to each pixel according to the second blurred Y component, the edge information, and the directional weight coefficient corresponding to each pixel;

[0021] Perform the conversion from the YUV color space to the RGB color space based on the target Y component, weighted U component, and weighted V component corresponding to each pixel to obtain a new image with directional soft shadows.

[0022] In a possible implementation, determining the target Y component corresponding to each pixel according to the second blurred Y component, the edge information, and the directional weight coefficient corresponding to each pixel includes:

[0023] Determine the soft shadow mask corresponding to each pixel according to the directional weight coefficient corresponding to each pixel;

[0024] Determine the target Y component corresponding to each pixel according to the second blurred Y component, the edge information, and the soft shadow mask corresponding to each pixel.

[0025] In a possible implementation, the determining at least the directional weight coefficient corresponding to each non-shadow pixel in the image according to the shadow template includes:

[0026] Determine the closest 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;

[0027] Determine the actual shadow area corresponding to each non-shadow pixel according to the light source distance and the shadow area parameter corresponding to each non-shadow pixel;

[0028] Determine 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.

[0029] In a possible implementation, generating a new image with directional soft shadows according to each directional weight coefficient, 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, original U component, and original V component corresponding to each non-shadow pixel;

[0031] Perform weighted processing on the original Y component, original U component, and original V component corresponding to each non-shadow pixel respectively according to the directional weight coefficient corresponding to each non-shadow pixel and the Y eigenvalue, U eigenvalue, and V eigenvalue determined based on the shadow area to obtain the weighted Y component, weighted U component, and weighted V component corresponding to each non-shadow pixel;

[0032] Perform blurred processing on the original Y component and the weighted Y component respectively to obtain the first blurred Y component and the second blurred Y component;

[0033] Obtain the edge information corresponding to each non - shadow pixel based on the original Y component and the first blurred Y component corresponding to each non - shadow pixel;

[0034] Determine the target Y component corresponding to each non - shadow pixel according to the second blurred Y component, the edge information, and the directional weight coefficient corresponding to each non - shadow pixel;

[0035] Perform a conversion 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 non - shadow pixel, to obtain the new non - shadow area of the image with directional soft shadows;

[0036] Form a new image with directional soft shadows according to the new non - shadow area and the shadow area.

[0037] In a possible implementation manner, determining the shadow area in the image and generating a shadow template corresponding to the image includes:

[0038] Determine the shadow area in the image, perform binarization processing on the image according to the shadow area, to obtain the shadow template corresponding to the image, where the value of the shadow pixels in the shadow area of the shadow template is the first value, and the value of the non - shadow pixels in the non - shadow area is the 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 area in the image and generate a shadow template corresponding to the image according to the shadow area;

[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 directional weight coefficient, 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 area according to the shadow template, and determine the light source distance from each non - shadow pixel to the light source;

[0045] The first area determination sub-module is configured to determine the actual shadow area corresponding to each non-shadow pixel according to the light source distance and the shadow area parameter corresponding to each non-shadow pixel;

[0046] The first coefficient determination sub-module is configured to determine the directional weight coefficient corresponding to each non-shadow pixel according to the nearest distance and the actual shadow area corresponding to each non-shadow pixel;

[0047] The second coefficient determination sub-module is configured to set the directional weight coefficient of each shadow pixel to 1 according to the shadow template.

[0048] In a possible implementation manner, the image generation module includes:

[0049] The first component determination sub-module is configured 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] The first weighting sub-module is configured to perform weighted processing on the original Y component, the original U component, and the original V component corresponding to each pixel respectively 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, to obtain the weighted Y component, the weighted U component, and the weighted V component corresponding to each pixel;

[0051] The first blur processing sub-module is configured to perform blur processing on the original Y component and the weighted Y component respectively to obtain the first blurred Y component and the second blurred Y component;

[0052] The first edge information determination sub-module is configured to obtain the edge information corresponding to each pixel according to the original Y component and the first blurred Y component corresponding to each pixel;

[0053] The first component calculation sub-module is configured to determine the target Y component corresponding to each pixel according to the second blurred Y component, the edge information, and the directional weight coefficient corresponding to each pixel;

[0054] The first image generation sub-module is configured to perform conversion 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.

[0055] In a possible implementation manner, determining the target Y component corresponding to each pixel according to the second blurred Y component, the edge information, and the directional weight coefficient corresponding to each pixel includes:

[0056] Determine the soft shadow mask corresponding to each pixel according to the directional weight coefficient corresponding to each pixel;

[0057] Determine the target Y component corresponding to each pixel according to the second blurred Y component, the edge information, and the soft shadow mask corresponding to each pixel.

[0058] In a possible implementation, the weight coefficient generation module includes:

[0059] The second distance calculation sub-module is used to determine the closest 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;

[0060] The second area determination sub-module is used to determine the actual shadow area corresponding to each non-shadow pixel according to the light source distance and the shadow area parameter corresponding to each non-shadow pixel;

[0061] The third coefficient determination sub-module is used to determine 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.

[0062] In a possible implementation, the image generation module includes:

[0063] The second component determination sub-module 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 non-shadow pixel;

[0064] The second weighting sub-module is used to perform weighting processing on the original Y component, the original U component, and the original V component corresponding to each non-shadow pixel respectively according to the directional weight coefficient corresponding to each non-shadow pixel and the Y eigenvalue, the U eigenvalue, and the V eigenvalue determined based on the shadow area, to obtain the weighted Y component, the weighted U component, and the weighted V component corresponding to each non-shadow pixel;

[0065] The second blur processing sub-module is used to perform blur processing on the original Y component and the weighted Y component respectively to obtain the first blurred Y component and the second blurred Y component;

[0066] The second edge information determination sub-module is used to obtain the edge information corresponding to each non-shadow pixel according to the original Y component and the first blurred Y component corresponding to each non-shadow pixel;

[0067] A second component calculation sub-module, configured to determine a target Y component corresponding to each non-shadow pixel according to the second blurred Y component, the edge information, and the directional weight coefficient corresponding to each non-shadow pixel;

[0068] A region generation sub-module, configured to perform a conversion 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 non-shadow pixel, to obtain a new non-shadow region of the image with directional soft shadows;

[0069] A second image generation sub-module, configured to form a new image with directional soft shadows according to the new non-shadow region and the shadow region.

[0070] In a possible implementation manner, the shadow template generation module includes:

[0071] A template generation sub-module, configured to determine a shadow region in the image, perform binarization processing on the image according to the shadow region, to obtain a shadow template corresponding to the image, where the value of the shadow pixel in the shadow region of the shadow template is a first value, and the value of the non-shadow pixel in the non-shadow region is a second value.

[0072] According to another aspect of the present disclosure, there is provided a chip, which is configured to implement the steps of the above method.

[0073] According to another aspect of the present disclosure, there is provided an image processing device, including a memory, a processor, and a computer program stored on the memory, where the processor executes the computer program to implement the steps of the above method.

[0074] According to another aspect of the present disclosure, there is provided a non-volatile computer-readable storage medium, 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, there is provided a computer program product, including a computer program, or a non-volatile computer-readable storage medium carrying the computer program, and when the computer program is executed by a processor, the steps of the above method are implemented.

[0076] The image processing method and apparatus 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 calculation amount for generating the directional soft shadows is small, which is applicable to various types of terminal devices. The soft shadows in the new image can be better integrated with the original shadows, solving the boundary problem of the fusion of hard and soft shadows and the jagged problem in the shadow area in the related art, making the soft shadows in the new image softer and more realistic, and the visual effect of the overall image smoother, more fluent, and more vivid. Moreover, the directionality of the soft shadows in the new image is controllable, which is closer to the directionality of the soft shadows in the real physical world and is applicable to the processing of images in various scenarios.

[0077] Other features and aspects of the present disclosure will become clear from the following detailed description of the exemplary embodiments with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0078] The accompanying drawings, which are included in and constitute a part of this specification, illustrate exemplary embodiments, features, and aspects of the present disclosure together with the specification and are used to explain the principles of the present disclosure.

[0079] Figure 1 The flowchart showing the image processing method according to an embodiment of the present disclosure.

[0080] Figure 2 The flowchart showing step S20 in the image processing method according to an embodiment of the present disclosure.

[0081] Figure 3 The flowchart showing step S30 in the image processing method according to an embodiment of the present disclosure.

[0082] Figure 4 Another flowchart showing step S30 in the image processing method according to an embodiment of the present disclosure.

[0083] Figure 5 The schematic flowchart showing the image processing method according to an embodiment of the present disclosure.

[0084] Figure 6 The block diagram showing an apparatus 1900 for image processing according to an exemplary embodiment. DETAILED DESCRIPTION OF THE EMBODIMENTS

[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 drawings denote elements having the same or similar functions. Although various aspects of the embodiments are shown in the drawings, the drawings are not necessarily drawn to scale unless otherwise specified.

[0086] As used herein, the terms "comprising," "including," "having," or variations thereof are open-ended and include one or more stated features, integers, elements, steps, components, or functions, but do not preclude the presence or addition of one or more other features, integers, elements, steps, components, functions, or groups thereof.

[0087] When an element is referred to as being "connected," "coupled," "responsive," or variations thereof to another element, it can be directly connected, coupled, or responsive to the other element, or intervening elements may be present.

[0088] Although the terms first, second, third, etc. may be used herein to describe various elements / operations, these elements / operations should not be limited by these terms. These terms are only used to distinguish one element / operation from another. Thus, without departing from the teachings of the inventive concept, a first element / operation in some embodiments may be referred to as a second element / operation in other embodiments.

[0089] As used herein, the word "exemplary" means "serving as an example, instance, or illustration." Any embodiment so described herein as "exemplary" need not be construed as superior or better than other embodiments.

[0090] In addition, for a better illustration of the present disclosure, numerous specific details are given in the following detailed description. Those skilled in the art should understand that the present disclosure can be implemented without some of these specific details. In some instances, methods, means, elements, and circuits well known to those skilled in the art are not described in detail so as to highlight the gist of the present disclosure.

[0091] Soft shadow technology can generate more realistic shadow images. In the related art, the uniformly diffused shadow effect generated after soft shadow processing of 2D images is difficult to show the directional characteristics of soft shadows in the real physical world, and obvious boundaries will appear when soft and hard shadows are fused, seriously affecting the final visual effect. Therefore, to make the overall visual effect of the shadow smoother and more vivid, it is necessary to generate directional soft shadows. Since the soft shadow rendering algorithm has a large amount of computation and high requirements for the performance of the terminal device, in order to make the shadow effect rendered by the terminal device better, it is necessary to further reduce the computation amount of 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 view of the above problems, embodiments of the present disclosure provide an image processing method and apparatus. After processing an image with shadows after rendering, a new image with directional soft shadows can be generated, and the computational cost of generating directional soft shadows is small, which is applicable to various terminal devices. The soft shadows in the new image can be better integrated with the original shadows, solving the boundary problem of the fusion of hard and soft shadows and the jagged problem in the shadow area in the related art, making the soft shadows in the new image more soft and realistic, and the visual effect of the overall image is smoother, more fluent, 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 scenarios.

[0093] Figure 1 FIG. shows a flowchart of an image processing method according to an embodiment of the present disclosure. As Figure 1 shown, the method includes steps S10 - S30. The method can be applied to terminal devices, for example, devices such as smart phones, tablet computers, laptop computers, virtual reality (VR) devices, augmented reality (AR) devices, etc. that meet the resource requirements of the above image processing method. The present disclosure does not limit this.

[0094] Step S10, determining a shadow area in the image and generating a shadow template corresponding to the image according to the shadow area.

[0095] In this embodiment, the above image can be a 2D image and the image can be represented by an RGB color space. The 2D image can 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 can be determined by methods such as brightness analysis and color feature recognition, 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. The hard shadow technology is used to simulate the clear and sharp shadow edges formed after light is blocked by an object and can be implemented by means such as shadow mapping and ray tracing. The present disclosure does not limit this.

[0096] In a possible implementation, step S10 may include: determining a shadow area in the image, performing binarization processing on the image according to the shadow area to obtain a shadow template corresponding to the image. The shadow template can be used to mark whether each pixel in the image is a shadow pixel in the shadow area or a non-shadow pixel in the non-shadow area. At each position in the shadow template, it can be marked whether a corresponding pixel in the image belongs to a shadow pixel (or whether it belongs to a non-shadow pixel). Then, the values at each position in the shadow template can be set as needed to distinguish between shadow pixels and non-shadow pixels. The shadow pixels and non-shadow pixels can be set as a first value and a second value respectively as needed. That is, in the shadow template, the first value of the shadow pixels in the shadow area can be set as x, and the second value of the non-shadow pixels in the non-shadow area can be set as y, and a shadow template composed of x and y can be obtained. Among them, x≠y, and x and y can be "0, 1", "0, 255", etc. The present disclosure does not limit this.

[0097] Among them, through binarization processing, the image can be converted into a shadow template containing only two values, which is convenient for subsequent further processing of the image. The image can be binarized by methods such as the global threshold method. The present disclosure does not limit this.

[0098] Step S20, determining at least the 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 finally, and the directional soft shadows are in the non-shadow area of the image, in order to generate a new image, it is necessary to calculate the directional weight coefficient corresponding to each non-shadow pixel in the image. The directional weight coefficient of a pixel can be used to characterize a quantization index of the shadow intensity or blur degree associated with the light source direction 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 pixels in the shadow area of the image at this pixel is higher, making the color of this pixel closer to the color of the shadow pixels 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 coefficients corresponding to each pixel (including shaded pixels and non-shaded pixels) in the image can be calculated according to Method 1, or the directional weight coefficients corresponding to each non-shaded pixel in the image can be calculated according to Method 2, and then step S30 is executed. For different implementation manners of step S20, the implementation processes of "executing step S20 according to Method 1 and then executing step S30" by Implementation Manner 1 and "executing step S20 according to Method 2 and then executing step S30" by Implementation Manner 2 are respectively described schematically below.

[0102] Implementation Manner 1:

[0103] As Figure 2 shown, step S20 may include steps S201 - S204.

[0104] Step S201, determine the nearest distance from each non-shaded pixel to the shadow area according to the shadow template, and determine the light source distance from each non-shaded pixel to the light source.

[0105] Among them, the nearest distance from each non-shaded pixel to the shadow area may be the nearest distance from the non-shaded pixel to the shadow area, and this nearest distance can be calculated by the distance between the non-shaded pixel and the shaded pixel with the shortest distance among the nearest shaded pixels in the shadow area. This nearest distance can be calculated by distance transformation algorithms such as Euclidean Distance Transform (EDT) and Manhattan Distance Transform. The present disclosure does not limit this.

[0106] Among them, the light source can be an approximate form in 2D space of any type of light source such as a point light source or a parallel light source (such as a directional light). 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-shaded pixel to the light source can be the Euclidean distance between the non-shaded pixel and the light source; if the light source is a parallel light source, the light source distance from the non-shaded pixel to the light source can be the perpendicular distance or the projection distance between the non-shaded pixel and the occluder. 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 occluder. The present disclosure does not limit this.

[0107] Step S202, determine the actual shadow area corresponding to each non-shaded pixel according to the light source distance and the shadow area parameter corresponding to each non-shaded pixel.

[0108] In a possible implementation manner, for the actual shadow area corresponding to each non-shaded pixel, it 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 is 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). This shadow area parameter can be a parameter representing the maximum shadow area of the corresponding non-shadow pixel, and is used to control the spread range of the shadow. Among them, the shadow area parameters corresponding to each non-shadow pixel can be determined according to the light source characteristics (distance from the light source, size of the light source, light intensity, etc.) corresponding to the non-shadow pixel, object characteristics (characteristics of the object where the non-shadow pixel is located), scene complexity (complexity of the scene in the image), and application requirements, etc. The present disclosure does not limit this. ratio ij is the proportionality factor corresponding to the non-shadow pixel at position (i, j) in the image. The proportionality factor ratio ij is used to control the spread range of the shadow, and is mainly determined according to the light source distance from the position (i, j) of the non-shadow pixel to the corresponding light source, and the size of the light source, etc. The proportionality factor value can be between 0 and 1. When the proportionality factor is closer to 1, shadow_size ij is larger, indicating that the spread range of the shadow is larger, and the actual shadow area shadow_size ij is closer to the shadow area parameter max_shadow_size ij ; conversely, when the proportionality factor is close to 0, shadow_size ij is smaller, indicating that the spread range of the shadow is smaller, and the actual shadow area shadow_size ij approaches 0. By adjusting the proportionality factor ratio ij , precise control of the shadow spread range can be achieved, and then the directional natural change effect presented by the shadow under different light source conditions can be simulated.

[0111] Step S203: Determine the directional weight coefficient corresponding to each non-shadow pixel according to the nearest distance and the actual shadow area corresponding to each non-shadow pixel.

[0112] In a possible implementation manner, determining the directional weight coefficient corresponding to each non-shadow pixel can be calculated by the following formula 2:

[0113] Formula 2

[0114] where distance_data ij is the closest distance corresponding 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, for the pixels in the soft shadow area shown in Figure 5 , the shadow_data ij ∈(0, 1), and for the pixels in the non-shadow pixels that are not in the soft shadow area shown in Figure 5 , the shadow_data ij = 1.

[0115] Among them, by determining the directional weight coefficient corresponding to each non-shadow pixel, the closest distance distance_data of each non-shadow pixel point ij can be normalized by the actual shadow area shadow_size ij to provide the directional weight coefficient shadow_data for shadow diffusion ij . Among them, The larger the ij shadow_size ij , the larger the range that shadow_data can be normalized, so that more non-shadow pixels will participate in the generation of soft shadows, thereby realizing 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 corresponding directional intensity of the point, and the closer it is to 1, the greater the corresponding directional intensity of 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 the normalization process, it can be ensured that the shadow edge in the finally generated new image transitions naturally, avoiding obvious jagged or fault phenomena.

[0116] In a possible implementation manner, 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 influences 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 in combination with the image resolution to ensure the consistency of shadow diffusion.

[0117] Step S204: Set the directional weight coefficient of each of the shadow pixels 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, ensuring that the original content information in the shadow area is preserved and not lost in subsequent Step S30.

[0118] As Figure 3 shown, Step S30 may include Step S301 - Step S306.

[0119] Step S301: Convert the image from the RGB color space to the YUV color space to obtain the original Y component, original U component, and original V component corresponding to each pixel in the image.

[0120] In a possible implementation, during the process of converting the image from the RGB color space to the YUV color space, the YUV components corresponding to each pixel can be obtained based on the RGB values of each pixel through the following Formulas 3 - 5:

[0121] Y 原ij = 0.299R 原ij + 0.587G 原ij + 0.114B 原ij Formula 3

[0122] U 原ij = -0.14713R 原ij - 0.28886G 原ij + 0.436B 原ij + 128 Formula 4

[0123] V 原ij = 0.615R 原ij - 0.51498G 原ij - 0.10001B 原ij + 128 Formula 5

[0124] where Y 原ij , U 原ij , V 原ij are respectively the original Y component, original U component, and original V component corresponding to the pixel at position (i, j) in the image, and R 原ij , G 原ij , B 原ij are the values of the R, G, and B channels corresponding to the pixel at position (i, j) in the image.

[0125] Among them, the RGB color space is an additive color model based on the three primary colors of light, where R represents red, G represents green, and B represents blue. The YUV color space represents luminance (Y) and chrominance (UV) separately. Y represents luminance information, used to represent the brightness and darkness of an image, and U and V represent chrominance information. U represents the difference between blue and luminance, and V represents the difference between red and luminance. Through the above conversion formula, the image data in the RGB color space can be efficiently converted into the luminance component and chrominance component in the YUV color space, providing a more flexible and efficient data basis for subsequent image processing and analysis.

[0126] Step S302: According to the directional weight coefficients corresponding to each of the pixels and the Y eigenvalue, U eigenvalue, and V eigenvalue determined based on the shadow region, perform weighted processing on the original Y component, original U component, and original V component corresponding to each of the pixels respectively, to obtain the weighted Y component, weighted U component, and weighted V component corresponding to each of the pixels.

[0127] Among them, the Y eigenvalue (Y 特 ), U eigenvalue (U 特 ), and V eigenvalue (V 特 are statistical values corresponding to each component of all the shadow pixels in the shadow region, used to characterize the characteristics of the shadow region pixels. Among them, they can be respectively set to the average values of the Y component, U component, and V component of all the shadow pixels in the shadow region, or they can also be respectively set to the modes of the Y component, U component, and V component of all the shadow pixels in the shadow region. The present disclosure does not limit this.

[0128] In a possible implementation manner, the weighted Y component (Y 加权ij ), weighted U component (U 加权ij ), and weighted V component (V 加权ij ) corresponding to each of the pixels can be calculated through the following formulas 6 - 8:

[0129] Y 加权ij =shadow_data ij ×Y 原ij + (1 - shadow_data ij ) × Y 特 Formula 6

[0130] U 加权ij =shadow_data ij ×U 原ij + (1 - shadow_data ij ) × U 特 Formula 7

[0131] V加权ij = shadow_data ij × V 原ij +(1 - shadow_data ij )× V 特 Formula 8

[0132] Step S303: Perform blur processing on the original Y component and the weighted Y component respectively to obtain a first blurred Y component and a second blurred Y component.

[0133] Among them, the original Y component (Y 原ij ), and the weighted Y component (Y 加权ij ) can be respectively subjected to edge-preserving blur processing through methods such as Gaussian blur and bilateral blur to obtain a first blurred Y component (Y 模糊1-ij ) and a second blurred Y component (Y 模糊2-ij ).

[0134] Step S304: Obtain the edge information corresponding to each pixel according to the original Y component and the first blurred Y component corresponding to each pixel.

[0135] Among them, the edge information (Edge Information) can be the area where the pixel intensity (brightness or color) in the image changes significantly, and these changes usually correspond to the outline of an object, the boundary of a shape, or the dividing line between different objects.

[0136] In a possible implementation, the edge information corresponding to each pixel can be calculated by the following formula 9:

[0137]

[0138] Among them, Y 模糊1-ij is the first blurred Y component corresponding to the pixel at position (i, j) in the image. After calculating the edge information Edge ij corresponding to the pixel at position (i, j) in the image through formula 9, 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 finally generated new image can be eliminated (that is, to solve the boundary problem of soft and hard shadow fusion).

[0139] Step S305: Determine the target Y component corresponding to each pixel according to the second blurred Y component, the edge information, and the directional weight coefficient corresponding to each pixel.

[0140] Among them, the target Y component (Y 目标ij ) corresponding to each pixel can be determined according to the following formula 10:

[0141]

[0142] Among them, Y 目标ij is the target Y component corresponding to the pixel at position (i, j). Y 模糊2-ij is 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 according to the directional weight coefficients of each pixel and the shadow template. Among them, since the directional weight coefficients of each pixel are between 0 and 1, and the directional weight coefficients for non-shadow pixels should change from 0 to 1 outward from the boundary of the shadow area, in order to distinguish the shadow area and the non-shadow area, the values of each position of the soft shadow mask can be set to 0 or 1. Among them, in the soft shadow mask soft_shadow_mask, the original shadow pixels set the mask value of the shadow pixels to 1 according to the shadow template; the mask value of the pixels with directional weight coefficients less than 1 among the non-shadow pixels is set to 1; the mask value of the pixels with directional weight coefficients equal to 1 among the non-shadow pixels is set to 0.

[0143] Step S306, perform a conversion from the YUV color space to the RGB color space according to the target Y component, weighted U component, and weighted V component corresponding to each pixel, to obtain a new image with directional soft shadows.

[0144] Among them, based on the target Y component Y 目标ij , weighted U component U 加权ij and weighted V component V 加权ij perform the conversion according to the following formulas 11 - 13 to obtain the RGB channel values of the pixels at each position in the new image. The new image formed includes directional soft shadows around the original shadow area.

[0145]

[0146] Among them, R 新ij , G 新ij , B 新ij respectively represent the R channel value, G channel value, and B channel value of the pixel at position (i, j) in the new image.

[0147] Implementation method two:

[0148] Step S20 may include: determining the nearest 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 the shadow area parameter corresponding to each non-shadow pixel; determining the directional weight coefficient corresponding to each non-shadow pixel according to the nearest distance and the actual shadow area corresponding to each non-shadow pixel. Among them, the implementation manner of step S20 may refer to steps S201-S203 above, and will not be elaborated to avoid redundancy.

[0149] Then, based on the implementation of the above step S20, as Figure 4 shown, step S30 may include steps S401-S407.

[0150] Step S401, converting the non-shadow pixels of the image from the RGB color space to the YUV color space to obtain the original Y component, original U component, and original V component corresponding to each non-shadow pixel.

[0151] Step S402, respectively performing weighted processing on the original Y component, original U component, and original V component corresponding to each non-shadow pixel according to the directional weight coefficient corresponding to each non-shadow pixel and the Y eigenvalue, U eigenvalue, and V eigenvalue determined based on the shadow area to obtain the weighted Y component, weighted U component, and weighted V component corresponding to each non-shadow pixel.

[0152] Step S403, respectively performing blurring processing on the original Y component and the weighted Y component to obtain the first blurred Y component and the second blurred Y component.

[0153] Step S404, obtaining the edge information corresponding to each non-shadow pixel according to the original Y component and the first blurred Y component corresponding to each non-shadow pixel.

[0154] Step S405, determining the target Y component corresponding to each non-shadow pixel according to the second blurred Y component, the edge information, and the directional weight coefficient corresponding to each non-shadow pixel.

[0155] Among them, steps S401-S405 may refer to the implementation manners of steps S301-S305 above, and will not be elaborated to avoid redundancy.

[0156] Step S406, performing conversion from the YUV color space to the RGB color space according to the target Y component, weighted U component, and weighted V component corresponding to each non-shadow pixel to obtain the new non-shadow area of the image with directional soft shadows. The conversion method is referred to step S306 above, and will not be elaborated to avoid redundancy.

[0157] Step S407: Form a new image with directional soft shadows based on the new non-shadow area and the shadow area. In this way, splicing the new non-shadow area and the shadow area can obtain a new image with directional soft shadows.

[0158] In this way, through the above Implementation Manner 1 and Implementation Manner 2, as Figure 5 shown, it is possible to generate a new image with directional soft shadows based on an image originally including a shadow area generated by a hard shadow technique.

[0159] The embodiments of the present disclosure further provide an image processing apparatus, which includes:

[0160] A shadow template generation module, configured to determine the shadow area in the image and generate a shadow template corresponding to the image according to the shadow area;

[0161] A weight coefficient generation module, configured to determine at least the directional weight coefficient corresponding to each non-shadow pixel in the image according to the shadow template;

[0162] 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.

[0163] In a possible implementation manner, the weight coefficient generation module includes:

[0164] A first distance calculation sub-module, configured to determine the closest 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;

[0165] A first area determination sub-module, configured to determine the actual shadow area corresponding to each non-shadow pixel according to the light source distance and the shadow area parameter corresponding to each non-shadow pixel;

[0166] A first coefficient determination sub-module, configured to determine 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;

[0167] A second coefficient determination sub-module, configured to set the directional weight coefficient of each shadow pixel to 1 according to the shadow template.

[0168] In a possible implementation manner, the image generation module includes:

[0169] A first component determination sub-module, configured 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;

[0170] The first weighting sub-module is configured to perform weighted processing on the original Y component, original U component, and original V component corresponding to each pixel respectively according to the directional weight coefficient corresponding to each pixel and the Y eigenvalue, U eigenvalue, and V eigenvalue determined based on the shadow region, so as to obtain the weighted Y component, weighted U component, and weighted V component corresponding to each pixel;

[0171] The first blurring processing sub-module is configured to perform blurring processing on the original Y component and the weighted Y component respectively to obtain a first blurred Y component and a second blurred Y component;

[0172] The first edge information determination sub-module is configured to obtain the edge information corresponding to each pixel according to the original Y component and the first blurred Y component corresponding to each pixel;

[0173] The first component calculation sub-module is configured to determine the target Y component corresponding to each pixel according to the second blurred Y component, the edge information, and the directional weight coefficient corresponding to each pixel;

[0174] The first image generation sub-module is configured to perform conversion from the YUV color space to the RGB color space according to the target Y component, weighted U component, and weighted V component corresponding to each pixel, so as to obtain a new image with directional soft shadows.

[0175] In a possible implementation manner, determining the target Y component corresponding to each pixel according to the second blurred Y component, the edge information, and the directional weight coefficient corresponding to each pixel includes:

[0176] Determining the soft shadow mask corresponding to each pixel according to the directional weight coefficient corresponding to each pixel;

[0177] Determining the target Y component corresponding to each pixel according to the second blurred Y component, the edge information, and the soft shadow mask corresponding to each pixel.

[0178] In a possible implementation manner, the weight coefficient generation module includes:

[0179] The second distance calculation sub-module is 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 non-shadow pixel to the light source;

[0180] The second area determination sub-module is configured to determine the actual shadow area corresponding to each non-shadow pixel according to the light source distance and the shadow area parameter corresponding to each non-shadow pixel;

[0181] A third coefficient determination sub-module, configured to determine a directional weight coefficient corresponding to each non-shadow pixel according to the nearest distance corresponding to each non-shadow pixel and the actual shadow area.

[0182] In a possible implementation manner, the image generation module includes:

[0183] A second component determination sub-module, configured to convert the non-shadow pixels of the image from the RGB color space to the YUV color space, and obtain the original Y component, original U component, and original V component corresponding to each non-shadow pixel;

[0184] A second weighting sub-module, configured to perform weighting processing on the original Y component, original U component, and original V component corresponding to each non-shadow pixel respectively according to the directional weight coefficient corresponding to each non-shadow pixel and the Y eigenvalue, U eigenvalue, and V eigenvalue determined based on the shadow area, and obtain the weighted Y component, weighted U component, and weighted V component corresponding to each non-shadow pixel;

[0185] A second blur processing sub-module, configured to perform blur processing on the original Y component and the weighted Y component respectively, and obtain a first blurred Y component and a second blurred Y component;

[0186] A second edge information determination sub-module, configured to obtain the edge information corresponding to each non-shadow pixel according to the original Y component and the first blurred Y component corresponding to each non-shadow pixel;

[0187] A second component calculation sub-module, configured to determine the target Y component corresponding to each non-shadow pixel according to the second blurred Y component, the edge information, and the directional weight coefficient corresponding to each non-shadow pixel;

[0188] A region generation sub-module, configured to perform conversion from the YUV color space to the RGB color space according to the target Y component, weighted U component, and weighted V component corresponding to each non-shadow pixel, and obtain a new non-shadow region of the image with directional soft shadows;

[0189] A second image generation sub-module, configured to form a new image with directional soft shadows according to the new non-shadow region and the shadow region.

[0190] In a possible implementation manner, the shadow template generation module includes:

[0191] A template generation sub-module, configured to determine the shadow region in the image, perform binarization processing on the image according to the shadow region, and obtain a shadow template corresponding to the image, where the value of the shadow pixel in the shadow region of the shadow template is a first value, and the value of the non-shadow pixel in the non-shadow region is a second value.

[0192] In some embodiments, the functions or modules included in the apparatus provided by the embodiments of the present disclosure can be used to execute the methods described in the above method embodiments. The specific implementation can refer to the description of the above method embodiments. For the sake of brevity, it will not be repeated here.

[0193] It should be noted that although the above embodiments are used as examples to introduce the image processing method and apparatus as above, those skilled in the art can understand 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 solutions of the present disclosure are satisfied.

[0194] The embodiments of the present disclosure also provide an image processing apparatus, including a memory, a processor, and a computer program stored on the memory. The processor executes the computer program to implement the steps of the above method.

[0195] The embodiments of the present disclosure also provide a chip for implementing the steps of the above method. In some embodiments, the chip may 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 a terminal device such as a mobile phone, a field-programmable gate array (FPGA) with related similar functions, an application-specific integrated circuit (ASIC), etc. The present disclosure does not limit this.

[0196] The embodiments of the present disclosure also provide a non-volatile computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above method are implemented.

[0197] The embodiments of the present disclosure also provide a computer program product, including a computer program, or a non-volatile computer-readable storage medium carrying the computer program. When the computer program is executed by a processor, the steps of the above method are implemented.

[0198] Figure 6 FIG. 1900 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. Refer to Figure 6, Device 1900 includes a processing component 1922, which further includes one or more processors, and memory resources represented by a memory 1932 for storing instructions executable by the processing component 1922, such as application programs. The application programs 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-described method.

[0199] Device 1900 may also include a power 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 TM , MacOS X TM , Unix TM , Linux TM , FreeBSD TM or the like.

[0200] In an exemplary embodiment, a non-transitory computer-readable storage medium is also provided, such as the memory 1932 including computer program instructions, and the computer program instructions can be executed by the processing component 1922 of the device 1900 to complete the above-described method.

[0201] A computer-readable storage medium can be a tangible device that can hold and store programs / instructions used by an instruction execution device. A computer-readable storage medium can 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 (non-exhaustive list) of the computer-readable storage medium 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 disc read-only memory (CD-ROM), a digital versatile disc (DVD), a memory stick, a floppy disk, a mechanical encoding device, such as a punched card or raised structures in grooves storing instructions thereon, and any suitable combination of the above. The computer-readable storage medium used herein is not construed as an instantaneous signal itself, such as radio waves or other freely propagating electromagnetic waves, electromagnetic waves propagating through a waveguide or other transmission medium (e.g., optical pulses through an optical fiber cable), or electrical signals transmitted through wires.

[0202] The computer programs (or computer-readable program instructions) described herein can be downloaded to various computing / processing devices from a computer-readable storage medium 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 can include copper transmission cables, optical fiber transmission, wireless transmission, routers, firewalls, switches, gateway computers, and / or edge servers. A 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 a computer-readable storage medium in each computing / processing device.

[0203] The computer programs (or computer program instructions) for performing the operations of the present disclosure may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-related instructions, microcode, firmware instructions, state-setting data, or source code or 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 the "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, executed as a stand-alone software package, partially on the user's computer and 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., via an Internet service provider through the Internet). In some embodiments, by using the state information of the computer-readable program instructions to customize an electronic circuit, such as a programmable logic circuit, a field-programmable gate array (FPGA), or a programmable logic array (PLA), the electronic circuit can execute the computer-readable program instructions to implement various aspects of the present disclosure.

[0204] Aspects of the present disclosure are described herein with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the present disclosure. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer-readable program instructions.

[0205] These computer-readable program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, or other programmable data processing apparatus to produce a machine such that the instructions, when executed by the processor of the computer or other programmable data processing apparatus, create an apparatus for implementing the functions / acts specified in one or more blocks of the flowchart and / or block diagram. These computer-readable program instructions may also be stored in a computer-readable storage medium that causes a computer, a programmable data processing apparatus, and / or other devices to function in a particular manner, such that the computer-readable medium storing the instructions comprises a manufacture including instructions for implementing various aspects of the functions / acts specified in one or more blocks of the flowchart and / or block diagram.

[0206] The computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other devices so that a series of operational steps are performed on the computer, other programmable data processing apparatus, or other devices to produce a computer-implemented process such that the instructions executed on the computer, other programmable data processing apparatus, or other devices implement the functions / acts specified in one or more blocks of the flowchart and / or block diagram.

[0207] The flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagram may represent a module, a segment of code, or a portion of an instruction, and the module, segment of code, or portion of an instruction may include one or more executable instructions for implementing the specified logical function. In some alternative implementations, the functions noted in the blocks may occur out of the order noted in the figures. For example, two consecutive blocks may in fact be executed substantially in parallel, or they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented by a dedicated hardware-based system for performing the specified functions or acts, or by a combination of dedicated hardware and computer instructions.

[0208] The embodiments of the present disclosure have been described above. The above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The choice of terms used herein is intended to best explain the principles of the embodiments, the practical application, or improvements made to the technology in the marketplace, or to enable other ordinary skilled persons in the art to understand the embodiments disclosed herein.

Claims

1. An image processing method, characterized in that, The method includes: Determining a shadow area in the image and generating a shadow template corresponding to the image according to the shadow area; Determining at least a directional weight coefficient corresponding to each non-shadow pixel in the image according to the shadow template, where the directional weight coefficient of a pixel is a quantization index for characterizing the shadow intensity or blur degree associated with the light source direction in the shadow area; 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; Wherein, the determining at least a directional weight coefficient corresponding to each non-shadow pixel in the image according to the shadow template includes: Determining the nearest 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 the shadow area parameter corresponding to each non-shadow pixel; Determining the directional weight coefficient corresponding to each non-shadow pixel according to the nearest distance and the actual shadow area corresponding to each non-shadow pixel.

2. The method according to claim 1, wherein The determining at least a directional weight coefficient corresponding to each non-shadow pixel in the image according to the shadow template further includes: Setting the directional weight coefficient of each shadow pixel 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, includes: Converting the image from the RGB color space to the YUV color space to obtain the original Y component, original U component, and original V component corresponding to each pixel in the image; Performing weighted processing on the original Y component, original U component, and original V component corresponding to each pixel respectively 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 to obtain the weighted Y component, weighted U component, and weighted V component corresponding to each pixel; Performing blur processing on the original Y component and the weighted Y component respectively to obtain a first blurred Y component and a second blurred Y component; Obtaining the edge information corresponding to each pixel according to the original Y component and the first blurred Y component corresponding to each pixel; Determining the target Y component corresponding to each pixel according to the second blurred Y component, the edge information, and the directional weight coefficient corresponding to each pixel; Performing a conversion from the YUV color space to the RGB color space according to the target Y component, weighted U component, and weighted V component corresponding to each pixel to obtain a new image with directional soft shadows.

4. The method according to claim 3, characterized in that Determining the target Y component corresponding to each pixel according to the second blurred Y component, the edge information, and the directional weight coefficient corresponding to each pixel, includes: Determining the soft shadow mask corresponding to each pixel according to the directional weight coefficient corresponding to each pixel; Determining the target Y component corresponding to each pixel according to the second blurred Y component, the edge information, and the soft shadow mask corresponding to each pixel.

5. The method according to claim 1, wherein Generate a new image with directional soft shadows based on 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, original U component, and original V component corresponding to each of the non-shadow pixels; Perform weighted processing on the original Y component, original U component, and original V component corresponding to each of the non-shadow pixels respectively 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 to obtain the weighted Y component, weighted U component, and weighted V component corresponding to each of the non-shadow pixels; Perform blur processing on the original Y component and the weighted Y component respectively to obtain a first blurred Y component and a second blurred Y component; Obtain the edge information corresponding to each of the non-shadow pixels according to the original Y component and the first blurred Y component corresponding to each of the non-shadow pixels; Determine the target Y component corresponding to each of the non-shadow pixels according to the second blurred Y component, the edge information, and the directional weight coefficient corresponding to each of the non-shadow pixels; Perform conversion from the YUV color space to the RGB color space according to the target Y component, weighted U component, and 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; Form a new image with directional soft shadows according to the new non-shadow area and the shadow area.

6. The method according to claim 1, wherein Determine the shadow area in the image and generate a shadow template corresponding to the image according to the shadow area, including: Determine the shadow area in the image, perform binarization processing on the image according to the shadow area to obtain a shadow template corresponding to the image, where the value of the shadow pixels in the shadow area of the shadow template is a first value, and the value of the non-shadow pixels in the non-shadow area is a second value.

7. An image processing apparatus, characterized in that, The device includes: A shadow template generation module, configured 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 generation module, configured to determine at least the directional weight coefficient corresponding to each non-shadow pixel in the image according to the shadow template, where the directional weight coefficient of a pixel is a quantization index for characterizing the shadow intensity or blur degree associated with the light source direction in the shadow area; 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; Among them, the determining at least the directional weight coefficient corresponding to each non-shadow pixel in the image according to the shadow template includes: Determine the closest 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 non-shadow pixel according to the light source distance and the shadow area parameter corresponding to each non-shadow pixel; Determine the directional weight coefficient corresponding to each non-shadow pixel according to the nearest distance corresponding to each non-shadow pixel and the actual shadow area.

8. An image processing apparatus, comprising a memory, a processor, and a computer program stored on 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 6.

9. 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 6 are implemented.

Citation Information

Patent Citations

  • Real-time soft shadow realization method based on image screen space

    CN104103089A

  • Method for approximately drawing soft shadow of three-dimensional scene

    CN104346831A