Image processing method, device, electronic device and computer readable storage medium

By first performing filtering and color quantization processing in comic special effects processing, the problem of noise effects and edge aliasing is solved, and the effect of image processing is improved.

CN111815659BActive Publication Date: 2024-10-22BEIJING MEISHE NETWORK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202010515208.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-06-08
Publication Date
2024-10-22
Estimated Expiration
2040-06-08

AI Technical Summary

Technical Problem

In the existing comic special effects processing technology, the original image noise affects the smooth structure tensor calculation results, resulting in a decrease in image quality, and the edge aliasing caused by color quantization affects the processing effect.

Method used

The original image is first filtered, the image edges are extracted and color quantized, and then the edges and the quantized image are superimposed, and then the smooth structure tensor is calculated and line integral convolution is performed to obtain the target image.

Benefits of technology

By first filtering to reduce noise, improve smooth structure tensor calculation results, effectively remove edge aliasing caused by color quantization, and improve the image quality and effect of comic special effects processing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN111815659B_ABST
    Figure CN111815659B_ABST
Patent Text Reader

Abstract

The present invention provides an image processing method, device, electronic device and computer-readable storage medium, which relate to the field of image processing technology. The method comprises filtering an original image to obtain a first image, performing edge extraction on the first image to obtain a second image, and performing color quantization on the first image to obtain a third image. The second image and the third image are superimposed to obtain a fourth image. Finally, a smooth structure tensor of the fourth image is calculated, and line integral convolution is performed on the fourth image to obtain a target image. Since the original image is first filtered, the noise of the original image is reduced, thereby improving the calculation result of the smooth structure tensor of the fourth image, and improving the overall effect of the image after comic special effects processing. In addition, the line integral convolution is performed on the fourth image, so the edge jagged edges caused by color quantization can be effectively removed, thereby improving the effect of image processing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of image processing technology, and in particular to an image processing method, device, electronic device and computer-readable storage medium. Background Art

[0002] At present, in the field of short videos and live video, comic special effects processing is very popular. It can convert the video images into comic effects in real time. Therefore, efficient comic special effects algorithms have become the object of research for experts in the field of image and video at home and abroad.

[0003] In the prior art, when performing comic special effects processing on an image in a video, the smooth structure tensor of the original image is first calculated, and then the image after the smooth structure tensor is calculated is filtered, and then the image edge is extracted from the filtered image, and the image after edge extraction is convolved with the result of calculating the smooth structure tensor of the original image by line integral. In addition, the filtered image needs to be color quantized, and the image after color quantization is superimposed with the image after line integral convolution to obtain the target image.

[0004] However, the current comic special effects processing method is to first calculate the smooth structure tensor of the original image and then perform filtering processing. However, if the original image is noisy, the noise will affect the calculation result of the smooth structure tensor, and further affect the image quality after the comic special effects processing. In addition, the existing technology is to first perform line integral convolution on the image after edge extraction and the result of smooth structure tensor calculation on the original image, and then superimpose it with the image after color quantization processing. In this way, the target image obtained will have edge jagged edges caused by color quantization, which affects the effect of image processing. Summary of the invention

[0005] The present invention provides an image processing method, device, electronic device and computer-readable storage medium to solve the existing problem that the calculation result of the smooth structure tensor is affected by the noise in the original image, and the edge jaggedness caused by color quantization in the obtained target image affects the image processing effect.

[0006] In order to solve the above problems, the present invention discloses an image processing method, which comprises:

[0007] Performing filtering on the original image to obtain a first image;

[0008] Extracting the image edge of the first image to obtain a second image;

[0009] Performing color quantization processing on the first image to obtain a third image;

[0010] superimposing the second image and the third image to obtain a fourth image;

[0011] calculating a smoothed structure tensor of the fourth image;

[0012] Performing line integral convolution on the fourth image according to the smooth structure tensor to obtain a target image.

[0013] Optionally, the step of filtering the original image to obtain the first image includes:

[0014] Perform a bilateral filtering process on the original image to obtain a first image.

[0015] Optionally, the step of performing a bilateral filtering process on the original image to obtain the first image includes:

[0016] According to N pixels adjacent to each first target pixel in the original image in the first direction, filtering is performed on each first target pixel in turn to obtain a first intermediate image; the first target pixel is any pixel in the original image;

[0017] According to N pixels adjacent to each second target pixel in the first intermediate image in the second direction, filtering is performed on each second target pixel in turn to obtain a first image; the second target pixel is any pixel in the first intermediate image;

[0018] Wherein, N is a positive integer greater than or equal to 1; the first direction is a horizontal direction, and the second direction is a vertical direction, or the first direction is a vertical direction, and the second direction is a horizontal direction.

[0019] Optionally, before the step of extracting the image edge of the first image to obtain the second image, the step further includes:

[0020] The first image is compressed so that the length and width of the compressed first image are smaller than the length and width of the first image before compression.

[0021] Optionally, the step of extracting the image edge of the first image to obtain the second image includes:

[0022] Extracting the edge of the first image using an extended Gaussian difference algorithm to obtain the second image;

