Image blurring method and device based on progressive Gaussian filtering, and storage medium
Through the image blurring method based on progressive Gaussian filtering, the image segmentation model is used to determine the target probability of pixel points and set up the Gaussian filtering algorithm, the problem of inadequate image blurring in the prior art is solved, and a more natural image blurring effect is achieved.
Patent Information
- Application Number
- CN202411729804.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-28
- Publication Date
- 2025-04-29
- Estimated Expiration
- 2044-11-28
AI Technical Summary
When the existing image blurring method deals with image blurring, the pixel changes between the subject object and the background are not natural enough, especially the edges of the subject object are not clear and sharp enough.
The image blurring method based on progressive Gaussian filtering is adopted, and the target probability of each pixel point is determined through the pre-trained image segmentation model, and the corresponding Gaussian filtering algorithm is determined based on this probability. The Gaussian filtering operation is performed on each pixel point to generate an object blurred picture.
It realizes smooth pixel changes between the subject object part and the background part in the image, and the edges of the subject object are clear and sharp, making the image blur effect more natural.
Smart Images

Figure CN119904376A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image blurring, and in particular to an image blurring method and device based on progressive Gaussian filtering, and a storage medium. Background Art
[0002] Image blurring methods are often used in the field of image or video processing. Image blurring methods are image processing methods that highlight the main object in the image and blur the parts other than the main object. For example, the common portrait blurring operation requires that the portrait be displayed clearly and the parts other than the portrait be blurred.
[0003] Existing image blurring methods mainly rely on multi-camera systems or advanced single cameras. In a multi-camera system, two or more cameras are used to capture different perspectives of the same scene. By comparing the phase differences captured by different cameras, the depth information of the scene is calculated to distinguish the main object and background of the image, and the background blurring is achieved in combination with software. Image blurring methods based on advanced single cameras, such as full-pixel dual-core focusing technology, obtain the depth information of the scene by capturing multiple light information of each pixel, and combine software to achieve the blurring effect. Practice has shown that when the above methods are used to blur images, the blurred images are often not natural enough, which is mainly reflected in: the pixel changes between the main object part and the background part are relatively abrupt, especially the edges of the main object are not clear and sharp enough.
[0004] Therefore, a new image blurring method is proposed to make the pixel changes between the main object and the background in the image smoother and the edges of the main object clearer and sharper during image blurring, thereby making the image blurring more natural. This has become a technical problem that needs to be solved in the field of image blurring. Summary of the invention
[0005] The present invention provides an image blurring method and device based on progressive Gaussian filtering, and a storage medium, so that when the image is blurred, the pixel changes between the main object part and the background part in the image are smoother, the edges of the main object are clearer and sharper, and the image blurring is more natural.
[0006] In order to solve the above technical problems, the first aspect of the present invention discloses an image blurring method based on progressive Gaussian filtering, the method comprising:
[0007] For each pixel point on the image to be blurred, the target probability of the pixel point being a pixel point of the target object is determined based on the pre-trained image segmentation model; according to the target probability corresponding to the pixel point, the target Gaussian filter algorithm corresponding to the pixel point is determined;
[0008] For each pixel point on the image to be blurred, a Gaussian filtering operation is performed on the pixel point based on the target Gaussian filtering algorithm corresponding to the pixel point to obtain a filtered pixel value corresponding to the pixel point;
[0009] A blurred image of the object corresponding to the image to be blurred is determined according to the filtered pixel value corresponding to each pixel point on the image to be blurred.
[0010] As an optional implementation, in the first aspect of the present invention, for each pixel point on the image to be blurred, determining the target probability that the pixel point is a pixel point of the target object based on a pre-trained image segmentation model includes:
[0011] Inputting the image to be blurred into a pre-trained image segmentation model to obtain an object segmentation probability map output by the image segmentation model;
[0012] For each pixel point on the image to be blurred, determining the target probability that the pixel point is a pixel point of the target object according to the object segmentation probability map;
[0013] The pixel value of each pixel in the object segmentation probability map is used to represent the probability that the pixel is a pixel of the target object;
[0014] And, for each pixel point on the image to be blurred, determining the target Gaussian filtering algorithm corresponding to the pixel point according to the target probability, comprises:
[0015] For each pixel point on the image to be blurred, determine the target algorithm parameter corresponding to the pixel point according to the target probability corresponding to the pixel point, and determine the target Gaussian filter algorithm corresponding to the pixel point according to the target algorithm parameter;
[0016] The target algorithm parameters include at least a target filter kernel size kernel_size and a target Gaussian function standard deviation σ.
[0017] As an optional implementation, in the first aspect of the present invention, for each pixel point on the image to be blurred, determining the target Gaussian filtering algorithm corresponding to the pixel point according to the target probability corresponding to the pixel point includes:
[0018] For each pixel point on the image to be blurred, if the target probability corresponding to the pixel point is less than a preset first probability threshold, the pixel point is determined to be a non-target object pixel point, and the target algorithm parameter corresponding to the pixel point is determined to be the first algorithm parameter; if the target probability corresponding to the pixel point is greater than or equal to the first probability threshold and less than a preset second probability threshold, the pixel point is determined to be an object edge pixel point, and the target algorithm parameter corresponding to the pixel point is determined to be the second algorithm parameter;
[0019] The first probability threshold is smaller than the second probability threshold.
[0020] As an optional implementation, in the first aspect of the present invention, for each pixel point on the image to be blurred, performing a Gaussian filtering operation on the pixel point based on the target Gaussian filtering algorithm corresponding to the pixel point to obtain a filtered pixel value corresponding to the pixel point includes:
[0021] Using a plurality of preset Gaussian filtering algorithms respectively to perform Gaussian filtering operations on all the pixel points of the image to be blurred, to obtain a plurality of pre-filtered pixel values corresponding to each pixel point of the image to be blurred; and obtaining a pre-processed image corresponding to each of the preset Gaussian filtering algorithms according to all the pre-filtered pixel values corresponding to all the pixel points of the image to be blurred;
[0022] For each pixel point on the image to be blurred, determine a target preset Gaussian filtering algorithm that matches the target Gaussian filtering algorithm corresponding to the pixel point according to the target Gaussian filtering algorithm corresponding to the pixel point, and determine the target preprocessed image corresponding to the pixel point from all the preprocessed images according to the target preset Gaussian filtering algorithm; determine the filtered pixel value corresponding to the pixel point according to the pixel value of the matching pixel point corresponding to the pixel point in the target preprocessed image.
[0023] As an optional implementation, in the first aspect of the present invention, for each pixel point on the image to be blurred, determining the target algorithm parameter corresponding to the pixel point according to the target probability corresponding to the pixel point includes:
[0024] For each pixel on the image to be blurred, determine the target Gaussian function standard deviation σ corresponding to the pixel according to the target probability corresponding to the pixel, and determine the target filter kernel size kernel_size corresponding to the pixel according to the target Gaussian function standard deviation σ corresponding to the pixel;
[0025] The target filter kernel size kernel_size corresponding to the pixel is determined according to the target Gaussian function standard deviation σ corresponding to the pixel, which is specifically implemented by the following formula:
[0026]
[0027] kernel_size=2*radius+1
[0028] In the above formula, This is a round-up operation, with radius as the intermediate parameter.
[0029] As an optional implementation, in the first aspect of the present invention, for each pixel point on the image to be blurred, performing a Gaussian filtering operation on the pixel point based on the target Gaussian filtering algorithm corresponding to the pixel point to obtain a filtered pixel value corresponding to the pixel point includes:
[0030] For each pixel point on the image to be blurred, determine the pixel point as the target pixel point, take the target pixel point as the coordinate origin, take the target filter kernel size kernel_siz corresponding to the target pixel point as the side length, and construct a target filter kernel corresponding to the target pixel point with a size of kernel_size*kernel_size; determine the filter kernel weight matrix corresponding to the target filter kernel according to the target Gaussian function standard deviation σ corresponding to the target pixel point;
[0031] For each of the target pixels on the image to be blurred, convolution calculation is performed on all pixels on the image to be blurred that are located within the target filter kernel corresponding to the target pixel with the filter kernel weight matrix to obtain a filter pixel value corresponding to the target pixel;
[0032] Among them, for each target pixel point on the image to be blurred, the filter kernel weight matrix corresponding to the target filter kernel is determined according to the target Gaussian function standard deviation σ corresponding to the target pixel point, which is specifically implemented by the following formula:
[0033]
[0034] In the above formula, x is the horizontal coordinate of any pixel point in the target filter kernel, where the value range of x is [-radius, radius]; y is the vertical coordinate of any pixel point in the target filter kernel, where the value range of y is also [-radius, radius]; the coordinates of the target pixel point are (0,0); f(x,y) is the weight parameter of the pixel point at (x,y).
[0035] As an optional implementation, in the first aspect of the present invention, the inputting the image to be blurred into a pre-trained image segmentation model to obtain the object segmentation probability map output by the image segmentation model includes:
[0036] Acquire an image to be blurred with a resolution of ih*iw, and preprocess the image to be blurred to obtain a preprocessed image;
[0037] Scaling the preprocessed image into an intermediate image with a resolution of nh*nw;
[0038] Input the intermediate image into a pre-trained image segmentation model to obtain an initial probability map with a resolution of nh*nw output by the image segmentation model;
[0039] Performing bilinear interpolation upsampling on the initial probability map to obtain an object segmentation probability map with a resolution of ih*iw;
[0040] The preprocessing of the image to be blurred to obtain the preprocessed image specifically includes:
[0041] Calculating the pixel mean and pixel variance of all the pixels on the image to be blurred;
[0042] For each pixel point on the image to be blurred, subtract the pixel mean from the pixel value of the pixel point and divide the result by the pixel variance to obtain a standardized pixel value of the pixel point;
[0043] Performing a normalization operation on the standardized pixel values of all the pixels on the image to be blurred, to obtain a preprocessed pixel value of each pixel on the image to be blurred;
[0044] A preprocessed image is obtained according to the preprocessed pixel values of all the pixel points on the image to be blurred.
[0045] A second aspect of the present invention discloses an image blurring device based on progressive Gaussian filtering, the device comprising:
[0046] The image segmentation module is used to determine the target probability of each pixel point on the image to be blurred being a pixel point of the target object based on the pre-trained image segmentation model; and determine the target Gaussian filter algorithm corresponding to the pixel point according to the target probability corresponding to the pixel point;
[0047] A Gaussian filtering module is used to perform a Gaussian filtering operation on each pixel point on the image to be blurred based on the target Gaussian filtering algorithm corresponding to the pixel point, so as to obtain a filtered pixel value corresponding to the pixel point;
[0048] The image blur module is used to determine the object blur picture corresponding to the image to be blurred according to the filtered pixel value corresponding to each pixel point on the image to be blurred.
[0049] As an optional implementation, in the second aspect of the present invention, the image segmentation module determines, for each pixel on the image to be blurred, based on a pre-trained image segmentation model, a specific method of determining the target probability that the pixel is a pixel of the target object, including:
[0050] Inputting the image to be blurred into a pre-trained image segmentation model to obtain an object segmentation probability map output by the image segmentation model;
[0051] For each pixel point on the image to be blurred, determining the target probability that the pixel point is a pixel point of the target object according to the object segmentation probability map;
[0052] The pixel value of each pixel in the object segmentation probability map is used to represent the probability that the pixel is a pixel of the target object;
[0053] And, for each pixel point on the image to be blurred, determining the target Gaussian filtering algorithm corresponding to the pixel point according to the target probability, comprises:
[0054] For each pixel point on the image to be blurred, determine the target algorithm parameter corresponding to the pixel point according to the target probability corresponding to the pixel point, and determine the target Gaussian filter algorithm corresponding to the pixel point according to the target algorithm parameter;
[0055] The target algorithm parameters include at least a target filter kernel size kernel_size and a target Gaussian function standard deviation σ.
[0056] As an optional implementation, in the second aspect of the present invention, the image segmentation module determines, for each pixel on the image to be blurred, according to the target probability corresponding to the pixel, a specific method of the target Gaussian filtering algorithm corresponding to the pixel, including:
[0057] For each pixel point on the image to be blurred, if the target probability corresponding to the pixel point is less than a preset first probability threshold, the pixel point is determined to be a non-target object pixel point, and the target algorithm parameter corresponding to the pixel point is determined to be the first algorithm parameter; if the target probability corresponding to the pixel point is greater than or equal to the first probability threshold and less than a preset second probability threshold, the pixel point is determined to be an object edge pixel point, and the target algorithm parameter corresponding to the pixel point is determined to be the second algorithm parameter;
[0058] The first probability threshold is smaller than the second probability threshold.
[0059] As an optional implementation, in the second aspect of the present invention, the Gaussian filtering module performs a Gaussian filtering operation on each pixel point on the image to be blurred based on the target Gaussian filtering algorithm corresponding to the pixel point, and obtains a specific method of obtaining a filtered pixel value corresponding to the pixel point, including:
[0060] Using a plurality of preset Gaussian filtering algorithms respectively to perform Gaussian filtering operations on all the pixel points of the image to be blurred, to obtain a plurality of pre-filtered pixel values corresponding to each pixel point of the image to be blurred; and obtaining a pre-processed image corresponding to each of the preset Gaussian filtering algorithms according to all the pre-filtered pixel values corresponding to all the pixel points of the image to be blurred;
[0061] For each pixel point on the image to be blurred, determine a target preset Gaussian filtering algorithm that matches the target Gaussian filtering algorithm corresponding to the pixel point according to the target Gaussian filtering algorithm corresponding to the pixel point, and determine the target preprocessed image corresponding to the pixel point from all the preprocessed images according to the target preset Gaussian filtering algorithm; determine the filtered pixel value corresponding to the pixel point according to the pixel value of the matching pixel point corresponding to the pixel point in the target preprocessed image.
[0062] As an optional implementation, in the second aspect of the present invention, the image segmentation module determines, for each pixel on the image to be blurred, according to the target probability corresponding to the pixel, a specific method of determining the target algorithm parameter corresponding to the pixel, including:
[0063] For each pixel on the image to be blurred, determine the target Gaussian function standard deviation σ corresponding to the pixel according to the target probability corresponding to the pixel, and determine the target filter kernel size kernel_size corresponding to the pixel according to the target Gaussian function standard deviation σ corresponding to the pixel;
[0064] The target filter kernel size kernel_size corresponding to the pixel is determined according to the target Gaussian function standard deviation σ corresponding to the pixel, which is specifically implemented by the following formula:
[0065]
[0066] kernel_size=2*radius+1
[0067] In the above formula, This is a round-up operation, with radius as the intermediate parameter.
[0068] As an optional implementation, in the second aspect of the present invention, the Gaussian filtering module performs a Gaussian filtering operation on each pixel point on the image to be blurred based on the target Gaussian filtering algorithm corresponding to the pixel point, and obtains a specific method of obtaining a filtered pixel value corresponding to the pixel point, including:
[0069] For each pixel point on the image to be blurred, determine the pixel point as the target pixel point, take the target pixel point as the coordinate origin, take the target filter kernel size kernel_siz corresponding to the target pixel point as the side length, and construct a target filter kernel corresponding to the target pixel point with a size of kernel_size*kernel_size; determine the filter kernel weight matrix corresponding to the target filter kernel according to the target Gaussian function standard deviation σ corresponding to the target pixel point;
[0070] For each of the target pixels on the image to be blurred, convolution calculation is performed on all pixels on the image to be blurred that are located within the target filter kernel corresponding to the target pixel with the filter kernel weight matrix to obtain a filter pixel value corresponding to the target pixel;
[0071] Among them, for each target pixel point on the image to be blurred, the filter kernel weight matrix corresponding to the target filter kernel is determined according to the target Gaussian function standard deviation σ corresponding to the target pixel point, which is specifically implemented by the following formula:
[0072]
[0073] In the above formula, x is the horizontal coordinate of any pixel point in the target filter kernel, where the value range of x is [-radius, radius]; y is the vertical coordinate of any pixel point in the target filter kernel, where the value range of y is also [-radius, radius]; the coordinates of the target pixel point are (0,0); f(x,y) is the weight parameter of the pixel point at (x,y).
[0074] As an optional implementation, in the second aspect of the present invention, the image segmentation module inputs the image to be blurred into a pre-trained image segmentation model, and a specific method of obtaining the object segmentation probability map output by the image segmentation model includes:
[0075] Acquire an image to be blurred with a resolution of ih*iw, and preprocess the image to be blurred to obtain a preprocessed image;
[0076] Scaling the preprocessed image into an intermediate image with a resolution of nh*nw;
[0077] Input the intermediate image into a pre-trained image segmentation model to obtain an initial probability map with a resolution of nh*nw output by the image segmentation model;
[0078] Performing bilinear interpolation upsampling on the initial probability map to obtain an object segmentation probability map with a resolution of ih*iw;
[0079] The image segmentation module preprocesses the image to be blurred to obtain a preprocessed image, which specifically includes:
[0080] Calculating the pixel mean and pixel variance of all the pixels on the image to be blurred;
[0081] For each pixel point on the image to be blurred, subtract the pixel mean from the pixel value of the pixel point and divide the result by the pixel variance to obtain a standardized pixel value of the pixel point;
[0082] Performing a normalization operation on the standardized pixel values of all the pixels on the image to be blurred, to obtain a preprocessed pixel value of each pixel on the image to be blurred;
[0083] A preprocessed image is obtained according to the preprocessed pixel values of all the pixel points on the image to be blurred.
[0084] The third aspect of the present invention discloses another image blurring device based on progressive Gaussian filtering, the device comprising:
[0085] A memory storing executable program code;
[0086] a processor coupled to the memory;
[0087] The processor calls the executable program code stored in the memory to execute the image blurring method based on progressive Gaussian filtering disclosed in the first aspect of the present invention.
[0088] The fourth aspect of the present invention discloses a computer storage medium, which stores computer instructions. When the computer instructions are called, they are used to execute the image blurring method based on progressive Gaussian filtering disclosed in the first aspect of the present invention.
[0089] Compared with the prior art, the present invention has the following beneficial effects:
[0090] The present invention determines the target probability that each pixel point on the image to be blurred is a pixel point of the target object based on a pre-trained image segmentation model; determines the target Gaussian filtering algorithm corresponding to the pixel point according to the target probability corresponding to the pixel point; for each pixel point on the image to be blurred, performs a Gaussian filtering operation on the pixel point based on the target Gaussian filtering algorithm corresponding to the pixel point to obtain a filtered pixel value corresponding to the pixel point; determines the object blurred picture corresponding to the image to be blurred according to the filtered pixel value corresponding to each pixel point on the image to be blurred. It can be seen that the image blurring method based on progressive Gaussian filtering of the present invention can set different Gaussian filtering algorithms according to different probability ranges, thereby designing a progressive Gaussian filtering method, so that the pixel changes between the main object part and the background part in the image are smoother, thereby making the image blur more natural. BRIEF DESCRIPTION OF THE DRAWINGS
[0091] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0092] Figure 1 It is a flowchart of an image blurring method based on progressive Gaussian filtering disclosed in an embodiment of the present invention;
[0093] Figure 2 It is a flowchart diagram of another image blurring method based on progressive Gaussian filtering disclosed in an embodiment of the present invention;
[0094] Figure 3 is a schematic diagram of a Gaussian filtering operation disclosed in an embodiment of the present invention;
[0095] Figure 4 is another schematic diagram of Gaussian filtering operation disclosed in an embodiment of the present invention;
[0096] Figure 5 It is a structural schematic diagram of an image blurring device based on progressive Gaussian filtering disclosed in an embodiment of the present invention;
[0097] Figure 6 It is a structural schematic diagram of another image blurring device based on progressive Gaussian filtering disclosed in an embodiment of the present invention. DETAILED DESCRIPTION
[0098] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0099] The terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish different objects rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, device, product or end including a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units that are not listed, or may optionally include other steps or units inherent to these processes, methods, products or ends.
[0100] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present invention. The appearance of the phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0101] The present invention discloses an image blurring method and device based on progressive Gaussian filtering, and a storage medium, so that when the image is blurred, the pixel change between the main object part and the background part in the image is smoother, the edge of the main object is clearer and sharper, and the image blurring is more natural.
[0102] Embodiment 1
[0103] See also Figure 1 , Figure 1 : is a flow chart of an image blurring method based on progressive Gaussian filtering disclosed in an embodiment of the present invention. Figure 1 The described image blurring method based on progressive Gaussian filtering can be applied to an image blurring device based on progressive Gaussian filtering, and the image blurring device based on progressive Gaussian filtering can be integrated in a cloud server or a local server, which is not limited in the embodiments of the present invention. Figure 1 As shown, the image blurring method based on progressive Gaussian filtering may include the following operations:
[0104] Step 101: for each pixel on the image to be blurred, based on a pre-trained image segmentation model, determine the target probability that the pixel is a pixel of the target object; and determine the target Gaussian filter algorithm corresponding to the pixel according to the target probability corresponding to the pixel.
[0105] In the embodiment of the present invention, image blurring is an image processing method that highlights the main object in the image and blurs the parts other than the main object. For example, in the common portrait blurring operation, the portrait needs to be clearly displayed, while the parts other than the portrait are blurred. In the blurred image, the main object that needs to be highlighted in the image is the target object. For example, the image to be blurred may be an image containing a human body, and the target object is the human body.
[0106] In the embodiment of the present invention, image segmentation means separating the target object and the non-target object in the image. In the embodiment of the present invention, a trained image segmentation model is used to achieve the segmentation of the target object and the non-target object in the image to be blurred. The image segmentation model can analyze the input image and then output the target probability that each pixel is a pixel of the target object. For example, for an image containing a human body, after being processed by the image segmentation model, the pixels on the image that are judged by the image segmentation model as human body parts have a high probability, non-human pixels have a very small probability value, and the probability value of pixels between human body and non-human body is in the middle. In the embodiment of the present invention, the Gaussian filtering algorithm that should be executed on the pixel is determined according to the probability that the pixel is the target pixel, so as to highlight the main part and blur the background part.
[0107] In an optional embodiment, the image to be blurred is a portrait, and the image segmentation model is a portrait segmentation model. The portrait segmentation model can be obtained by the following method:
[0108] S1. Collect training image data: Combined with actual scenes, collect actual scene data, mainly considering different portrait sizes, postures and other data under different indoor and outdoor light and scenes;
[0109] S2. Label the image: Label the portrait and non-portrait parts of the image. The portrait segmentation data needs to be refined to each pixel, otherwise it will cause classification errors;
[0110] S3. Image preprocessing: Perform online image enhancement on the selected high-quality public portrait dataset and the collected training data, including cropping, rotation, color gamut conversion, mean subtraction and variance division, etc.
[0111] S4. Portrait segmentation model training: forward propagation calculates the loss function, back propagation calculates the parameter gradient, and uses the gradient to update the parameters. The above process is repeated until the model converges or reaches the maximum number of iterations, then the training is stopped and the training model is output. After the model training iterations for a fixed period, the performance of the model is tested using actual scene data that is not in the training set until the segmentation criteria are met and the model is output.
[0112] It can be seen that this optional embodiment better combines the actual scene and the size and posture of the portrait to enhance the model segmentation performance during the portrait segmentation model training stage, thereby obtaining a portrait segmentation model with better performance.
[0113] Step 102: for each pixel point on the image to be blurred, perform a Gaussian filtering operation on the pixel point based on a target Gaussian filtering algorithm corresponding to the pixel point to obtain a filtered pixel value corresponding to the pixel point.
[0114] In the embodiment of the present invention, different pixels correspond to different Gaussian filtering algorithms. Optionally, different Gaussian filtering algorithms can be set according to different probability ranges. For example, for the portrait part, the first Gaussian filtering algorithm is set; for the non-portrait part, the second Gaussian filtering algorithm is set; for the edge part of the portrait, the third Gaussian filtering algorithm is set. Thus, a progressive Gaussian filtering method is designed, which makes the transition between the edge of the portrait and the background area more natural, and does not rely on dual-camera lenses and other hardware costs, and achieves the algorithm effect of portrait blur.
[0115] Step 103: Determine the object blurred picture corresponding to the image to be blurred according to the filtered pixel value corresponding to each pixel point on the image to be blurred.
[0116] It can be seen that the image blurring method based on progressive Gaussian filtering in the embodiment of the present invention can set different Gaussian filtering algorithms according to different probability ranges, thereby designing a progressive Gaussian filtering method, so that the pixel changes between the main object part and the background part in the image are smoother, thereby making the image blur more natural.
[0117] It should be noted that the embodiments of the present invention can be used in any image or video application that needs to highlight the subject, such as the portrait mode of a camera, a beauty algorithm APP, etc.
[0118] In an optional embodiment, for each pixel on the image to be blurred, determining the target probability that the pixel is a pixel of the target object based on a pre-trained image segmentation model may include:
[0119] Input the image to be blurred into a pre-trained image segmentation model to obtain an object segmentation probability map output by the image segmentation model;
[0120] For each pixel point on the image to be blurred, the target probability of the pixel point being a pixel point of the target object is determined according to the object segmentation probability map;
[0121] And, for each pixel point on the image to be blurred, determining the target Gaussian filtering algorithm corresponding to the pixel point according to the target probability may include:
[0122] For each pixel on the image to be blurred, the target algorithm parameters corresponding to the pixel are determined according to the target probability corresponding to the pixel, and the target Gaussian filtering algorithm corresponding to the pixel is determined according to the target algorithm parameters.
[0123] In this optional embodiment, the pixel value of each pixel in the object segmentation probability map is used to represent the probability that the pixel is a pixel of the target object; the target algorithm parameters may include at least a target filter kernel size kernel_size and a target Gaussian function standard deviation σ.
[0124] In this optional embodiment, taking the blurring of a human portrait as an example, an example is given as follows:
[0125] The portrait image is input into a pre-trained image segmentation model to obtain an object segmentation probability map output by the image segmentation model, wherein the pixel value of each pixel in the object segmentation probability map is used to represent the probability that the pixel is a portrait pixel.
[0126] For each pixel point on the portrait image, determine the target probability that the pixel point is a portrait according to the object segmentation probability map;
[0127] For each pixel on the portrait image, the target filter kernel size kernel_size and the target Gaussian function standard deviation σ corresponding to the pixel are determined according to the target probability corresponding to the pixel, and the target Gaussian filter algorithm corresponding to the pixel is determined according to the target filter kernel size kernel_size and the target Gaussian function standard deviation σ.
[0128] It can be seen that this optional embodiment can input the image to be blurred into a pre-trained image segmentation model to obtain an object segmentation probability map output by the image segmentation model. The pixel value of each pixel in the object segmentation probability map is used to represent the probability that the pixel is a pixel of the target object. Therefore, one object segmentation probability map can be used to save the probability that all pixels on the image to be blurred are pixels of the target object, which is conducive to the computer system to quickly process the image to be blurred; according to the object segmentation probability map, the target filter kernel size kernel_size and the target Gaussian function standard deviation σ corresponding to the pixel are quickly determined, and the corresponding Gaussian filtering algorithm is efficiently determined.
[0129] In another optional embodiment, for each pixel on the image to be blurred, determining the target Gaussian filter algorithm corresponding to the pixel according to the target probability corresponding to the pixel may include:
[0130] For each pixel on the image to be blurred, if the target probability corresponding to the pixel is less than a preset first probability threshold, the pixel is determined to be a non-target object pixel, and the target algorithm parameter corresponding to the pixel is determined to be the first algorithm parameter; if the target probability corresponding to the pixel is greater than or equal to the first probability threshold and less than a preset second probability threshold, the pixel is determined to be an object edge pixel, and the target algorithm parameter corresponding to the pixel is determined to be the second algorithm parameter;
[0131] In this optional embodiment, if each pixel corresponds to a different Gaussian filtering algorithm, then tens of thousands of pixels on the entire image will bring a huge amount of calculation. To solve the above problem, in this optional embodiment, the pixels within a certain probability range are classified into one category, and then one category of pixels corresponds to the same Gaussian filtering algorithm. In this way, tens of thousands of pixels on the entire image only need to be divided into two categories of pixels: pixels with a target probability less than a preset first probability threshold are non-target object pixels, and pixels with a target probability greater than or equal to the first probability threshold and less than a preset second probability threshold are object edge pixels. Then, corresponding Gaussian filtering algorithms are set for the above two categories of pixels, which greatly reduces the amount of calculation and improves the efficiency of image blurring.
[0132] In this optional embodiment, the first probability threshold is less than the second probability threshold, the optional first probability value is set to 0.9, and the second probability value is set to 0.95; taking the portrait as an example, that is: the pixel points with a target probability less than 0.9 are non-portrait pixels, the target probability greater than or equal to 0.9 and less than 0.95 are portrait edge pixels, and the pixel points with a target probability greater than or equal to 0.95 are portrait pixels.
[0133] It can be seen that in this optional embodiment, the pixels on the image to be blurred are divided into two categories: pixels whose target probability is less than the preset first probability threshold are non-target object pixels, and pixels whose target probability is greater than or equal to the first probability threshold and less than the preset second probability threshold are object edge pixels. And corresponding Gaussian filtering algorithms are set for the above two types of pixels, which greatly reduces the amount of calculation and improves the efficiency of image blurring.
[0134] In yet another optional embodiment, for each pixel point on the image to be blurred, performing a Gaussian filtering operation on the pixel point based on a target Gaussian filtering algorithm corresponding to the pixel point to obtain a filtered pixel value corresponding to the pixel point may include:
[0135] Using a plurality of preset Gaussian filtering algorithms respectively to perform Gaussian filtering operations on all pixel points of the image to be blurred, a plurality of pre-filtered pixel values corresponding to each pixel point of the image to be blurred are obtained; and a pre-processed image corresponding to each preset Gaussian filtering algorithm is obtained according to all pre-filtered pixel values corresponding to all pixel points of the image to be blurred;
[0136] For each pixel on the image to be blurred, determine the target preset Gaussian filtering algorithm that matches the target Gaussian filtering algorithm corresponding to the pixel point according to the target Gaussian filtering algorithm corresponding to the pixel point, and determine the target preprocessed image corresponding to the pixel point from all preprocessed images according to the target preset Gaussian filtering algorithm; determine the filtered pixel value corresponding to the pixel point according to the pixel value of the matching pixel point corresponding to the pixel point in the target preprocessed image.
[0137] In this optional embodiment, if the corresponding Gaussian filtering algorithm is executed only after the target probability range of the pixel point on the image to be blurred is determined each time, then each determination is followed by a calculation operation, and the calculation efficiency is still not high enough. In order to further improve the calculation efficiency, in the embodiment of the present invention, all points in the image to be blurred are first filtered and calculated in advance according to different Gaussian filtering algorithms to obtain a pre-processed image that has been filtered in advance. After the target probability range of the pixel point on the image to be blurred is determined, it is only necessary to match the target pre-processed image and then determine the filtered pixel value corresponding to the pixel point according to the pixel value of the matching pixel point corresponding to the pixel point in the target pre-processed image.
[0138] Taking the blurring of a human portrait as an example, the optional embodiment is illustrated as follows:
[0139] Four filter kernels are set. The first three have the size of kernel_size. The center point values of the filter kernels are replaced with 0, 0.2, and 0.4 respectively and then normalized. The last size is kernel_size / 4. The center point value of the filter kernel is replaced with 0.92 and then normalized. The above filter kernels are used to perform four Gaussian filtering on the original image. Then, according to the weight information, the pixels with weights in [0, 0.1) are replaced with the pixels corresponding to the filtering results of filter kernel 1; the pixels with weights in [0.1, 0.5) are replaced with the pixels corresponding to the filtering results of filter kernel 2; the pixels with weights in [0.5, 0.9) are replaced with the pixels corresponding to the filtering results of filter kernel 3; the pixels with weights in [0.9, 0.95) are replaced with the pixels corresponding to the filtering results of filter kernel 4; and the pixels with weights in [0.95, 1) are replaced with the pixels corresponding to the original image. By setting different filter kernels to filter the image multiple times and then fusing them according to the weight information of portrait segmentation, the efficiency of the algorithm is improved.
[0140] It can be seen that in this optional embodiment, the image to be blurred is pre-processed according to different Gaussian filtering algorithms to obtain several pre-processed images; after determining the target probability range of the pixel points on the image to be blurred, it is only necessary to match the target pre-processed image and then determine the filtered pixel value corresponding to the pixel point based on the pixel value of the matching pixel point corresponding to the pixel point in the target pre-processed image, thereby further improving the computational efficiency of image blur.
[0141] Embodiment 2
[0142] See also Figure 2 , Figure 2 1 is a flow chart of another method for blurring an image based on progressive Gaussian filtering disclosed in an embodiment of the present invention. The method for blurring an image based on progressive Gaussian filtering may include the following operations:
[0143] Step 201: input the image to be blurred into a pre-trained image segmentation model to obtain an object segmentation probability map output by the image segmentation model; for each pixel point on the image to be blurred, determine the target probability that the pixel point is a pixel point of the target object according to the object segmentation probability map.
[0144] Step 202: for each pixel on the image to be blurred, determine the target Gaussian function standard deviation σ corresponding to the pixel according to the target probability corresponding to the pixel, determine the target filter kernel size kernel_size corresponding to the pixel according to the target Gaussian function standard deviation σ, and determine the target Gaussian filter algorithm corresponding to the pixel according to the target algorithm parameters.
[0145] In the embodiment of the present invention, the target algorithm parameters may include at least a target filter kernel size kernel_size and a target Gaussian function standard deviation σ; optionally, the target filter kernel size kernel_size corresponding to the pixel point is determined according to the target Gaussian function standard deviation σ corresponding to the pixel point, which may be implemented by the following formula:
[0146]
[0147] kernel_size=2*radius+1
[0148] In the above formula, is a rounding operation, radius is an intermediate parameter. Through the above formula, a Gaussian filtering algorithm that is more suitable for image blurring can be constructed.
[0149] Step 203 : for each pixel point on the image to be blurred, perform a Gaussian filtering operation on the pixel point based on the target Gaussian filtering algorithm corresponding to the pixel point to obtain a filtered pixel value corresponding to the pixel point.
[0150] Step 204: Determine the object blurred picture corresponding to the image to be blurred according to the filtered pixel value corresponding to each pixel point on the image to be blurred.
[0151] For the specific description of steps 203 and 204, please refer to the description of steps 102 and 103, which will not be repeated in the embodiment of the present invention.
[0152] It can be seen that the image blurring method based on progressive Gaussian filtering in the embodiment of the present invention can input the image to be blurred into a pre-trained image segmentation model to obtain an object segmentation probability map output by the image segmentation model. The pixel value of each pixel in the object segmentation probability map is used to represent the probability that the pixel is a pixel of the target object. Thus, the probability that all pixels on the image to be blurred are pixels of the target object can be saved using one object segmentation probability map, which is beneficial for the computer system to quickly process the image to be blurred. According to the target probability corresponding to the pixel, the target Gaussian function standard deviation σ corresponding to the pixel is determined. According to the target Gaussian function standard deviation σ corresponding to the pixel, the target filter kernel size kernel_size corresponding to the pixel is determined, so that a Gaussian filtering algorithm that is more suitable for image blurring can be constructed. In summary, the embodiment of the present invention can further improve the efficiency of the image blurring method.
[0153] In an optional embodiment, for each pixel point on the image to be blurred, performing a Gaussian filtering operation on the pixel point based on a target Gaussian filtering algorithm corresponding to the pixel point to obtain a filtered pixel value corresponding to the pixel point may include:
[0154] For each pixel point on the image to be blurred, determine the pixel point as the target pixel point, take the target pixel point as the coordinate origin, take the target filter kernel size kernel_siz corresponding to the target pixel point as the side length, and construct the target filter kernel corresponding to the target pixel point with a size of kernel_size*kernel_size; according to the standard deviation σ of the target Gaussian function corresponding to the target pixel point, determine the filter kernel weight matrix corresponding to the target filter kernel;
[0155] For each target pixel on the image to be blurred, all pixels on the image to be blurred that are located within the target filter kernel corresponding to the target pixel are convolved with the filter kernel weight matrix to obtain a filter pixel value corresponding to the target pixel;
[0156] Among them, for each target pixel on the image to be blurred, the filter kernel weight matrix corresponding to the target filter kernel is determined according to the target Gaussian function standard deviation σ corresponding to the target pixel, which is specifically implemented by the following formula:
[0157]
[0158] In this optional embodiment, x is the horizontal coordinate of any pixel point in the target filter kernel, where the value range of x is [-radius, radius]; y is the vertical coordinate of any pixel point in the target filter kernel, where the value range of y is also [-radius, radius]; the coordinates of the target pixel point are (0,0); f(x,y) is the weight parameter of the pixel point at (x,y). In the above formula, σ 2 is the variance, which indicates the average fluctuation of the sample. σ determines the steepness of the curve. The curve with σ=1 is relatively smooth, so the blur will also be relatively smooth.
[0159] Taking portrait blur as an example, the image blur method based on progressive Gaussian filtering in this optional embodiment is illustrated as follows:
[0160] For an RGB image, the progressive Gaussian filter divides each pixel into the following channels: background non-portrait area, portrait edge area, and portrait internal area. It also presets the division thresholds for different areas, processes the filter kernels corresponding to the pixels in different areas with different schemes, and then convolves them with the original image area of the corresponding size to obtain the filtering result of the pixel.
[0161] For background non-portrait areas, such as Figure 3 As shown, the probability value of the current pixel point is less than 0.9. For this optional embodiment, it is hoped that the edges of the subject and the background are very clear and sharp. Based on experimental verification, the background segmentation threshold is set to 0.9. For the pixel value of this point that meets the above requirements, the corresponding filter kernel is set according to Scheme 1: the point is used as the center point of the filter kernel with a size of [kernel_size, kernel_size], and then the modified filter kernel is renormalized; the corresponding input image area selects an image area with the current pixel point as the center and kernel_size as the width, and the pixel points in the edge area are filled with 0 for the area exceeding the image size, that is, the original image is padded with kernel_size / 2 on the top, bottom, left and right, and then the filter kernel and the selected input image area are convolved: the corresponding pixels are multiplied and added as the filtering result of the current pixel point.
[0162] For the edge area of the portrait, such as Figure 4As shown, the probability value of segment_weights at the current pixel point is between [0.9, 0.95). Since the probability value of portrait segmentation will rise rapidly in the edge area of the portrait, after filtering the background non-portrait area, it is also necessary to ensure that the blur degree of the edge connection area is smooth and gradual, so this point is used as the center point of the filter kernel with a size of [kernel_size / 4, kernel_size / 4], and then the modified filter kernel is renormalized; the corresponding input image area is selected with the current pixel point as the center and kernel_size / 4 as the width of the image area, and the pixel points in the edge area are filled with 0 for the area beyond the image size, that is, the original image is padded with kernel_size / 8 on the top, bottom, left and right, and then the filter kernel and the selected input image area are convolved: the corresponding pixels are multiplied and added as the filtering result of the current pixel point.
[0163] For the internal area of the portrait, that is, the probability value of the current pixel is greater than 0.95. In this optional embodiment, the portrait blur hopes to keep the portrait in the picture clear while blurring the rest of the background. Make the main part of the picture stand out. The internal area of the portrait is the pixel area that the portrait segmentation network strongly identifies as a person, so after completing the filtering of the background non-portrait area and the transition filtering of the portrait edge area, this part of the pixel points uses the original image pixel point as the output of the pixel at this point. At this point, the portrait blur algorithm of the progressive Gaussian filter for the entire image is complete.
[0164] It can be seen that in this optional embodiment, each pixel point that needs to be filtered is reassigned using the "weighted average of surrounding neighbor pixels", so that the pixel point is filtered according to the distribution of pixels around it, thereby blurring the background of the entire image.
[0165] In yet another optional embodiment, inputting the image to be blurred into a pre-trained image segmentation model to obtain an object segmentation probability map output by the image segmentation model may include:
[0166] Acquire an image to be blurred with a resolution of ih*iw, preprocess the image to be blurred, and obtain a preprocessed image;
[0167] Scale the preprocessed image to an intermediate image with a resolution of nh*nw;
[0168] Input the intermediate image into the pre-trained image segmentation model to obtain the initial probability map with a resolution of nh*nw output by the image segmentation model;
[0169] The initial probability map is upsampled by bilinear interpolation to obtain an object segmentation probability map with a resolution of ih*iw;
[0170] The process of preprocessing the image to be blurred to obtain the preprocessed image may specifically include:
[0171] Calculate the pixel mean and pixel variance of all pixels on the image to be blurred;
[0172] For each pixel on the image to be blurred, the pixel value of the pixel is subtracted from the pixel mean and then divided by the pixel variance to obtain the standardized pixel value of the pixel;
[0173] Performing a normalization operation on the standardized pixel values of all pixels on the image to be blurred to obtain a preprocessed pixel value of each pixel on the image to be blurred;
[0174] A preprocessed image is obtained according to the preprocessed pixel values of all pixels on the image to be blurred.
[0175] In this optional embodiment, after the image segmentation model is trained, it is used to analyze images of a specific size. However, the actual image size is often very large, so it is necessary to scale it to a size suitable for the image segmentation model. After the image segmentation model analysis is completed, the scaled image is upsampled: "enlarged" back.
[0176] Taking the blurring of a human portrait as an example, the optional embodiment is illustrated as follows:
[0177] Input the original resolution image (ih*iw), subtract the mean of the image according to the training strategy, divide it by the variance normalization operation, and then scale the image to the input size (nh*nw) of the portrait segmentation network. After the portrait segmentation algorithm, the segmentation probability map is obtained, that is, the resolution is (nh*nw), and the probability value of each pixel between 0 and 1 represents the possibility of judging the pixel as a person; the probability map is upsampled to the resolution (ih*iww) by bilinear interpolation.
[0178] It can be seen that this optional embodiment can adjust the image to be blurred to a size suitable for use by the image segmentation model through image scaling, upsampling and preprocessing technology, thereby facilitating the efficient use of the image segmentation model and improving the efficiency of the image blurring method.
[0179] Embodiment 3
[0180] See also Figure 5 , Figure 5 Schematic diagram of the structure of an image blurring device based on progressive Gaussian filtering disclosed in an embodiment of the present invention. Figure 5 As shown, the image blurring device based on progressive Gaussian filtering may include:
[0181] The image segmentation module 301 is used to determine, for each pixel point on the image to be blurred, the target probability that the pixel point is a pixel point of the target object based on a pre-trained image segmentation model; and determine the target Gaussian filter algorithm corresponding to the pixel point according to the target probability corresponding to the pixel point;
[0182] The Gaussian filtering module 302 is used to perform a Gaussian filtering operation on each pixel point on the image to be blurred based on a target Gaussian filtering algorithm corresponding to the pixel point, so as to obtain a filtered pixel value corresponding to the pixel point;
[0183] The image blur module 303 is used to determine the object blur picture corresponding to the image to be blurred according to the filtered pixel value corresponding to each pixel point on the image to be blurred.
[0184] It can be seen that the image blurring device based on progressive Gaussian filtering in the embodiment of the present invention can set different Gaussian filtering algorithms according to different probability ranges, thereby designing a progressive Gaussian filtering method, so that the pixel changes between the main object part and the background part in the image are smoother, thereby making the image blurring more natural.
[0185] In an optional embodiment, the image segmentation module 301 determines, for each pixel on the image to be blurred, the target probability that the pixel is a pixel of the target object based on a pre-trained image segmentation model, which may include:
[0186] Input the image to be blurred into a pre-trained image segmentation model to obtain an object segmentation probability map output by the image segmentation model;
[0187] For each pixel point on the image to be blurred, the target probability of the pixel point being a pixel point of the target object is determined according to the object segmentation probability map;
[0188] The pixel value of each pixel in the object segmentation probability map is used to represent the probability that the pixel is a pixel of the target object;
[0189] And, for each pixel point on the image to be blurred, determining the target Gaussian filtering algorithm corresponding to the pixel point according to the target probability may include:
[0190] For each pixel on the image to be blurred, the target algorithm parameter corresponding to the pixel is determined according to the target probability corresponding to the pixel, and the target Gaussian filter algorithm corresponding to the pixel is determined according to the target algorithm parameter;
[0191] The target algorithm parameters may include at least a target filter kernel size kernel_size and a target Gaussian function standard deviation σ.
[0192] It can be seen that this optional embodiment can input the image to be blurred into a pre-trained image segmentation model to obtain an object segmentation probability map output by the image segmentation model. The pixel value of each pixel in the object segmentation probability map is used to represent the probability that the pixel is a pixel of the target object. Therefore, one object segmentation probability map can be used to save the probability that all pixels on the image to be blurred are pixels of the target object, which is conducive to the computer system to quickly process the image to be blurred; according to the object segmentation probability map, the target filter kernel size kernel_size and the target Gaussian function standard deviation σ corresponding to the pixel are quickly determined, and the corresponding Gaussian filtering algorithm is efficiently determined.
[0193] In another optional embodiment, the image segmentation module 301 determines, for each pixel on the image to be blurred, the target Gaussian filtering algorithm corresponding to the pixel according to the target probability corresponding to the pixel, which may include:
[0194] For each pixel on the image to be blurred, if the target probability corresponding to the pixel is less than a preset first probability threshold, the pixel is determined to be a non-target object pixel, and the target algorithm parameter corresponding to the pixel is determined to be the first algorithm parameter; if the target probability corresponding to the pixel is greater than or equal to the first probability threshold and less than a preset second probability threshold, the pixel is determined to be an object edge pixel, and the target algorithm parameter corresponding to the pixel is determined to be the second algorithm parameter;
[0195] The first probability threshold is smaller than the second probability threshold.
[0196] It can be seen that in this optional embodiment, the pixels on the image to be blurred are divided into two categories: pixels whose target probability is less than the preset first probability threshold are non-target object pixels, and pixels whose target probability is greater than or equal to the first probability threshold and less than the preset second probability threshold are object edge pixels. And corresponding Gaussian filtering algorithms are set for the above two types of pixels, which greatly reduces the amount of calculation and improves the efficiency of image blurring.
[0197] In another optional embodiment, the Gaussian filtering module 302 performs a Gaussian filtering operation on each pixel point on the image to be blurred based on the target Gaussian filtering algorithm corresponding to the pixel point, and a specific method of obtaining a filtered pixel value corresponding to the pixel point may include:
[0198] Using a plurality of preset Gaussian filtering algorithms respectively to perform Gaussian filtering operations on all pixel points of the image to be blurred, a plurality of pre-filtered pixel values corresponding to each pixel point of the image to be blurred are obtained; and a pre-processed image corresponding to each preset Gaussian filtering algorithm is obtained according to all pre-filtered pixel values corresponding to all pixel points of the image to be blurred;
[0199] For each pixel on the image to be blurred, determine the target preset Gaussian filtering algorithm that matches the target Gaussian filtering algorithm corresponding to the pixel point according to the target Gaussian filtering algorithm corresponding to the pixel point, and determine the target preprocessed image corresponding to the pixel point from all preprocessed images according to the target preset Gaussian filtering algorithm; determine the filtered pixel value corresponding to the pixel point according to the pixel value of the matching pixel point corresponding to the pixel point in the target preprocessed image.
[0200] It can be seen that in this optional embodiment, the image to be blurred is pre-processed according to different Gaussian filtering algorithms to obtain several pre-processed images; after determining the target probability range of the pixel points on the image to be blurred, it is only necessary to match the target pre-processed image and then determine the filtered pixel value corresponding to the pixel point based on the pixel value of the matching pixel point corresponding to the pixel point in the target pre-processed image, thereby further improving the computational efficiency of image blur.
[0201] In another optional embodiment, the image segmentation module 301 determines, for each pixel on the image to be blurred, according to the target probability corresponding to the pixel, a specific method of the target algorithm parameter corresponding to the pixel may include:
[0202] For each pixel on the image to be blurred, determine the target Gaussian function standard deviation σ corresponding to the pixel according to the target probability corresponding to the pixel, and determine the target filter kernel size kernel_size corresponding to the pixel according to the target Gaussian function standard deviation σ corresponding to the pixel;
[0203] Among them, according to the standard deviation σ of the target Gaussian function corresponding to the pixel point, the target filter kernel size kernel_size corresponding to the pixel point is determined, which is specifically implemented by the following formula:
[0204]
[0205] kernel_size=2*radius+1
[0206] In the above formula, This is a round-up operation, with radius as the intermediate parameter.
[0207] It can be seen that the image blurring device based on progressive Gaussian filtering in the embodiment of the present invention can determine the target filter kernel size kernel_size corresponding to the pixel point according to the target Gaussian function standard deviation σ corresponding to the pixel point, and can construct a Gaussian filtering algorithm that is more suitable for image blurring. In summary, the embodiment of the present invention can further improve the efficiency of the image blurring method.
[0208] In another optional embodiment, the Gaussian filtering module 302 performs a Gaussian filtering operation on each pixel point on the image to be blurred based on the target Gaussian filtering algorithm corresponding to the pixel point, and a specific method of obtaining a filtered pixel value corresponding to the pixel point may include:
[0209] For each pixel point on the image to be blurred, determine the pixel point as the target pixel point, take the target pixel point as the coordinate origin, take the target filter kernel size kernel_siz corresponding to the target pixel point as the side length, and construct the target filter kernel corresponding to the target pixel point with a size of kernel_size*kernel_size; according to the standard deviation σ of the target Gaussian function corresponding to the target pixel point, determine the filter kernel weight matrix corresponding to the target filter kernel;
[0210] For each target pixel on the image to be blurred, all pixels on the image to be blurred that are located within the target filter kernel corresponding to the target pixel are convolved with the filter kernel weight matrix to obtain a filter pixel value corresponding to the target pixel;
[0211] Among them, for each target pixel on the image to be blurred, the filter kernel weight matrix corresponding to the target filter kernel is determined according to the target Gaussian function standard deviation σ corresponding to the target pixel, which is specifically implemented by the following formula:
[0212]
[0213] In the above formula, x is the horizontal coordinate of any pixel point in the target filter kernel, where the value range of x is [-radius, radius]; y is the vertical coordinate of any pixel point in the target filter kernel, where the value range of y is also [-radius, radius]; the coordinates of the target pixel point are (0,0); f(x,y) is the weight parameter of the pixel point at (x,y).
[0214] It can be seen that in this optional embodiment, each pixel point that needs to be filtered is reassigned using the "weighted average of surrounding neighbor pixels", so that the pixel point is filtered according to the distribution of pixels around it, thereby blurring the background of the entire image.
[0215] In another optional embodiment, the image segmentation module 301 inputs the image to be blurred into a pre-trained image segmentation model, and a specific method of obtaining the object segmentation probability map output by the image segmentation model may include:
[0216] Acquire an image to be blurred with a resolution of ih*iw, preprocess the image to be blurred, and obtain a preprocessed image;
[0217] Scale the preprocessed image to an intermediate image with a resolution of nh*nw;
[0218] Input the intermediate image into the pre-trained image segmentation model to obtain the initial probability map with a resolution of nh*nw output by the image segmentation model;
[0219] The initial probability map is upsampled by bilinear interpolation to obtain an object segmentation probability map with a resolution of ih*iw;
[0220] The image segmentation module 301 preprocesses the image to be blurred to obtain a preprocessed image, which may specifically include:
[0221] Calculate the pixel mean and pixel variance of all pixels on the image to be blurred;
[0222] For each pixel on the image to be blurred, the pixel value of the pixel is subtracted from the pixel mean and then divided by the pixel variance to obtain the standardized pixel value of the pixel;
[0223] Performing a normalization operation on the standardized pixel values of all pixels on the image to be blurred to obtain a preprocessed pixel value of each pixel on the image to be blurred;
[0224] A preprocessed image is obtained according to the preprocessed pixel values of all pixels on the image to be blurred.
[0225] It can be seen that this optional embodiment can adjust the image to be blurred to a size suitable for use by the image segmentation model through image scaling, upsampling and preprocessing technology, thereby facilitating the efficient use of the image segmentation model and improving the efficiency of the image blurring method.
[0226] Embodiment 4
[0227] See also Figure 6 , Figure 6 is a structural schematic diagram of another image blurring device based on progressive Gaussian filtering disclosed in an embodiment of the present invention. Figure 6 As shown, the image blurring device based on progressive Gaussian filtering may include:
[0228] A memory 401 storing executable program codes;
[0229] a processor 402 coupled to the memory 401;
[0230] The processor 402 calls the executable program code stored in the memory 401 to execute the steps of the image blurring method based on progressive Gaussian filtering described in the first or second embodiment of the present invention.
[0231] Embodiment 5
[0232] An embodiment of the present invention discloses a computer storage medium, which stores computer instructions. When the computer instructions are called, they are used to execute the steps of the image blurring method based on progressive Gaussian filtering described in Embodiment 1 or Embodiment 2 of the present invention.
[0233] Embodiment 6
[0234] An embodiment of the present invention discloses a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and the computer program is operable to enable a computer to execute the steps of the image blurring method based on progressive Gaussian filtering described in Embodiment 1 or Embodiment 2.
[0235] The device embodiments described above are only illustrative, wherein the modules described as separate components may or may not be physically separated, and the components displayed as modules may or may not be physical modules, i.e., they may be located in one place, or they may be distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Those of ordinary skill in the art may understand and implement it without creative work.
[0236] Through the specific description of the above embodiments, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on such an understanding, the above technical solution can be essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, and the storage medium includes a read-only memory (ROM), a random access memory (RAM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), a one-time programmable read-only memory (OTPROM), an electronically erasable rewritable read-only memory (EEPROM), a compact disc (CD-ROM) or other optical disc storage, magnetic disk storage, magnetic tape storage, or any other computer-readable medium that can be used to carry or store data.
[0237] Finally, it should be noted that the image blurring method, device and storage medium based on progressive Gaussian filtering disclosed in the embodiments of the present invention are only preferred embodiments of the present invention, which are only used to illustrate the technical solution of the present invention, rather than to limit it. 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 can still be modified, or some of the technical features can 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. An image blurring method based on progressive Gaussian filtering, characterized in that: The method comprises: For each pixel point on the image to be blurred, the target probability of the pixel point being a pixel point of the target object is determined based on the pre-trained image segmentation model; according to the target probability corresponding to the pixel point, the target Gaussian filter algorithm corresponding to the pixel point is determined; For each pixel point on the image to be blurred, a Gaussian filtering operation is performed on the pixel point based on the target Gaussian filtering algorithm corresponding to the pixel point to obtain a filtered pixel value corresponding to the pixel point; A blurred image of the object corresponding to the image to be blurred is determined according to the filtered pixel value corresponding to each pixel point on the image to be blurred.
2. The image blurring method based on progressive Gaussian filtering according to claim 1, characterized in that: The method of determining, for each pixel point on the image to be blurred, a target probability of the pixel point being a pixel point of the target object based on a pre-trained image segmentation model, includes: Inputting the image to be blurred into a pre-trained image segmentation model to obtain an object segmentation probability map output by the image segmentation model; For each pixel point on the image to be blurred, determining the target probability that the pixel point is a pixel point of the target object according to the object segmentation probability map; The pixel value of each pixel in the object segmentation probability map is used to represent the probability that the pixel is a pixel of the target object; And, for each pixel point on the image to be blurred, determining the target Gaussian filtering algorithm corresponding to the pixel point according to the target probability, comprises: For each pixel point on the image to be blurred, determine the target algorithm parameter corresponding to the pixel point according to the target probability corresponding to the pixel point, and determine the target Gaussian filter algorithm corresponding to the pixel point according to the target algorithm parameter; The target algorithm parameters include at least a target filter kernel size kernel_size and a target Gaussian function standard deviation σ.
3. The image blurring method based on progressive Gaussian filtering according to claim 2, characterized in that: For each pixel point on the image to be blurred, determining the target Gaussian filtering algorithm corresponding to the pixel point according to the target probability corresponding to the pixel point includes: For each pixel point on the image to be blurred, if the target probability corresponding to the pixel point is less than a preset first probability threshold, the pixel point is determined to be a non-target object pixel point, and the target algorithm parameter corresponding to the pixel point is determined to be the first algorithm parameter; if the target probability corresponding to the pixel point is greater than or equal to the first probability threshold and less than a preset second probability threshold, the pixel point is determined to be an object edge pixel point, and the target algorithm parameter corresponding to the pixel point is determined to be the second algorithm parameter; The first probability threshold is smaller than the second probability threshold.
4. The image blurring method based on progressive Gaussian filtering according to claim 1, characterized in that: For each pixel point on the image to be blurred, performing a Gaussian filtering operation on the pixel point based on the target Gaussian filtering algorithm corresponding to the pixel point to obtain a filtered pixel value corresponding to the pixel point includes: Using a plurality of preset Gaussian filtering algorithms respectively to perform Gaussian filtering operations on all the pixel points of the image to be blurred, to obtain a plurality of pre-filtered pixel values corresponding to each pixel point of the image to be blurred; and obtaining a pre-processed image corresponding to each of the preset Gaussian filtering algorithms according to all the pre-filtered pixel values corresponding to all the pixel points of the image to be blurred; For each pixel point on the image to be blurred, determine a target preset Gaussian filtering algorithm that matches the target Gaussian filtering algorithm corresponding to the pixel point according to the target Gaussian filtering algorithm corresponding to the pixel point, and determine the target preprocessed image corresponding to the pixel point from all the preprocessed images according to the target preset Gaussian filtering algorithm; determine the filtered pixel value corresponding to the pixel point according to the pixel value of the matching pixel point corresponding to the pixel point in the target preprocessed image.
5. The image blurring method based on progressive Gaussian filtering according to claim 2, characterized in that: For each pixel point on the image to be blurred, determining the target algorithm parameter corresponding to the pixel point according to the target probability corresponding to the pixel point includes: For each pixel on the image to be blurred, determine the target Gaussian function standard deviation σ corresponding to the pixel according to the target probability corresponding to the pixel, and determine the target filter kernel size kernel_size corresponding to the pixel according to the target Gaussian function standard deviation σ corresponding to the pixel; The target filter kernel size kernel_size corresponding to the pixel is determined according to the target Gaussian function standard deviation σ corresponding to the pixel, which is specifically implemented by the following formula: kernel_size=2*radius+1 In the above formula, This is a round-up operation, with radius as the intermediate parameter.
6. The image blurring method based on progressive Gaussian filtering according to claim 5, characterized in that: For each pixel point on the image to be blurred, performing a Gaussian filtering operation on the pixel point based on the target Gaussian filtering algorithm corresponding to the pixel point to obtain a filtered pixel value corresponding to the pixel point includes: For each pixel point on the image to be blurred, determine the pixel point as the target pixel point, take the target pixel point as the coordinate origin, take the target filter kernel size kernel_siz corresponding to the target pixel point as the side length, and construct a target filter kernel corresponding to the target pixel point with a size of kernel_size*kernel_size; determine the filter kernel weight matrix corresponding to the target filter kernel according to the target Gaussian function standard deviation σ corresponding to the target pixel point; For each of the target pixels on the image to be blurred, convolution calculation is performed on all pixels on the image to be blurred that are located within the target filter kernel corresponding to the target pixel with the filter kernel weight matrix to obtain a filter pixel value corresponding to the target pixel; Among them, for each target pixel point on the image to be blurred, the filter kernel weight matrix corresponding to the target filter kernel is determined according to the target Gaussian function standard deviation σ corresponding to the target pixel point, which is specifically implemented by the following formula: In the above formula, x is the horizontal coordinate of any pixel point in the target filter kernel, where the value range of x is [-radius, radius]; y is the vertical coordinate of any pixel point in the target filter kernel, where the value range of y is also [-radius, radius]; the coordinates of the target pixel point are (0,0); f(x,y) is the weight parameter of the pixel point at (x,y).
7. The image blurring method based on progressive Gaussian filtering according to claim 2, characterized in that: The inputting of the image to be blurred into a pre-trained image segmentation model to obtain an object segmentation probability map output by the image segmentation model comprises: Acquire an image to be blurred with a resolution of ih*iw, and preprocess the image to be blurred to obtain a preprocessed image; Scaling the preprocessed image into an intermediate image with a resolution of nh*nw; Input the intermediate image into a pre-trained image segmentation model to obtain an initial probability map with a resolution of nh*nw output by the image segmentation model; Performing bilinear interpolation upsampling on the initial probability map to obtain an object segmentation probability map with a resolution of ih*iw; The preprocessing of the image to be blurred to obtain the preprocessed image specifically includes: Calculating the pixel mean and pixel variance of all the pixels on the image to be blurred; For each pixel point on the image to be blurred, subtract the pixel mean from the pixel value of the pixel point and divide the result by the pixel variance to obtain a standardized pixel value of the pixel point; Performing a normalization operation on the standardized pixel values of all the pixels on the image to be blurred, to obtain a preprocessed pixel value of each pixel on the image to be blurred; A preprocessed image is obtained according to the preprocessed pixel values of all the pixel points on the image to be blurred.
8. An image blurring device based on progressive Gaussian filtering, characterized in that: The device comprises: The image segmentation module is used to determine the target probability of each pixel point on the image to be blurred being a pixel point of the target object based on the pre-trained image segmentation model; and determine the target Gaussian filter algorithm corresponding to the pixel point according to the target probability corresponding to the pixel point; A Gaussian filtering module is used to perform a Gaussian filtering operation on each pixel point on the image to be blurred based on the target Gaussian filtering algorithm corresponding to the pixel point, so as to obtain a filtered pixel value corresponding to the pixel point; The image blur module is used to determine the object blur picture corresponding to the image to be blurred according to the filtered pixel value corresponding to each pixel point on the image to be blurred.
9. An image blurring device based on progressive Gaussian filtering, characterized in that: The device includes: a memory storing executable program code; a processor coupled to the memory; the processor calls the executable program code stored in the memory to execute the image blurring method based on progressive Gaussian filtering as described in any one of claims 1-7.
10. A computer storage medium, characterized in that: The computer storage medium stores computer instructions, and when the computer instructions are called, they are used to execute the image blurring method based on progressive Gaussian filtering as described in any one of claims 1-7.
Citation Information
Patent Citations
Image blurring method and apparatus, and electronic device
CN107085825A
Foreground recognition method and device, electronic equipment and storage medium
CN109784164A
Image blurring method, terminal, storage medium and processor
CN111127328A
Image processing method and device, electronic equipment and storage medium
CN115330610A