Gaussian blur method and related device for image contour preservation

Through the Gaussian blur method of image contour preservation, the problems of insufficient fineness of image blur processing and serious contour loss in the prior art are solved, and the effect of efficiently retaining image contour and improving the fineness of blur processing is achieved.

CN116579946BActive Publication Date: 2025-02-11SHENZHEN SHANJIAN INTELLIGENT SCI & TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202310600958.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-05-24
Publication Date
2025-02-11
Estimated Expiration
2043-05-24

AI Technical Summary

Technical Problem

The prior art lacks fineness in image blur processing, resulting in serious loss of image contours and destroys the authenticity and integrity of the image.

Method used

The Gaussian blur method with image contour preservation is adopted to obtain the target image, perform matrix processing, generate a convolution kernel, calculate the weight based on the Gaussian mixed formula, perform normalization processing, and generate Gaussian blur image.

Benefits of technology

Effectively preserve image outlines, improve the delicateness of blur processing, avoid contour loss, and enhance the authenticity and integrity of the image.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116579946B_ABST
    Figure CN116579946B_ABST
Patent Text Reader

Abstract

The present invention relates to the field of image processing, and discloses a Gaussian blur method for image contour preservation and a related device. The method comprises: obtaining a target image to be processed; performing matrix processing on the target image according to a preset conversion algorithm to obtain an image matrix; generating a convolution kernel according to a set blur radius; performing Gaussian mixture calculation processing on the image matrix based on the preset convolution kernel to generate the weight of each element in the convolution kernel; performing normalization processing on the image matrix using the convolution kernel according to the weight of each element in the convolution kernel to generate an image normalization matrix; generating a Gaussian blurred image corresponding to the target image based on the image normalization matrix. The present invention solves the technical problem of serious contour loss of images with insufficient fineness in the image blur processing of the prior art.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to the field of image processing, and in particular to a Gaussian blur method for preserving image contours and a related device. Background Art

[0002] In the field of image and video creation, especially for materials with characters as the theme, it is usually necessary to perform beautification processing such as skin smoothing and denoising. These processing usually require the use of blur algorithms. At present, most of the images on the market are blurred as a whole. While denoising, the outline of the characters also disappears. If the parameters are not handled properly, the characters in the picture will appear hazy and blurred, which seriously dilutes the theme of the characters. The blur is not fine enough and looks very rough, and even has a certain graininess, which may even give people the impression of poor image quality. In addition, the image outline elements are seriously lost, which seriously damages the authenticity and integrity of the image.

[0003] Therefore, in view of the technical problem that the image is not fine enough and the contour of the image is seriously lost in the image blurring processing of the prior art, a new solution is needed to solve the current problem. Summary of the invention

[0004] The main purpose of the present invention is to solve the technical problem of serious loss of contour of an image with insufficient fineness in the image blurring process in the prior art.

[0005] A first aspect of the present invention provides a Gaussian blur method for preserving image contours, the Gaussian blur method for preserving image contours comprising:

[0006] Obtaining a target image to be processed;

[0007] According to a preset conversion algorithm, matrix processing is performed on the target image to obtain an image matrix;

[0008] Generate a convolution kernel according to the set blur radius;

[0009] Based on a preset convolution kernel, performing Gaussian mixture calculation processing on the image matrix to generate a weight for each element in the convolution kernel;

[0010] According to the weight of each element in the convolution kernel, the image matrix is ​​normalized using the convolution kernel to generate an image normalization matrix;

[0011] Based on the image normalization matrix, a Gaussian blurred image corresponding to the target image is generated.

[0012] Optionally, in a first implementation of the first aspect of the present invention, the step of performing matrix processing on the target image according to a preset conversion algorithm to obtain an image matrix includes:

[0013] Perform RGB channel calculation on each pixel of the target image to generate an image matrix.

[0014] Optionally, in a second implementation of the first aspect of the present invention, generating a convolution kernel according to the set blur radius includes:

[0015] The center coordinates of the convolution kernel are defined, and based on the set blur radius, matrix expansion processing is performed on the center coordinates to obtain the convolution kernel.

[0016] Optionally, in a third implementation manner of the first aspect of the present invention, performing Gaussian mixture calculation processing on the image matrix based on a preset convolution kernel to generate a weight for each element in the convolution kernel includes:

[0017] According to the elements of the convolution kernel, select the target element in the image matrix;

[0018] Based on the shape of the convolution kernel, a preset Gaussian mixture formula is used to perform weight calculation on the target element to generate a weight for each element in the convolution kernel.

[0019] Optionally, in a fourth implementation of the first aspect of the present invention, the Gaussian mixture formula includes:

[0020]

[0021] , where W is the weight value of the element of the convolution kernel, exp() is an exponential function with the natural constant e as the base, disGray is the grayscale distance between the target element and the reference element, spacesigma is the standard deviation of the elements in the spatial domain of the convolution kernel corresponding to the matrix, garyGrads is the gradient value of the target element, colorsigma is the standard deviation of the color domain of the convolution kernel corresponding to the matrix, uGrayGrand is the grayscale gradient threshold, step(|garyGrads|, uGrayGrand) is a step function that takes the value of 0 when |garyGrads| is less than uGrayGrand and 1 otherwise, and mix(a, b, c) is a mixing function.

[0022] Optionally, in a fifth implementation manner of the first aspect of the present invention, the step of normalizing the image matrix using the convolution kernel according to the weight of each element in the convolution kernel to generate an image normalization matrix includes:

[0023] Based on the weight of each element in the convolution kernel, convolution processing is performed on the target area of ​​the image matrix to obtain a normalized total;

[0024] Based on the normalized total, element value division processing is performed on the target area of ​​the image matrix to obtain an image normalized matrix.

[0025] Optionally, in a sixth implementation manner of the first aspect of the present invention, generating a Gaussian blurred image corresponding to the target image based on the image normalization matrix includes:

[0026] Using the PIL library, the image normalization matrix is ​​traversed row by row and mapped to the RGB channels of the preset blank image to generate a Gaussian blurred image corresponding to the target image.

[0027] A second aspect of the present invention provides a Gaussian blur device for preserving image contours, the Gaussian blur device for preserving image contours comprising:

[0028] An acquisition module, used for acquiring a target image to be processed;

[0029] A matrixing module, used for performing matrixing processing on the target image according to a preset conversion algorithm to obtain an image matrix;

[0030] The convolution kernel generation module is used to generate the convolution kernel according to the set blur radius;

[0031] A weight calculation module, used to perform Gaussian mixture calculation processing on the image matrix based on a preset convolution kernel to generate a weight for each element in the convolution kernel;

[0032] A normalization module, used for performing normalization processing on the image matrix using the convolution kernel according to the weight of each element in the convolution kernel, so as to generate an image normalization matrix;

[0033] The image generation module is used to generate a Gaussian blurred image corresponding to the target image based on the image normalization matrix.

[0034] The third aspect of the present invention provides a Gaussian blur device for preserving image contours, comprising: a memory and at least one processor, wherein instructions are stored in the memory, and the memory and the at least one processor are interconnected via lines; the at least one processor calls the instructions in the memory so that the Gaussian blur device for preserving image contours executes the above-mentioned Gaussian blur method for preserving image contours.

[0035] A fourth aspect of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores instructions, which, when executed on a computer, enable the computer to execute the above-mentioned Gaussian blur method for preserving image contours.

[0036] In an embodiment of the present invention, based on the normal distribution function and graphics-related content, a dual-factor weight function of the space domain and the color domain is fitted, and the performance indicators and beautification needs are considered, and relevant parameters such as the standard deviation, radius, and color gradient threshold are configured. The blur standard deviation, blur degree (blur radius), and color gradient threshold are configured to present effects of different blur degrees and aesthetics, thereby solving the technical problem of insufficient fineness and serious loss of image contours in the image blurring processing of the prior art. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] Figure 1 A schematic diagram of an embodiment of a Gaussian blur method for preserving image contours in an embodiment of the present invention;

[0038] Figure 2 Schematic diagram of a convolution kernel in an embodiment of the present invention;

[0039] Figure 3 A schematic diagram of an embodiment of a Gaussian blur device for preserving image contours in an embodiment of the present invention;

[0040] Figure 4 A schematic diagram of another embodiment of a Gaussian blur device for preserving image contours in an embodiment of the present invention;

[0041] Figure 5 A schematic diagram of an embodiment of a Gaussian blur device for preserving image contours in an embodiment of the present invention. DETAILED DESCRIPTION