[0023] Wherein, the extended Gaussian difference algorithm is:

[0024]

[0025] Where u = G σ(n)-τ*G kσ (n), u is the Gaussian difference result after deformation, G σ (n) is the Gaussian filtering result with Gaussian kernel σ, G kσ (n) is the Gaussian filtering result with a Gaussian kernel of kσ, k is a constant, τ is a constant used to adjust the cutoff effect strength of the Gaussian difference result, and n is the grayscale value of the pixel in the first image; T ε,φ,u To expand the Gaussian difference result, which is used to characterize the edge degree of the pixel in the first image, ε is the threshold, and φ is the edge acceptance coefficient.

[0026] Optionally, the step of performing color quantization processing on the first image to obtain a third image includes:

[0027] Using a color quantization algorithm to perform color quantization processing on each pixel in the first image in turn to obtain the third image;

[0028] Wherein, the color quantization algorithm is as follows:

[0029]

[0030] Wherein, C is the pixel value of the pixel in the first image, C O is the pixel value of the pixel in the third image, d is the quantization coefficient, For The result is rounded down.

[0031] Optionally, the step of superimposing the second image and the third image to obtain a fourth image includes:

[0032] Superimposing the second image and the third image according to an image superposition algorithm to obtain the fourth image;

[0033] Wherein, the image superposition algorithm is as follows:

[0034] C rgb =F rgb *F a +(1-F a )*B rgb *B a ,

[0035] C a =F a +(1-F a )*B a

[0036] Among them, F rgb is the RGB value of the pixel in the second image, F a is the alpha value of the pixel in the second image, Brgb is the RGB value of the pixel in the third image, B a is the alpha value of the pixel in the third image, C rgb is the RGB value of the pixel in the fourth image, C a is the alpha value of the pixel in the fourth image.

[0037] In order to solve the above problem, the present invention further discloses an image processing device, which comprises:

[0038] A filtering processing module, used for performing filtering processing on the original image to obtain a first image;

[0039] An image edge extraction module, used to extract the image edge of the first image to obtain a second image;

[0040] A color quantization processing module, used for performing color quantization processing on the first image to obtain a third image;

[0041] An image superposition module, used for superimposing the second image and the third image to obtain a fourth image;

[0042] A smooth structure tensor calculation module, used for calculating the smooth structure tensor of the fourth image;

[0043] A line integral convolution module is used to perform line integral convolution on the fourth image according to the smooth structure tensor to obtain a target image.

[0044] Optionally, the filtering processing module includes:

[0045] The filtering processing submodule is used to perform a bilateral filtering process on the original image to obtain a first image. Optionally, the filtering processing submodule includes:

[0046] A first filtering processing unit is used to perform a filtering process on each first target pixel in the original image according to N pixels adjacent to each first target pixel in the first direction, so as to obtain a first intermediate image; the first target pixel is any pixel in the original image;

[0047] a second filtering processing unit, configured to perform filtering processing on each second target pixel in the first intermediate image according to N pixels adjacent to each second target pixel in the second direction, to obtain a first image; the second target pixel is any pixel in the first intermediate image;

[0048] Wherein, N is a positive integer greater than or equal to 1; the first direction is a horizontal direction, and the second direction is a vertical direction, or the first direction is a vertical direction, and the second direction is a horizontal direction.

[0049] Optionally, the image processing device further includes:

[0050] The image compression module is used to compress the first image so that the length and width of the first image after compression are smaller than the length and width of the first image before compression.

[0051] Optionally, the image edge extraction module includes:

[0052] An image edge extraction submodule, configured to extract the edge of the first image by using an extended Gaussian difference algorithm to obtain the second image;

[0053] Wherein, the extended Gaussian difference algorithm is:

[0054]

[0055] Where u = G σ (n)-τ*G kσ (n), u is the Gaussian difference result after deformation, G σ (n) is the Gaussian filtering result with Gaussian kernel σ, G kσ (n) is the Gaussian filtering result with a Gaussian kernel of kσ, k is a constant, τ is a constant used to adjust the cutoff effect strength of the Gaussian difference result, and n is the grayscale value of the pixel in the first image; T ε,φ,u To expand the Gaussian difference result, which is used to characterize the edge degree of the pixel in the first image, ε is the threshold, and φ is the edge acceptance coefficient.

[0056] Optionally, the color quantization processing module includes:

[0057] A color quantization processing submodule, configured to use a color quantization algorithm to sequentially perform color quantization processing on each pixel in the first image to obtain the third image;

[0058] Wherein, the color quantization algorithm is as follows:

[0059]

[0060] Wherein, C is the pixel value of the pixel in the first image, C O is the pixel value of the pixel in the third image, d is the quantization coefficient, For The result is rounded down.

[0061] Optionally, the image overlay module includes:

[0062] An image superposition submodule, used for superimposing the second image and the third image according to an image superposition algorithm to obtain the fourth image;

[0063] Wherein, the image superposition algorithm is as follows:

[0064] C rgb =F rgb *F a +(1-F a )*B rgb *B a ,

