CN111199514B - Image background blurring method, device and equipment and readable storage medium - Google Patents

Image background blurring method, device and equipment and readable storage medium Download PDF

Info

Publication number
CN111199514B
CN111199514B CN201911425908.6A CN201911425908A CN111199514B CN 111199514 B CN111199514 B CN 111199514B CN 201911425908 A CN201911425908 A CN 201911425908A CN 111199514 B CN111199514 B CN 111199514B
Authority
CN
China
Prior art keywords
image
target
blurring
processed
fuzzy
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201911425908.6A
Other languages
Chinese (zh)
Other versions
CN111199514A (en
Inventor
周雄伟
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Wuxi Yuning Intelligent Technology Co ltd
Original Assignee
Wuxi Yuning Intelligent Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Wuxi Yuning Intelligent Technology Co ltd filed Critical Wuxi Yuning Intelligent Technology Co ltd
Priority to CN201911425908.6A priority Critical patent/CN111199514B/en
Publication of CN111199514A publication Critical patent/CN111199514A/en
Application granted granted Critical
Publication of CN111199514B publication Critical patent/CN111199514B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T3/00Geometric image transformations in the plane of the image
    • G06T3/04Context-preserving transformations, e.g. by using an importance map

Landscapes

  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Image Processing (AREA)

Abstract

The application discloses an image background blurring method, an image background blurring device and a readable storage medium, wherein the image background blurring method comprises the following steps: receiving an image to be processed, performing fuzzy processing on the image to be processed to obtain a target fuzzy processing image, generating a target mask image corresponding to the image to be processed, and mixing the image to be processed, the target fuzzy processing image and the target mask image to obtain a background blurring image. The method and the device solve the technical problems that the image background blurring effect is poor and the hardware requirement is high.

Description

Image background blurring method, device and equipment and readable storage medium
Technical Field
The present application relates to the field of image processing technologies, and in particular, to a method, an apparatus, a device, and a readable storage medium for blurring an image background.
Background
With the rapid development of the intelligent terminal, the photographing function of the intelligent terminal is more and more popularized, and the requirement of the user for photographing is higher and higher, that is, the user is no longer limited to only photographing a clear image, but wants to photograph a more prominent and more beautiful image of the image subject.
Disclosure of Invention
The present application mainly aims to provide an image background blurring method, an image background blurring device, and a readable storage medium, and aims to solve the technical problem in the prior art that image background blurring hardware requirements are high.
In order to achieve the above object, the present application provides an image background blurring method, where the image background blurring method is applied to an image background blurring device, and the image background blurring method includes:
receiving an image to be processed, and performing fuzzy processing on the image to be processed to obtain a target fuzzy processing image;
and generating a target mask image corresponding to the image to be processed, and mixing the image to be processed, the target blurred image and the target mask image to obtain a background blurring image.
Optionally, the step of receiving an image to be processed, performing a blurring process on the image to be processed, and obtaining a target blurred image includes:
receiving the image to be processed, and acquiring a target fuzzy degree corresponding to the image to be processed;
calculating a target fuzzy radius through a preset target fuzzy radius calculation formula based on the target fuzzy degree;
and respectively carrying out horizontal blurring processing and vertical blurring processing on the image to be processed based on the target blurring radius to obtain the target blurring processed image.
Optionally, the step of respectively performing horizontal blurring processing and vertical blurring processing on the image to be processed based on the target blurring radius to obtain the target blurring processed image includes:
performing the horizontal blurring processing from left to right on the image to be processed based on the target blurring radius to obtain a first blurring processed image;
performing the horizontal blurring processing from right to left on the first blurring processed image based on the target blurring radius to obtain a second blurring processed image;
based on the target fuzzy radius, performing vertical fuzzy processing on the second fuzzy processing image from top to bottom to obtain a third fuzzy processing image;
and performing the vertical blurring processing on the third blurring processed image from bottom to top based on the target blurring radius to obtain the target blurring processed image.
Optionally, the step of receiving the image to be processed and obtaining the target blur degree corresponding to the image to be processed includes:
calculating the integer target fuzzy radius through a preset integer target fuzzy radius calculation formula based on the target fuzzy degree;
and respectively carrying out horizontal blurring processing and vertical blurring processing on the image to be processed through a preset integer blurring processing algorithm based on the integer target blurring radius to obtain the target blurring processed image.
Optionally, the step of calculating the target blur radius by using a preset target blur radius calculation formula based on the target blur degree includes:
acquiring a cache target fuzzy degree, and comparing the cache target fuzzy degree with the target fuzzy degree;
and if the cache target fuzzy degree is consistent with the target fuzzy degree, taking a cache fuzzy radius corresponding to the cache target fuzzy degree as the target fuzzy radius.
Optionally, the step of generating the target mask map corresponding to the image to be processed includes:
acquiring cached aperture information, and comparing the cached aperture information with target aperture information corresponding to the image to be processed;
and if the cached aperture information is consistent with the target aperture information, taking a cached mask image corresponding to the cached aperture information as the target mask image.
Optionally, the step of mixing the image to be processed, the target blurred image, and the target mask image to obtain a background blurred image includes:
inputting a first pixel matrix corresponding to the image to be processed, a second pixel matrix of the target fuzzy processing image and a third pixel matrix of the target mask image into a preset image matrix mixing calculation formula to obtain a target pixel matrix;
and acquiring the background blurring image based on the target pixel matrix.
The present application further provides an image background blurring device, where the image background blurring device is a virtual device, and the image background blurring device is applied to an image background blurring device, the image background blurring device includes:
the fuzzy processing module is used for receiving the image to be processed, and carrying out fuzzy processing on the image to be processed to obtain a target fuzzy processing image;
and the mixing module is used for generating a target mask image corresponding to the image to be processed, and mixing the image to be processed, the target blurred image and the target mask image to obtain a background blurring image.
Optionally, the blur processing module includes:
the acquisition unit is used for receiving the image to be processed and acquiring a target fuzzy degree corresponding to the image to be processed;
the first calculating unit is used for calculating a target fuzzy radius through a preset target fuzzy radius calculating formula based on the target fuzzy degree;
and the first fuzzy processing unit is used for respectively carrying out horizontal fuzzy processing and vertical fuzzy processing on the image to be processed based on the target fuzzy radius to obtain the target fuzzy processing image.
Optionally, the first blur processing unit includes:
the first blurring processing subunit is configured to perform, on the basis of the target blurring radius, the horizontal blurring processing from left to right on the image to be processed to obtain a first blurring processed image;
a second blurring processing subunit, configured to perform, on the basis of the target blurring radius, the horizontal blurring processing from right to left on the first blurring processed image to obtain a second blurring processed image;
a third blur processing subunit, configured to perform, on the basis of the target blur radius, the vertical blur processing from top to bottom on the second blur processed image, so as to obtain a third blur processed image;
and the fourth blurring processing subunit is configured to perform, on the basis of the target blurring radius, the vertical blurring processing on the third blurring processed image from bottom to top to obtain the target blurring processed image.
Optionally, the blur processing module includes:
the second calculation unit is used for calculating the integer target fuzzy radius through a preset integer target fuzzy radius calculation formula based on the target fuzzy degree;
and the second fuzzy processing unit is used for respectively carrying out horizontal fuzzy processing and vertical fuzzy processing on the image to be processed through a preset integer fuzzy processing algorithm based on the integer target fuzzy radius to obtain the target fuzzy processing image.
Optionally, the blur processing module includes:
the comparison unit is used for acquiring the fuzzy degree of the cache target and comparing the fuzzy degree of the cache target with the fuzzy degree of the target;
and the determining unit is used for taking the cache fuzzy radius corresponding to the cache target fuzzy degree as the target fuzzy radius if the cache target fuzzy degree is consistent with the target fuzzy degree.
Optionally, the image background blurring device further includes:
the first acquisition module is used for acquiring the cached aperture information and comparing the cached aperture information with target aperture information corresponding to the image to be processed;
and the determining module is used for taking the cache mask image corresponding to the cache aperture information as the target mask image if the cache aperture information is consistent with the target aperture information.
Optionally, the mixing module comprises:
the calculation module is used for inputting a first pixel matrix corresponding to the image to be processed, a second pixel matrix of the target fuzzy processing image and a third pixel matrix of the target mask image into a preset image matrix mixing calculation formula to obtain a target pixel matrix;
a second obtaining module, configured to obtain the background blurred image based on the target pixel matrix.
The present application further provides an image background blurring device, where the image background blurring device is an entity device, and the image background blurring device includes: a memory, a processor and a program of the image background blurring method stored on the memory and executable on the processor, the program of the image background blurring method when executed by the processor may implement the steps of the image background blurring method as described above.
The present application further provides a readable storage medium, on which a program for implementing the image background blurring method is stored, and when executed by a processor, the program for implementing the image background blurring method implements the steps of the image background blurring method as described above.
The method comprises the steps of receiving an image to be processed, carrying out fuzzy processing on the image to be processed to obtain a target fuzzy processing image, further generating a target mask image corresponding to the image to be processed, mixing the image to be processed, the target fuzzy processing image and the target mask image to obtain a background blurring image. That is, in the present application, a target blurred image is obtained by performing a blurring process on an image to be processed, a target mask diagram corresponding to the image to be processed is generated, and the image to be processed, the target blurred image, and the target mask diagram are mixed, so that a background blurred image can be obtained. That is, in the present application, a background blurring operation, a mask map generation operation, and a mixing operation of the to-be-processed image, the target blurring image, and the target mask map are performed respectively, and the blurring operation, the mask map generation operation, and the mixing operation can be performed using an algorithm, so that the background blurring of the to-be-processed image can be performed without hardware, and the blurring operation, the mask map generation operation, and the mixing operation are all processes of processing based on an image pixel matrix, so that the blurring operation, the mask map generation operation, and the mixing operation can be performed precisely on each pixel of the to-be-processed image, respectively, thereby enhancing an image layering sense of the background blurring image, that is, improving an image background blurring effect, and thus solving technical problems of poor image background blurring effect and high hardware requirement.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and together with the description, serve to explain the principles of the application.
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings needed to be used in the description of the embodiments or the prior art will be briefly described below, and it is obvious for those skilled in the art to obtain other drawings without inventive exercise.
FIG. 1 is a schematic flowchart illustrating a first embodiment of an image background blurring method according to the present application;
FIG. 2 is a schematic diagram of a target mask in the image background blurring method of the present application;
FIG. 3 is a flowchart illustrating a second embodiment of an image background blurring method according to the present application;
fig. 4 is a schematic device structure diagram of a hardware operating environment according to an embodiment of the present application.
The implementation, functional features and advantages of the objectives of the present application will be further explained with reference to the accompanying drawings.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the present application and are not intended to limit the present application.
An embodiment of the present application provides an image background blurring method, where the image background blurring method is applied to an image background blurring device, and in a first embodiment of the image background blurring method of the present application, with reference to fig. 1, the image background blurring method includes:
step S10, receiving an image to be processed, and performing fuzzy processing on the image to be processed to obtain a target fuzzy processing image;
in this embodiment, it should be noted that the blurring process includes a horizontal blurring process and a vertical blurring process, and the image to be processed may be extracted from a preset database or captured by a camera.
Receiving an image to be processed, performing blur processing on the image to be processed to obtain a target blur processed image, specifically, receiving the image to be processed, and obtaining a target blur degree corresponding to the image to be processed, wherein the target blur degree can be set by a user or a system default value is used as the target blur degree, a target blur radius is calculated by a preset target blur radius calculation formula based on the target blur degree, and then, the image to be processed is respectively subjected to horizontal blur processing and vertical blur processing based on the target blur radius to obtain the target blur processed image, wherein the preset target blur radius calculation formula is as follows,
alpha=1.0f-exp(-9.0f*n*n/20000)
wherein alpha is the target blur radius, wherein the target blur radius is greater than or equal to 0 and less than 1,n, the target blur degree value is greater than or equal to 0 and less than 100, when n =0, the target blur degree is 0, when n =100, the target blur degree is 100%, the larger the target blur degree value is, the higher the target blur degree is, and f represents that the data type is real.
And S20, generating a target mask image corresponding to the image to be processed, and mixing the image to be processed, the target blurred image and the target mask image to obtain a background blurring image.
In this embodiment, it should be noted that, referring to fig. 2, the target mask image includes a blurred region, a transition region and a sharp region, the transition region, the sharp region, the target blurred image and the image region obtained by mixing the image to be processed in the target mask image are aperture portions, that is, are main regions of the background blurred image, the main regions are regions that need to be protruded in the background blurred image, the image region obtained by mixing the blurred region, the target blurred image and the image to be processed in the target mask image is a background region of the background blurred image, the background region is a region that needs to be blurred in the background blurred image, and the radius of the transition region is r 1 The radius of the clear area is r 0 And r is 1 =k*r 0 Wherein the value of k can be set by the user himself, e.g. r can be set 1 =4*r 0 Additionally, it should be noted that the target mask pattern has the same width and height as the image to be processed, and the target mask patternThe value ranges of the pixel values of the image matrix corresponding to the film map are all greater than or equal to 0 and less than or equal to 1, wherein the closer the pixel value is to 0, the more fuzzy the image area corresponding to the pixel value is, the more fuzzy the image area corresponding to the background blurred image is, and the closer the pixel value is to 1, the clearer the image area corresponding to the pixel value is, and the clearer the image area corresponding to the background blurred image is.
Generating a target mask image corresponding to the image to be processed, and mixing the image to be processed, the target blurred image and the target mask image to obtain a background blurred image, specifically, generating the target mask image corresponding to the image to be processed based on a preset mask image generation rule, wherein the image to be processed, the target blurred image and the target mask image are all the same in width and height, and further calculating a pixel matrix of the background blurred image through a preset image matrix mixing calculation formula based on a first pixel matrix of the image to be processed, a second pixel matrix of the target blurred image and a third pixel matrix of the target mask image to obtain the background blurred image.
In step S20, the step of mixing the image to be processed, the target blurred image, and the target mask image to obtain a background blurring image includes:
step S21, inputting a first pixel matrix corresponding to the image to be processed, a second pixel matrix of the target fuzzy processing image and a third pixel matrix of the target mask image into a preset image matrix mixing calculation formula to obtain a target pixel matrix;
in this embodiment, a preset image matrix mixing calculation formula is input to a first pixel matrix corresponding to the image to be processed, a second pixel matrix of the target blurred image, and a third pixel matrix of the target mask image, so as to obtain a target pixel matrix, specifically, a preset image processing tool is used to obtain the first pixel matrix corresponding to the image to be processed, the second pixel matrix of the target blurred image, and the third pixel matrix of the target mask image, and the first pixel matrix, the second pixel matrix, and the third pixel matrix are substituted into the preset image matrix mixing calculation formula, so as to obtain the target pixel matrix through calculation, where the preset image processing tool includes matlab and the like, and the preset image matrix mixing calculation formula is as follows,
T ij =Mask ij *S ij +(1-Mask ij )*B ij
wherein, T is ij For the target pixel matrix, the Mask ij Is the third pixel matrix, S ij Is the first pixel matrix, B ij The second matrix of pixels.
And S22, acquiring the background blurring image based on the target pixel matrix.
In this embodiment, the background blurred image is obtained based on the target pixel matrix, and specifically, the preset image processing tool converts the target pixel matrix into an image to obtain the background blurred image.
In step S20, the step of generating the target mask map corresponding to the image to be processed includes:
step A10, obtaining cache aperture information, and comparing the cache aperture information with target aperture information corresponding to the image to be processed;
in this embodiment, the cached aperture information includes a cached aperture size and a cached aperture position, the target aperture information includes a target aperture size and a target aperture position, and the aperture information of the current to-be-processed image is stored in a preset local database as the cached aperture information every time the background blurring image is acquired, that is, the cached aperture information is the to-be-processed image when the target mask map is generated last time.
The method comprises the steps of obtaining cache aperture information, comparing the cache aperture information with target aperture information corresponding to an image to be processed, specifically, extracting the size and the position of the cache aperture from a preset local database, obtaining the size and the position of the target aperture of the image to be processed, comparing the size and the position of the cache aperture with the size of the target aperture respectively, and comparing the position of the cache aperture with the position of the target aperture.
And step A20, if the cached aperture information is consistent with the target aperture information, taking the cached mask map corresponding to the cached aperture information as the target mask map.
In this embodiment, if the cached aperture information is consistent with the target aperture information, the cached mask map corresponding to the cached aperture information is used as the target mask map, and if the cached aperture size is consistent with the target aperture size and the cached aperture position is consistent with the target aperture position, the cached mask map corresponding to the cached aperture information is queried in a preset database, and the cached mask map is used as the target mask map.
In this embodiment, a to-be-processed image is received, a target blurred image is obtained by performing blurring processing on the to-be-processed image, a target mask image corresponding to the to-be-processed image is further generated, and the to-be-processed image, the target blurred image and the target mask image are mixed to obtain a background blurred image. That is, in this embodiment, the background blurred image may be obtained by performing blur processing on the image to be processed to obtain a target blurred image and generating a target mask map corresponding to the image to be processed, and then mixing the image to be processed, the target blurred image, and the target mask map. That is, in this embodiment, a blurring operation, a mask map generation operation, and a mixing operation of the to-be-processed image, the target blurring image, and the target mask map are respectively performed to directly obtain a background blurring image, and the blurring operation, the mask map generation operation, and the mixing operation can all be performed using an algorithm, so that the background blurring of the to-be-processed image can be performed without hardware, and the blurring operation, the mask map generation operation, and the mixing operation are all processes of processing based on an image pixel matrix, so that the blurring operation, the mask map generation operation, and the mixing operation can be accurately performed on each pixel of the to-be-processed image, respectively, thereby enhancing an image layering sense of the background blurring image, that is, improving an image background blurring effect, and thus solving technical problems of poor image background blurring effect and high hardware requirement.
Further, referring to fig. 3, in another embodiment of the image background blurring method based on the first embodiment of the present application, the step of receiving an image to be processed, performing blurring processing on the image to be processed, and obtaining a target blurred image includes:
s11, receiving the image to be processed and acquiring a target fuzzy degree corresponding to the image to be processed;
in this embodiment, it should be noted that the value of the target blur degree is greater than or equal to 0 and less than 100, and the larger the value is, the higher the target blur degree is, and the value of the target blur degree may be set by a user or a system default value may be directly adopted.
The step of receiving the image to be processed and obtaining the target blurring degree corresponding to the image to be processed comprises the following steps:
step B10, based on the target fuzzy degree, calculating a integer target fuzzy radius through a preset integer target fuzzy radius calculation formula;
in this embodiment, it should be noted that the integer target blur radius refers to that the target blur radius data type is integer, so as to avoid a large number of floating point calculations and improve the calculation efficiency.
Calculating the integer target fuzzy radius through a preset integer target fuzzy radius calculation formula based on the target fuzzy degree, in particular substituting the target fuzzy degree into the preset integer target fuzzy radius calculation formula to obtain the integer target fuzzy radius through calculation, wherein the preset integer target fuzzy radius calculation formula is shown as follows,
alpha _ prec = (int) (1.0 f-exp (-9.0 f x n/20000) × (1 < < prec)), where alpha _ prec is the integer target blur radius, int denotes that the data type is integer, and prec =16,1< < prec equals 65536.
And step B20, respectively carrying out horizontal blurring processing and vertical blurring processing on the image to be processed through a preset integer blurring processing algorithm based on the integer target blurring radius to obtain the target blurring processed image.
In this embodiment, it should be noted that the preset integer fuzzy processing algorithm includes a first integer fuzzy processing formula, a second integer fuzzy processing formula, a third integer fuzzy processing formula, and a fourth integer fuzzy processing formula, where the first integer fuzzy processing formula is used to perform horizontal fuzzy processing from left to right, the second integer fuzzy processing formula is used to perform horizontal fuzzy processing from right to left, the third integer fuzzy processing formula is used to perform vertical fuzzy processing from top to bottom, and the fourth integer fuzzy processing formula is used to perform vertical fuzzy processing from bottom to top.
Respectively carrying out horizontal blurring processing and vertical blurring processing on the image to be processed by a preset reshaping blurring processing algorithm based on the reshaping target blurring radius to obtain the target blurring processed image, specifically, substituting the reshaping target blurring radius into the first reshaping blurring processing formula to carry out horizontal blurring processing from left to right on the image to be processed, namely, calculating each column of a pixel matrix of the image to be processed from left to right, wherein the first reshaping blurring processing formula is shown as follows,
B1 ij =(((1<<prec)-alpha_prec)*S ij +alpha_prec*B1 (i-1)j )>>prec
wherein, the B1 ij Alpha _ prec is the blurring radius of the integer target for the pixel matrix corresponding to the first blurred image after the horizontal blurring from left to right is performed, and S ij For the pixel matrix corresponding to the image to be processed, 1<<The pre is equal to the number 65536,>>prec is expressed as divided by 65536,prec =16, the first integer blur processing formula is a column-by-column cyclic calculation of the pixel matrix of the image to be processed from left to right, i.e. from the image to be processedThe 1 st row of the image is circularly calculated to the last row, and each calculation is performed on the basis of the pixel matrix of the last calculation, wherein, the B1 (i-1)j I.e. the pixel matrix calculated last time, and when i =0, B1 0j =S 0j Further, performing horizontal blurring from right to left on the first blurred image based on a second integer blurring formula to obtain a second blurred image, wherein the second integer blurring formula is shown as follows,
B2 ij =(((1<<prec)-alpha_prec)*B1 ij +alpha_prec*B2 (i+1)j )>>prec
wherein, the B2 ij Alpha _ prec is the blurring radius of the integer target for the pixel matrix corresponding to the second blurred image after the right-to-left horizontal blurring processing, B1 ij For the pixel matrix corresponding to the first blurred image, 1<<The pre is equal to the number 65536,>>prec is expressed as being divided by 65536,prec =16, since the calculation of the pixel matrix of the image to be processed is performed from right to left in a column-by-column cycle, i.e. from the last row to the 1 st row of the image to be processed, and each calculation is performed on the basis of the pixel matrix of the last calculation, wherein B2 is the calculation of the pixel matrix of the image to be processed (i+1)j I.e. the pixel matrix calculated last time, and when i = w-1, w is the image width, B2 (w-1)j =B1 (w-1)j Further, the second blurred image is vertically blurred from top to bottom based on the third integer blur processing formula to obtain a third blurred image, wherein the third integer blur processing formula is as follows,
B3 ij =(((1<<prec)-alpha_prec)*B2 ij +alpha_prec*B3 i(j-1) )>>prec
wherein, the B3 ij Alpha _ prec is the integer target blur radius for the pixel matrix corresponding to the third blur processed image after the vertical blur processing from top to bottom, B2 ij For the pixel matrix corresponding to the second blurred image, 1<<The pre is equal to the value of 65536,>>prec is expressed as divided by 65536,prec =16, since the calculation of the pixel matrix of the image to be processed is performed cyclically from top to bottom, i.e. cyclically from the 1 st column to the last column of the image to be processed, each calculation being performed on the basis of the pixel matrix calculated last time, where B2 is i(j-1) I.e. the pixel matrix calculated last time, and when j =0, B3 i0 =B2 i0 Further, the third blur processing image is vertically blurred from bottom to top based on a fourth integer blur processing formula to obtain a target blur processing image, wherein the fourth integer blur processing formula is shown as follows,
B ij =(((1<<prec)-alpha_prec)*B3 ij +alpha_prec*B i(j+1) )>>prec
wherein, B is ij Alpha _ prec is the integer target blur radius for the pixel matrix corresponding to the target blur processed image after the vertical blur processing from bottom to top, B3 ij For the pixel matrix corresponding to the third blurred image, 1<<The pre is equal to the value of 65536,>>prec is expressed as being divided by 65536,prec =16, since the calculation of the pixel matrix of the image to be processed is performed cyclically from bottom to top, i.e. cyclically from the last column to the 1 st column of the image to be processed, each calculation being performed on the basis of the pixel matrix of the last calculation, where B is i(j+1) I.e. the pixel matrix calculated last time, and when j = h-1, h is the image height, B i(h-1) =B3 i(h-1)
In addition, the target mask map may also be converted into an integer calculation, specifically, a pixel matrix corresponding to the target mask map is multiplied by 128, so that a value range of each pixel value corresponding to the target mask map is greater than or equal to 0 and less than or equal to 128, and then the preset image matrix mixing calculation formula is subjected to integer replacement to obtain an integer image matrix mixing calculation formula, which is shown as follows,
T ij =(Mask ij *S ij +(128-Mask ij )*B ij )>>7
wherein, T is ij For the target pixel matrix, the Mask ij Is the third pixel matrix, S ij Is the first pixel matrix, B ij Said second matrix of pixels is arranged in a matrix of pixels,>>7 denotes division by 128.
Step S12, based on the target fuzzy degree, calculating a target fuzzy radius through a preset target fuzzy radius calculation formula;
in this embodiment, based on the target blur degree, a target blur radius is calculated through a preset target blur radius calculation formula, and specifically, the target blur radius is obtained through calculation by substituting the target blur degree into the preset target blur radius calculation formula.
Wherein, the step of calculating the target blur radius through a preset target blur radius calculation formula based on the target blur degree comprises:
step C10, obtaining the fuzzy degree of a cache target, and comparing the fuzzy degree of the cache target with the fuzzy degree of the target;
in this embodiment, it should be noted that, each time the image background of the image to be processed is blurred, the blurring degree set in the blurring of the image background this time is cached in a preset cache queue or a preset local database, so as to obtain the caching target blurring degree.
And step C20, if the cache target fuzzy degree is consistent with the target fuzzy degree, taking a cache fuzzy radius corresponding to the cache target fuzzy degree as the target fuzzy radius.
In this embodiment, if the cache target blur degree is consistent with the target blur degree, the cache blur radius corresponding to the cache target blur degree is used as the target blur radius, and specifically, if the cache target blur degree is consistent with the target blur degree, the cache blur radius corresponding to the cache target blur degree is directly extracted and used as the target blur radius, so as to save the calculation process of the target blur radius.
And S13, respectively carrying out horizontal blurring processing and vertical blurring processing on the image to be processed based on the target blurring radius to obtain the target blurring processed image.
In this embodiment, based on the target blur radius, performing horizontal blur processing and vertical blur processing on the image to be processed respectively to obtain the target blur processed image, specifically, based on a preset blur processing algorithm and the target blur radius, performing horizontal blur processing on the image to be processed to obtain a horizontal blur processed image, and further performing vertical blur processing on the horizontal blur processed image to obtain the target blur processed image.
Wherein, the step of respectively performing horizontal blurring processing and vertical blurring processing on the image to be processed based on the target blurring radius to obtain the target blurring processed image comprises:
step S131, performing the horizontal blurring processing from left to right on the image to be processed based on the target blurring radius to obtain a first blurring processed image;
in this embodiment, it should be noted that the preset blur processing algorithm includes a first blur processing formula, a second blur processing formula, a third blur processing formula, and a fourth blur processing formula.
Performing the horizontal blurring from left to right on the image to be processed based on the target blurring radius to obtain a first blurred image, specifically, substituting the target blurring radius into the first blurring formula, and performing the horizontal blurring from left to right on the image to be processed to obtain a first blurred image, wherein the first blurring formula is as follows,
B1 ij =(1-alpha)*S ij +alpha*B1 (i-1)j
wherein, the B1 ij A pixel matrix corresponding to the first blurred image after the horizontal blurring from left to right is represented by alphaSolid object blur radius, S ij For the pixel matrix corresponding to the image to be processed, since the pixel matrix of the image to be processed is circularly calculated column by column from left to right, that is, the pixel matrix of the image to be processed is circularly calculated from the 1 st row to the last row of the image to be processed, and each calculation is performed on the basis of the pixel matrix calculated last time, wherein the B1 (i-1)j I.e. the pixel matrix calculated last time, and when i =0, B1 0j =S 0j
Step S132, based on the target blur radius, performing the horizontal blur processing from right to left on the first blur processed image to obtain a second blur processed image;
in this embodiment, the horizontal blurring processing from right to left is performed on the first blurred image based on the target blur radius to obtain a second blurred image, specifically, the horizontal blurring processing from right to left is performed on the to-be-processed image based on the target blur radius and a second blurring processing formula to obtain a second blurred image, where the second blurring processing formula is as follows,
B2 ij =(1-alpha)*B1 ij +alpha*B2 (i+1)j
wherein, B2 is ij A pixel matrix corresponding to the second blurred image after the right-to-left horizontal blurring processing is performed, wherein alpha is the blurring radius of the real type target, and B1 ij For the pixel matrix corresponding to the first blurred image, since the pixel matrix of the image to be processed is circularly calculated column by column from right to left, that is, the pixel matrix of the image to be processed is circularly calculated from the last row to the 1 st row, and each calculation is performed on the basis of the pixel matrix calculated last time, wherein B2 is described (i+1)j I.e. the pixel matrix calculated last time, and when i = w-1, w is the image width, B2 (w-1)j =B1 (w-1)j
Step S133, based on the target blur radius, performing vertical blur processing from top to bottom on the second blur processed image to obtain a third blur processed image;
in this embodiment, the vertical blurring processing is performed from top to bottom on the second blurring processed image based on the target blurring radius to obtain a third blurring processed image, specifically, the horizontal blurring processing is performed from top to bottom on the to-be-processed image based on the target blurring radius and a third blurring processing formula to obtain a third blurring processed image, where the third blurring processing formula is as follows,
B3 ij =(1-alpha)*B2 ij +alpha*B3 i(j-1)
wherein, the B3 ij A pixel matrix corresponding to the third blurred image after vertical blurring from top to bottom, wherein alpha is the blurring radius of the real target, and B2 ij For the pixel matrix corresponding to the second blurred image, the pixel matrix of the image to be processed is cyclically calculated line by line from top to bottom, that is, the pixel matrix of the image to be processed is cyclically calculated from the 1 st column to the last column of the image to be processed, and each calculation is performed on the basis of the pixel matrix calculated last time, wherein B2 i(j-1) I.e. the pixel matrix calculated last time, and when j =0, B3 i0 =B2 i0
Step S134, based on the target blur radius, performing the vertical blur processing from bottom to top on the third blur processed image to obtain the target blur processed image.
In this embodiment, the vertical blurring processing from bottom to top is performed on the third blurring processed image based on the target blurring radius to obtain the target blurring processed image, specifically, the horizontal blurring processing from bottom to top is performed on the to-be-processed image based on the target blurring radius and a fourth blurring processing formula to obtain the target blurring processed image, where the fourth blurring processing formula is as follows,
B ij =(1-alpha)*B3 ij +alpha*B i(j+1)
wherein, B is ij Is carried out to hang from bottom to topA pixel matrix corresponding to the target fuzzy processing image after the straight fuzzy processing, alpha is the fuzzy radius of the real target, B3 ij For the pixel matrix corresponding to the third blurred image, since the pixel matrix of the image to be processed is cyclically calculated row by row from bottom to top, that is, cyclically calculated from the last column to the 1 st column of the image to be processed, and calculated from each time on the basis of the pixel matrix calculated from the last time, B i(j+1) I.e. the pixel matrix calculated last time, and when j = h-1, h is the image height, B i(h-1) =B3 i(h-1)
Additionally, in this embodiment, it should be noted that all pixel matrices use line-type data for storage, and in order to facilitate storage and extraction of data, when performing the vertical blurring processing, a pixel matrix calculation process corresponding to the vertical blurring processing may be performed by caching a temporary line, so as to avoid directly traversing the column direction of the pixel matrix.
In addition, in this implementation, the blur processing process, the process of generating the target mask map, and the process of mixing the to-be-processed image, the target blur processed image, and the target mask map may be divided into multiple threads for parallel computation, specifically, a multi-thread parallel computation algorithm model is created first, and multiple threads are executed asynchronously at the background, and then the to-be-computed functions and parameters that need to be computed are submitted to a task queue, where the to-be-computed functions include the blur processing process, the process of generating the target mask map, and all functions involved in the mixing process, and a certain thread at the background executes the to-be-computed function, and then when all currently submitted tasks are completed, computing resources are released, and all threads are closed, for example, when horizontal blur processing and vertical blur processing are performed, rows and rows, and columns of a pixel matrix are independent from each other, multi-thread parallel computation may be used, and further it is assumed that the to-be-processed image that is h is divided into 4 to-be-processed subimages that are h/4 in height, and then the 4 to-be processed subimages are respectively submitted, and reversely merged after the to-be processed images are obtained.
In this embodiment, the target blur processing image is obtained by receiving the image to be processed, obtaining a target blur degree corresponding to the image to be processed, calculating a target blur radius through a preset target blur radius calculation formula based on the target blur degree, and performing horizontal blur processing and vertical blur processing on the image to be processed respectively based on the target blur radius. That is, the present embodiment provides a blurring processing method, that is, firstly, a target blurring degree of an image to be processed is set, and then a blurring radius is calculated based on the target blurring degree, and then based on the blurring radius, according to a preset blurring processing algorithm, horizontal blurring processing and vertical blurring processing are performed on the image to be processed, and then a target blurring processed image is obtained, so that blurring processing using a gaussian blurring algorithm with too high complexity is avoided, and calculation efficiency is improved, and a situation that blurring effect is poor due to the fact that mean blurring processing is not calculated to calculate a weight, and further a blurring effect of blurring processing is improved is avoided.
Referring to fig. 4, fig. 4 is a schematic device structure diagram of a hardware operating environment according to an embodiment of the present application.
As shown in fig. 4, the image background blurring apparatus may include: a processor 1001, such as a CPU, a memory 1005, and a communication bus 1002. The communication bus 1002 is used to realize connection and communication between the processor 1001 and the memory 1005. The memory 1005 may be a high-speed RAM memory or a non-volatile memory (e.g., a magnetic disk memory). The memory 1005 may alternatively be a memory device separate from the processor 1001 described above.
Optionally, the image background blurring device may further include a rectangular user interface, a network interface, a camera, an RF (Radio Frequency) circuit, a sensor, an audio circuit, a WiFi module, and the like. The rectangular user interface may comprise a Display screen (Display), an input sub-module such as a Keyboard (Keyboard), and the optional rectangular user interface may also comprise a standard wired interface, a wireless interface. The network interface may optionally include a standard wired interface, a wireless interface (e.g., WI-FI interface).
Those skilled in the art will appreciate that the image background blurring device configuration shown in fig. 4 does not constitute a limitation of the image background blurring device, and may include more or fewer components than those shown, or some components may be combined, or a different arrangement of components.
As shown in fig. 4, a memory 1005, which is a kind of computer storage medium, may include therein an operating system, a network communication module, and an image background blurring program. The operating system is a program that manages and controls hardware and software resources of the image background blurring device, and supports the execution of the image background blurring program and other software and/or programs. The network communication module is used to implement communication between the components inside the memory 1005 and with other hardware and software in the image background blurring system.
In the image background blurring device shown in fig. 4, the processor 1001 is configured to execute an image background blurring program stored in the memory 1005, and implement the steps of the image background blurring method described in any one of the above.
The specific implementation of the image background blurring device of the present application is substantially the same as the embodiments of the image background blurring method, and is not described herein again.
An embodiment of the present invention further provides an image background blurring device, where the image background blurring device is applied to an image background blurring device, and the image background blurring device includes:
the fuzzy processing module is used for receiving the image to be processed, and carrying out fuzzy processing on the image to be processed to obtain a target fuzzy processing image;
and the mixing module is used for generating a target mask image corresponding to the image to be processed, and mixing the image to be processed, the target blurred image and the target mask image to obtain a background blurring image.
Optionally, the blur processing module includes:
the acquisition unit is used for receiving the image to be processed and acquiring a target fuzzy degree corresponding to the image to be processed;
the first calculating unit is used for calculating a target fuzzy radius through a preset target fuzzy radius calculating formula based on the target fuzzy degree;
and the first fuzzy processing unit is used for respectively carrying out horizontal fuzzy processing and vertical fuzzy processing on the image to be processed based on the target fuzzy radius to obtain the target fuzzy processing image.
Optionally, the first blur processing unit includes:
the first blurring processing subunit is configured to perform, on the basis of the target blurring radius, the horizontal blurring processing from left to right on the image to be processed to obtain a first blurring processed image;
a second blurring processing subunit, configured to perform, on the basis of the target blurring radius, the horizontal blurring processing from right to left on the first blurring processed image to obtain a second blurring processed image;
a third blurring processing subunit, configured to perform, on the basis of the target blurring radius, the vertical blurring processing from top to bottom on the second blurring processed image to obtain a third blurring processed image;
and the fourth blurring processing subunit is configured to perform, on the basis of the target blurring radius, the vertical blurring processing on the third blurring processed image from bottom to top to obtain the target blurring processed image.
Optionally, the blur processing module includes:
the second calculation unit is used for calculating the integer target fuzzy radius through a preset integer target fuzzy radius calculation formula based on the target fuzzy degree;
and the second fuzzy processing unit is used for respectively carrying out horizontal fuzzy processing and vertical fuzzy processing on the image to be processed through a preset integer fuzzy processing algorithm based on the integer target fuzzy radius to obtain the target fuzzy processing image.
Optionally, the blur processing module includes:
the comparison unit is used for acquiring the fuzzy degree of the cache target and comparing the fuzzy degree of the cache target with the fuzzy degree of the target;
and the determining unit is used for taking the cache fuzzy radius corresponding to the cache target fuzzy degree as the target fuzzy radius if the cache target fuzzy degree is consistent with the target fuzzy degree.
Optionally, the image background blurring device further includes:
the first acquisition module is used for acquiring the cached aperture information and comparing the cached aperture information with target aperture information corresponding to the image to be processed;
and the determining module is used for taking the cache mask image corresponding to the cache aperture information as the target mask image if the cache aperture information is consistent with the target aperture information.
Optionally, the mixing module comprises:
the calculation module is used for inputting a first pixel matrix corresponding to the image to be processed, a second pixel matrix of the target fuzzy processing image and a third pixel matrix of the target mask image into a preset image matrix mixing calculation formula to obtain a target pixel matrix;
a second obtaining module, configured to obtain the background blurred image based on the target pixel matrix.
The specific implementation of the image background blurring device of the present application is substantially the same as the embodiments of the image background blurring method, and is not described herein again.
The embodiment of the present application provides a readable storage medium, and the readable storage medium stores one or more programs, which are also executable by one or more processors for implementing the steps of the image background blurring method described in any one of the above.
The specific implementation of the readable storage medium of the present application is substantially the same as that of the embodiments of the image background blurring method, and is not described herein again.
The above description is only a preferred embodiment of the present application, and not intended to limit the scope of the present application, and all modifications of equivalent structures and equivalent processes, which are made by the contents of the specification and the drawings, or which are directly or indirectly applied to other related technical fields, are included in the scope of the present application.

Claims (8)

1. An image background blurring method, applied to a first device, includes:
receiving an image to be processed, and performing fuzzy processing on the image to be processed to obtain a target fuzzy processing image;
generating a target mask image corresponding to the image to be processed, and mixing the image to be processed, the target blurred image and the target mask image to obtain a background blurred image, wherein the target mask image has the same width and height as the image to be processed, the target mask image comprises a blurred region, a transition region and a clear region, an image region corresponding to the transition region and the clear region is a main region of the background blurred image, and an image region corresponding to the blurred region is a background region of the background blurred image,
the step of receiving an image to be processed, performing fuzzy processing on the image to be processed, and obtaining a target fuzzy processing image comprises the following steps:
receiving the image to be processed, and acquiring a target fuzzy degree corresponding to the image to be processed;
based on the target fuzzy degree, calculating a integer target fuzzy radius through a preset integer target fuzzy radius calculation formula;
performing horizontal fuzzy processing on the image to be processed based on the integer target fuzzy radius and a preset integer fuzzy processing algorithm to obtain a horizontal fuzzy processing image;
and carrying out vertical blurring processing on the horizontal blurring processed image according to the preset integer blurring processing algorithm to obtain the target blurring processed image.
2. The image background blurring method according to claim 1, wherein the step of performing horizontal blurring processing and vertical blurring processing on the image to be processed respectively based on the target blurring radius to obtain the target blurring processed image comprises:
performing the horizontal blurring processing from left to right on the image to be processed based on the target blurring radius to obtain a first blurring processed image;
performing the horizontal blurring processing from right to left on the first blurring processed image based on the target blurring radius to obtain a second blurring processed image;
based on the target fuzzy radius, performing vertical fuzzy processing on the second fuzzy processing image from top to bottom to obtain a third fuzzy processing image;
and performing the vertical blurring processing on the third blurring processed image from bottom to top based on the target blurring radius to obtain the target blurring processed image.
3. The image background blurring method as claimed in claim 1, wherein the step of calculating the target blur radius by a preset target blur radius calculation formula based on the target blur degree comprises:
acquiring a cache target fuzzy degree, and comparing the cache target fuzzy degree with the target fuzzy degree;
and if the cache target fuzzy degree is consistent with the target fuzzy degree, taking a cache fuzzy radius corresponding to the cache target fuzzy degree as the target fuzzy radius.
4. The method for blurring the background of an image according to claim 1, wherein the step of generating the target mask map corresponding to the image to be processed comprises:
acquiring cached aperture information, and comparing the cached aperture information with target aperture information corresponding to the image to be processed;
and if the cached aperture information is consistent with the target aperture information, taking a cached mask image corresponding to the cached aperture information as the target mask image.
5. The image background blurring method as claimed in claim 1, wherein the step of blending the image to be processed, the target blurred image and the target mask image to obtain a background blurring image comprises:
inputting a first pixel matrix corresponding to the image to be processed, a second pixel matrix of the target fuzzy processing image and a third pixel matrix of the target mask image into a preset image matrix mixing calculation formula to obtain a target pixel matrix;
and acquiring the background blurring image based on the target pixel matrix.
6. An image background blurring device, comprising:
the fuzzy processing module is used for receiving an image to be processed, and carrying out fuzzy processing on the image to be processed to obtain a target fuzzy processing image;
a mixing module, configured to generate a target mask map corresponding to the image to be processed, and mix the image to be processed, the target blurred image, and the target mask map to obtain a background blurred image, where the target mask map has the same width and height as the image to be processed, the target mask map includes a blurred region, a transition region, and a clear region, an image region corresponding to the transition region and the clear region together is a main region of the background blurred image, and an image region corresponding to the blurred region is a background region of the background blurred image,
the step of receiving an image to be processed, performing blurring processing on the image to be processed, and obtaining a target blurring processed image includes:
receiving the image to be processed, and acquiring a target fuzzy degree corresponding to the image to be processed;
calculating the integer target fuzzy radius through a preset integer target fuzzy radius calculation formula based on the target fuzzy degree;
performing horizontal fuzzy processing on the image to be processed based on the integer target fuzzy radius and a preset integer fuzzy processing algorithm to obtain a horizontal fuzzy processing image;
and carrying out vertical blurring processing on the horizontal blurring processed image according to the preset integer blurring processing algorithm to obtain the target blurring processed image.
7. An image background blurring device, characterized by comprising: a memory, a processor, and a program stored on the memory for implementing the image background blurring method,
the memory is used for storing a program for realizing the image background blurring method;
the processor is configured to execute a program for implementing the image background blurring method to implement the steps of the image background blurring method according to any one of claims 1 to 5.
8. A readable storage medium having stored thereon a program for implementing an image background blurring method, the program being executed by a processor to implement the steps of the image background blurring method according to any one of claims 1 to 5.
CN201911425908.6A 2019-12-31 2019-12-31 Image background blurring method, device and equipment and readable storage medium Active CN111199514B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911425908.6A CN111199514B (en) 2019-12-31 2019-12-31 Image background blurring method, device and equipment and readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911425908.6A CN111199514B (en) 2019-12-31 2019-12-31 Image background blurring method, device and equipment and readable storage medium

Publications (2)

Publication Number Publication Date
CN111199514A CN111199514A (en) 2020-05-26
CN111199514B true CN111199514B (en) 2022-11-18

Family

ID=70746705

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911425908.6A Active CN111199514B (en) 2019-12-31 2019-12-31 Image background blurring method, device and equipment and readable storage medium

Country Status (1)

Country Link
CN (1) CN111199514B (en)

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106530241A (en) * 2016-10-31 2017-03-22 努比亚技术有限公司 Image blurring processing method and apparatus
CN108230333A (en) * 2017-11-28 2018-06-29 深圳市商汤科技有限公司 Image processing method, device, computer program, storage medium and electronic equipment
CN108564541A (en) * 2018-03-28 2018-09-21 麒麟合盛网络技术股份有限公司 A kind of image processing method and device

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105303514B (en) * 2014-06-17 2019-11-05 腾讯科技(深圳)有限公司 Image processing method and device

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106530241A (en) * 2016-10-31 2017-03-22 努比亚技术有限公司 Image blurring processing method and apparatus
CN108230333A (en) * 2017-11-28 2018-06-29 深圳市商汤科技有限公司 Image processing method, device, computer program, storage medium and electronic equipment
CN108564541A (en) * 2018-03-28 2018-09-21 麒麟合盛网络技术股份有限公司 A kind of image processing method and device

Also Published As

Publication number Publication date
CN111199514A (en) 2020-05-26

Similar Documents

Publication Publication Date Title
WO2021115136A1 (en) Anti-shake method and apparatus for video image, electronic device, and storage medium
US20110299783A1 (en) Object Detection in an Image
US9613404B2 (en) Image processing method, image processing apparatus and electronic device
CN112051959B (en) Method, device and equipment for generating image drawing process and storage medium
WO2019210546A1 (en) Data processing method and computing device
CN110428382B (en) Efficient video enhancement method and device for mobile terminal and storage medium
CN110765799B (en) Client code scanning identification method, device, equipment and storage medium
CN111667504B (en) Face tracking method, device and equipment
WO2019184888A1 (en) Image processing method and apparatus based on convolutional neural network
WO2018113339A1 (en) Projection image construction method and device
US20190318461A1 (en) Histogram Statistics Circuit and Multimedia Processing System
WO2022267939A1 (en) Image processing method and apparatus, and computer-readable storage medium
JP7253621B2 (en) Image stabilization method for panorama video and portable terminal
EP2465095A1 (en) System and method for region-of-interest-based artifact reduction in image sequences
CN113240578B (en) Image special effect generation method and device, electronic equipment and storage medium
CN112070854B (en) Image generation method, device, equipment and storage medium
CN111199514B (en) Image background blurring method, device and equipment and readable storage medium
CN113628259A (en) Image registration processing method and device
CN114095659B (en) Video anti-shake method, device, equipment and storage medium
CN116320792A (en) Method for enhancing resolution and reducing noise in multi-frame image
US20230060988A1 (en) Image processing device and method
JP6762737B2 (en) Image processing device
CN113256484A (en) Method and device for stylizing image
CN113628133A (en) Rain and fog removing method and device based on video image
CN114612294A (en) Image super-resolution processing method and computer equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant