Image shadow adding method and system and computer program product
By generating a graphic mask and offset processing, the shadow layer is generated, and the pixel information of the texture image is mixed for processing, which solves the problem of cumbersome, complex and time-cost addition of shadows in the prior art, and achieves efficient and general Add effects to shadows.
Patent Information
- Application Number
- CN202411538957.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-30
- Publication Date
- 2025-02-14
AI Technical Summary
The prior art methods of adding shadows to textured images are cumbersome, complex, and time-consuming, making it difficult to improve efficiency and versatility.
By acquiring the texture image, generating a graphic mask, offsetting the mask based on the preset scaling factor, generating a shadow layer, and mixing the pixel information of the shadow layer with the pixel information of the texture image to generate a new texture image.
Improves the efficiency of adding shadows in texture images, reduces time costs, and improves the versatility of adding shadows.
Smart Images

Figure CN119444902A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of computer image processing, and in particular to a method, system and computer program product for adding shadows to an image. Background Art
[0002] Texture images are two-dimensional images that can be used to represent the color, pattern, details and other information on the surface of an object. They are widely used in fields such as virtual reality, animation and game development. Adding shadows to texture images can make them produce more realistic and vivid visual effects. The current method of adding shadows to texture images is to manually cut out the image in an image processing tool and complete the production and splicing of shadows, and finally output and save them locally. This process is very tedious and complicated, and the time cost of adding shadows is also very high.
[0003] In view of this, some embodiments of the present specification provide a method, system and computer program product for adding shadows to images, aiming to improve the efficiency of adding shadows to texture images, reduce the time cost of adding shadows, and enhance the versatility of adding shadows. Summary of the invention
[0004] One or more embodiments of the present specification provide a method for adding shadows to an image, the method comprising: acquiring a first texture image; generating a graphic mask based on a foreground area and / or a background area of the first texture image; offsetting the graphic mask based on a first preset scaling factor to generate a shadow layer; mixing first pixel information of the shadow layer with first pixel information of the first texture image to generate a second texture image, wherein a pixel area in the second texture image where the foreground area overlaps with the shadow layer is set as first pixel information of the foreground area of the first texture image, and the first pixel information includes a color value of the pixel, or a color value of the pixel and a transparency of the pixel.
[0005] According to the method provided by one or more embodiments of the present specification, generating a graphic mask based on the foreground area and / or background area of the first texture image includes: comparing first pixel information of the first texture image with a first preset threshold to separate the foreground area and the background area; generating a graphic mask based on the foreground area and / or the background area, wherein the color of the pixel area corresponding to the foreground area in the graphic mask is a preset shadow color.
[0006] According to the method provided by one or more embodiments of this specification, generating a graphic mask based on the foreground area and / or background area of the first texture image further includes: repairing hole pixels in the graphic mask based on the first texture image.
[0007] According to the method provided by one or more embodiments of the present specification, repairing hole pixels in a graphic mask based on a first texture image includes: determining second pixel information of the first texture image, wherein the first texture image includes a foreground area and a mixed area, and the mixed area includes pixels in the first texture image corresponding to the hole pixels in the graphic mask and pixels in the background area of the first texture image; performing the following processing on a first unit pixel in the first texture image or the mixed area: counting the number of pixels whose second pixel information corresponding to pixels located in a preset pixel area meets a second preset threshold condition, wherein the position of the first unit pixel is located in the preset pixel area; when the number of pixels meeting the second preset threshold condition meets the second preset threshold condition, setting the color of the pixel corresponding to the first unit pixel in the graphic mask to a preset shadow color.
[0008] According to the method provided by one or more embodiments of the present specification, the preset pixel area is an area that is uniformly diffused around the first unit pixel according to a preset offset.
[0009] According to the method provided by one or more embodiments of this specification, determining the second pixel information of the first texture image includes: determining the second pixel information of the foreground area of the first texture image and the second pixel information of the mixed area of the first texture image based on the graphic mask.
[0010] According to the method provided by one or more embodiments of the present specification, determining the second pixel information of the foreground area of the first texture image and the second pixel information of the mixed area of the first texture image based on the graphic mask includes: setting the color value of the pixel in the first texture image corresponding to the pixel used to represent display in the graphic mask to a preset color value, so that the color value of the foreground area of the first texture image is the preset color value, retaining the original color value of the pixel in the first texture image corresponding to the pixel used to represent hidden in the graphic mask, so that the color value of the mixed area is the original color value, wherein the preset color value is less than or equal to the original color value of the mixed area; or setting the color value of the pixel in the first texture image corresponding to the pixel used to represent hidden in the graphic mask to a preset color value, so that the color value of the mixed area is the preset color value, retaining the original color value of the pixel in the first texture image corresponding to the pixel used to represent display in the graphic mask, so that the color value of the foreground area of the first texture image is the original color value, wherein the preset color value is less than or equal to the original color value of the foreground area.
[0011] According to the method provided by one or more embodiments of the present specification, determining the second pixel information of the foreground area of the first texture image and the second pixel information of the mixed area of the first texture image based on the graphic mask also includes: converting the color values of the mixed area and the foreground area into grayscale values respectively.
[0012] According to the method provided by one or more embodiments of the present specification, after offsetting the graphic mask based on a first preset scaling factor to generate a shadow layer, it also includes: offsetting the pixel position in the shadow layer based on a height gradient, so that the closer the pixel position in the shadow layer is to a preset height parameter in a preset axial direction, the smaller the offset of the pixel position in the shadow layer in the preset axial direction, wherein the height gradient is determined based on a preset height parameter and a position component of the pixel position in the shadow layer in the preset axial direction, the preset height parameter is used to control the offset amplitude of the shadow layer in the preset axial direction, and the pixel position in the shadow layer is the pixel position after the graphic mask is offset based on the first preset scaling factor.
[0013] According to the method provided by one or more embodiments of the present specification, mixing the first pixel information of the shadow layer with the first pixel information of the first texture image to generate the second texture image includes: filtering the background area of the first texture image based on a graphic mask; setting the pixel information of the second unit pixel of the second texture image at the corresponding pixel position based on the filtered first texture image and the first pixel information of the shadow layer; wherein, when the filtered first texture image has the first pixel information at the corresponding pixel position, the pixel information of the second unit pixel is set to the first pixel information of the filtered first texture image at the corresponding pixel position; when the filtered first texture image does not have the first pixel information at the corresponding pixel position, and the shadow layer has the first pixel information at the corresponding pixel position, the pixel information of the second unit pixel is set to the first pixel information of the shadow layer at the corresponding pixel position.
[0014] The method provided according to one or more embodiments of the present specification also includes: judging whether the positions of each pixel of the second texture image are located outside a preset display area based on a first scaling factor and a size of the second texture image, wherein the first scaling factor is determined based on a first preset scaling factor; and filtering pixels in the second texture image that are located outside the preset display area.
[0015] According to the method provided by one or more embodiments of the present specification, judging whether the positions of each pixel of the second texture image are located outside the preset display area based on the first scaling factor and the size of the second texture image includes: determining the offset position corresponding to each pixel in the second texture image based on the first scaling factor and the initial position corresponding to each pixel in the second texture image, wherein the initial position corresponding to each pixel in the second texture image corresponds to the pixel position in the first texture image; judging whether the offset position corresponding to each pixel in the second texture image is located outside the preset display area, wherein the preset display area is determined based on the first scaling factor and the size of the second texture image.
[0016] According to the method provided by one or more embodiments of the present specification, before determining whether the offset position corresponding to each pixel in the second texture image is outside the preset display area, the method further includes: updating the offset position corresponding to each pixel in the second texture image based on preset mirror parameters.
[0017] One or more embodiments of the present specification also provide an image shadow adding system, the system comprising: an acquisition module for acquiring a first texture image; a mask generation module for generating a graphic mask based on a foreground area and / or a background area of the first texture image; a shadow generation module for offsetting the graphic mask based on a first preset scaling factor to generate a shadow layer; a blending processing module for blending first pixel information of the shadow layer with first pixel information of the first texture image to generate a second texture image, wherein a pixel area in the second texture image where the foreground area overlaps with the shadow layer is set as the first pixel information of the foreground area of the first texture image, and the first pixel information comprises a color value of the pixel, or a color value of the pixel and a transparency of the pixel.
[0018] One or more embodiments of the present specification further provide a computer program product, including a computer program. When at least a portion of the computer program is executed by a processor, the image shadow adding method described in some embodiments of the present specification can be implemented. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] This specification will be further explained by way of exemplary embodiments, which will be described in detail by way of the accompanying drawings. The same numbers in the drawings represent the same structures or steps.
[0020] Figure 1 It is a schematic diagram of a texture image shown in some embodiments of this specification.
[0021] Figure 2 is an exemplary flow chart of a method for adding shadows to an image according to some embodiments of the present specification.
[0022] Figure 3 This is a schematic diagram of a first texture image according to some embodiments of this specification.
[0023] Figure 4 It is a schematic diagram of a graphic mask shown in some embodiments of this specification.
[0024] Figure 5 It is a schematic diagram of a stretched graphic mask shown in some embodiments of this specification.
[0025] Figure 6 It is a schematic diagram of second texture images generated in batches according to some embodiments of this specification.
[0026] Figure 7 is a schematic diagram of a graphic mask containing hole pixels according to some embodiments of this specification.
[0027] Figure 8 It is an exemplary flow chart of a cavity repair method shown in some embodiments of this specification.
[0028] Fig. 9 is a schematic diagram of a second texture image according to some embodiments of this specification.
[0029] Fig.10 This is an exemplary flow chart of a first pixel information filtering method according to some embodiments of this specification.
[0030] Fig.11 is a schematic diagram of a second texture image according to some embodiments of this specification.
[0031] Fig.12 is an exemplary block diagram of a system for adding shadows to an image according to some embodiments of the present specification. DETAILED DESCRIPTION
[0032] In order to more clearly illustrate the technical solutions of the embodiments of this specification, the embodiments will be described in detail below with reference to the accompanying drawings. Obviously, the contents described below are some examples or embodiments of this specification. For ordinary technicians in this field, without paying creative work, the technical solutions or means disclosed in this specification can also be applied to other scenarios based on these technical contents.
[0033] It should be understood that the "system", "device", "unit" and / or "module" used in this specification is a method for distinguishing different components, elements, parts, portions or assemblies at different levels. However, if other words can achieve the same purpose, the words can be replaced by other expressions.
[0034] Unless otherwise specified, technical terms used in this specification to describe components, elements, etc. do not refer to the singular, but may also include the plural. Generally speaking, terms such as "include", "comprise", etc. only indicate that the steps, elements, or components that have been clearly identified are included, and these steps, elements, and components do not constitute an exclusive list, such as the method or device described may also include other steps or components.
[0035] Flowcharts are used in this specification to illustrate the operation steps performed by the device or system of the relevant embodiments, but unless otherwise specified, the order used to describe these steps should not be understood as a limitation on the order in which the steps are performed. A person of ordinary skill in the art can adjust the order in which these steps are performed based on the knowledge and information conveyed by the embodiments of this specification, and the adjustment includes but is not limited to swapping the order, merging multiple steps, and splitting a certain step.
[0036] Texture images (or textures) are two-dimensional images that can be used to represent the color, pattern, details and other information on the surface of an object. They can be applied to three-dimensional models to add color, pattern, details and other information to the three-dimensional model, making the rendered image of the three-dimensional model more vivid and realistic. Texture images can store the color information of pixels, which can be represented by three channels: R (Red), G (Green), and B (Blue), and can further include an A (Alpha, transparency) channel. Combinations of different colors can form patterns and texture details. For example, patterns can represent certain virtual objects, such as virtual buildings, virtual natural elements (such as mountains, rocks, plants, leaves, etc.), virtual vehicles, virtual animals, etc. Figure 1 is a schematic diagram of a texture image according to some embodiments of this specification, such as Figure 1 As shown, the texture image can display the pattern of a specific virtual object. In other texture images, the texture image can further store the normal direction information of the pixel, the height information of the pixel relative to the reference plane, or the material attribute information of the pixel, so as to express more information about the surface of the three-dimensional model. For example, the normal direction information can express the details and concave-convex effects of the surface of the three-dimensional model, the height information can express the height change of the surface of the three-dimensional model, and the material attribute information can express the metal characteristics of the surface of the three-dimensional model or the roughness of the surface.
[0037] Texture images can be widely used in film and television production, advertising marketing, virtual reality, animation, and game development. Taking game development as an example, texture images can be created through image production software and post-processed according to the needs of game development. For example, shadows can be added to texture images to make them more realistic and vivid. After that, the texture images are mapped to the three-dimensional model through texture coordinates to express the color, pattern, details and other information on the surface of the model.
[0038] In some embodiments, the method of adding shadows to the texture image is to manually cut out the image in an image processing tool and complete the shadow production and splicing, and then output and save it locally. Figure 1 For example, you can manually cut out in the image processing tool Figure 1The process of obtaining a pattern of a virtual object in the image and then drawing a shadow for the pattern of the virtual object, or combining the pattern of the virtual object with the preset shadow to generate a texture image with the pattern of the virtual object and the pattern shadow, is very tedious and complicated. When shadows need to be generated for a large number of texture images, it will bring a lot of complex and repetitive labor, which greatly increases the time cost of adding shadows.
[0039] To this end, some embodiments of the present specification propose a method for adding shadows to an image, which generates a graphic mask based on the foreground area and / or background area of a first texture image, and offsets the image mask based on a first preset scaling factor to generate a shadow layer, and mixes the first pixel information of the shadow layer with the first pixel information of the first texture image to generate a second texture image, thereby improving the efficiency of adding shadows to texture images, reducing the time cost of adding shadows, and improving the versatility of adding shadows.
[0040] Figure 2 is an exemplary flow chart of a method for adding shadows to an image according to some embodiments of the present specification. Figure 2 The process 200 shown can be executed by a computing device, for example, it can be implemented by an image shadow adding system 1200 deployed on the computing device. In some embodiments, the computing device can be a desktop computer, a laptop computer, a mobile phone, a VR device, a tablet computer, etc. In some embodiments, the computing device can be a user-end device, or a server-end device or a cloud device. In some embodiments, part of the process 200 can be executed by a computing device as a user end, and another part can be executed by a computing device as a server end. Figure 2 As shown, process 200 may include the following steps.
[0041] Step 210 , obtaining a first texture image. In some embodiments, step 210 may be implemented by obtaining module 1210 .
[0042] In some embodiments, the first texture image may be a picture containing color information, such as a picture created by image production software or a picture taken by a camera. In other embodiments, the first texture image may also be a texture image containing color information and specific texture information, wherein the specific texture information may be, for example, normal direction information, height information, or material attribute information.
[0043] In some embodiments, the color information displayed in the first texture image can express the pattern of a virtual object, such as a virtual building, a virtual vehicle, a virtual character, and an animal, etc. The pattern of the virtual object can be displayed as a foreground in the first texture image. The color information displayed in the first texture image can also express the background. The color information of the background can make the pattern of the virtual object stand out visually. For example, the color information of the background can be the same or a similar color.
[0044] In some embodiments, the first texture image may be obtained by extracting the first texture image from a specified path.
[0045] Step 220 , generating a graphic mask based on the foreground area and / or the background area of the first texture image. In some embodiments, step 220 may be implemented by a mask generation module 1220 .
[0046] In some embodiments, the foreground area may refer to the pixel area where the object of focus in the first texture image is located. For example, the image displayed in the foreground area may be a highlighted building, vehicle, person or animal, etc.; the background area may refer to other pixel areas in the first texture image except the foreground area. For example, the background area may display the same or similar color information. Figure 3 is a schematic diagram of a first texture image according to some embodiments of this specification. For example, the foreground area of the first texture image can be as follows Figure 3 As shown in the area within the middle dashed line, the pattern of the virtual object with rich color information can be displayed in this area. Figure 3 The area outside the middle dotted line may be the background area, and the color of the background area may be the same or similar color. It should be understood that the foreground area and the background area are not the preset pixel areas in the first texture image, and they can change dynamically according to the setting of the color information in the first texture image. The pixels corresponding to the foreground area and the background area can be determined by comparing with the first preset threshold value below. In addition, Figure 3 The dashed lines and pointing lines in the figure are only identifiers to assist understanding, so as to clarify the annotated objects in the first texture image, and should not be understood as part of the first texture image. There are dashed lines and / or pointing lines with similar functions in the schematic diagrams of subsequent images, and their functions are similar to this, and will not be repeated in the following.
[0047] In some embodiments, the first pixel information of the first texture image can be compared with the first preset threshold to separate the foreground area and the background area. The pixel information of the image may include color value, transparency, grayscale value, etc. Exemplarily, the color value can be represented by the three channels of RGB (red, green, and blue); the transparency can be represented by the Alpha channel, which represents the degree of transparency of the pixel color value; the grayscale value can represent the brightness information of the pixel, and the color value can be converted to the grayscale value by a preset conversion formula (for example, using the weighted average method, grayscale value = 0.2989×R+0.5870×G+0.1140×B). In some embodiments, the first pixel information may include a color value, and the first preset threshold may be a numerical value corresponding to the color value, such as setting corresponding preset thresholds for the three RGB channels. Specifically, the first preset threshold can be set based on the color of the background in the first texture image, and the color value of each pixel in the first texture image can be compared with the first preset threshold to determine whether the pixel belongs to the foreground area or the background area. Exemplarily, with Figure 3 Taking the first texture image shown as an example, the color of the background area is white (RGB value is 255, 255, 255) or close to white, then the first preset threshold can be set to RGB (200, 200, 200). When the values of the three RGB channels of a pixel of the first texture image are all greater than 200, it is determined that the pixel belongs to the background area. Otherwise, the pixel belongs to the foreground area. In other embodiments, in addition to comparing the values of the three RGB channels, the value of the Alpha channel can be further compared, and the pixels whose Alpha channel also meets the threshold condition can be determined as the foreground area or the background area. After comparing all the pixels in the first texture image, it can be determined as follows: Figure 3 The foreground area is shown within the dotted area, and the background area is shown outside the dotted area.
[0048] In some embodiments, after determining the foreground area and the background area of the first texture image, a graphic mask can be further generated based on the foreground area and / or the background area. The graphic mask is a two-dimensional array of the same size as the original image, and each element in the graphic mask corresponds to a pixel in the original image. The two-dimensional array of the graphic mask can indicate which pixel areas in the original image need to be processed and how to process them. In some embodiments, the graphic mask can be a binary mask, and the numerical value corresponding to the pixel in the graphic mask can indicate whether the pixel is displayed in the original image. As one example, a numerical value of 1 (such as represented by white in the graphic mask) can indicate that the pixel is displayed in the original image, and a numerical value of 0 (such as represented by black in the graphic mask) can indicate that the pixel is hidden in the original image. As another example, other colors may be used to represent the numerical value 1 or 0, or different colors may be used to represent the same numerical value. Specifically, by setting a threshold, different colors in the graphic mask may be discretized into a specific numerical value. For example, the RGB (200, 200, 200) corresponding to light gray may be set as the threshold corresponding to the discretization. Then, pixels in the graphic mask whose color values are greater than the threshold may be discretized into the numerical value 1. For example, white or other colors whose RGB is greater than (200, 200, 200) may be discretized into the numerical value 1.
[0049] In some embodiments, the color values of corresponding pixels in the graphic mask can be set to a preset shadow color based on the pixels in the foreground area of the first texture image, and discretization processing can be performed so that the numerical values corresponding to the pixels in the graphic mask whose color values are the preset shadow color can be 1, and the color values of corresponding pixels in the graphic mask can be set to black based on the pixels in the background area of the first texture image. The numerical values corresponding to the pixels represented by black can be 0, thereby generating a corresponding graphic mask for the first texture image. Figure 4 is a schematic diagram of a graphic mask according to some embodiments of this specification, for example, Figure 3 The first texture image shown in FIG. 1 , and the corresponding generated graphic mask can be as follows Figure 4 As shown, it can be seen that Figure 4 Zhongyu Figure 3 The color of the pixel area corresponding to the foreground area is the preset shadow color, which can be discretized into a value of 1 to represent the Figure 3 The foreground area in Figure 4 Zhongyu Figure 3 The color of the pixel area corresponding to the background area is black, and black corresponds to the value 0, indicating that Figure 3 Hide the background area in the image.
[0050] Step 230 , offset the graphic mask based on the first preset scaling factor to generate a shadow layer. In some embodiments, step 230 may be implemented by the shadow generation module 1230 .
[0051] In some embodiments, the graphic mask may also be used as an image to generate shadows corresponding to the foreground area image in the first texture image.
[0052] In some embodiments, the graphic mask may be offset, such as stretched or compressed, based on a first preset scaling factor to generate a shadow layer. Among them, the preset coordinate system (such as the texture coordinate system) corresponding to the first texture image may be applied to the graphic mask to offset the pixels at each coordinate position in the graphic mask. In some embodiments, a preset coordinate system may be established based on the width and height of the first texture image mapped to the range of [0,1]. For example, the horizontal direction of the preset coordinate system may be represented by U (or x), and the vertical direction of the preset coordinate system may be represented by V (or y), with (0,0) representing the lower left corner of the first texture image and (1,1) representing the upper right corner of the first texture image. Since the graphic mask is generated based on the first texture image and has the same size as the first texture image, the coordinates corresponding to each pixel in the first texture image may be directly applied to the graphic mask.
[0053] In some embodiments, the first preset scaling factor may be used to characterize the degree to which the graphic mask is proportionally enlarged or reduced in a specific direction (such as a specific axis). The first preset scaling factor may be an adjustable parameter open to user input, and is used to offset the shadow pattern in the graphic mask, such as stretching or compressing, to change the shape of the shadow pattern. The first preset scaling factor may be determined based on the position of the light source, the state of the shadow to be presented, etc. Figure 5 is a schematic diagram of a stretched graphic mask according to some embodiments of the present specification. For example, assuming that the light source is located at the upper left, the first preset scaling factor can be set to stretch in the positive direction of the x-axis (such as to the right) and compress in the negative direction of the y-axis to simulate the stretching effect of the shadow. The stretched graphic mask can be as follows: Figure 5 shown.
[0054] In some embodiments, the position of each pixel in the shadow layer can be further offset based on the height gradient, so that the closer the pixel position in the shadow layer is to the preset height parameter in the preset axial direction, the smaller the offset of the pixel position in the shadow layer in the preset axial direction. The height gradient is determined based on the preset height parameter and the position component of the pixel position in the shadow layer in the preset axial direction. The preset height parameter is an adjustable height parameter value, which is used to control the offset amplitude of the shadow layer in the preset axial direction. The pixel position in the shadow layer is the pixel position after the graphic mask is offset based on the first preset scaling factor. Exemplarily, the height gradient corresponding to the pixel coordinates of the shadow layer on the y-axis component can be determined based on the distance function to calculate the distance between the pixel position in the shadow layer and the preset height parameter on the y-axis, so that the closer the pixel coordinates of the shadow layer are to the preset height parameter on the y-axis component, the smaller the height gradient corresponding to the pixel coordinates of the shadow layer on the y-axis component. When the pixel coordinates of the shadow layer exceed the preset height parameter on the y-axis component, the height gradient can be set to 0 to avoid affecting the undesired pixel position. Further, the offset corresponding to each pixel position in the shadow layer is calculated based on the height gradient corresponding to the pixel position in the shadow layer, and the position of each pixel in the shadow layer is updated based on the offset. Exemplarily, the pixel coordinates of the shadow layer can be multiplied on the y-axis component by the height gradient corresponding to the y-axis component to obtain the offset of the pixel coordinates of the shadow layer on the y-axis component, and the offset is added to the current component of the pixel coordinates of the shadow layer on the y-axis to update the pixel coordinates of the shadow layer, so that the closer the pixel position in the shadow layer is to the preset height parameter in the preset axial direction, the smaller the offset of the pixel position of the shadow layer is, so that the shadow displayed in the shadow layer is stretched according to the preset height parameter and the stretching effect tends to decay, thereby simulating a more realistic negative effect.
[0055] In some embodiments, the transparency of pixels whose pixel color values in the shadow layer are black may be further set to 0, thereby hiding the black background and displaying only the shadow pattern whose color value in the shadow layer is set to a preset shadow color.
[0056] Step 240 , mixing the first pixel information of the shadow layer with the first pixel information of the first texture image to generate a second texture image. In some embodiments, step 240 may be implemented by a mixing processing module 1240 .
[0057] In some embodiments, the first pixel information of the foreground area of the first texture image can be mixed with the first pixel information of the shadow layer, and the pixel area where the foreground area and the shadow layer overlap in the second texture image is set as the first pixel information of the foreground area of the first texture image, so that the image of the foreground area of the first texture image is fully displayed in the second texture image, wherein the shadow in the shadow layer can be partially or fully displayed to present the effect of generating a shadow for the image of the foreground area of the first texture image. In some embodiments, the first pixel information can be a color value.
[0058] In some embodiments, the background area of the first texture image can be filtered based on the graphic mask, and specifically, the first pixel information of the background area of the first texture image can be filtered based on the graphic mask, so as to hide the background area of the first texture image. Specifically, the color value of each pixel of the first texture image can be multiplied by the numerical value corresponding to each pixel in the image mask, wherein the numerical value corresponding to each pixel in the image mask can be a numerical value discretized into 0 and 1, and the numerical value 1 can indicate that the pixel is displayed in the first texture image, and the numerical value 0 can indicate that the pixel is hidden in the first texture image. The color value of the foreground area in the first texture image can be retained by multiplication calculation, and the color value of the background area of the first texture image can be filtered. In some embodiments, when a part of the graphic mask has a hole problem, the graphic mask can be further repaired for the hole. The graphic mask used in this step can be a graphic mask after the hole repair. The hole repair method of the graphic mask can refer to the description in the process 800 below, which will not be repeated here.
[0059] In some embodiments, the pixel information of the second unit pixel of the second texture image at the corresponding pixel position can be further set based on the first pixel information of the filtered first texture image and the shadow layer at the corresponding pixel position. The unit pixel can be the smallest displayable unit in the image, representing a single pixel, and the second unit pixel can be any unit pixel in the second texture image. Specifically, for any second unit pixel in the second texture image, it can be determined whether the first pixel information exists at the corresponding pixel position of the second unit pixel in the filtered first texture image. When the first pixel information exists at the corresponding pixel position of the filtered first texture image, the pixel information of the second unit pixel is set to the first pixel information of the filtered first texture image at the corresponding pixel position. When the first pixel information does not exist at the corresponding pixel position of the filtered first texture image and the first pixel information exists at the corresponding pixel position of the shadow layer, the pixel information of the second unit pixel is set to the first pixel information of the shadow layer at the corresponding pixel position. Because the shadow pattern in the shadow layer has been stretched and offset, the shadow pattern in the shadow layer does not completely overlap with the pattern in the foreground area of the first texture image. This allows the pattern in the foreground area of the first texture image to be fully displayed in the second texture image, while the shadow pattern in the shadow layer is only displayed in the non-overlapping area, thereby presenting the effect of creating a shadow for the image in the foreground area of the first texture image.
[0060] In some embodiments, when a background color needs to be added to the second texture image, the background color value desired to be added may be further configured for the second unit pixel in the second texture image that is not set with a color value.
[0061] In some embodiments, the first pixel information corresponding to each pixel position obtained by mixing the first pixel information of the shadow layer with the first pixel information of the first texture image can be drawn into the rendering target texture, thereby generating a second texture image. The rendering target texture can be used to capture, store and reuse rendering results in graphics rendering, and it can store the rendered image data in a texture object for use in subsequent rendering processes.
[0062] In some embodiments, multiple first texture images with the same or similar backgrounds may be automatically batch processed by repeating steps 210 - 240 . Figure 6 is a schematic diagram of a second texture image generated in batches according to some embodiments of this specification, such as Figure 6As shown, through automated batch processing, corresponding shadow layers can be quickly generated for a large number of first texture images, and the first pixel information of the shadow layer is mixed with the first pixel information of the first texture image to automatically generate second texture images in batches, thereby effectively reducing the time cost and operation cost of making shadow layers and improving the efficiency of making shadow layers. In addition, applying this automated batch shadow generation solution to game development can greatly improve game development efficiency and shorten the game development cycle.
[0063] In some embodiments, because the color of some pixels in the foreground area of the first texture image is too close to the color of the background pixels, or the precision of the first preset threshold setting is not accurate enough, hole pixels are generated when generating a graphic mask based on the foreground area and / or background area of the first texture image, wherein a hole pixel refers to a pixel in the graphic mask that should originally represent the foreground area of the first texture image but is mistakenly judged to represent the background area of the first texture image. For example, the value corresponding to the pixel in the graphic mask used to display the foreground area of the first texture image should be 1 (the corresponding displayed color is the preset shadow color), but because it is mistakenly judged as the background area, the value corresponding to the pixel is set to 0 (the corresponding displayed color is black). Figure 7 is a schematic diagram of a graphic mask containing hole pixels according to some embodiments of this specification, such as Figure 7 As shown in the dotted area, some pixels in the graphic mask representing the foreground area in the first texture image should originally be set to the preset shadow color, but are currently misjudged as pixels representing the background area in the first texture image and are set to black, so the hole pixels in the graphic mask need to be repaired.
[0064] In some embodiments, the hole pixels in the graphic mask may be repaired based on the first texture image. Specifically, one or more unit pixels in the first texture image may be determined by convolution, and whether to repair the unit pixel is determined based on the second pixel information of the pixels around the unit pixel. The following specifically introduces the method for repairing the hole pixels through process 800. Figure 8 It is an exemplary flow chart of a cavity repair method shown in some embodiments of this specification. Figure 8 The process 800 shown may be executed by a computing device, for example, may be implemented by a hole repair module 1250 in an image shadow adding system 1200 arranged on the computing device. Figure 8 As shown, process 800 may include the following steps.
[0065] Step 810: Determine second pixel information of the first texture image.
[0066] In some embodiments, the first texture image may include a foreground area and a mixed area, and the mixed area may include pixels in the first texture image corresponding to the hole pixels in the graphic mask and pixels in the background area of the first texture image. The second pixel information may include a color value or a grayscale value.
[0067] In some embodiments, the second pixel information of the foreground area of the first texture image and the second pixel information of the mixed area of the first texture image can be determined based on the graphic mask. In some embodiments, the numerical value corresponding to each pixel in the graphic mask can represent whether the corresponding pixel in the first texture image is displayed or not. For example, when the numerical value corresponding to a certain pixel in the graphic mask is 1, it indicates that the display state of the pixel corresponding to the pixel in the first texture image is displayed, and when the numerical value corresponding to a certain pixel in the graphic mask is 0, it indicates that the display state of the pixel corresponding to the pixel in the first texture image is hidden.
[0068] In some embodiments, the color value of the pixel in the first texture image corresponding to the pixel used to represent display in the graphic mask can be set to a preset color value, so that the color value of the foreground area of the first texture image is the preset color value, and the original color value of the pixel in the first texture image corresponding to the pixel used to represent hidden in the graphic mask is retained, so that the color value of the mixed area is the original color value, wherein the preset color value is less than or equal to the original color value of the mixed area. Exemplarily, the preset color value can be black, and the corresponding RGB is (0, 0, 0) to ensure that the preset color value is less than or equal to any original color value of the mixed area. For example, when the numerical value corresponding to the pixel in the graphic mask is 1, the color value of the corresponding pixel in the first texture image can be set to black, so that the color value of the foreground area of the first texture image is black; when the numerical value corresponding to the pixel in the graphic mask is 0, the original color value of the corresponding pixel in the first texture image can be retained, so that the color value of the mixed area is the original color value.
[0069] In other embodiments, the color value of the pixel in the first texture image corresponding to the pixel used to represent the hidden pixel in the graphic mask can be set to a preset color value, so that the color value of the mixed area is the preset color value, and the original color value of the pixel in the first texture image corresponding to the pixel used to represent the displayed pixel in the graphic mask is retained, so that the color value of the foreground area of the first texture image is the original color value, wherein the preset color value is less than or equal to the original color value of the foreground area. For example, when the numerical value corresponding to the pixel in the graphic mask is 0, the color value of the corresponding pixel in the first texture image can be set to black, so that the color value of the mixed area of the first texture image is black; when the numerical value corresponding to the pixel in the graphic mask is 1, the original color value of the corresponding pixel in the first texture image can be retained, so that the color value of the foreground area is the original color value.
[0070] In some embodiments, the transparency of the pixels in the first texture image can also be directly used to determine the second pixel information of the foreground area of the first texture image and the second pixel information of the mixed area of the first texture image. Specifically, when separating the foreground area and the background area of the first texture image, the transparency of the foreground area can be set to opaque, and the transparency of the background area can be set to transparent. At this time, the background area containing hole pixels can be regarded as a mixed area. Further, the color value of the pixel with transparent transparency in the first texture image can be set to a preset color value, so that the color value of the mixed area is the preset color value, and the original color value of the pixel with opaque transparency in the first texture image is retained, so that the color value of the foreground area of the first texture image is the original color value, wherein the preset color value is less than or equal to the original color value of the foreground area. Exemplarily, the preset color value can be black, and the corresponding RGB is (0, 0, 0).
[0071] The color value of the foreground area of the first texture image is set to a preset color value and the original color value of the mixed area is retained, or the color value of the mixed area is set to a preset color value and the original color value of the foreground area of the first texture image is retained. Both results can distinguish the colors of the foreground area and the mixed area of the first texture image, so as to make a subsequent judgment based on the difference in color values of the two areas.
[0072] In some embodiments, when the color of the foreground area or the mixed area of the first texture image is relatively complex, the color values of the mixed area and the foreground area may be further converted into grayscale values, for example, the values of the three channels of the color are converted into the grayscale values of a single channel based on a preset conversion formula, so as to reduce the number of judgment channels when performing threshold judgment in subsequent steps. In some embodiments, determining the color value or grayscale value of the foreground area and the mixed area of the first texture image may be a one-time operation performed on the entire first texture image, for example, all pixels in the first texture image are processed to determine the color value or grayscale value of the foreground area and the mixed area of the first texture image. In other embodiments, determining the color value or grayscale value of the foreground area and the mixed area of the first texture image may be multiple operations performed on the first texture image sub-areas, for example, in step 820, the color value or grayscale value of the pixel belonging to the foreground area or the mixed area in each preset pixel area centered on the first unit pixel is determined in the preset pixel area.
[0073] In some embodiments, the color values set for the foreground area and the mixed area of the first texture image in step 810 are only used as intermediate values so that judgment is made based on the intermediate values in step 820, which does not change the color values originally displayed in the first texture image.
[0074] Step 820, perform the following processing on the first unit pixel in the first texture image or mixed area: count the number of pixels whose second pixel information corresponding to the pixels located in the preset pixel area meets the second preset threshold condition; when the number of pixels meeting the second preset threshold condition meets the third preset threshold condition, set the color of the pixel corresponding to the first unit pixel in the graphic mask to the preset shadow color.
[0075] In some embodiments, the position of the first unit pixel may be located within a preset pixel area, wherein the unit pixel may be the smallest displayable unit in the image, representing a single pixel, and the first unit pixel may be any unit pixel in the first texture image. In some embodiments, the preset pixel area may be an area that is uniformly diffused around the first unit pixel according to a preset offset. Exemplarily, assuming that the preset offset is the distance corresponding to four unit pixels, the preset pixel area may be a 9×9 pixel matrix formed by offsetting four unit pixels in the four directions of left, right, top, and bottom with the first unit pixel as the center. The preset pixel area may also be a 3×3, 5×5, or 7×7 pixel matrix area to ensure that the pixels on the left and right and top and bottom of the first unit pixel in the preset pixel area are symmetrically distributed.
[0076] In some embodiments, the number of pixels in the preset pixel area that meet the second preset threshold condition can be determined by diffusion in a "M" shape with the position of the first unit pixel as the center to the surrounding pixels. Among them, the "M"-shaped diffusion can be a mode of diffusion in eight directions (up, down, left, right, upper left, upper right, lower left, and lower right) around the position of the first unit pixel. For example, for a 3×3 pixel area, the first unit pixel can be used as the center to diffuse in eight directions around, that is, eight pixels in a circle around the first unit pixel, to determine the number of pixels in the 3×3 pixel area that meet the second preset threshold condition. In other embodiments, the number of pixels in the preset pixel area that meet the second preset threshold condition can also be determined in a "M"-shaped diffusion manner. For example, for a 9×9 pixel area, the 9×9 pixel area can be traversed with the first unit pixel as the center, and the number of pixels in the 9×9 pixel area that meet the second preset threshold condition can be determined.
[0077] In some embodiments, the second preset threshold condition can be determined based on the color values set for the foreground area and the mixed area in the first texture image in step 810. Exemplarily, when the color value of the foreground area of the first texture image is a preset color value (such as black) and the mixed area retains the original color value, if the color value or grayscale value corresponding to the pixel in the preset pixel area is less than the second preset threshold, it is determined that the second preset threshold condition is met; when the color value of the mixed area of the first texture image is a preset color value (such as black) and the foreground area of the first texture image retains the original color value, if the color value or grayscale value corresponding to the pixel in the preset pixel area is greater than the second preset threshold, it is determined that the second preset threshold condition is met. When a pixel meets the second preset threshold condition, it means that the probability that the pixel belongs to the foreground area in the first texture image is high.
[0078] When comparing the color value with the second preset threshold, the second preset threshold may include three thresholds set for the three RGB channels respectively. When performing the threshold comparison, the three channel values may be compared respectively. This method may be used for the first texture image with simpler colors. When the colors in the first texture image are more complex, the number of comparisons may be simplified and the accuracy of the comparison may be improved by comparing the grayscale values corresponding to the colors.
[0079] In some embodiments, when the number of pixels in a preset pixel area that meets the second preset threshold condition is greater than a third preset threshold, it indicates that the preset pixel area corresponding to the first unit pixel has a high probability of belonging to the foreground area of the first texture image, and the color of the pixel corresponding to the first unit pixel in the graphic mask is set to the preset shadow color.
[0080] In some embodiments, each first unit pixel in the first texture image may be processed according to the method of step 820 to determine whether the area where each first unit pixel is located is the foreground area of the first texture image. When the area where a first unit pixel is located is determined to be the foreground area, the color of the pixel corresponding to the first unit pixel in the graphic mask is set to the preset shadow color to repair the hole pixel in the graphic mask. In some embodiments, when the area where a first unit pixel is located is determined to be the foreground area according to the method of step 820, it is further determined whether the color of the pixel corresponding to the first unit pixel in the graphic mask is the preset shadow color. If it is not the preset shadow color, the color of the pixel corresponding to the first unit pixel in the graphic mask is set to the preset shadow color. In other embodiments, the first unit pixels of a specific pixel area in the first texture image may also be processed, for example, the first unit pixels of the mixed area in the first texture image are processed according to the method of step 820. For the first unit pixel located in the mixed area, or the pixel belonging to the background area of the first texture image, or the hole pixel, when the number of pixels that meet the second preset threshold condition in the preset pixel area corresponding to the first unit pixel meets the third preset threshold condition, it means that the probability that the first unit pixel belongs to the foreground area in the first texture image is high. In other words, the probability that the first unit pixel belongs to the hole pixel is high, and the color of the pixel corresponding to the first unit pixel in the graphic mask can be set to the preset shadow color, so as to directly repair the hole pixel.
[0081] In some embodiments, process 800 may be a subsequent step of step 220, for example, process 800 may be performed between step 220 and step 230. When multiple first texture images with the same or similar backgrounds are automatically batch processed by repeating steps 210-240, process 800 may participate in the automatic batch processing as a step performed between step 220 and step 230 to improve the efficiency of processing hole pixels.
[0082] In some embodiments, since the shadow layer is stretched by offsetting, scaling, and other operations on the graphic mask when generating the shadow layer, the pixel position in the shadow layer may exceed the texture range (such as [0,1]), resulting in repeated edge drawing problems during texture addressing. Texture addressing refers to obtaining data in a texture image based on texture coordinates, such as sampling and blending the colors in the shadow layer and the first texture image based on the pixel position of the shadow layer (such as texture coordinates). Specifically, when texture addressing is performed based on an edge mode, when the texture coordinates exceed the texture range, the texture coordinates that exceed the texture range will be restricted to the edge of the texture range, thereby performing repeated drawing at the edge. Fig. 9This is a schematic diagram of a second texture image shown in some embodiments of the present specification. It can be seen that the second texture image has a problem of repeated edge drawing. When the second texture image is offset or scaled, the repeatedly drawn area will be displayed in the visible range, so the repeatedly drawn area needs to be hidden.
[0083] The following specifically introduces how to hide the repeatedly drawn area through process 1000. Fig.10 This is an exemplary flow chart of a first pixel information filtering method according to some embodiments of this specification. Fig.10 The process 1000 shown may be executed by a computing device, for example, may be implemented by an information filtering module 1260 in an image shadow adding system 1200 arranged on the computing device. Fig.10 As shown, process 1000 may include the following steps.
[0084] Step 1010: determine whether each pixel position of the second texture image is located outside a preset display area based on the first scaling factor and the size of the second texture image.
[0085] In some embodiments, the offset position corresponding to each pixel in the second texture image can be determined based on the first scaling factor and the initial position corresponding to each pixel in the second texture image. The initial position corresponding to each pixel in the second texture image corresponds to the pixel position in the first texture image. For example, the initial position corresponding to each pixel in the second texture image can be the texture coordinate corresponding to each pixel in the first texture image. Since the second texture image is generated based on a graphic mask, and the graphic mask is generated based on the first texture image, the initial position corresponding to each pixel in the second texture image can be regarded as the texture coordinate corresponding to each pixel in the first texture image. Since the shadow layer is generated by performing a corresponding offset operation on the graphic mask (such as offsetting the graphic mask based on the first scaling factor), the coordinate position of each pixel in the correspondingly generated second texture image is also offset. The subsequent scaling operation on the second texture image will also cause the coordinate position of each pixel in the second texture image to be further offset. Therefore, the offset position corresponding to each pixel in the second texture image can be the offset coordinate position corresponding to the corresponding offset operation and scaling operation.
[0086] In some embodiments, the first scaling factor may be determined based on a first preset scaling factor. The first preset scaling factor may be an adjustable parameter open to user input when generating the shadow layer in step 230, and is used to offset the shadow pattern in the graphic mask to change the shape of the shadow pattern. Specifically, the absolute value of the larger value of the scaling component of the first preset scaling factor in the x-axis direction and the scaling component in the y-axis direction may be used as the first scaling factor. Further, the larger value may be multiplied by the preset coefficient to obtain the first scaling factor, thereby adaptively scaling the second texture graphic. In some embodiments, the first scaling factor may be further updated based on a preset reference scaling factor, wherein the preset reference scaling factor may be a fixed scaling factor set by the software or engine for uniformly displaying the image when the second texture image is applied to a specific image production software or engine (such as a game engine). Exemplarily, the preset reference scaling factor may be added to the first scaling factor to further update the first scaling factor.
[0087] In some embodiments, the initial position corresponding to each pixel in the second texture image may be multiplied by the first scaling factor to obtain the offset position corresponding to each pixel in the second texture image. In other embodiments, since the coordinate (0,0) of the texture image is usually located at the lower left corner of the texture image, if scaling is performed directly, the reference position of the scaling operation will be scaled from the lower left corner (0,0), so the scaling reference position may be further adjusted to the center position of the texture image based on the first scaling factor, such as the center coordinate (0.5,0.5), so that when scaling the second texture image, the center coordinate (0.5,0.5) may be used as the reference position for scaling.
[0088] For example, the formula float2uv=( s *i.uv+( s *-0.5)+0.5) To calculate the offset position corresponding to each pixel in the second texture image, where s represents the first scaling factor, i.uv Indicates the initial position of each pixel in the second texture image, s *i.uv It means multiplying the initial position corresponding to each pixel in the second texture image by the first scaling factor. ( s *-0.5)+0.5) It means that the center position of each pixel in the second texture image is further adjusted so that when the second texture image is scaled, the center coordinate (0.5, 0.5) is used as the reference position for scaling. float2uv Indicates the offset position corresponding to each pixel in the second texture image.
[0089] In some embodiments, the offset position corresponding to each pixel in the second texture image may also be updated based on a preset mirror parameter. The preset mirror parameter may be a parameter open to user input for mirroring the second texture image. Exemplarily, the offset position corresponding to each pixel in the second texture image may be multiplied by the preset mirror parameter to update the offset position corresponding to each pixel in the second texture image. In other embodiments, when the pixel position in the shadow layer is offset based on the height gradient, the offset position corresponding to each pixel in the second texture image may also be updated based on the height gradient.
[0090] Exemplarily, the initial position (x0, y0) corresponding to each pixel in the second texture image may be multiplied by the first scaling factor s to obtain the offset position ( , ), the offset position ( , ) Multiplying the height gradient Δy corresponding to the y-axis component gives the offset position ( , ) is the offset on the y-axis component Δy, and the offset Δy and the offset position ( , ) on the y-axis Add to obtain the offset position corresponding to each pixel in the updated second texture image ( , Δy), and then update the offset position corresponding to each pixel in the second texture image ( , Δy) is multiplied by the preset mirror parameter to obtain the final offset position corresponding to each pixel in the second texture image ( , Δy) *Mirror .
[0091] In some embodiments, after determining the offset position corresponding to each pixel in the second texture image, it can be further determined whether the offset position corresponding to each pixel in the second texture image is located outside the preset display area. The preset display area can be a display area determined based on the size of the second texture image and the first scaling factor, and is used to display the pixel area in the second texture image where no repeated drawing problem occurs. The size of the second texture image can be the width or height of the second texture image, and the size of the second texture image can correspond to the size of the first texture image, for example, the size of the second texture image can be the same as the size of the first texture image. Exemplarily, the size of the second texture image and the first scaling factor can be multiplied to determine the range of the preset display area corresponding to the second texture image in the texture coordinate system corresponding to the canvas, including the texture coordinates corresponding to the left and lower boundaries of the preset display area, and the texture coordinates corresponding to the right and upper boundaries of the preset display area. Exemplarily, assuming that the size of the first texture image is X*Y, the lower left corner of the first texture image corresponds to the coordinate position (0,0) in the texture coordinate system, and the upper right corner of the first texture image corresponds to the coordinate position (X,Y) in the texture coordinate system, and its center coordinates are (X / 2,Y / 2). When the second texture image is scaled with its center coordinate (X / 2, Y / 2) as the reference position, assuming that the first scaling factor is 0.5, it means that the size of the second texture image in the X-axis and Y-axis directions is reduced to half of the original size, that is, the size of the scaled image is X / 2*Y / 2. Still taking (X / 2, Y / 2) as the center coordinate, the texture coordinates corresponding to the left and lower boundaries of the preset display area after scaling are (X / 4, Y / 4), and the texture coordinates corresponding to the right and upper boundaries of the preset display area are (3X / 4, 3Y / 4).
[0092] Step 1020: Filter pixels in the second texture image that are outside a preset display area.
[0093] In some embodiments, when the position of a pixel of the second texture image is outside the preset display area, the pixel is hidden, and when the position of a pixel of the second texture image is within the preset display area, the pixel is displayed. Exemplarily, the pixels in the second texture image can be hidden or displayed by generating a graphic mask for the second texture image. For example, when the value of the pixel in the graphic mask corresponding to the second texture image is set to 0, it means that the pixel is hidden in the second texture image, and when the value of the pixel in the graphic mask corresponding to the second texture image is set to 1, it means that the pixel is displayed in the second texture image. In this way, the pixels in the second texture image that are outside the preset display area are filtered to solve the problem of repeated drawing except for edges. Fig.11is a schematic diagram of a second texture image according to some embodiments of this specification. For example, the second texture image with the problem of edge duplication removed can be as follows: Fig.11 shown.
[0094] In some embodiments, steps 1010-1020 can be repeated to automatically batch process multiple second texture images to quickly and efficiently solve the problem of repeated edge drawing in a batch of second texture images, thereby effectively reducing the time cost of processing the second texture images and improving processing efficiency. In addition, applying the solution for automatic batch processing of repeated edge drawing problems to game development can greatly improve game development efficiency and shorten the game development cycle.
[0095] This specification also provides an image shadow adding system. Fig.12 FIG. 1 is an exemplary block diagram of an image shadow adding system according to some embodiments of the present specification. Fig.12 As shown, in some embodiments, the image shadow adding system 1200 may include an acquisition module 1210 , a mask generation module 1220 , a shadow generation module 1230 , and a blending processing module 1240 .
[0096] The acquisition module 1210 is used to acquire a first texture image.
[0097] The mask generating module 1220 is configured to generate a graphic mask based on the foreground area and / or the background area of the first texture image.
[0098] The shadow generating module 1230 is used to offset the graphic mask based on a first preset scaling factor to generate a shadow layer.
[0099] The blending processing module 1240 is used to blend the first pixel information of the shadow layer with the first pixel information of the first texture image to generate a second texture image, wherein the pixel area where the foreground area and the shadow layer overlap in the second texture image is set as the first pixel information of the foreground area of the first texture image, and the first pixel information includes the color value of the pixel, or the color value of the pixel and the transparency of the pixel.
[0100] In some optional embodiments, the mask generation module 1220 is also used to compare the first pixel information of the first texture image with the first preset threshold to separate the foreground area and the background area; generate a graphic mask based on the foreground area and / or the background area, wherein the color of the pixel area corresponding to the foreground area in the graphic mask is a preset shadow color.
[0101] In some optional embodiments, the shadow generation module 1230 is also used to offset the pixel position in the shadow layer based on the height gradient, so that the closer the pixel position in the shadow layer is to a preset height parameter in the preset axis direction, the smaller the offset of the pixel position in the shadow layer in the preset axis direction, wherein the height gradient is determined based on the preset height parameter and the position component of the pixel position in the shadow layer in the preset axis direction, the preset height parameter is used to control the offset amplitude of the shadow layer in the preset axis direction, and the pixel position in the shadow layer is the pixel position after the graphic mask is offset based on the first preset scaling factor.
[0102] In some optional embodiments, the blending processing module 1240 is also used to filter the background area of the first texture image based on the graphic mask; based on the first pixel information of the filtered first texture image and the shadow layer at the corresponding pixel position, set the pixel information of the second unit pixel of the second texture image at the corresponding pixel position; wherein, when the filtered first texture image has the first pixel information at the corresponding pixel position, the pixel information of the second unit pixel is set to the first pixel information of the filtered first texture image at the corresponding pixel position; when the filtered first texture image does not have the first pixel information at the corresponding pixel position, and the shadow layer has the first pixel information at the corresponding pixel position, the pixel information of the second unit pixel is set to the first pixel information of the shadow layer at the corresponding pixel position.
[0103] In some optional embodiments, the image shadow adding system 1200 may further include a hole repairing module 1250 for repairing hole pixels in the graphic mask based on the first texture image.
[0104] In some optional embodiments, the hole repair module 1250 is also used to determine second pixel information of the first texture image, wherein the first texture image includes a foreground area and a mixed area, the mixed area includes pixels in the first texture image corresponding to the hole pixels in the graphic mask and pixels in the background area of the first texture image, and the second pixel information includes the color value or grayscale value of the pixel; performing the following processing on the first unit pixel in the first texture image or the mixed area: counting the number of pixels whose second pixel information corresponding to the pixels located in the preset pixel area meets the second preset threshold condition, wherein the position of the first unit pixel is located in the preset pixel area; when the number of pixels meeting the second preset threshold condition meets the third preset threshold condition, setting the color of the pixel corresponding to the first unit pixel in the graphic mask to the preset shadow color.
[0105] In some optional embodiments, the hole repair module 1250 is further configured to determine, based on the graphic mask, second pixel information of the foreground area of the first texture image and second pixel information of the mixed area of the first texture image.
[0106] In some optional embodiments, the hole repair module 1250 is also used to set the color value of the pixel in the first texture image corresponding to the pixel used to represent the display in the graphic mask to a preset color value, so that the color value of the foreground area of the first texture image is the preset color value, and retain the original color value of the pixel in the first texture image corresponding to the pixel used to represent the hidden in the graphic mask, so that the color value of the mixed area is the original color value, wherein the preset color value is less than or equal to the original color value of the mixed area; or set the color value of the pixel in the first texture image corresponding to the pixel used to represent the hidden in the graphic mask to the preset color value, so that the color value of the mixed area is the preset color value, and retain the original color value of the pixel in the first texture image corresponding to the pixel used to represent the display in the graphic mask, so that the color value of the foreground area of the first texture image is the original color value, wherein the preset color value is less than or equal to the original color value of the foreground area.
[0107] In some optional embodiments, the hole repair module 1250 is further used to convert the color values of the mixed area and the foreground area into grayscale values respectively.
[0108] In some optional embodiments, the image shadow adding system 1200 may further include an information filtering module 1260, which is used to determine whether the pixel positions of the second texture image are located outside the preset display area based on the first scaling factor and the size of the second texture image, wherein the first scaling factor is determined based on the first preset scaling factor; and filter the pixels in the second texture image that are located outside the preset display area.
[0109] In some optional embodiments, the information filtering module 1260 is also used to determine the offset position corresponding to each pixel in the second texture image based on the first scaling factor and the initial position corresponding to each pixel in the second texture image, wherein the initial position corresponding to each pixel in the second texture image corresponds to the pixel position in the first texture image; and determine whether the offset position corresponding to each pixel in the second texture image is outside a preset display area, wherein the preset display area is determined based on the first scaling factor and the size of the second texture image.
[0110] In some optional embodiments, the information filtering module 1260 is further used to, before determining whether the offset position corresponding to each pixel in the second texture image is outside the preset display area, also include: updating the offset position corresponding to each pixel in the second texture image based on preset mirror parameters.
[0111] For more information about each module, see Figures 1 to 11 The relevant description of will not be repeated here. It should be understood that Fig.12The system and its modules shown can be implemented in various ways. For example, in some embodiments, the system and its modules can be implemented by hardware, software, or a combination of software and hardware. Among them, the hardware part can be implemented using dedicated logic; the software part can be stored in a memory and executed by an appropriate instruction execution system, such as a microprocessor or dedicated design hardware. Those skilled in the art will understand that the above methods and systems can be implemented using computer executable instructions and / or control codes contained in a processor, such as a disk, CD or DVD-ROM, etc., and such codes are provided in a carrier medium or a memory of a programmable device. The system and its modules of this specification can not only be implemented by hardware circuits such as ultra-large-scale integrated circuits or gate arrays, semiconductors such as logic chips, transistors, etc., or programmable hardware devices such as field programmable gate arrays, programmable logic devices, etc., but can also be implemented by software executed by various types of processors, and can also be implemented by a combination of the above hardware circuits and software (e.g., firmware).
[0112] It should be noted that the above description of the system and its modules is only for convenience of description and does not limit this specification to the scope of the embodiments. It is understandable that for those skilled in the art, after understanding the principle of the system, it is possible to arbitrarily combine the modules without deviating from this principle to form a subsystem connected to other modules. Or some modules may be split to obtain more modules or multiple units under the module. Such variations are all within the scope of the disclosure of this specification.
[0113] Some embodiments of the present specification also provide a computer program product, including computer instructions. When at least part of the computer instructions are executed by a processor, the present specification can be implemented. Figures 1 to 11 In some embodiments, the computer program product may only involve computer instructions, which may be carried by a storage medium or a processing device. In other embodiments, the computer program product may also be a storage medium or a processing device containing the aforementioned computer instructions. The processing device may include one or more processors and a storage medium.
[0114] In some embodiments, the processor may be a combination of one or more of the following processors: a central processing unit (CPU), an application specific integrated circuit (ASIC), an application specific instruction set processor (ASIP), a graphics processing unit (GPU), a physical processing unit (PPU), a digital signal processor (DSP), a field programmable gate array (FPGA), a programmable logic device (PLD), a programmable logic controller (PLC), a reduced instruction set computer (RISC), and a microprocessor.
[0115] In some embodiments, the storage medium may include a combination of one or more of the following: a mass storage, a removable storage, a volatile read-write memory, and a read-only memory (ROM). Exemplary mass storage may include a magnetic disk, an optical disk, a solid-state hard disk, and the like. Exemplary removable storage may include a flash disk, a floppy disk, an optical disk, a memory card, a compressed hard disk, a magnetic tape, and the like. Exemplary volatile read-write memory may include a random access memory (RAM). Exemplary random access memory may include a dynamic random access memory (DRAM), a double data rate synchronous dynamic random access memory (DDRSDRAM), a static random access memory (SRAM), a thyristor random access memory (T-RAM), and a zero capacitance memory (Z-RAM), and the like. Exemplary read-only memory may include a masked read-only memory (MROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), a compact disk read-only memory (CD-ROM), and a digital multifunction hard disk read-only memory, and the like.
[0116] The beneficial effects that may be brought about by the embodiments of this specification include but are not limited to: (1) by generating a graphic mask based on the foreground area and / or background area of the first texture image, offsetting the image mask based on the first preset scaling factor, generating a shadow layer, mixing the first pixel information of the shadow layer with the first pixel information of the first texture image to generate a second texture image, thereby improving the efficiency of adding shadows to the texture image, reducing the time cost of adding shadows, and improving the versatility of adding shadows; (2) by repairing the hole pixels, the accuracy of generating the graphic mask is improved, so that the shadow layer can be generated based on the graphic mask later; (3) by filtering the pixels outside the preset display area, the problem of repeated edge drawing is solved, and the display effect of the second texture image is optimized; (4) by automatically batch processing, the corresponding shadow layers are quickly generated for a large number of first texture images, effectively reducing the time cost and operation cost of making shadow layers, and improving the efficiency of making shadow layers. The method has strong automation, does not require complex operations, can save time and labor costs, and improve game development efficiency. It should be noted that different embodiments may produce different beneficial effects. In different embodiments, the beneficial effects that may be produced may be any one or a combination of the above, or any other beneficial effects that may be obtained.
[0117] The basic concepts have been described above. Obviously, for those skilled in the art, the above detailed disclosure is only for example and does not constitute a limitation of this specification. Although not explicitly stated here, those skilled in the art may make various modifications, improvements and corrections to this specification. Such modifications, improvements and corrections are taught in this specification, so such modifications, improvements and corrections still belong to the spirit and scope of the exemplary embodiments of this specification.
Claims
1. A method for adding shadows to an image, characterized in that: The method comprises: Obtaining a first texture image; generating a graphic mask based on a foreground area and / or a background area of the first texture image; offsetting the graphic mask based on a first preset scaling factor to generate a shadow layer; The first pixel information of the shadow layer is mixed with the first pixel information of the first texture image to generate a second texture image, wherein the pixel area where the foreground area in the second texture image overlaps with the shadow layer is set as the first pixel information of the foreground area of the first texture image, and the first pixel information includes the color value of the pixel, or the color value of the pixel and the transparency of the pixel.
2. The method according to claim 1, characterized in that The step of generating a graphic mask based on the foreground area and / or the background area of the first texture image comprises: Comparing the first pixel information of the first texture image with a first preset threshold to separate the foreground area from the background area; The graphic mask is generated based on the foreground area and / or the background area, wherein the color of the pixel area corresponding to the foreground area in the graphic mask is a preset shadow color.
3. The method according to claim 2, characterized in that The step of generating a graphic mask based on the foreground area and / or the background area of the first texture image further comprises: The hole pixels in the graphic mask are repaired based on the first texture image.
4. The method according to claim 3, characterized in that The repairing of the hole pixels in the graphic mask based on the first texture image comprises: Determining second pixel information of the first texture image, wherein the first texture image includes a foreground area and a mixed area, the mixed area includes pixels in the first texture image corresponding to the hole pixels in the graphic mask and pixels in the background area of the first texture image, and the second pixel information includes a color value or a grayscale value of the pixel; The first unit pixel in the first texture image or the mixed area is processed as follows: Counting the number of pixels whose second pixel information corresponding to pixels located in a preset pixel area meets a second preset threshold condition, wherein the position of the first unit pixel is located in the preset pixel area; When the number of pixels satisfying the second preset threshold condition satisfies the second preset threshold condition, the color of the pixel corresponding to the first unit pixel in the graphic mask is set to a preset shadow color.
5. The method according to claim 4, characterized in that The preset pixel area is an area that is uniformly diffused around the first unit pixel according to a preset offset.
6. The method according to claim 4, characterized in that Determining the second pixel information of the first texture image includes: Second pixel information of a foreground area of the first texture image and second pixel information of a mixed area of the first texture image are determined based on the graphic mask.
7. The method according to claim 6, characterized in that The determining, based on the graphic mask, second pixel information of the foreground area of the first texture image and second pixel information of the mixed area of the first texture image comprises: Setting the color value of the pixel in the first texture image corresponding to the pixel used to represent display in the graphic mask to a preset color value, so that the color value of the foreground area of the first texture image is the preset color value, retaining the original color value of the pixel in the first texture image corresponding to the pixel used to represent concealment in the graphic mask, so that the color value of the mixed area is the original color value, wherein the preset color value is less than or equal to the original color value of the mixed area; or The color value of the pixel in the first texture image corresponding to the pixel used to represent hiddenness in the graphic mask is set to a preset color value, so that the color value of the mixed area is the preset color value, and the original color value of the pixel in the first texture image corresponding to the pixel used to represent display in the graphic mask is retained, so that the color value of the foreground area of the first texture image is the original color value, wherein the preset color value is less than or equal to the original color value of the foreground area.
8. The method according to claim 7, characterized in that The determining, based on the graphic mask, second pixel information of the foreground area of the first texture image and second pixel information of the mixed area of the first texture image further includes: The color values of the mixed area and the foreground area are converted into grayscale values respectively.
9. The method according to claim 1, characterized in that: After offsetting the graphic mask based on the first preset scaling factor to generate the shadow layer, the method further includes: The pixel position in the shadow layer is offset based on the height gradient, so that the closer the pixel position in the shadow layer is to a preset height parameter in the preset axial direction, the smaller the offset of the pixel position in the shadow layer in the preset axial direction, wherein the height gradient is determined based on the preset height parameter and a position component of the pixel position in the shadow layer in the preset axial direction, the preset height parameter is used to control the offset amplitude of the shadow layer in the preset axial direction, and the pixel position in the shadow layer is the pixel position after the graphic mask is offset based on a first preset scaling factor.
10. The method according to claim 1, characterized in that The mixing of the first pixel information of the shadow layer with the first pixel information of the first texture image to generate the second texture image comprises: filtering a background area of the first texture image based on the graphic mask; Based on the filtered first texture image and the first pixel information of the shadow layer at the corresponding pixel position, setting the pixel information of the second unit pixel of the second texture image at the corresponding pixel position; Wherein, when the filtered first texture image has first pixel information at the corresponding pixel position, the pixel information of the second unit pixel is set to the first pixel information of the filtered first texture image at the corresponding pixel position; When the filtered first texture image does not have first pixel information at the corresponding pixel position, and the shadow layer has first pixel information at the corresponding pixel position, the pixel information of the second unit pixel is set to the first pixel information of the shadow layer at the corresponding pixel position.
11. The method according to claim 1, characterized in that Also includes: determining whether each pixel position of the second texture image is located outside a preset display area based on a first scaling factor and a size of the second texture image, wherein the first scaling factor is determined based on a first preset scaling factor; Pixels in the second texture image that are outside the preset display area are filtered.
12. The method according to claim 11, characterized in that The step of judging whether each pixel position of the second texture image is located outside a preset display area based on the first scaling factor and the size of the second texture image comprises: determining an offset position corresponding to each pixel in the second texture image based on the first scaling factor and an initial position corresponding to each pixel in the second texture image, wherein the initial position corresponding to each pixel in the second texture image corresponds to a pixel position in the first texture image; It is determined whether the offset position corresponding to each pixel in the second texture image is outside the preset display area, wherein the preset display area is determined based on the first scaling factor and the size of the second texture image.
13. The method according to claim 12, characterized in that Before determining whether the offset position corresponding to each pixel in the second texture image is outside the preset display area, the method further includes: The offset position corresponding to each pixel in the second texture image is updated based on the preset mirror parameter.
14. An image shadow adding system, characterized in that: The system comprises: An acquisition module, used for acquiring a first texture image; A mask generation module, configured to generate a graphic mask based on a foreground area and / or a background area of the first texture image; A shadow generation module, configured to offset the graphic mask based on a first preset scaling factor to generate a shadow layer; A blending processing module is used to blend the first pixel information of the shadow layer with the first pixel information of the first texture image to generate a second texture image, wherein the pixel area where the foreground area in the second texture image overlaps with the shadow layer is set as the first pixel information of the foreground area of the first texture image, and the first pixel information includes the color value of the pixel, or the color value of the pixel and the transparency of the pixel.
15. A computer program product, characterized in that The invention comprises a computer program, and when at least a part of the computer program is executed by a processor, the method according to any one of claims 1 to 13 can be implemented.