[0065] C a =F a +(1-F a )*B a

[0066] Among them, F rgb is the RGB value of the pixel in the second image, F a is the alpha value of the pixel in the second image, B rgb is the RGB value of the pixel in the third image, B a is the alpha value of the pixel in the third image, C rgb is the RGB value of the pixel in the fourth image, C a is the alpha value of the pixel in the fourth image.

[0067] In order to solve the above problems, the present invention also discloses an electronic device, including a processor, a memory and a computer program stored in the memory and executable on the processor, wherein the computer program implements the steps of the above image processing method when executed by the processor.

[0068] In order to solve the above problem, the present invention further discloses a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of the above image processing method are implemented.

[0069] Compared with the prior art, the present invention has the following advantages:

[0070] In an embodiment of the present invention, a first image is obtained by filtering the original image; the image edge of the first image is extracted to obtain a second image; the first image is color quantized to obtain a third image; the second image and the third image are superimposed to obtain a fourth image; the smooth structure tensor of the fourth image is calculated; and the fourth image is line integral convolved according to the smooth structure tensor to obtain a target image. In the image processing process, the original image is first filtered to obtain the first image, and then the first image is subsequently processed. The filtering process can reduce the noise of the original image, and further improve the calculation result of the smooth structure tensor of the fourth image after the subsequent superposition of the second image and the third image, thereby improving the overall effect of the image after the comic special effect processing. In addition, the line integral convolution is performed on the fourth image after the second image after the image edge extraction and the third image after the color quantization are superimposed. Therefore, the edge jagged caused by color quantization can be effectively removed, thereby improving the effect of image processing. BRIEF DESCRIPTION OF THE DRAWINGS

[0071] Figure 1 A flowchart of an image processing method provided by Embodiment 1 of the present invention is shown;

[0072] Figure 2 A flowchart of an image processing method provided by Embodiment 2 of the present invention is shown;

[0073] Figure 3 An original image in an image processing method provided by an embodiment of the present invention is shown;

[0074] Figure 4 shows a second image in an image processing method provided by an embodiment of the present invention;

[0075] Figure 5 shows a third image in an image processing method provided by an embodiment of the present invention;

[0076] Figure 6 shows a fourth image in an image processing method provided by an embodiment of the present invention;

[0077] Figure 7 A target image in an image processing method provided by an embodiment of the present invention is shown;

[0078] Figure 8 A structural block diagram of an image processing device provided by an embodiment of the present invention is shown;

[0079] Fig. 9 A structural block diagram of another image processing device provided by an embodiment of the present invention is shown. DETAILED DESCRIPTION

[0080] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.

[0081] Embodiment 1

[0082] Reference Figure 1 , shows a flowchart of an image processing method provided by Embodiment 1 of the present invention, which may specifically include the following steps:

[0083] Step 101, filter the original image to obtain a first image.

[0084] In an embodiment of the present invention, an original image is first acquired. The original image may be an image captured by a camera of a mobile terminal, or may be any image stored in the mobile terminal, or may be any image downloaded from the Internet. After acquiring the original image, the original image is filtered. By filtering, the noise in the original image can be reduced, thereby improving the effect of subsequent image processing.

[0085] Step 102: extract the image edge of the first image to obtain a second image.

[0086] In the embodiment of the present invention, after acquiring the first image, the image edge of the first image is extracted, and the extracted image edge is used as the second image, and the second image is used to provide edge information for subsequent image mixing to obtain a target image.

[0087] Step 103: Perform color quantization processing on the first image to obtain a third image.

[0088] In an embodiment of the present invention, after acquiring the first image, it is necessary to perform color quantization processing on the first image, that is, to merge similar colors in the first image into the same color to reduce the number of colors in the first image, which is also beneficial to improve the efficiency of subsequent image processing.

[0089] Step 104: superimpose the second image and the third image to obtain a fourth image.

[0090] In an embodiment of the present invention, after edge extraction is performed on the first image to obtain the second image, and color quantization is performed on the first image to obtain the third image, the second image and the third image are superimposed to obtain a fourth image, so that the fourth image contains edge information in the second image and color quantization information in the third image.

[0091] Step 105: Calculate the smooth structure tensor of the fourth image.

[0092] In the embodiment of the present invention, after the second image and the third image are superimposed to obtain the fourth image, the smooth structure tensor of each pixel in the fourth image is calculated, and a predetermined pixel point f is selected in the fourth image. The calculation formula of the gradient structure tensor of the predetermined pixel point is as follows:

[0093]

[0094] in, is the gradient of R, G, B of the predetermined pixel along the x direction, is the gradient of R, G, B of the predetermined pixel along the y direction, J is the gradient vector of the predetermined pixel, J T is the transpose of the gradient vector of the predetermined pixel point, (g ij ) is the gradient structure tensor of the predetermined pixel point. After calculating the gradient structure tensor of the predetermined pixel point, the gradient structure tensor of the predetermined pixel point is smoothed to obtain the smoothed structure tensor of the predetermined pixel point, that is, the vector direction of the predetermined pixel point. The predetermined pixel point is any pixel point in the fourth image. The smoothing process can adopt any smoothing process method.

[0095] In an embodiment of the present invention, after the second image and the third image are superimposed to obtain the fourth image, a smooth structure tensor of each pixel in the fourth image is calculated, and the smooth structure tensor represents the vector direction of each pixel in the fourth image, that is, the vector direction of each pixel in the fourth image can be obtained by calculating the smooth structure tensor, and the calculation result of the smooth structure tensor is used to provide the vector direction of the pixel point when performing line integral convolution on the fourth image.

[0096] Step 106: Perform line integral convolution on the fourth image according to the smooth structure tensor to obtain a target image.

[0097] In the embodiment of the present invention, after the smooth structure tensor of the fourth image is calculated, the fourth image is subjected to line integral convolution according to the smooth structure tensor to obtain a target image, that is, a vector field data is visualized in the form of an image. In the obtained smooth structure tensor of the fourth image, for a pixel point at a certain fixed position, there is only the vector direction of the pixel point. To visualize the pixel point with the vector direction, the line integral convolution is used to advance a certain distance along the vector direction of the current pixel point in the smooth structure tensor in the fourth image to obtain a new coordinate position, and the pixel value of this position in the fourth image is recorded. After that, the new position also has its corresponding vector direction, and it continues to advance along this direction and executes the recording of the corresponding pixel value. Points at different positions constitute a curve. Points at different positions on this curve have different weight values. The weight value and the pixel value in the fourth image corresponding to each position are weighted averaged to obtain a visualized pixel value, which is used to connect the discontinuous edges in the same vector direction into a solid edge.

[0098] When performing line integral convolution, the vector direction of the line integral convolution needs to be determined according to the following algorithm:

[0099]

[0100] in, λ1 is the gradient structure tensor of the predetermined pixel point in formula (1) (g ij ) is the maximum value of the eigenvalue, λ2 is the gradient structure tensor (g ij ) (λ2 does not participate in the line integral convolution calculation), v1 is the tangent direction, which is used to provide the vector direction when performing line integral convolution.

[0101] In the embodiment of the present invention, for each pixel in the fourth image, integration is performed along its vector direction, so that the discontinuous edges in the fourth image in the same vector direction are connected into a solid edge. At the same time, since the fourth image is generated by superimposing the image after edge extraction and the image after color quantization, that is, the step of performing line integral convolution on the fourth image is performed after color quantization processing is performed on the first image, the line integral convolution can effectively remove the edge jagged phenomenon of the target image caused by color quantization processing.

[0102] In addition, the image processing scheme of the embodiment of the present invention is implemented based on OpenGL (Open Graphics Library). When performing image processing under OpenGL, multiple pixels can be processed in parallel at the same time. Compared with the existing image processing method implemented by CPU (Central Processing Unit), the image processing efficiency is greatly improved.

[0103] In an embodiment of the present invention, during the image processing, the original image is first filtered to obtain a first image, and then the first image is subsequently processed. The filtering process can reduce the noise of the original image, and further improve the calculation result of the smooth structure tensor of the fourth image after the subsequent superposition of the second image and the third image, thereby improving the overall effect of the image after the comic special effects processing. In addition, the line integral convolution is performed on the fourth image after the second image after image edge extraction and the third image after color quantization are superimposed. Therefore, the edge jagged edges caused by color quantization can be effectively removed, thereby improving the effect of image processing.

[0104] Embodiment 2

[0105] Reference Figure 2 , shows a flow chart of an image processing method provided by Embodiment 2 of the present invention, which may specifically include the following steps:

[0106] Step 201, filter the original image to obtain a first image.

[0107] In the embodiment of the present invention, step 201 may specifically be: performing a bilateral filtering process on the original image to obtain a first image.

[0108] In the embodiment of the present invention, the original image is first obtained, such as Figure 3 As shown, then, only one bilateral filtering process needs to be performed on the original image to obtain the first image. In the prior art, the image after calculating the smooth structure tensor needs to undergo multiple bilateral filtering. Therefore, compared with the prior art, the embodiment of the present invention can greatly improve the efficiency of image processing.

[0109] A specific implementation manner is to perform a filtering process on each first target pixel in the original image according to the N pixels adjacent to the first target pixel in the first direction, so as to obtain a first intermediate image; the first target pixel is any pixel in the original image; according to the N pixels adjacent to each second target pixel in the first intermediate image in the second direction, perform a filtering process on each second target pixel in the first intermediate image, so as to obtain a first image; the second target pixel is any pixel in the first intermediate image; wherein N is a positive integer greater than or equal to 1; the first direction is a horizontal direction, and the second direction is a vertical direction, or the first direction is a vertical direction, and the second direction is a horizontal direction.

[0110] In an embodiment of the present invention, a first target pixel is selected from an original image, and N pixels adjacent to the first target pixel are selected on both sides of the first target pixel along a first direction, and a bilateral filtering is performed on the first target pixel according to the selected N pixels. The first target pixel is any pixel in the original image, and each pixel in the original image is filtered according to the above-mentioned step of filtering the first target pixel to obtain a first intermediate image.