[0042] The embodiment of the present invention provides a Gaussian blur method for preserving image contour and a related device.

[0043] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including" or "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0044] For ease of understanding, the specific process of the embodiment of the present invention is described below. Figure 1 An embodiment of the Gaussian blur method for preserving image contours in an embodiment of the present invention includes:

[0045] 101. Obtain a target image to be processed;

[0046] In this embodiment, the target image to be processed is selected from the data set, which can be selected according to specific conditions or randomly. The target image can be visualized to ensure its correctness, and the label or attribute of the image can be specified by manual or automatic labeling to obtain the target image.

[0047] 102. Perform matrix processing on the target image according to a preset conversion algorithm to obtain an image matrix;

[0048] In this embodiment, assume that a 256*256 pixel color image needs to be matrixed. The following steps can be followed: 1. Convert the image row by row into a grayscale image, so that each pixel only needs a numerical value to represent the brightness. 2. Map the brightness value of each pixel to the interval [0, 1]. 3. Sort multiple 1*256 pixels according to the original generation sequence to generate an image matrix.

[0049] Furthermore, at 102, the following steps may be performed:

[0050] 1021. Perform RGB channel calculation on each pixel of the target image to generate an image matrix.

[0051] In step 1021, each pixel of the target image can be read using the cv2.imread() function, a blank RGB image matrix is ​​created using the numpy library, and a for loop is used to iterate over each pixel and store its RGB value in the matrix.

[0052] 103. Generate a convolution kernel according to the set blur radius;

[0053] In this embodiment, reference can be made to Figure 2 , Figure 2 This is a schematic diagram of an embodiment of a convolution kernel, in which the element marked as "1" is the central element, and the surrounding elements marked as "2" constitute a convolution kernel with a blur radius of 1, so the convolution kernel is 3*3 at this time.

[0054] Furthermore, the following steps may be performed at 103:

[0055] 1031. Define the center coordinates of the convolution kernel, and based on the set blur radius, perform matrix expansion processing on the center coordinates to obtain the convolution kernel.

[0056] In step 1031, it is necessary to first define the center coordinates of the convolution kernel, generate a matrix element based on the center coordinates, and then generate matrix elements by stacking them in a ring at the center of the matrix element according to the size of the blur radius. For example, if the blur radius is X, then a convolution kernel of (2X+1)*(2X+1) is finally generated.

[0057] 104. Based on a preset convolution kernel, perform Gaussian mixture calculation processing on the image matrix to generate a weight of each element in the convolution kernel;

[0058] In this embodiment, the closer the normal distribution image is to the center position, the larger the function value is, and vice versa. A standard normal distribution function is as follows:

[0059]

[0060] Among them, exp() is an exponential function with the natural constant e as the base, x is the coordinate of the auxiliary pixel point, u represents the coordinate of the current pixel point. In the field of graphic special effects processing, it can be understood as two vectors. The square of the subtraction of the two vectors represents the square of the modulus of the final vector, and f(x) is the value after normal distribution. σ represents the standard deviation, which is reflected in the image as the smoothness of the image. The larger the value, the smoother the image, and vice versa. The above function explanation is viewed from the perspective of the spatial domain. At this time, it is the weight calculated by the spatial distance factor. Now we extend the above understanding to the color domain and replace the above spatial distance with the color gradient. The algorithm still makes sense. At this time, it is the weight calculated by the color factor.

[0061] The overall function value coefficients are removed and are meaningless in graphics (need to be normalized). It is the standard coefficient of the normal distribution function, which controls the overall height of the function image. Because in graphics, the range value of the RGBA color space is usually ∈[0,1], so after accumulating all the pixel colors in the convolution kernel, the calculated color needs to be normalized (the RGBA corresponding components are remapped to the range [0,1.]). Because of this operation, the standard coefficient has no meaning in this calculation, so it is necessary to eliminate the preceding coefficient.

[0062] Under normal circumstances, the normal distribution function only constrains the weight of a single factor, that is, the composite variable in the function is: -0.5*((xu) / σ)^2. If we treat the color gradient difference and the distance difference as the same, then the current composite variable should be: -0.5*((xu) / σ)^2-0.5*((yv) / θ)^2. The relevant expressions are explained as follows:

[0063] xu: distance gradient;

[0064] σ: variance in distance. The larger the value, the smoother the curve and the more evenly the weight distribution.

