Shadow image generation method and device
By generating a shadow mask and merging it with a target image, the problem of cumbersome shadow image generation in the prior art is solved, and the effect of quickly and automatically generating a shadow image is achieved.
Patent Information
- Application Number
- CN202310386060.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-11
- Publication Date
- 2024-10-18
AI Technical Summary
In the existing technology, obtaining a clear shadow image requires cumbersome operations, which consumes a lot of time and energy.
By determining the shadow distance matrix and the shadow gradient matrix, a shadow mask is generated, and the target image is fused with the shadow mask to automatically generate a shadow image.
It simplifies the generation process of shadow images, avoids the consumption of a lot of time and energy, and achieves rapid and automatic generation of shadow images.
Smart Images

Figure CN118799478A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a shadow image generation method and device. Background Art
[0002] Shadows are everywhere in our lives. Currently, in order to train a model to remove shadows, shadow images and their corresponding clear images are required as training samples. However, clear shadow images in real scenes are difficult to obtain.
[0003] In the related art, in order to obtain a clear shadow image, Photoshop is usually needed to manually remove and repair the shadow image, which is cumbersome and takes a lot of time and effort to obtain a clear shadow image. Summary of the invention
[0004] In order to solve the above technical problem that obtaining a clear shadow image requires complicated operations and a lot of time and effort, the embodiments of the present invention provide a shadow image generation method, device, electronic device and storage medium. The specific technical solution is as follows:
[0005] In a first aspect of an embodiment of the present invention, a shadow image generation method is first provided, the method comprising:
[0006] Determine a shadow distance matrix, wherein each first element in the shadow distance matrix is a distance vector;
[0007] Determine a shadow gradient matrix, wherein each second element in the shadow gradient matrix is a gradient vector;
[0008] Generate a shadow mask according to the shadow distance matrix and the shadow gradient matrix;
[0009] A target image is acquired, and the target image is fused with the shadow mask to obtain a shadow image.
[0010] In an optional implementation, determining the shadow gradient matrix includes:
[0011] Create an N×A angle array, wherein each third element in the angle array is an angle, and N and A are positive integers;
[0012] Generate an N×A initial shadow gradient matrix according to the angle array, wherein the fourth element in the initial shadow gradient matrix corresponds one-to-one to the third element in the angle array;
[0013] The initial shadow gradient matrix is clipped according to a preset clipping rule to obtain an M×B shadow gradient matrix, where M and B are positive integers and M is less than N.
[0014] In an optional implementation, generating an N×A initial shadow gradient matrix according to the angle array includes:
[0015] For any third element in the angle array, the following processing is performed to generate an N×A initial shadow gradient matrix:
[0016] Performing a first trigonometric function operation on the third element to obtain a first value;
[0017] Perform a second trigonometric function operation on the third element to obtain a second value;
[0018] The first value and the second value are concatenated to obtain an initial gradient vector corresponding to the third element.
[0019] In an optional implementation, the initial shadow gradient matrix is clipped according to a preset clipping rule to obtain an M×B shadow gradient matrix, including:
[0020] According to a preset vertex clipping rule, clipping the fourth element of M×B from at least one vertex of the initial shadow gradient matrix;
[0021] The fourth element of the M×B matrix is determined as the M×B shadow gradient matrix.
[0022] In an optional implementation, the number of the shadow gradient matrix is at least one, and generating a shadow mask according to the shadow distance matrix and the shadow gradient matrix includes:
[0023] For any of the shadow gradient matrices, generating an influence value matrix corresponding to the shadow gradient matrix;
[0024] Wherein, each fifth element in the influence value matrix is an influence value, representing the influence of the corresponding first element in the shadow distance matrix on the shadow distance matrix;
[0025] Mapping the shadow distance matrix to obtain a mapping result matrix, wherein each sixth element in the mapping result matrix is a mapping result of the corresponding first element in the shadow distance matrix;
[0026] According to a preset fusion algorithm, the mapping result matrix is fused with all the influence value matrices to generate a shadow mask.
[0027] In an optional implementation, generating an influence value matrix corresponding to the shadow gradient matrix includes:
[0028] Performing an interpolation operation on the shadow gradient matrix to obtain a first matrix having the same size as the shadow distance matrix;
[0029] The first matrix is dot-producted with the shadow distance matrix to obtain a second matrix, and the values contained in each seventh element in the second matrix are added to obtain an influence value matrix.
[0030] In an optional implementation, the step of fusing the mapping result matrix with all the influence value matrices to generate a shadow mask according to a preset fusion algorithm includes:
[0031] According to a preset weighting algorithm, a weighted operation is performed on the mapping result matrix and all the influence value matrices to generate a shadow mask.
[0032] In an optional implementation, performing a weighted operation on the mapping result matrix and all the influence value matrices to generate a shadow mask includes:
[0033] A weighted operation is performed on the mapping result matrix and all the influence value matrices, and the weighted operation result is amplified according to a preset amplification algorithm to generate a shadow mask.
[0034] In an optional implementation, fusing the target image with the shadow mask to obtain a shadow image includes:
[0035] The shadow mask is multiplied by a preset value to obtain a target shadow mask, and the target image is fused with the target shadow mask to obtain a shadow image.
[0036] In an optional implementation, fusing the target image with the target shadow mask to obtain a shadow image includes:
[0037] An image weighting operation is performed on the target image and the target shadow mask to obtain a shadow image.
[0038] In an optional implementation, determining the shadow distance matrix includes:
[0039] Obtain a value range, and generate a row vector and a column vector according to the value range, wherein the eighth element in the row vector and the ninth element in the column vector are both equidistantly distributed;
[0040] A shadow distance matrix is generated by using the eighth element in the row vector and the ninth element in the column vector.
[0041] In an optional implementation, generating a shadow distance matrix using the eighth element in the row vector and the ninth element in the column vector includes:
[0042] For any eighth element in the row vector, determine the row order of the eighth element in the row vector, and perform the following processing to obtain the distance vector and the position of the distance vector in the shadow distance matrix, and generate the shadow distance matrix from the distance vector and the position:
[0043] For any ninth element in the column vector, determine the column order of the ninth element in the column vector;
[0044] Concatenate the eighth element and the ninth element to obtain a distance vector;
[0045] Combining the row order with the column order to obtain the position of the distance vector in the shadow distance matrix;
[0046] or,
[0047] For any ninth element in the column vector, determine the column order of the ninth element in the column vector, and perform the following processing to obtain the distance vector and the position of the distance vector in the shadow distance matrix, and generate the shadow distance matrix from the distance vector and the position:
[0048] For any eighth element in the row vector, determine the row order of the eighth element in the row vector;
[0049] Concatenate the eighth element and the ninth element to obtain a distance vector;
[0050] The row order is combined with the column order to obtain the position of the distance vector in the shadow distance matrix.
[0051] In a second aspect of the embodiments of the present invention, a shadow image generating device is further provided, the device comprising:
[0052] A shadow distance matrix determination module, used to determine a shadow distance matrix, wherein each first element in the shadow distance matrix is a distance vector;
[0053] A shadow gradient matrix determination module, used to determine a shadow gradient matrix, wherein each second element in the shadow gradient matrix is a gradient vector;
[0054] A shadow mask generating module, used for generating a shadow mask according to the shadow distance matrix and the shadow gradient matrix;
[0055] The shadow image generation module is used to acquire a target image, and fuse the target image with the shadow mask to obtain a shadow image.
[0056] In an optional implementation, the shadow gradient matrix determination module specifically includes:
[0057] An array creation submodule, used to create an N×A angle array, wherein each third element in the angle array is an angle, and N and A are positive integers;
[0058] An initial shadow gradient matrix generation submodule, used to generate an N×A initial shadow gradient matrix according to the angle array, wherein the fourth element in the initial shadow gradient matrix corresponds one-to-one to the third element in the angle array;
[0059] The initial shadow gradient matrix clipping submodule is used to clip the initial shadow gradient matrix according to a preset clipping rule to obtain an M×B shadow gradient matrix, where M and B are positive integers and M is less than N.
[0060] In an optional implementation, the initial shadow gradient matrix generation submodule is specifically used for:
[0061] For any third element in the angle array, the following processing is performed to generate an N×A initial shadow gradient matrix:
[0062] Performing a first trigonometric function operation on the third element to obtain a first value;
[0063] Perform a second trigonometric function operation on the third element to obtain a second value;
[0064] The first value and the second value are concatenated to obtain an initial gradient vector corresponding to the third element.
[0065] In an optional implementation, the initial shadow gradient matrix clipping submodule is specifically used to:
[0066] According to a preset vertex clipping rule, clipping the fourth element of M×B from at least one vertex of the initial shadow gradient matrix;
[0067] The fourth element of the M×B matrix is determined as the M×B shadow gradient matrix.
[0068] In an optional implementation, the number of the shadow gradient matrix is at least one, and the shadow mask generation module specifically includes:
[0069] An influence value matrix generation submodule, used for generating an influence value matrix corresponding to any of the shadow gradient matrices;
[0070] Wherein, each fifth element in the influence value matrix is an influence value, representing the influence of the corresponding first element in the shadow distance matrix on the shadow distance matrix;
[0071] A shadow distance matrix mapping submodule, used for mapping the shadow distance matrix to obtain a mapping result matrix, wherein each sixth element in the mapping result matrix is a mapping result of the corresponding first element in the shadow distance matrix;
[0072] The shadow mask generation submodule is used to fuse the mapping result matrix with all the influence value matrices according to a preset fusion algorithm to generate a shadow mask.
[0073] In an optional implementation, the influence value matrix generation submodule is specifically used for:
[0074] Performing an interpolation operation on the shadow gradient matrix to obtain a first matrix having the same size as the shadow distance matrix;
[0075] The first matrix is dot-producted with the shadow distance matrix to obtain a second matrix, and the values contained in each seventh element in the second matrix are added to obtain an influence value matrix.
[0076] In an optional implementation, the shadow mask generation submodule is specifically used to:
[0077] According to a preset weighting algorithm, a weighted operation is performed on the mapping result matrix and all the influence value matrices to generate a shadow mask.
[0078] In an optional implementation, the shadow mask generation submodule is specifically used to:
[0079] A weighted operation is performed on the mapping result matrix and all the influence value matrices, and the weighted operation result is amplified according to a preset amplification algorithm to generate a shadow mask.
[0080] In an optional implementation, the shadow image generation module specifically includes:
[0081] A target shadow mask generating submodule, used for multiplying the shadow mask by a preset value to obtain a target shadow mask;
[0082] The shadow image generation submodule is used to fuse the target image with the target shadow mask to obtain a shadow image.
[0083] In an optional implementation, the shadow image generation submodule is specifically used for:
[0084] An image weighting operation is performed on the target image and the target shadow mask to obtain a shadow image.
[0085] In an optional implementation, the shadow distance matrix determination module specifically includes:
[0086] A vector generation submodule, used for obtaining a value range, and generating a row vector and a column vector according to the value range, wherein the eighth element in the row vector and the ninth element in the column vector are both arithmetically distributed;
[0087] The shadow distance matrix generating submodule is used to generate a shadow distance matrix through the eighth element in the row vector and the ninth element in the column vector.
[0088] In an optional implementation, the shadow distance matrix generation submodule is specifically used for:
[0089] For any eighth element in the row vector, determine the row order of the eighth element in the row vector, and perform the following processing to obtain the distance vector and the position of the distance vector in the shadow distance matrix, and generate the shadow distance matrix from the distance vector and the position:
[0090] For any ninth element in the column vector, determine the column order of the ninth element in the column vector;
[0091] Concatenate the eighth element and the ninth element to obtain a distance vector;
[0092] Combining the row order with the column order to obtain the position of the distance vector in the shadow distance matrix;
[0093] or,
[0094] For any ninth element in the column vector, determine the column order of the ninth element in the column vector, and perform the following processing to obtain the distance vector and the position of the distance vector in the shadow distance matrix, and generate the shadow distance matrix from the distance vector and the position:
[0095] For any eighth element in the row vector, determine the row order of the eighth element in the row vector;
[0096] Concatenate the eighth element and the ninth element to obtain a distance vector;
[0097] The row order is combined with the column order to obtain the position of the distance vector in the shadow distance matrix.
[0098] In a third aspect of an embodiment of the present invention, there is further provided an electronic device, comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus;
[0099] Memory, used to store computer programs;
[0100] The processor is used to implement any shadow image generation method described in the first aspect when executing the program stored in the memory.
[0101] In a fourth aspect of the embodiments of the present invention, a storage medium is further provided, wherein instructions are stored in the storage medium, and when the instructions are executed on a computer, the computer executes any shadow image generation method described in the first aspect.
[0102] In a fifth aspect of the embodiments of the present invention, a computer program product comprising instructions is also provided, which, when executed on a computer, enables the computer to execute any of the above-mentioned shadow image generation methods.
[0103] The technical solution provided by the embodiment of the present invention determines a shadow distance matrix, wherein each first element in the shadow distance matrix is a distance vector, determines a shadow gradient matrix, wherein each second element in the shadow gradient matrix is a gradient vector, generates a shadow mask according to the shadow distance matrix and the shadow gradient matrix, obtains a target image, and fuses the target image with the shadow mask to obtain a shadow image. By determining a shadow distance matrix and a shadow gradient matrix, generating a shadow mask according to the shadow distance matrix and the shadow gradient matrix, and then fusing the target image with the shadow mask to obtain a shadow image, a shadow image can be automatically generated, the operation is simple, and a lot of time and effort are avoided. BRIEF DESCRIPTION OF THE DRAWINGS
[0104] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0105] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0106] Figure 1 It is a schematic diagram of an implementation flow of a shadow image generation method shown in an embodiment of the present invention;
[0107] Figure 2 is a schematic diagram of a shadow distance matrix shown in an embodiment of the present invention;
[0108] Figure 3 is a schematic diagram of a shadow mask shown in an embodiment of the present invention;
[0109] Figure 4 A schematic diagram of a clear image shown in an embodiment of the present invention;
[0110] Figure 5 is a schematic diagram of a shadow image shown in an embodiment of the present invention;
[0111] Figure 6 It is a schematic diagram of an implementation flow of another shadow image generation method shown in an embodiment of the present invention;
[0112] Figure 7 It is a schematic diagram of an implementation flow of a method for determining a shadow distance matrix shown in an embodiment of the present invention;
[0113] Figure 8 is a schematic diagram of a row vector and a column vector shown in an embodiment of the present invention;
[0114] Fig. 9 It is a schematic diagram of an implementation flow of a method for determining a shadow gradient matrix shown in an embodiment of the present invention;
[0115] Fig.10 is a schematic diagram of an initial shadow gradient matrix shown in an embodiment of the present invention;
[0116] Fig.11 It is a schematic diagram of an implementation flow of a method for generating an influence value matrix shown in an embodiment of the present invention;
[0117] Fig.12 is a structural schematic diagram of a shadow image generating device shown in an embodiment of the present invention;
[0118] Fig.13 It is a schematic diagram of the structure of an electronic device shown in an embodiment of the present invention. DETAILED DESCRIPTION
[0119] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0120] At present, in order to obtain a clear shadow image, it is usually necessary to use PhotoShop to manually remove and repair the shadow image. In order to obtain a clear shadow image, the operation is cumbersome and requires a lot of time and energy.
[0121] To this end, in an embodiment of the present invention, by introducing Perlin noise to simulate the entire shadow area mask, it is fused with the original image to obtain a shadow image, so that the shadow image can be automatically generated, the operation is simple, and a lot of time and effort are avoided.
[0122] Specifically, based on the above-mentioned inventive concept, Figure 1 FIG. 1 is a schematic diagram of an implementation flow of a shadow image generation method provided by an embodiment of the present invention. The method is applied to an electronic device and may specifically include the following steps:
[0123] S101, determining a shadow distance matrix, wherein each first element in the shadow distance matrix is a distance vector.
[0124] In an embodiment of the present invention, a shadow distance matrix may be determined, wherein each first element in the shadow distance matrix is a distance vector. Figure 2 The shadow distance matrix shown has a dimension of 6Х6Х2, denoted as a, where each first element in a is a distance vector.
[0125] It should be noted that, for the first element in the shadow distance matrix, the value constituting the first element is within a certain value range, for example Figure 2 As shown, the value of the first element is between 0 and 1, which is not limited in the embodiment of the present invention.
[0126] S102, determining a shadow gradient matrix, wherein each second element in the shadow gradient matrix is a gradient vector.
[0127] In the embodiment of the present invention, a shadow gradient matrix may be determined, wherein each second element in the shadow gradient matrix is a gradient vector, and the number of shadow gradient matrices is at least one, which is not limited in the embodiment of the present invention.
[0128] For example, a shadow gradient matrix is determined. Specifically, the number of shadow gradient matrices may be 4, which are respectively recorded as B1, B2, B3, and B4, wherein each second element in the shadow gradient matrix is a gradient vector, and the shadow gradient matrix may be a random shadow gradient matrix.
[0129] S103: Generate a shadow mask according to the shadow distance matrix and the shadow gradient matrix.
[0130] In the embodiment of the present invention, for the determined shadow distance matrix and shadow gradient matrix, a shadow mask can be generated through the shadow distance matrix and the shadow gradient matrix. The generated shadow mask is as follows: Figure 3 As shown, the entire shadow area mask can be simulated.
[0131] S104, acquiring a target image, and fusing the target image with the shadow mask to obtain a shadow image.
[0132] In the embodiment of the present invention, a target image may be obtained, wherein the target image may be a clear image and may not contain a shadow mask. In addition, the target image may be specified by a user or randomly obtained from an image library, which is not limited in the embodiment of the present invention.
[0133] In addition, the generated shadow mask can be fused with the target image to obtain a shadow image. In this way, the shadow image can be automatically generated, the operation is simple, and a lot of time and effort can be avoided.
[0134] For example, to obtain the target image, Figure 4 The clear image shown in FIG. 1 (the clear image here is only an exemplary description, and the content shown in the clear image is not limited) can be fused with the target image and the shadow mask to obtain a shadow image, such as Figure 5 shown.
[0135] Through the above description of the technical solution provided by the embodiment of the present invention, a shadow distance matrix is determined, wherein each first element in the shadow distance matrix is a distance vector, a shadow gradient matrix is determined, wherein each second element in the shadow gradient matrix is a gradient vector, a shadow mask is generated according to the shadow distance matrix and the shadow gradient matrix, a target image is obtained, and the target image is fused with the shadow mask to obtain a shadow image.
[0136] By determining the shadow distance matrix and the shadow gradient matrix, a shadow mask is generated according to the shadow distance matrix and the shadow gradient matrix, and then the target image is fused with the shadow mask to obtain a shadow image. In this way, the shadow image can be automatically generated, the operation is simple, and a lot of time and effort are avoided.
[0137] like Figure 6 FIG. 1 is a schematic diagram of an implementation flow of another shadow image generation method provided by an embodiment of the present invention. The method is applied to an electronic device and may specifically include the following steps:
[0138] S601, determining a shadow distance matrix, wherein each first element in the shadow distance matrix is a distance vector.
[0139] In an embodiment of the present invention, a shadow distance matrix may be determined, wherein each first element in the shadow distance matrix is a distance vector. For the method of determining the shadow distance matrix, reference may be made to Figure 7 The method shown.
[0140] like Figure 7 FIG. 1 is a schematic diagram of an implementation flow of a method for determining a shadow distance matrix provided by an embodiment of the present invention. The method is applied to an electronic device and may specifically include the following steps:
[0141] S701, obtaining a value range, and generating a row vector and a column vector according to the value range, wherein the eighth element in the row vector and the ninth element in the column vector are both equidistantly distributed.
[0142] In the embodiment of the present invention, a value range may be obtained, for example, the value range may be 0 to 1. Thus, a row vector and a column vector may be generated according to the value range, wherein the eighth element in the row vector and the ninth element in the column vector are both equidistantly distributed, and the smallest eighth element and the largest eighth element in the eighth element in the row vector may be the two ends of the above value range, and the same is true for the ninth element in the column vector.
[0143] For example, get the value range 0 to 1, generate row vectors and column vectors according to the value range, where the row vectors and column vectors are as follows Figure 8 As shown by Figure 8 It can be seen that the eighth element in the row vector and the ninth element in the column vector are both equidistantly distributed, and the smallest eighth element 0 and the largest eighth element 1 in the eighth element in the row vector are the two ends of the value range 0 to 1, and the same is true for the ninth element in the column vector.
[0144] It should be noted that, for the generation algorithm of the row vector and the column vector, reference may be made to the existing algorithm, and the embodiment of the present invention does not limit this. In addition, the number of the eighth elements in the row vector is consistent with the number of columns of the first element of the shadow distance matrix, and the number of the ninth elements in the column vector is consistent with the number of rows of the first element of the shadow distance matrix.
[0145] S702, generate a shadow distance matrix using the eighth element in the row vector and the ninth element in the column vector.
[0146] In an embodiment of the present invention, for the generated row vector and column vector, a shadow distance matrix can be generated by the eighth element in the row vector and the ninth element in the column vector. The eighth element in the row vector and the ninth element in the column vector can be combined according to a certain rule to generate the shadow distance matrix.
[0147] Specifically, with the row vector as a reference, for any eighth element in the row vector, determine the row order of the eighth element in the row vector, and perform the following processing to obtain the distance vector and the position of the distance vector in the shadow distance matrix, and generate the shadow distance matrix from the distance vector and the position:
[0148] For any ninth element in the column vector, determine the column order of the ninth element in the column vector; concatenate the eighth element and the ninth element to obtain a distance vector; combine the row order with the column order to obtain the position of the distance vector in the shadow distance matrix.
[0149] For example, Figure 8As shown, for the eighth element 0 in the row vector, determine the row order 1 of the eighth element 0 in the row vector, and perform the following processing: for the ninth element 0 in the column vector, determine the column order 1 of the ninth element 0 in the column vector, concatenate the eighth element 0 in the row vector with the ninth element 0 in the column vector to obtain the distance vector (0, 0), combine the row order 1 with the column order 1, and obtain the position of the distance vector in the shadow distance matrix, that is, the 1st row and the 1st column, representing the first element of the 1st row and the 1st column in the shadow distance matrix, that is, the distance vector (0, 0.2);
[0150] Then, for the ninth element 0.2 in the column vector, determine the column order 2 of the ninth element 0.2 in the column vector, concatenate the eighth element 0 in the row vector with the ninth element 0.2 in the column vector to obtain the distance vector (0, 0.2), combine the row order 1 with the column order 2 to obtain the position of the distance vector in the shadow distance matrix, i.e., the 2nd row and 1st column, representing the first element of the 2nd row and 1st column in the shadow distance matrix, i.e., the distance vector (0, 0.2), and the processing for the remaining ninth elements in the column vector is similar. In this way, for any eighth element in the row vector, determine the row order of the eighth element in the row vector, and perform the above processing to obtain the distance vector and the position of the distance vector in the shadow distance matrix, and generate the shadow distance matrix from the distance vector and the position, as shown in FIG. Figure 2 shown.
[0151] Alternatively, with the column vector as a reference, for any ninth element in the column vector, determine the column order of the ninth element in the column vector, and perform the following processing to obtain the distance vector and the position of the distance vector in the shadow distance matrix, and generate the shadow distance matrix from the distance vector and the position:
[0152] For any eighth element in the row vector, determine the row order of the eighth element in the row vector; concatenate the eighth element with the ninth element to obtain a distance vector; combine the row order with the column order to obtain the position of the distance vector in the shadow distance matrix.
[0153] For example, Figure 8 As shown, for the ninth element 0 in the column vector, determine the column order 1 of the ninth element 0 in the column vector, and perform the following processing: for the eighth element 0 in the row vector, determine the row order 1 of the eighth element 0 in the row vector, concatenate the eighth element 0 in the row vector with the ninth element 0 in the column vector to obtain the distance vector (0, 0), combine the row order 1 with the column order 1, and obtain the position of the distance vector in the shadow distance matrix, the 1st row and the 1st column, representing the first element of the 1st row and the 1st column in the shadow distance matrix, that is, the distance vector (0, 0);
[0154] Then, for the eighth element 0.2 in the row vector, determine the row order 2 of the eighth element 0.2 in the row vector, concatenate the eighth element 0.2 in the row vector with the ninth element 0 in the column vector, and obtain the distance vector (0, 0.2). Combine the row order 2 with the column order 1 to obtain the position of the distance vector in the shadow distance matrix, row 1, column 2, representing the first element of row 1, column 2 in the shadow distance matrix, i.e., the distance vector (0, 0.2). The processing for the remaining eighth elements in the row vector is similar. In this way, for any ninth element in the column vector, determine the column order of the ninth element in the column vector, and perform the above processing to obtain the distance vector and the position of the distance vector in the shadow distance matrix, and generate the shadow distance matrix from the distance vector and the position.
[0155] S602: Determine a shadow gradient matrix, wherein each second element in the shadow gradient matrix is a gradient vector.
[0156] In an embodiment of the present invention, a shadow gradient matrix may be determined, wherein each second element in the shadow gradient matrix is a gradient vector, and the number of shadow gradient matrices is at least one. Fig. 9 The method shown.
[0157] like Fig. 9 FIG. 1 is a schematic diagram of an implementation flow of a method for determining a shadow gradient matrix provided by an embodiment of the present invention. The method is applied to an electronic device and may specifically include the following steps:
[0158] S901, create an N×A angle array, wherein each third element in the angle array is an angle, and N is a positive integer.
[0159] In an embodiment of the present invention, an N×A angle array is created, wherein the N×A angle array can be randomly created, that is, an N×A random angle array is created, and each third element in the angle array is an angle (the angle is between 0 and 360°), N and A are positive integers, and N and A can be equal or different.
[0160] It should be noted that the third element in the angle array represents the value of the angle vector, which needs to be subjected to trigonometric operations, and therefore needs to be between 0 and 360°, that is, between 0 and 2Pi. This is not limited in the embodiment of the present invention.
[0161] For example, create a 3×3 random angle array, where each third element in the random angle array is an angle and is between 0 and 360 degrees, as shown below.
[0162]
[0163] S902, generating an N×A initial shadow gradient matrix according to the angle array, wherein the fourth element in the initial shadow gradient matrix corresponds one-to-one to the third element in the angle array.
[0164] In an embodiment of the present invention, for the created angle array, an N×A initial shadow gradient matrix can be generated through the angle array, wherein the fourth element in the initial shadow gradient matrix is an initial gradient vector and corresponds one-to-one to the third element in the angle array.
[0165] Among them, for any third element in the angle array, the following processing is performed to generate an N×A initial shadow gradient matrix:
[0166] A first trigonometric function operation is performed on the third element to obtain a first value; a second trigonometric function operation is performed on the third element to obtain a second value; and the first value and the second value are concatenated to obtain an initial gradient vector corresponding to the third element.
[0167] It should be noted that the above-mentioned first trigonometric function operation can be one of the trigonometric function operations such as sine, cosine, tangent, cotangent, secant or cosecant. The same is true for the second trigonometric function. The first trigonometric function operation is different from the second trigonometric function operation, and the embodiment of the present invention does not limit this.
[0168] For example, take the third element in the first row and first column of the angle array as an example, perform a cosine operation on the third element to obtain a first value c0, perform a sin operation on the third element to obtain a second value s0, concatenate the first value c0 and the second value s0 to obtain the initial gradient vector (c0, s0) corresponding to the third element. In this way, the above processing is performed for any third element in the angle array to generate a 3×3 initial shadow gradient matrix with a dimension of 3×3×2, such as Fig.10 shown.
[0169] S903 , clipping the initial shadow gradient matrix according to a preset clipping rule to obtain an M×B shadow gradient matrix, where M and B are positive integers and M is less than N.
[0170] In an embodiment of the present invention, the initial shadow gradient matrix can be clipped according to a preset clipping rule to obtain an M×B shadow gradient matrix, where M and B are positive integers, where M and B can be equal or unequal, and M is less than N.
[0171] According to the preset corner clipping rule, the fourth element of M×B is clipped from at least one corner of the initial shadow gradient matrix, and the fourth element of M×B is determined as the shadow gradient matrix of M×B. The corners here include at least one of the following: upper left corner, upper right corner, lower left corner and lower right corner.
[0172] For example, Fig.10 The initial shadow gradient matrix shown, according to the preset top corner clipping rule, clips the 2×2 fourth elements from the upper left corner, upper right corner, lower left corner and lower right corner of the initial shadow gradient matrix respectively, and determines the 2×2 fourth elements as the 2×2 shadow gradient matrix, as shown below.
[0173]
[0174]
[0175]
[0176]
[0177] S603: For any shadow gradient matrix, generate an influence value matrix corresponding to the shadow gradient matrix.
[0178] In the embodiment of the present invention, the number of shadow gradient matrices is at least one, for example, the shadow gradient matrix may be the four shadow gradient matrices B1, B2, B3, B4, etc. For any shadow gradient matrix, an influence value matrix corresponding to the shadow gradient matrix is generated, wherein each fifth element in the influence value matrix is an influence value, representing the influence of the corresponding first element in the shadow distance matrix on the shadow distance matrix.
[0179] Among them, for the method of generating the influence value matrix, you can refer to Fig.11 As shown in the method. Fig.11 FIG. 1 is a schematic diagram of an implementation flow of a method for generating an influence value matrix provided by an embodiment of the present invention. The method is applied to an electronic device and may specifically include the following steps:
[0180] S1101, performing an interpolation operation on the shadow gradient matrix to obtain a first matrix having the same size as the shadow distance matrix.
[0181] S1102, performing a dot product operation on the first matrix and the shadow distance matrix to obtain a second matrix, and performing an addition operation on the values contained in each seventh element in the second matrix to obtain an influence value matrix.
[0182] In the embodiment of the present invention, for any shadow gradient matrix, the following processing is performed on the shadow gradient matrix to generate an influence value matrix corresponding to the shadow gradient matrix:
[0183] An interpolation operation is performed on the shadow gradient matrix to obtain a first matrix of the same size as the shadow distance matrix, a dot product is performed on the first matrix and the shadow distance matrix to obtain a second matrix, and the values contained in each seventh element in the second matrix are added to obtain an influence value matrix.
[0184] For example, for the above four shadow gradient matrices B1, B2, B3, and B4, for any shadow gradient matrix, the following processing is performed on the shadow gradient matrix to generate an influence value matrix corresponding to the shadow gradient matrix:
[0185] The shadow gradient matrix is interpolated by using an interpolation algorithm to obtain a first matrix of the same size as the shadow distance matrix, that is, the dimensions of the first matrix and the shadow distance matrix are both 6×6×2, so that a gradient vector of a random direction is obtained for each first element in the shadow distance matrix; then the first matrix is dot-producted with the shadow distance matrix to obtain a second matrix, and the values contained in each seventh element in the second matrix are added (for example, if the seventh element is (x, y), then the corresponding element in the influence value matrix is x+y) to obtain an influence value matrix. After the above processing, the influence value matrices corresponding to the four shadow gradient matrices B1, B2, B3, and B4, namely C1, C2, C3, and C4, can be obtained, and the dimensions are 6×6.
[0186] It should be noted that a linear interpolation algorithm or a bilinear interpolation algorithm may be used to perform an interpolation operation on the shadow gradient matrix to obtain a first matrix having the same size as the shadow distance matrix, which is not limited in the embodiment of the present invention.
[0187] S604, mapping the shadow distance matrix to obtain a mapping result matrix, wherein each sixth element in the mapping result matrix is a mapping result of the corresponding first element in the shadow distance matrix.
[0188] In the embodiment of the present invention, for the shadow distance matrix, the shadow distance matrix can be mapped to obtain a mapping result matrix, wherein each sixth element in the mapping result matrix is a mapping result of the corresponding first element in the shadow distance matrix.
[0189] Among them, since linear interpolation is not natural enough, a smoother, nonlinear interpolation function is needed: ease curve. The first element in the shadow distance matrix is nonlinearly mapped according to the ease curve to obtain a mapping result matrix.
[0190] For example, the easing curve is as follows. The first element in the shadow distance matrix is nonlinearly mapped according to the easing curve to obtain a mapping result matrix with a dimension of 6×6×2. For example, the first element is (Dx, Dy). After Dx and Dy are mapped by the easing curve, the mapping result (D0, D1) can be obtained. The mapping results form a mapping result matrix.
[0191] y=6x 5 -15x 4 +10 3 .
[0192] S605: According to a preset fusion algorithm, the mapping result matrix is fused with all influence value matrices to generate a shadow mask.
[0193] In the embodiment of the present invention, the mapping result matrix and all the influence value matrices may be fused according to a preset fusion algorithm to generate a shadow mask.
[0194] Here, according to a preset weighting algorithm, a weighted operation is performed on the mapping result matrix and all influence value matrices to generate a shadow mask.
[0195] In addition, a weighted operation may be performed on the mapping result matrix and all the influence value matrices, and the weighted operation result may be amplified according to a preset amplification algorithm to generate a shadow mask.
[0196] For example, the influence value matrix is C1, C2, C3, C4, where the elements can be represented by c1, c2, c3, c4, and the mapping result matrix, where the elements can be represented by (D0, D1), thus the mapping result matrix is fused with all the influence value matrices according to the following weighted algorithm to generate a shadow mask. Among them, the element (D0, D1) and the elements c1, c2, c3, c4 are in a one-to-one correspondence.
[0197] 1) E1 = c1*(1-D0)+c2*D0;
[0198] 2) E2 = c3*(1-D0)+c4*D0;
[0199] 3) F1 = E1*(1-D1+E2*D1);
[0200] 4) F2 = 1.414 * F1;
[0201] 5)F3=F2*min_val+min_val.
[0202] In the above formula, min_val is the manually set noise, and the minimum value can be set to 0.5. 1.414, 1, etc. in the above formula can be adjusted according to actual conditions, and they are essentially different constants.
[0203] In addition, it should be noted that the element (D0, D1) and the elements c1, c2, c3, c4 are obtained through the above formulas 1), 2), and 3) to obtain F1, where F1 can be regarded as a shadow mask, and the value is between 0 and 1. However, in order to amplify the difference of the first element in the shadow distance matrix, promote the generation of a better shadow mask, and thus generate a better shadow image, F1 is amplified by formulas 4) and 5) to obtain the final F3, that is, the final shadow mask.
[0204] S606, acquiring a target image, multiplying the shadow mask by a preset value to obtain a target shadow mask, and fusing the target image with the target shadow mask to obtain a shadow image.
[0205] In the embodiment of the present invention, a target image may be acquired, wherein the target image may be a clear image without a shadow mask, and may be specified by a user or randomly acquired from an image library, which is not limited in the embodiment of the present invention.
[0206] In addition, for the generated shadow mask, since its value range is, for example, between 0 and 1, it is necessary to multiply the shadow mask by a preset value, such as 255, to obtain a target shadow mask, and fuse the target image with the target shadow mask to obtain a shadow image.
[0207] For the target image and the target shadow mask, an image weighting operation can be used, so that the target image and the target shadow mask can be subjected to an image weighting operation to obtain a shadow image. The specific image weighting algorithm can refer to existing ones, and the embodiment of the present invention does not limit this.
[0208] Through the above description of the technical solution provided by the embodiment of the present invention, by determining the shadow distance matrix and the shadow gradient matrix, for any shadow gradient matrix, an influence value matrix corresponding to the shadow gradient matrix is generated, the shadow distance matrix is mapped to obtain a mapping result matrix, and according to a preset fusion algorithm, the mapping result matrix is fused with all influence value matrices to generate a shadow mask, and a target image is obtained. The shadow mask is multiplied by a preset value to obtain a target shadow mask, and the target image is fused with the target shadow mask to obtain a shadow image. In this way, a shadow image can be automatically generated, the operation is simple, and a lot of time and effort can be avoided.
[0209] Corresponding to the above method embodiment, the embodiment of the present invention further provides a shadow image generating device, such as Fig.12 As shown, the apparatus may include: a shadow distance matrix determination module 1210 , a shadow gradient matrix determination module 1220 , a shadow mask generation module 1230 , and a shadow image generation module 1240 .
[0210] A shadow distance matrix determination module 1210 is used to determine a shadow distance matrix, wherein each first element in the shadow distance matrix is a distance vector;
[0211] A shadow gradient matrix determination module 1220 is used to determine a shadow gradient matrix, wherein each second element in the shadow gradient matrix is a gradient vector;
[0212] A shadow mask generating module 1230, configured to generate a shadow mask according to the shadow distance matrix and the shadow gradient matrix;
[0213] The shadow image generation module 1240 is used to obtain a target image, and fuse the target image with the shadow mask to obtain a shadow image.
[0214] In an optional implementation, the shadow gradient matrix determination module specifically includes:
[0215] An array creation submodule, used to create an N×A angle array, wherein each third element in the angle array is an angle, and N and A are positive integers;
[0216] An initial shadow gradient matrix generation submodule, used to generate an N×A initial shadow gradient matrix according to the angle array, wherein the fourth element in the initial shadow gradient matrix corresponds one-to-one to the third element in the angle array;
[0217] The initial shadow gradient matrix clipping submodule is used to clip the initial shadow gradient matrix according to a preset clipping rule to obtain an M×B shadow gradient matrix, where M and B are positive integers and M is less than N.
[0218] In an optional implementation, the initial shadow gradient matrix generation submodule is specifically used for:
[0219] For any third element in the angle array, the following processing is performed to generate an N×A initial shadow gradient matrix:
[0220] Performing a first trigonometric function operation on the third element to obtain a first value;
[0221] Perform a second trigonometric function operation on the third element to obtain a second value;
[0222] The first value and the second value are concatenated to obtain an initial gradient vector corresponding to the third element.
[0223] In an optional implementation, the initial shadow gradient matrix clipping submodule is specifically used to:
[0224] According to a preset vertex clipping rule, clipping the fourth element of M×B from at least one vertex of the initial shadow gradient matrix;
[0225] The fourth element of the M×B matrix is determined as the M×B shadow gradient matrix.
[0226] In an optional implementation, the number of the shadow gradient matrix is at least one, and the shadow mask generation module specifically includes:
[0227] An influence value matrix generation submodule, used for generating an influence value matrix corresponding to any of the shadow gradient matrices;
[0228] Wherein, each fifth element in the influence value matrix is an influence value, representing the influence of the corresponding first element in the shadow distance matrix on the shadow distance matrix;
[0229] A shadow distance matrix mapping submodule, used for mapping the shadow distance matrix to obtain a mapping result matrix, wherein each sixth element in the mapping result matrix is a mapping result of the corresponding first element in the shadow distance matrix;
[0230] The shadow mask generation submodule is used to fuse the mapping result matrix with all the influence value matrices according to a preset fusion algorithm to generate a shadow mask.
[0231] In an optional implementation, the influence value matrix generation submodule is specifically used for:
[0232] Performing an interpolation operation on the shadow gradient matrix to obtain a first matrix having the same size as the shadow distance matrix;
[0233] The first matrix is dot-producted with the shadow distance matrix to obtain a second matrix, and the values contained in each seventh element in the second matrix are added to obtain an influence value matrix.
[0234] In an optional implementation, the shadow mask generation submodule is specifically used to:
[0235] According to a preset weighting algorithm, a weighted operation is performed on the mapping result matrix and all the influence value matrices to generate a shadow mask.
[0236] In an optional implementation, the shadow mask generation submodule is specifically used to:
[0237] A weighted operation is performed on the mapping result matrix and all the influence value matrices, and the weighted operation result is amplified according to a preset amplification algorithm to generate a shadow mask.
[0238] In an optional implementation, the shadow image generation module specifically includes:
[0239] A target shadow mask generating submodule, used for multiplying the shadow mask by a preset value to obtain a target shadow mask;
[0240] The shadow image generation submodule is used to fuse the target image with the target shadow mask to obtain a shadow image.
[0241] In an optional implementation, the shadow image generation submodule is specifically used for:
[0242] An image weighting operation is performed on the target image and the target shadow mask to obtain a shadow image.
[0243] In an optional implementation, the shadow distance matrix determination module specifically includes:
[0244] A vector generation submodule, used for obtaining a value range, and generating a row vector and a column vector according to the value range, wherein the eighth element in the row vector and the ninth element in the column vector are both arithmetically distributed;
[0245] The shadow distance matrix generating submodule is used to generate a shadow distance matrix through the eighth element in the row vector and the ninth element in the column vector.
[0246] In an optional implementation, the shadow distance matrix generation submodule is specifically used for:
[0247] For any eighth element in the row vector, determine the row order of the eighth element in the row vector, and perform the following processing to obtain the distance vector and the position of the distance vector in the shadow distance matrix, and generate the shadow distance matrix from the distance vector and the position:
[0248] For any ninth element in the column vector, determine the column order of the ninth element in the column vector;
[0249] Concatenate the eighth element and the ninth element to obtain a distance vector;
[0250] Combining the row order with the column order to obtain the position of the distance vector in the shadow distance matrix;
[0251] or,
[0252] For any ninth element in the column vector, determine the column order of the ninth element in the column vector, and perform the following processing to obtain the distance vector and the position of the distance vector in the shadow distance matrix, and generate the shadow distance matrix from the distance vector and the position:
[0253] For any eighth element in the row vector, determine the row order of the eighth element in the row vector;
[0254] Concatenate the eighth element and the ninth element to obtain a distance vector;
[0255] The row order is combined with the column order to obtain the position of the distance vector in the shadow distance matrix.
[0256] The embodiment of the present invention further provides an electronic device, such as Fig.13 As shown, it includes a processor 131, a communication interface 132, a memory 133 and a communication bus 134, wherein the processor 131, the communication interface 132, and the memory 133 communicate with each other through the communication bus 134.
[0257] A memory 133, for storing computer programs;
[0258] The processor 131 is used to execute the program stored in the memory 133 to implement the following steps:
[0259] Determine a shadow distance matrix, wherein each first element in the shadow distance matrix is a distance vector; determine a shadow gradient matrix, wherein each second element in the shadow gradient matrix is a gradient vector; generate a shadow mask according to the shadow distance matrix and the shadow gradient matrix; obtain a target image, and fuse the target image with the shadow mask to obtain a shadow image.
[0260] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0261] The communication interface is used for communication between the above electronic device and other devices.
[0262] The memory may include a random access memory (RAM) or a non-volatile memory, such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0263] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0264] In another embodiment of the present invention, a storage medium is provided. The storage medium stores instructions. When the instructions are executed on a computer, the computer executes the shadow image generation method described in any one of the above embodiments.
[0265] In another embodiment of the present invention, a computer program product including instructions is provided. When the computer program product is run on a computer, the computer executes the shadow image generating method described in any one of the above embodiments.
[0266] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented by software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a storage medium, or transmitted from one storage medium to another storage medium. For example, the computer instructions can be transmitted from one website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk Solid State Disk (SSD)), etc.
[0267] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0268] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0269] The above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.
Claims
1. A shadow image generation method, characterized in that: The method comprises: Determine a shadow distance matrix, wherein each first element in the shadow distance matrix is a distance vector; Determine a shadow gradient matrix, wherein each second element in the shadow gradient matrix is a gradient vector; Generate a shadow mask according to the shadow distance matrix and the shadow gradient matrix; A target image is acquired, and the target image is fused with the shadow mask to obtain a shadow image.
2. The method according to claim 1, characterized in that The determining of the shadow gradient matrix comprises: Create an N×A angle array, wherein each third element in the angle array is an angle, and N and A are positive integers; Generate an N×A initial shadow gradient matrix according to the angle array, wherein the fourth element in the initial shadow gradient matrix corresponds one-to-one to the third element in the angle array; The initial shadow gradient matrix is clipped according to a preset clipping rule to obtain an M×B shadow gradient matrix, where M and B are positive integers and M is less than N.
3. The method according to claim 2, characterized in that The step of generating an N×A initial shadow gradient matrix according to the angle array includes: For any third element in the angle array, the following processing is performed to generate an N×A initial shadow gradient matrix: Performing a first trigonometric function operation on the third element to obtain a first value; Perform a second trigonometric function operation on the third element to obtain a second value; The first value and the second value are concatenated to obtain an initial gradient vector corresponding to the third element.
4. The method according to claim 2, characterized in that: The initial shadow gradient matrix is clipped according to a preset clipping rule to obtain an M×B shadow gradient matrix, including: According to a preset vertex clipping rule, clipping the fourth element of M×B from at least one vertex of the initial shadow gradient matrix; The fourth element of the M×B matrix is determined as the M×B shadow gradient matrix.
5. The method according to claim 1, characterized in that The number of the shadow gradient matrix is at least one, and generating a shadow mask according to the shadow distance matrix and the shadow gradient matrix includes: For any of the shadow gradient matrices, generating an influence value matrix corresponding to the shadow gradient matrix; Wherein, each fifth element in the influence value matrix is an influence value, representing the influence of the corresponding first element in the shadow distance matrix on the shadow distance matrix; Mapping the shadow distance matrix to obtain a mapping result matrix, wherein each sixth element in the mapping result matrix is a mapping result of the corresponding first element in the shadow distance matrix; According to a preset fusion algorithm, the mapping result matrix is fused with all the influence value matrices to generate a shadow mask.
6. The method according to claim 5, characterized in that The generating an influence value matrix corresponding to the shadow gradient matrix comprises: Performing an interpolation operation on the shadow gradient matrix to obtain a first matrix having the same size as the shadow distance matrix; The first matrix is dot-producted with the shadow distance matrix to obtain a second matrix, and the values contained in each seventh element in the second matrix are added to obtain an influence value matrix.
7. The method according to claim 5, characterized in that The step of fusing the mapping result matrix with all the influence value matrices according to a preset fusion algorithm to generate a shadow mask includes: According to a preset weighting algorithm, a weighted operation is performed on the mapping result matrix and all the influence value matrices, and the weighted operation result is amplified according to a preset amplification algorithm to generate a shadow mask.
8. The method according to claim 1, characterized in that The step of fusing the target image with the shadow mask to obtain a shadow image includes: The shadow mask is multiplied by a preset value to obtain a target shadow mask, and an image weighting operation is performed on the target image and the target shadow mask to obtain a shadow image.
9. The method according to claim 1, characterized in that: Determining the shadow distance matrix includes: Obtain a value range, and generate a row vector and a column vector according to the value range, wherein the eighth element in the row vector and the ninth element in the column vector are both equidistantly distributed; A shadow distance matrix is generated by using the eighth element in the row vector and the ninth element in the column vector.
10. A shadow image generating device, characterized in that: The device comprises: A shadow distance matrix determination module, used to determine a shadow distance matrix, wherein each first element in the shadow distance matrix is a distance vector; A shadow gradient matrix determination module, used to determine a shadow gradient matrix, wherein each second element in the shadow gradient matrix is a gradient vector; A shadow mask generating module, used for generating a shadow mask according to the shadow distance matrix and the shadow gradient matrix; The shadow image generation module is used to acquire a target image, and fuse the target image with the shadow mask to obtain a shadow image.