[0111] After obtaining the first intermediate image, a second target pixel is selected from the first intermediate image, and N pixels adjacent to the second target pixel are selected on both sides of the second target pixel along the second direction, and a bilateral filtering is performed on the second target pixel according to the selected N pixels. The second target pixel is any pixel in the first intermediate image, and each pixel in the first intermediate image is filtered according to the above-mentioned steps of filtering the second target pixel to obtain the first image.

[0112] Wherein, N is a positive integer greater than or equal to 1; the first direction is a horizontal direction, and the second direction is a vertical direction, or the first direction is a vertical direction, and the second direction is a horizontal direction.

[0113] Among them, the bilateral filtering algorithm is as follows:

[0114]

[0115] Taking filtering the original image to obtain the first intermediate image as an example, formula (3) is explained, where I filtered is the RGBA value of each pixel in the first intermediate image, W p is the sum of the weight values ​​of the N pixels adjacent to the first target pixel in the original image, m i is the coordinate of the i-th pixel among the N pixels, I(m i ) is the RGBA value of the i-th pixel in the N pixels, m is the coordinate of the first target pixel in the original image, I(m) is the RGBA value of the first target pixel, f r is a Gaussian function with Gaussian kernel r, g s The Gaussian kernel is a Gaussian function of s.

[0116] In another specific implementation, a first target pixel is selected in the original image, a preset area is established with the first target pixel as the center, all pixels except the first target pixel in the preset area are selected to perform a bilateral filtering process on the first target pixel, and the algorithm of the bilateral filtering process is as shown in formula (3). The preset area can be a square or a circle, etc. The first target pixel is any pixel in the original image. According to the above-mentioned step of filtering the first target pixel, each pixel in the original image is filtered to obtain a first image.

[0117] In an embodiment of the present invention, in the process of filtering an original image to obtain a first image, the first target pixels in the original image are first filtered once along a first direction to obtain a first intermediate image, and then the second target pixels in the first intermediate image are filtered once along a second direction to obtain the first image. The above process of filtering the original image does not require selecting all pixels in a preset area around the first target pixel, and filtering the first target pixel based on all pixels in the preset area around the selected first target pixel, thereby improving the efficiency of the filtering process.

[0118] Step 202: compress the first image so that the length and width of the first image after compression are smaller than the length and width of the first image before compression.

[0119] In an embodiment of the present invention, after obtaining the first image by filtering the original image, the first image needs to be compressed so that the length and width of the compressed first image are smaller than the length and width of the first image before compression. Image compression can be performed using any image compression method, and the present invention does not limit this.

[0120] Preferably, the length of the first image is compressed to 1 / 2 of the original length, and the width of the first image is compressed to 1 / 2 of the original length, so that the size of the compressed image is 1 / 4 of the size of the image before compression. From the generation of the first target image to the acquisition of the target image, the size of the image in each step of the image processing is the size of the compressed image, thereby improving the efficiency of subsequent image processing.

[0121] Step 203: extract the image edge of the first image to obtain a second image.

[0122] In the embodiment of the present invention, step 203 specifically includes: extracting the edge of the first image using an extended Gaussian difference algorithm to obtain the second image;

[0123] Wherein, the extended Gaussian difference algorithm is:

[0124]

[0125] Where u = G σ (n)-τ*G kσ (n), u is the Gaussian difference result after deformation, G σ (n) is the Gaussian filtering result with Gaussian kernel σ, G kσ (n) is the Gaussian filtering result with Gaussian kernel kσ, k is a constant, τ is a constant used to adjust the cutoff effect strength of the Gaussian difference result, and n is the gray value of the pixel in the first image; Tε,φ,u To expand the Gaussian difference result, which is used to characterize the edge degree of the pixel in the first image, ε is the threshold, and φ is the edge acceptance coefficient.

[0126] In the embodiment of the present invention, the gray value n of each pixel in the first image is first obtained, and the gray value is substituted into u=G σ (n)-τ·G kσ (n), and obtain the deformed Gaussian difference result u, and then substitute the deformed Gaussian difference result u into formula (4) to obtain the extended Gaussian difference result T ε,φ,u , according to T ε,φ,u Determine whether the pixel is an edge pixel of the image in the first image. For example, when T ε,φ,u When it is 1, the pixel is determined to be the strongest edge pixel. ε,φ,u When it is 0, it is determined that the pixel is not an edge pixel.

[0127] In the embodiment of the present invention, an extended Gaussian difference algorithm is used to extract the edge of the first image to obtain a second image. Compared with the traditional Gaussian difference algorithm, the extended Gaussian difference algorithm introduces a new constant τ. By adjusting the τ value, more styles of second images can be obtained. When τ=1, it is an ordinary Gaussian difference. The extended Gaussian difference algorithm has more adjustable parameters and can meet more user needs. The edge of the first image is extracted by the extended Gaussian difference algorithm to obtain the second image, such as Figure 4 As shown, the values ​​of each RGBA channel (R: red, red channel; G: green, green channel; B: blue, blue channel; A: alpha, grayscale channel) of each pixel of the image are equal. For example, the values ​​of each RGBA channel are (0.5, 0.5, 0.5, 0.5). Compared with the traditional Sobel, Prewitt, and Canny algorithms, the extended Gaussian difference algorithm extracts more continuous image edges.