[0065] yv: color gradient difference

[0066] θ: Variance of color gradient. The larger the value, the blurrier the outline, and vice versa.

[0067] The above composite function adds a color gradient filter expression. As long as the color gradient difference reaches a certain threshold, the color gradient factor will take effect (affecting the final weight).

[0068] Based on the modified Gaussian function, the convolution kernel is used to calculate the image matrix and the relevant weight of each element in the convolution kernel is calculated.

[0069] Further, 104 may perform the following steps:

[0070] 1041. Select a target element in the image matrix according to the element of the convolution kernel;

[0071] 1042. Based on the shape of the convolution kernel, use a preset Gaussian mixture formula to perform weight calculation on the target element to generate a weight for each element in the convolution kernel.

[0072] In this embodiment, taking a 3*3 convolution kernel as an example, a 3*3 target area of ​​the image matrix is ​​selected using the 3*3 convolution kernel, and all elements in the target area are target elements. The 3*3 range is used to perform weight calculation on the corresponding 3*3 area in the image matrix to generate the weight of each element in the convolution kernel. The Gaussian mixture formula used for calculation includes:

[0073]

[0074] , where W is the weight value of the element of the convolution kernel, exp() is an exponential function with the natural constant e as the base, disGray is the grayscale distance between the target element and the reference element, spacesigma is the standard deviation of the elements in the spatial domain of the convolution kernel matrix, garyGrads is the gradient value of the target element, colorsigma is the standard deviation of the color domain of the convolution kernel matrix, uGrayGrand is the grayscale gradient threshold, step(|garyGrads|, uGrayGrand) is a step function that takes the value of 0 when |garyGrads| is less than uGrayGrand, otherwise it is 1, and mix(a, b, c) is a mixing function. mix(a, b, c) represents the weighted mixing of two Gaussian distributions according to the value of the step function. When |garyGrads| is less than uGrayGrand, only the spatial domain Gaussian distribution is used, otherwise the weighted mixture of the spatial domain Gaussian distribution and the color domain distribution is used to calculate the weight value of the convolution kernel.

[0075] 105. According to the weight of each element in the convolution kernel, the image matrix is ​​normalized using the convolution kernel to generate an image normalization matrix;

[0076] In this embodiment, for example, the convolution kernel is a 3*3 matrix, and the matrix elements are ordered as a, b, c, d, e, f, g, h, and l. Then the color value of each 3*3 pixel in the image matrix is ​​multiplied by the corresponding weight and the sum is accumulated to obtain the normalized total of the convolution, and then each 3*3 pixel in the image matrix is ​​divided by the normalized total to obtain a part of the image normalized matrix, and all image matrices are processed in a loop to generate an image normalized matrix.

[0077] Furthermore, at 105, the following steps may be performed:

[0078] 1051. Based on the weight of each element in the convolution kernel, perform convolution processing on the target area of ​​the image matrix to obtain a normalized total number;

[0079] 1052. Based on the normalized total, perform element value division processing on the target area of ​​the image matrix to obtain an image normalization matrix.

[0080] In steps 1051-1052, the convolution kernel is a 3*3 matrix, the matrix elements are arranged as a, b, c, d, e, f, g, h, l, the element value is also the element weight, the color value of each 3*3 pixel in the image matrix is ​​multiplied by the corresponding weight and the sum is accumulated to obtain the normalized total of the convolution, and then each 3*3 pixel in the image matrix is ​​divided by the normalized total to obtain a part of the image normalized matrix, and all image matrices are processed in a loop to generate an image normalized matrix.

[0081] 106. Generate a Gaussian blurred image corresponding to the target image based on the image normalization matrix.

[0082] In this embodiment, to convert a matrix into a color image, it is usually necessary to map each element in the matrix to the values ​​of the three channels of RGB (red, green, and blue). A simple method is to use linear mapping, that is, to map the minimum value in the matrix to the darkest color of the corresponding channel in RGB (such as red [0,0,0]), map the maximum value to the brightest color (such as white [255,255,255]), and distribute the values ​​between these two extremes to other colors in proportion.

[0083] Further, 106 may perform the following steps:

[0084] 1061. Using the PIL library, traverse the image normalization matrix row by row and map it to the RGB channels of the preset blank image to generate a Gaussian blurred image corresponding to the target image.

