A method and system for generating shadows for stick figures and line drawings
By performing RGB value perturbation and stroke density estimation on the original images of simple strokes and line drawings, combined with SR-CNN and convex hull methods, a shadow effect layer is generated, which solves the problems of high cost and slow rendering speed in the existing technology, and realizes the Efficient and low-cost shadow generation.
Patent Information
- Application Number
- CN202111388188.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-22
- Publication Date
- 2025-02-07
- Estimated Expiration
- 2041-11-22
AI Technical Summary
The existing brushstroke density estimation methods have high cost, slow rendering speed and cumbersome work when generating shadows for simple strokes and line drawings.
By perturbing the original image RGB value, the perturbed image is generated, and the artifact is removed using SR-CNN preprocessing. Then, the stroke density is estimated using the convex hull method, a shadow effect layer is generated, and the shadow is improved through wave function transformation and stroke density map Effect.
The low-cost and high-speed shadows are achieved to generate shadows for simple strokes and line drawings, significantly saving artists time and reducing workload.
Smart Images

Figure CN114332336B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of rendering technology, and in particular to a method and system for generating shadows for stick figures and line drawings. Background Art
[0002] The statements in this section merely provide background information related to the present invention and do not necessarily constitute prior art.
[0003] Non-realistic rendering is a part of computer graphics. Non-realistic rendering is more useful than realistic rendering in conveying some important information and increasing the simplicity of complex objects. Non-realistic rendering focuses more on artistry and is mostly used for drawing cartoons, watercolors, oil paintings, sketches, etc.
[0004] In many applications, such as architecture, industry, automobiles, and graphic design, non-realistic rendering can omit irrelevant details, focus on relevant features, simplify or eliminate ambiguous shapes, and show hidden parts or details to better convey information. Computer games and movies use non-realistic rendering to create stylized scenes or characters. Computer comics are also an important application of non-realistic rendering.
[0005] In life, shadows are everywhere. Lights and shadows imply artistic interpretations of characters and scenes. Shadows can be used to render the range of the picture. Image enhancement shadows can bring formal beauty. In previous studies, using brushstroke density to add shadows to images is more suitable for images with rich and colorful colors, but not suitable for simple drawings with a single color, especially large areas of white line drawings. By perturbing the RGB values of the image, the colors can be made richer and the pixels can be better extracted. After a series of processing on the perturbed image, the lighting effect layer is combined with the original image to obtain an image with shadows, and the effect is better. However, the existing brushstroke density estimation problem is still imperfect, and there are problems such as high cost, slow rendering speed and cumbersome work. Summary of the invention
[0006] In order to solve the above problems, the present invention proposes a method and system for generating shadows for stick figures and line drawings. The present invention can solve the problem of estimating brushstroke density.
[0007] According to some embodiments, the present invention adopts the following technical solutions:
[0008] A method for generating shading for stick figures and line drawings, comprising:
[0009] Get the original image;
[0010] Perturb the RGB value of the original image to generate a perturbed image;
[0011] Estimate the brush stroke density of the perturbed image and generate a shadow effect layer;
[0012] Combine the shadow effect layer with the original image to get the effect image.
[0013] Furthermore, the RGB value perturbation of the original image includes directly perturbing the RGB value of the image with a dark background, and performing mask processing and then perturbing the RGB value of the image with a light background.
[0014] Furthermore, after the perturbed image is generated, SR-CNN preprocessing is used to remove artifacts in the perturbed image.
[0015] Furthermore, estimating the brush stroke density of the disturbed image includes obtaining a brush stroke density map using a convex hull method.
[0016] Furthermore, the generating of the shadow effect layer includes smoothing the disturbed image and generating a blurred and rough image.
[0017] Furthermore, the generation of the shadow effect layer also includes generating a rough lighting effect diagram using a fuzzy rough image through wave function transformation.
[0018] Furthermore, the generating of the shadow effect layer also includes improving the rough light effect map through the brush stroke density map to obtain the shadow effect layer.
[0019] A system for generating shading for stick figures and line drawings, comprising:
[0020] The image acquisition module is configured to acquire an original image;
[0021] The image perturbation module is configured to perturb the RGB values of the original image to generate a perturbed image;
[0022] The shadow module is configured to estimate the brush stroke density for the perturbed image and generate a shadow effect layer;
[0023] The effect module is configured to combine the shadow effect layer with the original image to obtain an effect image.
[0024] A computer-readable storage medium stores a plurality of instructions, wherein the instructions are suitable for being loaded and executed by a processor of a terminal device for a method of generating shadows for stick figures and line drawings.
[0025] A terminal device includes a processor and a computer-readable storage medium, wherein the processor is used to implement various instructions; the computer-readable storage medium is used to store multiple instructions, wherein the instructions are suitable for being loaded and executed by the processor to generate shadows for stick figures and line drawings.
[0026] Compared with the prior art, the present invention has the following beneficial effects:
[0027] The present invention uses a brushstroke density method to add shadows to simple drawings and line drawings, which has low cost and fast running speed. The shadow effect can be obtained in only 20-30 seconds, which greatly saves the artist's time in adding shadows to images and reduces the workload. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] The drawings in the specification, which constitute a part of the present application, are used to provide further understanding of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute improper limitations on the present application.
[0029] Figure 1 is a flow chart of this embodiment;
[0030] Figure 2 It is the original picture material and the final effect picture of the line drawing of this embodiment;
[0031] Figure 3 It is the original picture material and the final effect picture of another line drawing of this embodiment;
[0032] Figure 4 It is the original picture material and the final effect picture of the stick figure of a single color in this embodiment;
[0033] Figure 5 It is the original picture material and the final effect picture of another single-color stick figure of this embodiment. DETAILED DESCRIPTION
[0034] The present invention will be further described below in conjunction with the accompanying drawings and embodiments.
[0035] It should be noted that the following detailed descriptions are illustrative and are intended to provide further explanation of the present application. Unless otherwise specified, all technical and scientific terms used herein have the same meanings as those commonly understood by those skilled in the art to which the present application belongs.
[0036] It should be noted that the terms used herein are only for describing specific embodiments and are not intended to limit the exemplary embodiments according to the present application. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should be understood that when the terms "comprise" and / or "include" are used in this specification, it indicates the presence of features, steps, operations, devices, components and / or combinations thereof.
[0037] Example 1.
[0038] like Figure 1 A method for generating shadows for stick figures and line drawings, comprising:
[0039] Get the original image;
[0040] Perturb the RGB value of the original image to generate a perturbed image;
[0041] Estimate the brush stroke density of the perturbed image and generate a shadow effect layer;
[0042] Combine the shadow effect layer with the original image to get the effect image.
[0043] The RGB value perturbation of the original image includes directly perturbing the RGB value of the image with a dark background, and performing mask processing and then perturbing the RGB value of the image with a light background.
[0044] After the perturbed image is generated, SR-CNN preprocessing is used to remove artifacts in the perturbed image.
[0045] The estimating the brush stroke density of the disturbed image includes obtaining a brush stroke density map using a convex hull method.
[0046] The generation of the shadow effect layer includes smoothing the disturbed image and generating a blurred and rough image.
[0047] The generating of the shadow effect layer also includes generating a rough lighting effect diagram using the fuzzy rough image through wave function transformation.
[0048] The generating of the shadow effect layer also includes improving the rough light effect map through the brush stroke density map to obtain the shadow effect layer.
[0049] Specifically,
[0050] First, the RGB value of the original image is perturbed:
[0051] The main task is to add shadows to simple drawings and line drawings with relatively single colors. First, the RGB value of the input original image is disturbed. We select pixels with RGB values greater than 100 in the image and randomly change their RGB values. The change value is as large as possible. We choose the change interval to be (20, 50) to make the disturbance larger, so that the pixels of the original image are richer, so as to facilitate better processing in the next step. Then the disturbed RGB values are processed, and a new image is generated through these pixels. The new image only has some changes in color, and no other changes, and still maintains important features.
[0052] The previous content is for images with dark background colors. For images with light background colors, we add a mask, and then perturb the RGB values of the image after mask processing.
[0053] Then adjust the image, process the perturbed image, use SR-CNN preprocessing to remove artifacts in the image. Resize the image according to the size ratio, adjust both the perturbed image and the original image, and adjust their image sizes to the same for later processing.
[0054] Second, the treatment of brush stroke density:
[0055] To estimate the brush stroke density of the image, a convex hull-based palette is chosen. The perturbed image is richer in color, easier to capture, and easier to calculate using the convex hull method. The color distribution of the image is convex in the RGB space, and the quick hull algorithm is used to create a convex hull in the RGB space for all pixels. The vertex colors of the convex hull are mixed with the convex weights to obtain all the colors in the image. The colors in the target image obtained through the convex hull are called a palette. The convex hull-based palette has a dense and continuous grid that can simplify the calculation of brush stroke density.
[0056] Sample n pixels in the grid, find the centroid of the n sampled points, and send a ray from the centroid g through the pixel c p , intersecting an edge of the grid at a point h p ,g,c p 、h p Collinear, calculate the weight of the pixel based on these three points and estimate the brush stroke density.
[0057] Guided filtering is used to process the brush stroke density map to improve its quality.
[0058] The third aspect is to generate a shadow effect layer and combine the generated shadow effect layer with the original image:
[0059] Using image pyramid processing, a smoothing filter is used to smooth the perturbed image I, and the image is downsampled from high resolution to low resolution, reducing the image size to one quarter of the original, with a downsampling factor of 2. Then, the image is upsampled, increasing the image size to four times the original, with an upsampling factor of 2. Then a blurred and rough image is generated.
[0060] Here, we discuss the situation of the light source and calculate the lighting effect map S, the original image R, the perturbed image I, the brush stroke density map K, the light source L, the light intensity γ, and the ambient light intensity O.
[0061] Calculate channel E in the rough light effect map E in a pixel-by-pixel manner i. Use the X and Y axes of the perturbed image I and the Z axis perpendicular to the image panel to establish an XYZ coordinate system. Define the position of the light source and any pixel, and calculate the distance and angle from the pixel to the light source. Generate a rough lighting effect based on the transformation of the wave function. Each peak of the wave function has one side facing the light source and the other side away from the light source. You can increase the intensity of the front side and reduce the intensity of the back side to simulate a light source.
[0062] Then the rough light effect map is improved by the brush density map to get a better shadow effect layer.
[0063] By multiplying the shadow effect layer obtained after a series of processing of the disturbed image with the original image, we can get the final rendering result, which is the effect image Q of adding shadows to the stick figure and line drawing.
[0064] Finally, for images with dark backgrounds, you can get better shadow effects. For light-colored images, you can also get good shadow effects by improving the background of the shadow effect.
[0065] Example 2.
[0066] like Figure 1 As shown, a method for generating shadows for stick figures and line drawings specifically includes:
[0067] Step 1: perturb the RGB value of the original image:
[0068] Since the simple drawings we are processing have fewer colors and a large area of the same color, especially line drawings, which only have black lines and a large area of white, the RGB values of the image colors need to be perturbed. The RGB values of the entire original image are traversed. For pixels with values greater than 100, their RGB values are randomly subtracted. The changed value is as large as possible, and the change interval is selected to be (20, 50). Then, a new image I is generated based on the perturbed RGB values. The new image I only slightly changes the color and still retains important features.
[0069] The previous example is for images with dark background colors. For images with light background colors, we add a mask, and then perturb the RGB values of the image after mask processing.
[0070] Then adjust the image, process the perturbed image, use SR-CNN preprocessing to remove artifacts in the image. Resize the image according to the size ratio, adjust both the perturbed image and the original image, and adjust their image sizes to the same.
[0071] Step 2, estimate the brush stroke density of the perturbed image:
[0072] For multiple colors to generate a color, the generated new color c has formula (1)
[0073]
[0074] c is the new color generated, C={c 1, ......., c n} is the color, A={a 1, ......., a n} is the weight of color mixing, that is, a new color can be generated by multiplying multiple colors by their respective weights and then adding them together. Weight α1+α2+…+α i =1,α i >0. Stick figures and line drawings are within the range and are drawn with one color. It is difficult to calculate the weight of one color, so the perturbed image is used to process the stroke density. We define the stroke density formula as
[0075]
[0076] n refers to the number of sampled pixels.
[0077] Use the quick hull algorithm to create a convex hull in RGB space for all pixels. Each vertex of the convex hull represents a color, and its vertex colors can be mixed with convex weights to obtain any color in the image. The colors in the target image can be obtained through the convex hull, which is called a palette. The convex hull-based palette has a dense and continuous grid that simplifies the calculation of brush stroke density. Then randomly sample n different pixels in the palette, sampling approximately n→+∞ pixels to obtain the best accuracy.
[0078] The formula for the centroid g of n sampling points is as follows:
[0079]
[0080] For each pixel p, output the stroke density K p In RGB space, for each pixel c p , send a ray from point g to point c p , this ray intersects with an edge of the grid at point h p . g, c p ,h p In the same straight line.
[0081] C={c 0, c i (i=1,2,.....,)},A={a 1, a i (i=1,2,.....,n)} (4)
[0082] c0=h p (5)
[0083] Then the weight α i The formula for and α0 is:
[0084]
[0085]
[0086]
[0087] |·| is the Euclidean distance. The new color c is generated according to formulas (5), (6), and (7). p The formula is:
[0088]
[0089] When the sampling point n→+∞ and the weight is close to the centroid of the grid M, the stroke density K p The stroke density K can be calculated from the limit of the blending weight according to formula (2): p The formula is:
[0090]
[0091] In order to improve the quality of the brush stroke density image, guided filtering is used to process the brush stroke density map.
[0092] Step 3: Generate a shadow effect layer and combine the generated shadow effect layer with the original image:
[0093] Using image pyramid processing, a smoothing filter is used to smooth the perturbed image I, and the image is downsampled from high resolution to low resolution, reducing the size of the image to one quarter of the original, with a downsampling factor of 2. Then, the image is upsampled, increasing the size of the image to four times the original, with an upsampling factor of 2. The resulting image is a blurred and rough image.
[0094] Here, we discuss the situation of the light source and calculate the lighting effect map S, the original image R, the perturbed image I, the brush stroke density map K, the light source L, the light intensity γ, and the ambient light intensity O.
[0095] Calculate channel E in the rough light effect map E in a pixel-by-pixel manner i. Use the X and Y axes of the perturbed image I and the Z axis perpendicular to the image panel to establish an XYZ coordinate system. Find the location of the light source and any pixel, and calculate the distance and angle from the pixel to the light source. Generate a rough lighting effect based on the transformation of the wave function. Each peak of the wave function has one side facing the light source and the other side away from the light source. You can increase the intensity of the front side and reduce the intensity of the back side to simulate a light source.
[0096] Then the rough light effect map E is improved by the brush stroke density map to obtain a better shadow effect layer. The formula of the shadow effect layer S is
[0097] S=γE⊙K+O (10)
[0098] ⊙ is the Hadamard product, which is a matrix operation type. We choose the light intensity γ = 0.85 and the ambient light intensity O = 0.45.
[0099] By multiplying the shadow effect layer S obtained after a series of processing of the disturbed image with the original image R, we can get the final rendering result, which is the effect image Q of adding shadows to the stick figure and line drawing. The rendering result is
[0100] Q=S×R (11)
[0101] Finally, for images with dark backgrounds, you can get better shadow effects. For light-colored images, you can also get good shadow effects by improving the background of the shadow effect.
[0102] Example 3.
[0103] A system for generating shading for stick figures and line drawings, comprising:
[0104] The image acquisition module is configured to acquire an original image;
[0105] The image perturbation module is configured to perturb the RGB values of the original image to generate a perturbed image;
[0106] The shadow module is configured to estimate the brush stroke density for the perturbed image and generate a shadow effect layer;
[0107] The effect module is configured to combine the shadow effect layer with the original image to obtain an effect image.
[0108] Example 4.
[0109] A computer-readable storage medium stores a plurality of instructions, wherein the instructions are suitable for being loaded and executed by a processor of a terminal device. A method for generating shadows for stick figures and line drawings provided in this embodiment.
[0110] Example 5.
[0111] A terminal device includes a processor and a computer-readable storage medium, wherein the processor is used to implement various instructions; the computer-readable storage medium is used to store multiple instructions, wherein the instructions are suitable for being loaded and executed by the processor. A method for generating shadows for stick figures and line drawings provided in this embodiment.
[0112] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0113] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0114] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0115] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0116] The above description is only the preferred embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
[0117] Although the above describes the specific implementation mode of the present invention in conjunction with the accompanying drawings, it is not intended to limit the scope of protection of the present invention. Those skilled in the art should understand that various modifications or variations that can be made by those skilled in the art on the basis of the technical solution of the present invention without creative work are still within the scope of protection of the present invention.
Claims
1. A method for generating shadows for stick figures and line drawings, characterized in that: include: Get the original image; Perturb the RGB value of the original image to generate a perturbed image; The RGB value perturbation of the original image includes directly perturbing the RGB value of the image with a dark background, and performing mask processing and then perturbing the RGB value of the image with a light background; Estimate the brush stroke density of the perturbed image and generate a shadow effect layer; The stroke density of the disturbed image is estimated as follows: in Refers to the n pixels sampled; is the weight of the color mixture, weight , ; Combine the shadow effect layer with the original image to get the effect image; After the perturbed image is generated, SR-CNN preprocessing is performed to remove artifacts in the perturbed image; The generating of the shadow effect layer also includes generating a rough light effect image by using the fuzzy rough image through wave function transformation; The generating of the shadow effect layer also includes improving the rough light effect map through the brush stroke density map to obtain the shadow effect layer.
2. A method for generating shadows for stick figures and line drawings as claimed in claim 1, characterized in that: The estimating the brush stroke density of the disturbed image includes obtaining a brush stroke density map using a convex hull method.
3. A method for generating shadows for stick figures and line drawings as claimed in claim 2, characterized in that: The generation of the shadow effect layer includes smoothing the disturbed image and generating a blurred and rough image.
4. A system for generating shadows for stick figures and line drawings, characterized in that: include: The image acquisition module is configured to acquire an original image; The image perturbation module is configured to perturb the RGB values of the original image to generate a perturbed image; The RGB value perturbation of the original image includes directly perturbing the RGB value of the image with a dark background, and performing mask processing and then perturbing the RGB value of the image with a light background; The shadow module is configured to estimate the brush stroke density for the perturbed image and generate a shadow effect layer; The stroke density of the disturbed image is estimated as follows: in Refers to the n pixels sampled; is the weight of the color mixture, weight , ; The effect module is configured to combine the shadow effect layer with the original image to obtain an effect image; After the perturbed image is generated, SR-CNN preprocessing is performed to remove artifacts in the perturbed image; The generating of the shadow effect layer also includes generating a rough light effect image by using the fuzzy rough image through wave function transformation; The generating of the shadow effect layer also includes improving the rough light effect map through the brush stroke density map to obtain the shadow effect layer.
5. A computer-readable storage medium, characterized in that: A plurality of instructions are stored therein, and the instructions are suitable for being loaded by a processor of a terminal device and executed by a method for generating shadows for stick figures and line drawings as described in any one of claims 1-3.
6. A terminal device, characterized in that: The invention comprises a processor and a computer-readable storage medium, wherein the processor is used to implement various instructions; and the computer-readable storage medium is used to store multiple instructions, wherein the instructions are suitable for being loaded by the processor and executed by a method for generating shadows for stick figures and line drawings according to any one of claims 1 to 3.
Citation Information
Patent Citations
Stick figure computer scoring and auxiliary coloring method
CN106530317A
Image processing method and device based on industrial camera shooting, and computer equipment
CN113592753A