[0128] Step 204: Perform color quantization processing on the first image to obtain a third image.

[0129] In the embodiment of the present invention, step 204 specifically includes: using a color quantization algorithm to perform color quantization processing on each pixel in the first image in turn to obtain the third image; wherein the color quantization algorithm is as follows:

[0130]

[0131] Wherein, C is the pixel value of the pixel in the first image, C O is the pixel value of the pixel in the third image, d is the quantization coefficient, For The result is rounded down, that is, the integer part of the ratio of the pixel value C in the first image to the quantization coefficient d is taken, for example, C is 169, d is 8, is 21.125, then is 21.

[0132] In the embodiment of the present invention, the pixel value C of each pixel in the first image is obtained, and the pixel value C of each pixel in the first image is substituted into formula (5), and the pixel value C of each pixel in the third image after color quantization is obtained accordingly: O ,like Figure 5 The figure shows a third image obtained after color quantization processing is performed on the first image. By performing color quantization processing on the first image, the number of colors in the first image can be reduced, which is beneficial to improving the image processing efficiency. For example, when d=8, the 256 colors of each channel of the original RGB image can be quantized into 256 / 8=32 colors.

[0133] Step 205: superimpose the second image and the third image to obtain a fourth image.

[0134] In the embodiment of the present invention, step 205 specifically includes: superimposing the second image and the third image according to an image superposition algorithm to obtain the fourth image; wherein the image superposition algorithm is as follows:

[0135] C rgb =F rgb *F a +(1-F a )*B rgb *B a (6)

[0136] C a =F a +(1-F a )*B a (7)

[0137] Among them, F rgb is the RGB value of the pixel in the second image, F a is the alpha value of the pixel in the second image, B rgb is the RGB value of the pixel in the third image, B a is the alpha value of the pixel in the third image, C rgb is the RGB value of the pixel in the fourth image, C a is the alpha value of the pixel in the fourth image.

[0138] In the embodiment of the present invention, after obtaining the second image and the third image, the second image is used as the foreground image, and the RGB value F of each pixel in the second image is obtained. rgband alpha value F a , use the third image as the background image, and obtain the RGB value B of each pixel in the third image rgb and alpha value B a , then F rgb , F a , B rgb and B a Substitute into formula (6) to calculate the RGB value C of each pixel in the fourth image after image superposition: rgb , F a and B a Substitute into formula (7) to calculate the alpha value C of each pixel in the fourth image after image superposition: a , through the image superposition algorithm, the superimposed fourth image contains the edge information in the second image and the color quantization information in the third image, such as Figure 6 As shown, a fourth image is obtained by superimposing the second image and the third image.

[0139] Step 206: Calculate the smooth structure tensor of the fourth image.

[0140] This step is similar in principle to step 105 in the first embodiment, and will not be described again here.

[0141] Step 207: Perform line integral convolution on the fourth image according to the smooth structure tensor to obtain a target image.

[0142] This step is similar in principle to step 106 in the first embodiment, and will not be described again here.

[0143] In the embodiment of the present invention, the fourth image is subjected to line integral convolution according to the smooth structure tensor to obtain a target image such as Figure 7 As shown, the line integral convolution is performed on the fourth image obtained by superimposing the second image after image edge extraction and the third image after color quantization. Therefore, there is no edge jaggedness caused by color quantization in the target image.

[0144] In an embodiment of the present invention, by performing bilateral filtering processing on the original image only once, the efficiency of filtering processing on the original image is improved, and the noise in the original image is effectively reduced, so that the calculation result of the smooth structure tensor of the fourth image after the subsequent superposition of the second image and the third image can be improved, thereby improving the overall effect of the image after comic special effects processing; and, by compressing the first image after filtering processing, so that the size of the image processed in the process from after the filtering processing step to before obtaining the target image is the size of the compressed image, the efficiency of image processing is significantly improved; in addition, the line integral convolution is performed on the fourth image after the second image after image edge extraction and the third image after color quantization are superimposed, therefore, the edge jagged caused by color quantization can be effectively removed, thereby improving the effect of image processing.

[0145] Embodiment 3

[0146] See also Figure 8 , shows a structural block diagram of an image processing device provided by an embodiment of the present invention.

[0147] The image processing device 800 comprises:

[0148] The filtering processing module 801 is used to perform filtering processing on the original image to obtain a first image.

[0149] The image edge extraction module 802 is used to extract the image edge of the first image to obtain a second image.

[0150] The color quantization processing module 803 is used to perform color quantization processing on the first image to obtain a third image.

[0151] The image superposition module 804 is used to superimpose the second image and the third image to obtain a fourth image.

[0152] The smooth structure tensor calculation module 805 is used to calculate the smooth structure tensor of the fourth image.