[0085] In step 1061, using the PIL library in Python, you can first create a blank color image, then traverse each element in the matrix row by row, map it to the RGB value, and finally fill these RGB values ​​into the corresponding positions in the image. For example: create a random 512x512x3 three-dimensional matrix (each element represents a channel in RGB), and then use the PIL library to create a blank 512x512 color image. Then traverse each element in the matrix row by row, map it to the corresponding RGB value, and fill these RGB values ​​into the corresponding positions in the image. Finally, save the generated color image to a local file.

[0086] In an embodiment of the present invention, based on the normal distribution function and graphics-related content, a dual-factor weight function of the space domain and the color domain is fitted, and the performance indicators and beautification needs are considered, and relevant parameters such as the standard deviation, radius, and color gradient threshold are configured. The blur standard deviation, blur degree (blur radius), and color gradient threshold are configured to present effects of different blur degrees and aesthetics, thereby solving the technical problem of insufficient fineness and serious loss of image contours in the image blurring processing of the prior art.

[0087] The Gaussian blur method for image contour preservation in the embodiment of the present invention is described above. The Gaussian blur device for image contour preservation in the embodiment of the present invention is described below. Figure 3 In one embodiment of the Gaussian blur device for image contour preservation in the embodiment of the present invention, the Gaussian blur device for image contour preservation comprises:

[0088] An acquisition module 301 is used to acquire a target image to be processed;

[0089] The matrixing module 302 is used to perform matrixing on the target image according to a preset conversion algorithm to obtain an image matrix;

[0090] A convolution kernel generation module 303, used to generate a convolution kernel according to a set blur radius;

[0091] A weight calculation module 304 is used to perform Gaussian mixture calculation processing on the image matrix based on a preset convolution kernel to generate a weight for each element in the convolution kernel;

[0092] A normalization module 305 is used to perform normalization processing on the image matrix using the convolution kernel according to the weight of each element in the convolution kernel to generate an image normalization matrix;

[0093] The image generation module 306 is used to generate a Gaussian blurred image corresponding to the target image based on the image normalization matrix.

[0094] In an embodiment of the present invention, based on the normal distribution function and graphics-related content, a dual-factor weight function of the space domain and the color domain is fitted, and the performance indicators and beautification needs are considered, and relevant parameters such as the standard deviation, radius, and color gradient threshold are configured. The blur standard deviation, blur degree (blur radius), and color gradient threshold are configured to present effects of different blur degrees and aesthetics, thereby solving the technical problem of insufficient fineness and serious loss of image contours in the image blurring processing of the prior art.

[0095] See also Figure 4 , another embodiment of the Gaussian blur device for image contour preservation in the embodiment of the present invention, the Gaussian blur device for image contour preservation comprises:

[0096] An acquisition module 301 is used to acquire a target image to be processed;

[0097] The matrixing module 302 is used to perform matrixing on the target image according to a preset conversion algorithm to obtain an image matrix;

[0098] A convolution kernel generation module 303, used to generate a convolution kernel according to a set blur radius;

[0099] A weight calculation module 304 is used to perform Gaussian mixture calculation processing on the image matrix based on a preset convolution kernel to generate a weight for each element in the convolution kernel;

[0100] A normalization module 305 is used to perform normalization processing on the image matrix using the convolution kernel according to the weight of each element in the convolution kernel to generate an image normalization matrix;

[0101] The image generation module 306 is used to generate a Gaussian blurred image corresponding to the target image based on the image normalization matrix.

[0102] The matrix module 302 is specifically used for:

[0103] Perform RGB channel calculation on each pixel of the target image to generate an image matrix.

[0104] The convolution kernel generation module 303 is specifically used for:

[0105] The center coordinates of the convolution kernel are defined, and based on the set blur radius, matrix expansion processing is performed on the center coordinates to obtain the convolution kernel.

[0106] Wherein, the weight calculation module 304 includes:

[0107] A selection unit 3041, configured to select a target element in the image matrix according to an element of the convolution kernel;

[0108] The weight calculation unit 3042 is used to perform weight calculation on the target element based on the shape of the convolution kernel and use a preset Gaussian mixture formula to generate a weight for each element in the convolution kernel.

[0109] Wherein, the Gaussian mixture formula includes:

[0110]