[0153] The line integral convolution module 806 is used to perform line integral convolution on the fourth image according to the smooth structure tensor to obtain a target image.

[0154] Reference Fig. 9 , shows a structural block diagram of another image processing device provided by an embodiment of the present invention.

[0155] exist Figure 8 On the basis of, optionally, the filtering processing module 801 includes:

[0156] The filtering processing submodule 8011 is used to perform a bilateral filtering process on the original image to obtain a first image.

[0157] Optionally, the filtering processing submodule 8011 includes:

[0158] The first filtering processing unit 80111 is used to perform a filtering process on each first target pixel in the original image in turn according to N pixels adjacent to the first target pixel in the first direction to obtain a first intermediate image; the first target pixel is any pixel in the original image.

[0159] The second filtering processing unit 80112 is used to perform filtering processing on each second target pixel in the first intermediate image in turn according to the N pixels adjacent to each second target pixel in the second direction to obtain the first image; the second target pixel is any pixel in the first intermediate image.

[0160] Wherein, N is a positive integer greater than or equal to 1; the first direction is a horizontal direction, and the second direction is a vertical direction, or the first direction is a vertical direction, and the second direction is a horizontal direction.

[0161] Optionally, the image processing device 800 further includes:

[0162] The image compression module 807 is used to compress the first image so that the length and width of the first image after compression are smaller than the length and width of the first image before compression.

[0163] Optionally, the image edge extraction module 802 includes:

[0164] The image edge extraction submodule 8021 is used to extract the edge of the first image by using an extended Gaussian difference algorithm to obtain the second image.

[0165] Wherein, the extended Gaussian difference algorithm is:

[0166]

[0167] Where u = G σ (n)-τ*G kσ (n), u is the Gaussian difference result after deformation, G σ (n) is the Gaussian filtering result with Gaussian kernel σ, G kσ (n) is the Gaussian filtering result with a Gaussian kernel of kσ, k is a constant, τ is a constant used to adjust the cutoff effect strength of the Gaussian difference result, and n is the grayscale value of the pixel in the first image; T ε,φ,u To expand the Gaussian difference result, which is used to characterize the edge degree of the pixel in the first image, ε is the threshold, and φ is the edge acceptance coefficient.

[0168] Optionally, the color quantization processing module 803 includes:

[0169] The color quantization processing submodule 8031 ​​is used to use a color quantization algorithm to perform color quantization processing on each pixel in the first image in turn to obtain the third image.

[0170] Wherein, the color quantization algorithm is as follows:

[0171]

[0172] Wherein, C is the pixel value of the pixel in the first image, C O is the pixel value of the pixel in the third image, d is the quantization coefficient, For The result is rounded down.

[0173] Optionally, the image overlay module 804 includes:

[0174] The image superposition submodule 8041 is used to superimpose the second image and the third image according to an image superposition algorithm to obtain the fourth image.

[0175] Wherein, the image superposition algorithm is as follows:

[0176] C rgb =F rgb *F a +(1-F a )*B rgb *B a (6)

[0177] C a =F a +(1-F a )*B a (7)

[0178] Among them, F rgb is the RGB value of the pixel in the second image, F a is the alpha value of the pixel in the second image, B rgb is the RGB value of the pixel in the third image, B a is the alpha value of the pixel in the third image, C rgb is the RGB value of the pixel in the fourth image, C a is the alpha value of the pixel in the fourth image.

[0179] As for the device 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.

[0180] In an embodiment of the present invention, during the image processing, the original image is first filtered to obtain a first image, and then the first image is subsequently processed. The filtering process can reduce the noise of the original image, and further improve the calculation result of the smooth structure tensor of the fourth image after the subsequent superposition of the second image and the third image, thereby improving the overall effect of the image after the comic special effects processing. In addition, the line integral convolution is performed on the fourth image after the second image after image edge extraction and the third image after color quantization are superimposed. Therefore, the edge jagged edges caused by color quantization can be effectively removed, thereby improving the effect of image processing.

[0181] Correspondingly, an embodiment of the present invention further provides an electronic device, comprising a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein when the computer program is executed by the processor, the steps of the image processing method described in Embodiment 1 and Embodiment 2 of the present invention are implemented.

[0182] The embodiment of the present invention further discloses a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of the image processing method described in the first and second embodiments of the present invention are implemented.

[0183] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0184] It will be appreciated by those skilled in the art that the embodiments of the present invention may be provided as methods, devices, or computer program products. Therefore, the embodiments of the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the embodiments of the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.

[0185] The embodiments of the present invention are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks 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 terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal 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 1A device that provides the functions specified in a block or multiple blocks.

[0186] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including 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.

[0187] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0188] Although the preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present invention.

[0189] Finally, 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 terminal 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 terminal 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 terminal device including the elements.

[0190] The image processing method, device, electronic device and computer-readable storage medium provided by the present invention are introduced in detail above. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of ​​the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.

Claims