[0111] , where W is the weight value of the element of the convolution kernel, exp() is an exponential function with the natural constant e as the base, disGray is the grayscale distance between the target element and the reference element, spacesigma is the standard deviation of the elements in the spatial domain of the convolution kernel corresponding to the matrix, garyGrads is the gradient value of the target element, colorsigma is the standard deviation of the color domain of the convolution kernel corresponding to the matrix, uGrayGrand is the grayscale gradient threshold, step(|garyGrads|, uGrayGrand) is a step function that takes the value of 0 when |garyGrads| is less than uGrayGrand and 1 otherwise, and mix(a, b, c) is a mixing function.

[0112] The normalization module 305 is specifically used for:

[0113] Based on the weight of each element in the convolution kernel, convolution processing is performed on the target area of ​​the image matrix to obtain a normalized total;

[0114] Based on the normalized total, element value division processing is performed on the target area of ​​the image matrix to obtain an image normalized matrix.

[0115] The image generation module 306 is specifically used for:

[0116] Using the PIL library, the image normalization matrix is ​​traversed row by row and mapped to the RGB channels of the preset blank image to generate a Gaussian blurred image corresponding to the target image.

[0117] In an embodiment of the present invention, based on the normal distribution function and graphics-related content, a dual-factor weight function of the space domain and the color domain is fitted, and the performance indicators and beautification needs are considered, and relevant parameters such as the standard deviation, radius, and color gradient threshold are configured. The blur standard deviation, blur degree (blur radius), and color gradient threshold are configured to present effects of different blur degrees and aesthetics, thereby solving the technical problem of insufficient fineness and serious loss of image contours in the image blurring processing of the prior art.

[0118] above Figure 3 and Figure 4The Gaussian blur device for preserving image contours in the embodiment of the present invention is described in detail from the perspective of modular functional entities. The Gaussian blur device for preserving image contours in the embodiment of the present invention is described in detail from the perspective of hardware processing.

[0119] Figure 5 1 is a schematic diagram of the structure of a Gaussian blur device for image contour preservation provided by an embodiment of the present invention. The Gaussian blur device 500 for image contour preservation may have relatively large differences due to different configurations or performances, and may include one or more processors (central processing units, CPU) 510 (for example, one or more processors) and a memory 520, and one or more storage media 530 (for example, one or more mass storage devices) for storing application programs 533 or data 532. Among them, the memory 520 and the storage medium 530 may be short-term storage or permanent storage. The program stored in the storage medium 530 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations in the Gaussian blur device 500 for image contour preservation. Furthermore, the processor 510 may be configured to communicate with the storage medium 530 to execute a series of instruction operations in the storage medium 530 on the Gaussian blur device 500 for image contour preservation.

[0120] The Gaussian blur device 500 based on image contour preservation may also include one or more power supplies 540, one or more wired or wireless network interfaces 550, one or more input and output interfaces 560, and / or one or more operating systems 531, such as Windows Serve, Mac OS X, Unix, Linux, Free BSD, etc. Those skilled in the art will appreciate that Figure 5 The structure of the Gaussian blur device for image contour preservation shown does not constitute a limitation on the Gaussian blur device based on image contour preservation, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.

[0121] The present invention also provides a computer-readable storage medium, which may be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium. Instructions are stored in the computer-readable storage medium. When the instructions are executed on a computer, the computer executes the steps of the Gaussian blur method for preserving image contours.

[0122] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the above-described system, device, or unit can refer to the corresponding process in the aforementioned method embodiment and will not be repeated here.

[0123] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program codes.

[0124] As described above, the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features thereof may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A Gaussian blurring method for image contour preservation, characterized in that: Includes steps: Obtaining a target image to be processed; According to a preset conversion algorithm, matrix processing is performed on the target image to obtain an image matrix; Generate a convolution kernel according to the set blur radius; Based on a preset convolution kernel, performing Gaussian mixture calculation processing on the image matrix to generate a weight for each element in the convolution kernel; According to the weight of each element in the convolution kernel, the image matrix is ​​normalized using the convolution kernel to generate an image normalization matrix; Based on the image normalization matrix, generating a Gaussian blurred image corresponding to the target image; The step of performing Gaussian mixture calculation processing on the image matrix based on a preset convolution kernel to generate the weight of each element in the convolution kernel includes: Selecting a target element in the image matrix according to an element of the convolution kernel; Based on the shape of the convolution kernel, a preset Gaussian mixture formula is used to perform weight calculation on the target element to generate a weight for each element in the convolution kernel; The Gaussian mixture formula includes: Among them, W is the weight value of the elements of the convolution kernel, exp() is an exponential function with the natural constant e as the base, disGray is the grayscale distance between the target element and the reference element, spacesigma is the standard deviation of the elements in the spatial domain of the convolution kernel corresponding to the matrix, garyGrads is the gradient value of the target element, colorsigma is the standard deviation of the color domain of the convolution kernel corresponding to the matrix, uGrayGrand is the grayscale gradient threshold, step(|garyGrads|, uGrayGrand) is a step function that takes the value of 0 when |garyGrads| is less than uGrayGrand, otherwise it is 1, and mix(a, b, c) is a mixing function.