1. An image processing method, characterized in that: The method comprises: Performing filtering on the original image to obtain a first image; Extracting the image edge of the first image to obtain a second image; Performing color quantization processing on the first image to obtain a third image; superimposing the second image and the third image to obtain a fourth image; calculating a smoothed structure tensor of the fourth image; Performing line integral convolution on the fourth image according to the smooth structure tensor to obtain a target image; Before the step of extracting the image edge of the first image to obtain the second image, the step further includes: compressing the first image so that the length and width of the first image after compression are both 1 / 2 of the length and width of the first image before compression; The step of performing color quantization processing on the first image to obtain a third image comprises: Using a color quantization algorithm to perform color quantization processing on each pixel in the first image in turn to obtain the third image; Wherein, the color quantization algorithm is as follows: Wherein, C is the pixel value of the pixel in the first image, C O is the pixel value of the pixel in the third image, d is the quantization coefficient, For The result is rounded down; The step of superimposing the second image and the third image to obtain a fourth image comprises: Superimposing the second image and the third image according to an image superposition algorithm to obtain the fourth image; Wherein, the image superposition algorithm is as follows: C rgb =F rgb *F a +(1-F a )*B rgb *B a , C a =F a +(1-F a )*B a Among them, F rgb is the RGB value of the pixel in the second image, F a is the alpha value of the pixel in the second image, B rgb is the RGB value of the pixel in the third image, B a is the alpha value of the pixel in the third image, C rgb is the RGB value of the pixel in the fourth image, C a is the alpha value of the pixel in the fourth image.

2. The image processing method according to claim 1, characterized in that: The step of filtering the original image to obtain the first image comprises: Perform a bilateral filtering process on the original image to obtain a first image.

3. The image processing method according to claim 2, characterized in that: The step of performing a bilateral filtering process on the original image to obtain a first image comprises: According to N pixels adjacent to each first target pixel in the original image in the first direction, filtering is performed on each first target pixel in turn to obtain a first intermediate image; the first target pixel is any pixel in the original image; According to N pixels adjacent to each second target pixel in the first intermediate image in the second direction, filtering is performed on each second target pixel in turn to obtain a first image; the second target pixel is any pixel in the first intermediate image; Wherein, N is a positive integer greater than or equal to 1; the first direction is a horizontal direction, and the second direction is a vertical direction, or the first direction is a vertical direction, and the second direction is a horizontal direction.

4. The image processing method according to claim 1, characterized in that: The step of extracting the image edge of the first image to obtain the second image comprises: Extracting the edge of the first image using an extended Gaussian difference algorithm to obtain the second image; Wherein, the extended Gaussian difference algorithm is: Where u = G σ (n)-τ*G kσ (n), u is the Gaussian difference result after deformation, G σ (n) is the Gaussian filtering result with Gaussian kernel σ, G kσ (n) is the Gaussian filtering result with a Gaussian kernel of kσ, k is a constant, τ is a constant used to adjust the cutoff effect strength of the Gaussian difference result, and n is the grayscale value of the pixel in the first image; T ε,φ,u To expand the Gaussian difference result, which is used to characterize the edge degree of the pixel in the first image, ε is the threshold, and φ is the edge acceptance coefficient.

5. An image processing device, characterized in that: The device comprises: A filtering processing module, used for performing filtering processing on the original image to obtain a first image; An image edge extraction module, used to extract the image edge of the first image to obtain a second image; A color quantization processing module, used for performing color quantization processing on the first image to obtain a third image; An image superposition module, used for superimposing the second image and the third image to obtain a fourth image; A smooth structure tensor calculation module, used for calculating the smooth structure tensor of the fourth image; A line integral convolution module, used for performing line integral convolution on the fourth image according to the smooth structure tensor to obtain a target image; an image compression module, configured to compress the first image so that the length and width of the first image after compression are both 1 / 2 of the length and width of the first image before compression; The color quantization processing module comprises: A color quantization processing submodule, configured to use a color quantization algorithm to sequentially perform color quantization processing on each pixel in the first image to obtain the third image; Wherein, the color quantization algorithm is as follows: Wherein, C is the pixel value of the pixel in the first image, C O is the pixel value of the pixel in the third image, d is the quantization coefficient, For The result is rounded down; The step of superimposing the second image and the third image to obtain a fourth image comprises: Superimposing the second image and the third image according to an image superposition algorithm to obtain the fourth image; Wherein, the image superposition algorithm is as follows: C rgb =F rgb *F a +(1-F a )*B rgb *B a , C a =F a +(1-F a )*B a Among them, F rgb is the RGB value of the pixel in the second image, F a is the alpha value of the pixel in the second image, B rgb is the RGB value of the pixel in the third image, B a is the alpha value of the pixel in the third image, C rgb is the RGB value of the pixel in the fourth image, C a is the alpha value of the pixel in the fourth image.

6. An electronic device, characterized in that: The method comprises a processor, a memory and a computer program stored in the memory and executable on the processor, wherein the computer program implements the steps of the image processing method according to any one of claims 1 to 4 when executed by the processor.

7. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the image processing method according to any one of claims 1 to 4 are implemented.