2. The Gaussian blurring method for image contour preservation according to claim 1, characterized in that: The target image is matrixed according to a preset conversion algorithm to obtain an image matrix, comprising: Perform RGB channel calculation on each pixel of the target image to generate an image matrix.

3. The Gaussian blurring method for image contour preservation according to claim 1, characterized in that: The generating of the convolution kernel according to the set blur radius includes: The center coordinates of the convolution kernel are defined, and based on the set blur radius, matrix expansion processing is performed on the center coordinates to obtain the convolution kernel.

4. The Gaussian blurring method for image contour preservation according to claim 1, characterized in that: According to the weight of each element in the convolution kernel, the image matrix is ​​normalized by using the convolution kernel to generate an image normalization matrix, which includes: Based on the weight of each element in the convolution kernel, convolution processing is performed on the target area of ​​the image matrix to obtain a normalized total; Based on the normalized total, element value division processing is performed on the target area of ​​the image matrix to obtain an image normalized matrix.

5. The Gaussian blurring method for image contour preservation according to claim 1, characterized in that: The step of generating a Gaussian blurred image corresponding to the target image based on the image normalization matrix includes: The PIL library is used to traverse the image normalization matrix row by row and map it to the RGB channels of the preset blank image to generate a Gaussian blurred image corresponding to the target image.

6. A Gaussian blur device for preserving image contours, characterized in that: The Gaussian blur device for image contour preservation comprises: An acquisition module, used for acquiring a target image to be processed; A matrixing module, used for performing matrixing processing on the target image according to a preset conversion algorithm to obtain an image matrix; The convolution kernel generation module is used to generate the convolution kernel according to the set blur radius; A weight calculation module, used to perform Gaussian mixture calculation processing on the image matrix based on a preset convolution kernel to generate a weight for each element in the convolution kernel; A normalization module, used for performing normalization processing on the image matrix using the convolution kernel according to the weight of each element in the convolution kernel, so as to generate an image normalization matrix; An image generation module, used for generating a Gaussian blurred image corresponding to the target image based on the image normalization matrix; Wherein, the weight calculation module is specifically used for: Selecting a target element in the image matrix according to an element of the convolution kernel; Based on the shape of the convolution kernel, a preset Gaussian mixture formula is used to perform weight calculation on the target element to generate a weight for each element in the convolution kernel; The Gaussian mixture formula includes: Among them, W is the weight value of the elements of the convolution kernel, exp() is an exponential function with the natural constant e as the base, disGray is the grayscale distance between the target element and the reference element, spacesigma is the standard deviation of the elements in the spatial domain of the convolution kernel corresponding to the matrix, garyGrads is the gradient value of the target element, colorsigma is the standard deviation of the color domain of the convolution kernel corresponding to the matrix, uGrayGrand is the grayscale gradient threshold, step(|garyGrads|, uGrayGrand) is a step function that takes the value of 0 when |garyGrads| is less than uGrayGrand, otherwise it is 1, and mix(a, b, c) is a mixing function.

7. A Gaussian blur device for preserving image contours, characterized in that: The Gaussian blur device for image contour preservation comprises: a memory and at least one processor, the memory stores instructions, and the memory and the at least one processor are interconnected via a line; The at least one processor calls the instructions in the memory to enable the image contour-preserving Gaussian blur device to perform the image contour-preserving Gaussian blur method according to any one of claims 1 to 5.

8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the Gaussian blur method for preserving image contours according to any one of claims 1 to 5 is implemented.

Citation Information

Patent Citations

  • High-contrast buffing algorithm

    CN114219739A