Image processing method and device

By randomly offsetting and blurring image pixels, blurred color values ​​are generated, solving the problem of grid effect or layering effect in blurring algorithms and improving image quality.

CN121169743APending Publication Date: 2025-12-19BEIJING ZITIAO NETWORK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410793565.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-19
Publication Date
2025-12-19

AI Technical Summary

Technical Problem

In existing blurring algorithms, a large sampling step size leads to grid or layering effects in the blurred image, and the computational cost is relatively small, making it difficult to improve this problem without increasing the number of sampling points.

Method used

By randomly offsetting the pixels to be blurred in the initial image, the offset positions are obtained and blurred to generate blurred color values, thus breaking the regular arrangement of the grid effect or layering effect.

Benefits of technology

Without increasing the number of sampling points, reduce or avoid grid or layering effects in blurred images, thereby improving image quality.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121169743A_ABST
    Figure CN121169743A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides an image processing method and device, and relates to the technical field of image processing. Comprising the following steps: acquiring a pixel position of a first pixel point in an initial image; the first pixel point is any pixel point to be blurred in the initial image; performing random offset processing on the pixel position of the first pixel point to obtain an offset position corresponding to the first pixel point; determining an offset pixel point corresponding to the first pixel point according to the offset position corresponding to the first pixel point; performing fuzzy processing on the offset pixel point corresponding to the first pixel point to obtain a fuzzy color value corresponding to the first pixel point; and assigning the color value of the first pixel point as a blurred color value corresponding to the first pixel point to generate a blurred image corresponding to the initial image. The embodiment of the invention is used for reducing or avoiding a lattice effect or a layering effect in the image after fuzzy processing without increasing the number of sampling points.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of image processing technology, and in particular to an image processing method and apparatus. Background Technology

[0002] Blurring an image refers to processing the color values ​​of pixels in an image in a specific way, making the details and edges of the image blurry, thereby achieving effects such as protecting privacy, artistic creation, and reducing noise.

[0003] Currently, blurring algorithms typically sample within a certain neighborhood of a pixel using a preset sampling step size. Then, a weight coefficient for each sampled pixel is calculated using a certain formula. Finally, a weighted average of all sampled color values ​​and their corresponding weight coefficients is performed to obtain the blurred color value of the pixel. When blurring an image, a larger sampling step size results in fewer sampled points and less computational complexity. Conversely, a smaller sampling step size results in more sampled points and more computational complexity. In many scenarios, a larger sampling step size is used to reduce computational complexity. However, setting a large sampling step size can lead to insufficient sampling, resulting in uneven transitions between pixels in the blurred image, leading to grid-like or layered effects. Summary of the Invention

[0004] In view of this, embodiments of this application provide an image processing method and apparatus for reducing or avoiding grid effects or layering effects in blurred images without increasing the number of sampling points.

[0005] To achieve the above objectives, the technical solutions provided in this application are as follows:

[0006] In a first aspect, embodiments of this application provide an image processing method, including:

[0007] Obtain the pixel position of the first pixel in the initial image; the first pixel is any pixel in the initial image to be blurred.

[0008] The pixel position of the first pixel is randomly offset to obtain the offset position corresponding to the first pixel.

[0009] Based on the offset position corresponding to the first pixel, determine the offset pixel corresponding to the first pixel;

[0010] The offset pixel corresponding to the first pixel is blurred to obtain the blurred color value corresponding to the first pixel;

[0011] The color value of the first pixel is assigned to the blurred color value corresponding to the first pixel to generate the blurred image corresponding to the initial image.

[0012] As an optional implementation of this application, the step of randomly offsetting the pixel position of the first pixel to obtain the offset position corresponding to the first pixel includes:

[0013] Generate the first and second random numbers;

[0014] The second coordinate value is obtained based on the first random number and the first coordinate value, wherein the first coordinate value is the horizontal axis coordinate value of the pixel position of the first pixel.

[0015] A fourth coordinate value is obtained based on the second random number and the third coordinate value, wherein the third coordinate value is the vertical coordinate value of the pixel position of the first pixel.

[0016] The offset position corresponding to the first pixel is obtained based on the second coordinate value and the fourth coordinate value.

[0017] As an optional implementation method of this application,

[0018] The step of obtaining the second coordinate value based on the first random number and the first coordinate value includes: calculating the product of the first random number and the first preset coefficient to obtain a first calculated value; and summing the first coordinate value and the first calculated value to obtain the second coordinate value.

[0019] The step of obtaining the fourth coordinate value based on the second random number and the third coordinate value includes: calculating the product of the second random number and the second preset coefficient to obtain a second calculated value; and summing the third coordinate value and the second calculated value to obtain the fourth coordinate value.

[0020] As an optional implementation of this application, the step of blurring the offset pixel corresponding to the first pixel to obtain the blurred color value corresponding to the first pixel includes:

[0021] Based on a preset sampling step size and a preset neighborhood range, multiple sampling points corresponding to the offset pixel point corresponding to the first pixel point are determined;

[0022] The blurred color value corresponding to the first pixel is obtained based on the color value of each sampling point and the weight coefficient of each sampling point.

[0023] As an optional implementation of this application, obtaining the blurred color value corresponding to the first pixel based on the color value of each sampling point and the weight coefficient of each sampling point includes:

[0024] The color values ​​of each sampling point are weighted and summed according to the weight coefficient of each sampling point to obtain the total color value;

[0025] Sum the weight coefficients of each sampling point to obtain the total weight coefficient;

[0026] Calculate the ratio of the total color value to the total weight coefficient to obtain the blurred color value corresponding to the first pixel.

[0027] As an optional implementation of this application, the step of determining multiple sampling points corresponding to the offset pixel point corresponding to the first pixel point based on a preset sampling step size and a preset neighborhood range includes:

[0028] Determine whether the first pixel region is located within the initial image. The first pixel region is the region within a preset neighborhood range of the offset pixel corresponding to the first pixel.

[0029] If at least one pixel in the first pixel region is located outside the initial image, then the at least one pixel is assigned a value according to the initial image, and sampling is performed in the first pixel region based on the preset sampling step size to determine the plurality of sampling points.

[0030] As an optional implementation of this application, the step of determining multiple sampling points corresponding to the offset pixel point corresponding to the first pixel point based on a preset sampling step size and a preset neighborhood range includes:

[0031] Determine whether the first pixel region is located within the initial image. The first pixel region is the region within a preset neighborhood range of the offset pixel corresponding to the first pixel.

[0032] If at least one pixel in the first pixel region is located outside the initial image, a second pixel region is determined based on the first pixel region and the initial image, wherein the second pixel region is the region in the first pixel region that is located within the initial image.

[0033] Based on the preset sampling step size, samples are taken within the second pixel region to determine the plurality of sampling points.

[0034] Secondly, embodiments of this application provide an image processing apparatus, including:

[0035] The acquisition unit is used to acquire the pixel position of a first pixel in the initial image; the first pixel is any pixel in the initial image to be blurred.

[0036] An offset unit is used to randomly offset the pixel position of the first pixel to obtain the offset position corresponding to the first pixel.

[0037] The determining unit is used to determine the offset pixel corresponding to the first pixel based on the offset position corresponding to the first pixel.

[0038] The processing unit is used to perform blurring processing on the offset pixel corresponding to the first pixel to obtain the blurred color value corresponding to the first pixel.

[0039] The generation unit is used to assign the color value of the first pixel to the blurred color value corresponding to the first pixel, so as to generate a blurred image corresponding to the initial image.

[0040] As an optional implementation of this application, the offset unit is specifically used to generate a first random number and a second random number; obtain a second coordinate value based on the first random number and a first coordinate value, wherein the first coordinate value is the horizontal coordinate value of the pixel position of the first pixel; obtain a fourth coordinate value based on the second random number and a third coordinate value, wherein the third coordinate value is the vertical coordinate value of the pixel position of the first pixel; and obtain the offset position corresponding to the first pixel based on the second coordinate value and the fourth coordinate value.

[0041] As an optional implementation of this application, the offset unit is specifically used to calculate the product of the first random number and the first preset coefficient to obtain a first calculated value; sum the first coordinate value and the first calculated value to obtain a second coordinate value; calculate the product of the second random number and the second preset coefficient to obtain a second calculated value; and sum the third coordinate value and the second calculated value to obtain a fourth coordinate value.

[0042] As an optional implementation of this application, the processing unit is specifically used to determine multiple sampling points corresponding to the offset pixel point corresponding to the first pixel point based on a preset sampling step size and a preset neighborhood range; and to obtain the blurred color value corresponding to the first pixel point according to the color value of each sampling point and the weight coefficient of each sampling point.

[0043] As an optional implementation of this application, the processing unit is specifically used to: sum the color values ​​of each sampling point according to the weight coefficient of each sampling point to obtain a total color value; sum the weight coefficients of each sampling point to obtain a total weight coefficient; and calculate the ratio of the total color value to the total weight coefficient to obtain the blurred color value corresponding to the first pixel.

[0044] As an optional implementation of this application, the processing unit is specifically used to determine whether a first pixel region is located within the initial image, wherein the first pixel region is a region within a preset neighborhood range of the offset pixel corresponding to the first pixel; if at least one pixel in the first pixel region is located outside the initial image, then the at least one pixel is assigned a value according to the initial image, and samples are performed within the first pixel region based on the preset sampling step size to determine the plurality of sampling points.

[0045] As an optional implementation of this application, the processing unit is specifically used to determine whether a first pixel region is located within the initial image, wherein the first pixel region is a region within a preset neighborhood of the offset pixel corresponding to the first pixel; if at least one pixel in the first pixel region is located outside the initial image, a second pixel region is determined based on the first pixel region and the initial image, wherein the second pixel region is a region in the first pixel region located within the initial image; and sampling is performed within the second pixel region based on the preset sampling step size to determine the plurality of sampling points.

[0046] Thirdly, embodiments of this application provide an electronic device, including: a memory and a processor, wherein the memory is used to store a computer program and the processor is used to cause the electronic device to implement the image processing method described in any of the above embodiments when executing the computer program.

[0047] Fourthly, embodiments of this application provide a computer-readable storage medium that, when executed by a computing device, causes the computing device to implement the image processing method described in any of the above embodiments.

[0048] Fifthly, embodiments of this application provide a computer program product that, when run on a computer, enables the computer to implement the image processing method described in any of the above embodiments.

[0049] The image processing method provided in this application, after obtaining the pixel position of the first pixel to be blurred in the initial image, first performs random offset processing on the pixel position of the first pixel to obtain the offset position corresponding to the first pixel. Then, based on the offset position corresponding to the first pixel, it determines the offset pixel corresponding to the first pixel, and performs blur processing on the offset pixel corresponding to the first pixel to obtain the blur color value corresponding to the first pixel. Finally, it assigns the color value of the first pixel to the blur color value corresponding to the first pixel to generate a blurred image corresponding to the initial image. Since this application embodiment performs blur processing on the offset pixel corresponding to the pixel to be blurred to obtain the blur color value corresponding to the first pixel, and assigns the color value of the first pixel to the blur color value corresponding to the first pixel, this application embodiment can break the regular arrangement of the original grid effect or layering effect, thereby reducing or avoiding the grid effect or layering effect in the blurred image without increasing the number of sampling points. Attached Figure Description

[0050] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.

[0051] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the accompanying drawings that need to be called in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0052] Figure 1 A flowchart illustrating the steps of the image processing method provided in this application embodiment;

[0053] Figure 2 A flowchart illustrating the steps of another image processing method provided in this application embodiment;

[0054] Figure 3 One of the schematic diagrams for assigning pixel values ​​in the embodiments of this application;

[0055] Figure 4 A second schematic diagram illustrating pixel assignment for embodiments of this application;

[0056] Figure 5 A schematic diagram of the second pixel region is provided for an embodiment of this application;

[0057] Figure 6 This is a schematic diagram of the structure of the image processing apparatus provided in the embodiments of this application;

[0058] Figure 7This is a schematic diagram of the hardware structure of the electronic device provided in the embodiments of this application. Detailed Implementation

[0059] To better understand the above-mentioned objectives, features, and advantages of this application, the solution of this application will be further described below. It should be noted that, unless otherwise specified, the embodiments and features described in these embodiments can be combined with each other.

[0060] Many specific details are set forth in the following description in order to provide a full understanding of this application, but this application may also be implemented in other ways different from those described herein. Obviously, the embodiments in the specification are only some embodiments of this application, and not all embodiments.

[0061] In the embodiments of this application, the terms "exemplary" or "for example" are used to indicate examples, illustrations, or explanations. Any embodiment or design described as "exemplary" or "for example" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or design solutions. Specifically, the use of terms such as "exemplary" or "for example" is intended to present the relevant concepts in a specific manner. Furthermore, in the description of the embodiments of this application, unless otherwise stated, "multiple" means two or more.

[0062] This application provides an image processing method, referring to... Figure 1 As shown, the image processing method includes the following steps:

[0063] S101. Obtain the pixel position of the first pixel in the initial image.

[0064] Wherein, the first pixel is any pixel in the initial image that needs to be blurred.

[0065] In this application embodiment, the initial image refers to the image that needs to be blurred, and the initial image can be any type of image.

[0066] In some embodiments, before obtaining the pixel position of the first pixel in the initial image, all pixels in the initial image that need to be blurred can be determined first to obtain a set of pixels to be blurred. Then, the pixels in the set of pixels to be blurred are traversed, and the current pixel is used as the first pixel to execute the image processing method provided in this application embodiment.

[0067] S102. Randomly offset the pixel position of the first pixel to obtain the offset position corresponding to the first pixel.

[0068] That is, an offset value is added to the pixel position of the first pixel to obtain another pixel position, and the newly obtained pixel position is determined as the pixel position of the first pixel.

[0069] In some embodiments, the pixel position of the first pixel includes: a horizontal axis coordinate value and a vertical axis coordinate value. Step S102 (randomly offsetting the pixel position of the first pixel to obtain the offset position corresponding to the first pixel) includes the following steps a to d:

[0070] Step a: Generate the first random number and the second random number.

[0071] That is, generate two random numbers and define the two random numbers as the first random number and the second random number, respectively.

[0072] Step b: Obtain the second coordinate value based on the first random number and the first coordinate value.

[0073] Wherein, the first coordinate value is the horizontal axis coordinate value of the pixel position of the first pixel.

[0074] In some embodiments, obtaining the second coordinate value based on the first random number and the first coordinate value includes:

[0075] The first random number is summed with the first coordinate value to obtain the second coordinate value.

[0076] That is, if we represent the first random number as p, the first coordinate value as x1, and the second coordinate value as x2, then we have:

[0077] x2 = x1 + p

[0078] Step c: Obtain the fourth coordinate value based on the second random number and the third coordinate value.

[0079] The third coordinate value is the vertical coordinate of the pixel position of the first pixel.

[0080] In some embodiments, obtaining a fourth coordinate value based on the second random number and the third coordinate value includes:

[0081] The second random number is summed with the third coordinate value to obtain the fourth coordinate value.

[0082] That is, if the second random number is denoted as q, the third coordinate value is denoted as y1, and the fourth coordinate value is denoted as y2, then:

[0083] y2=y1+q

[0084] Step d: Obtain the offset position corresponding to the first pixel point based on the second coordinate value and the fourth coordinate value.

[0085] As mentioned in the previous example, the second coordinate is x2 and the fourth coordinate is y2. Therefore, the coordinates of the offset position corresponding to the first pixel are (x2, y2).

[0086] S103. Determine the offset pixel corresponding to the first pixel based on the offset position corresponding to the first pixel.

[0087] In some embodiments, determining the offset pixel corresponding to the first pixel based on the offset position corresponding to the first pixel includes: determining the pixel whose center is closest to the offset position corresponding to the first pixel as the offset pixel corresponding to the first pixel.

[0088] That is, calculate the distance from the center of each pixel around the offset position corresponding to the first pixel to the offset position corresponding to the first pixel, and determine the pixel with the smallest distance as the offset pixel corresponding to the first pixel.

[0089] S104. Blur the offset pixel corresponding to the first pixel to obtain the blurred color value corresponding to the first pixel.

[0090] This application does not limit the blurring algorithm used when blurring the offset pixel corresponding to the first pixel. For example, the blurring algorithm can be: mean blur, Gaussian blur, median blur, bilateral filtering, guided filtering, etc.

[0091] S105. Assign the color value of the first pixel to the blurred color value corresponding to the first pixel to generate a blurred image corresponding to the initial image.

[0092] That is, for each pixel in the initial image to be blurred, the above steps S101 to S104 are used to obtain the blur color value corresponding to each pixel in the initial image to be blurred, and then the color value of each pixel in the initial image to be blurred is replaced with the corresponding blur color value, thereby obtaining the blurred image corresponding to the initial image.

[0093] The image processing method provided in this application, after obtaining the pixel position of the first pixel to be blurred in the initial image, first performs random offset processing on the pixel position of the first pixel to obtain the offset position corresponding to the first pixel. Then, based on the offset position corresponding to the first pixel, it determines the offset pixel corresponding to the first pixel, and performs blur processing on the offset pixel corresponding to the first pixel to obtain the blur color value corresponding to the first pixel. Finally, it assigns the color value of the first pixel to the blur color value corresponding to the first pixel to generate a blurred image corresponding to the initial image. Since this application embodiment performs blur processing on the offset pixel corresponding to the pixel to be blurred to obtain the blur color value corresponding to the first pixel, and assigns the color value of the first pixel to the blur color value corresponding to the first pixel, this application embodiment can break the regular arrangement of the original grid effect or layering effect, thereby reducing or avoiding the grid effect or layering effect in the blurred image without increasing the number of sampling points.

[0094] As an extension and refinement of the above embodiments, another embodiment of this application provides an image processing method, referring to... Figure 2 As shown, the image processing method includes the following steps:

[0095] S201. Obtain the pixel position of the first pixel in the initial image.

[0096] Wherein, the first pixel is any pixel in the initial image that needs to be blurred.

[0097] S202, Generate the first random number and the second random number.

[0098] In some embodiments, the first random number and the second random number can be generated by a pseudo-random number generator.

[0099] S203. Calculate the product of the first random number and the first preset coefficient to obtain the first calculated value.

[0100] Let p be the first random number, a be the first preset coefficient, and m be the first calculated value, then we have:

[0101] m = p * a

[0102] S204. Sum the first coordinate value and the first calculated value to obtain the second coordinate value.

[0103] Wherein, the first coordinate value is the horizontal axis coordinate value of the pixel position of the first pixel.

[0104] Let the first coordinate value be denoted as x1 and the second coordinate value as x2, then we have:

[0105] x2=x1+m=x1+p*a

[0106] S205. Calculate the product of the second random number and the second preset coefficient to obtain the second calculated value.

[0107] Wherein, the second coordinate value is the vertical coordinate value of the pixel position of the first pixel.

[0108] Let q represent the second random number, b represent the second preset coefficient, and n represent the second calculated value, then we have:

[0109] n = q * b

[0110] In some embodiments, the first preset coefficient is equal to the second preset coefficient.

[0111] S206. Sum the third coordinate value and the second calculated value to obtain the fourth coordinate value.

[0112] Let the third coordinate value be y1 and the second coordinate value be y2, then we have:

[0113] y2=y1+n=y1+q*b

[0114] S207. Obtain the offset position corresponding to the first pixel point based on the second coordinate value and the fourth coordinate value.

[0115] S208. Determine the offset pixel corresponding to the first pixel based on the offset position corresponding to the first pixel.

[0116] S209. Determine multiple sampling points corresponding to the offset pixel point corresponding to the first pixel point based on the preset sampling step size and the preset neighborhood range.

[0117] In some embodiments, step S209 (determining multiple sampling points corresponding to the offset pixel point corresponding to the first pixel point based on a preset sampling step size and a preset neighborhood range) includes the following steps 1 to 4:

[0118] Step 1: Determine whether the first pixel region is located within the initial image.

[0119] Wherein, the first pixel region is the region within a preset neighborhood range of the offset pixel corresponding to the first pixel.

[0120] In step 1 above, if all pixels in the first pixel region are located within the initial image, then step 2 is executed as follows:

[0121] Step 2: Sample within the first pixel area based on the preset sampling step size to determine the plurality of sampling points.

[0122] In step 1 above, if at least one pixel in the first pixel region is located outside the initial image, then steps 3 and 4 are executed as follows:

[0123] Step 3: Assign a value to the at least one pixel based on the initial image.

[0124] In some embodiments, assigning a value to the at least one pixel based on the initial image includes: obtaining the symmetrical pixel corresponding to each of the at least one pixel, and assigning the color value of each pixel to the color value of the corresponding symmetrical pixel. Wherein, the symmetrical pixel corresponding to any pixel is a pixel that is symmetrical about the boundary of the initial image.

[0125] For example, refer to Figure 3 As shown, Figure 3 The example uses an initial image with a resolution of 12*12 pixels and a preset neighborhood of 4 pixels. The pixel coordinates of the first pixel are (2, 4), and the pixel coordinates of the offset pixel corresponding to the first pixel are (7, 11). Multiple pixels in the first pixel region 31 within the preset neighborhood of the offset pixel corresponding to the first pixel are located outside the initial image 300. Therefore, the color values ​​of each pixel located outside the initial image 300 are assigned the color values ​​of the corresponding symmetrical pixels. For example, the color value of the pixel with pixel coordinates (4, 14) is assigned the color value of the pixel with pixel coordinates (4, 11). Another example: the color value of the pixel with pixel coordinates (6, 13) is assigned the color value of the pixel with pixel coordinates (6, 12).

[0126] In some embodiments, assigning a value to the at least one pixel based on the initial image includes: obtaining the nearest neighbor pixel corresponding to each of the at least one pixel, and assigning the color value of each pixel to the color value of its corresponding nearest neighbor pixel. Wherein, the nearest neighbor pixel corresponding to any pixel is the pixel with the smallest distance from that pixel in the initial image.

[0127] For example, refer to Figure 4 As shown, Figure 4The example uses an initial image with a resolution of 12*12 pixels and a preset neighborhood of 4 pixels. The pixel coordinates of the first pixel are (2, 4), and the pixel coordinates of the offset pixel corresponding to the first pixel are (7, 11). Multiple pixels in the first pixel region 41 within the preset neighborhood of the offset pixel corresponding to the first pixel are located outside the initial image 400. Therefore, the color value of each pixel located outside the initial image 400 is assigned the color value of its nearest neighbor pixel. For example, the color value of the pixel with pixel coordinates (6, 13) is assigned the color value of the pixel with pixel coordinates (6, 12). Another example: the color value of the pixel with pixel coordinates (9, 13) is assigned the color value of the pixel with pixel coordinates (9, 12).

[0128] In some embodiments, assigning a value to the at least one pixel based on the initial image includes: determining a preset value based on the initial image and assigning the color value of the at least one pixel to the preset value.

[0129] In some embodiments, the preset value may be the average color value of each pixel in the initial image.

[0130] In some embodiments, the preset value can be 0.

[0131] Step 4: Sample within the first pixel region based on the preset sampling step size to determine the plurality of sampling points.

[0132] In some embodiments, step S209 (determining multiple sampling points corresponding to the offset pixel point corresponding to the first pixel point based on a preset sampling step size and a preset neighborhood range) includes the following steps ① to ④:

[0133] Step ①: Determine whether the first pixel region is located within the initial image.

[0134] Wherein, the first pixel region is the region within a preset neighborhood range of the offset pixel corresponding to the first pixel.

[0135] In step ① above, if all pixels in the first pixel region are located within the initial image, then step ② is executed as follows:

[0136] Step 2: Sample within the first pixel region based on the preset sampling step size to determine the plurality of sampling points.

[0137] In step ① above, if at least one pixel in the first pixel region is located outside the initial image, then steps ③ and ④ are executed as follows:

[0138] Step 3: Determine the second pixel region based on the first pixel region and the initial image.

[0139] The second pixel region is the region within the initial image that is located in the first pixel region.

[0140] Step 4: Sample within the second pixel region based on the preset sampling step size to determine the plurality of sampling points.

[0141] For example, refer to Figure 5 As shown, Figure 5 The example uses an initial image with a resolution of 12*12 and a preset neighborhood range of 4 pixels. The pixel coordinates of the first pixel are (4, 5), and the pixel coordinates of the offset pixel corresponding to the first pixel are (10, 10). Multiple pixels in the first pixel region 51 within the preset neighborhood range of the offset pixel corresponding to the first pixel are located outside the initial image 400. Therefore, a second pixel region 52 is determined based on the first pixel region 51 and the initial image 500, and sampling is performed within the second pixel region based on the preset sampling step size to determine the multiple sampling points.

[0142] S210. Obtain the blurred color value corresponding to the first pixel point based on the color value of each sampling point and the weight coefficient of each sampling point.

[0143] In some embodiments, step S210 (obtaining the blurred color value corresponding to the first pixel based on the color value of each sampling point and the weight coefficient of each sampling point) includes: weighting and summing the color values ​​of each sampling point according to the weight coefficient of each sampling point to obtain a total color value; summing the weight coefficients of each sampling point to obtain a total weight coefficient; and calculating the ratio of the total color value to the total weight coefficient to obtain the blurred color value corresponding to the first pixel.

[0144] That is, the blurred color value corresponding to a pixel is represented as I. 模糊 The color value of the i-th sampling point is represented as I. i The weight coefficient of the i-th sampling point is represented as w. i Then we have:

[0145]

[0146] Where N is the total number of sampling points.

[0147] That is, the color values ​​of each sampling point are weighted and averaged according to the weight coefficient of each sampling point to obtain the blurred color value corresponding to the first pixel.

[0148] S211. Assign the color value of the first pixel to the blurred color value corresponding to the first pixel to generate a blurred image corresponding to the initial image.

[0149] Based on the same inventive concept, as an implementation of the above method, this application also provides an image processing device. This embodiment corresponds to the aforementioned method embodiment. For ease of reading, this embodiment will not repeat the details of the aforementioned method embodiment one by one, but it should be clear that the image processing device in this embodiment can implement all the contents of the aforementioned method embodiment.

[0150] This application provides an image processing apparatus. Figure 6 This is a schematic diagram of the image processing device, as shown below. Figure 6 As shown, the image processing apparatus 600 includes:

[0151] The acquisition unit 61 is used to acquire the pixel position of a first pixel in the initial image; the first pixel is any pixel in the initial image to be blurred.

[0152] Offset unit 62 is used to perform random offset processing on the pixel position of the first pixel to obtain the offset position corresponding to the first pixel.

[0153] The determining unit 63 is used to determine the offset pixel corresponding to the first pixel based on the offset position corresponding to the first pixel.

[0154] Processing unit 64 is used to perform blurring processing on the offset pixel corresponding to the first pixel to obtain the blurred color value corresponding to the first pixel.

[0155] The generation unit 65 is used to assign the color value of the first pixel to the blurred color value corresponding to the first pixel, so as to generate a blurred image corresponding to the initial image.

[0156] As an optional implementation of this application, the offset unit 62 is specifically used to generate a first random number and a second random number; obtain a second coordinate value based on the first random number and a first coordinate value, wherein the first coordinate value is the horizontal coordinate value of the pixel position of the first pixel; obtain a fourth coordinate value based on the second random number and a third coordinate value, wherein the third coordinate value is the vertical coordinate value of the pixel position of the first pixel; and obtain the offset position corresponding to the first pixel based on the second coordinate value and the fourth coordinate value.

[0157] As an optional implementation of this application, the offset unit 62 is specifically used to calculate the product of the first random number and the first preset coefficient to obtain a first calculated value; sum the first coordinate value and the first calculated value to obtain a second coordinate value; calculate the product of the second random number and the second preset coefficient to obtain a second calculated value; and sum the third coordinate value and the second calculated value to obtain a fourth coordinate value.

[0158] As an optional implementation of this application, the processing unit 64 is specifically used to determine multiple sampling points corresponding to the offset pixel point corresponding to the first pixel point based on a preset sampling step size and a preset neighborhood range; and to obtain the blurred color value corresponding to the first pixel point according to the color value of each sampling point and the weight coefficient of each sampling point.

[0159] As an optional implementation of this application, the processing unit 64 is specifically used to perform a weighted summation of the color values ​​of each sampling point according to the weight coefficient of each sampling point to obtain a total color value; to sum the weight coefficients of each sampling point to obtain a total weight coefficient; and to calculate the ratio of the total color value to the total weight coefficient to obtain the blurred color value corresponding to the first pixel.

[0160] As an optional implementation of this application, the processing unit 64 is specifically used to determine whether a first pixel region is located within the initial image, wherein the first pixel region is a region within a preset neighborhood range of the offset pixel corresponding to the first pixel; if at least one pixel in the first pixel region is located outside the initial image, then the at least one pixel is assigned a value according to the initial image, and samples are performed within the first pixel region based on the preset sampling step size to determine the plurality of sampling points.

[0161] As an optional implementation of this application, the processing unit 64 is specifically used to determine whether a first pixel region is located within the initial image, wherein the first pixel region is a region within a preset neighborhood of the offset pixel corresponding to the first pixel; if at least one pixel in the first pixel region is located outside the initial image, a second pixel region is determined based on the first pixel region and the initial image, wherein the second pixel region is a region in the first pixel region located within the initial image; and sampling is performed within the second pixel region based on the preset sampling step size to determine the plurality of sampling points.

[0162] The image processing apparatus provided in this application embodiment can execute the image processing method provided in any of the above embodiments. Its implementation principle and technical effect are similar, and will not be described again here.

[0163] Based on the same inventive concept, embodiments of this application also provide an electronic device. Figure 7 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application, such as... Figure 7 As shown, the electronic device provided in this embodiment includes a memory 71 and a processor 72. The memory 71 is used to store computer programs, and the processor 72 is used to execute the image processing method provided in the above embodiment when executing the computer programs.

[0164] Based on the same inventive concept, embodiments of this application also provide a computer-readable storage medium storing a computer program, which, when executed by a processor, causes the computing device to implement the image processing method provided in the above embodiments.

[0165] Based on the same inventive concept, this application also provides a computer program product that, when run on a computer, enables the computing device to implement the image processing method provided in the above embodiments.

[0166] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product implemented on one or more computer-usable storage media containing computer-usable program code.

[0167] The processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor can be a microprocessor or any conventional processor.

[0168] Memory may include non-persistent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, like read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.

[0169] Computer-readable media include both permanent and non-permanent, removable and non-removable storage media. Storage media can store information using any method or technology; the information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media do not include transient computer-readable media, such as modulated data signals and carrier waves.

[0170] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the foregoing embodiments, or make equivalent substitutions for some or all of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.

Claims

1. An image processing method, characterized in that, include: Get the pixel position of the first pixel in the initial image; The first pixel is any pixel in the initial image that needs to be blurred; The pixel position of the first pixel is randomly offset to obtain the offset position corresponding to the first pixel. Based on the offset position corresponding to the first pixel, determine the offset pixel corresponding to the first pixel; The offset pixel corresponding to the first pixel is blurred to obtain the blurred color value corresponding to the first pixel; The color value of the first pixel is assigned to the blurred color value corresponding to the first pixel to generate the blurred image corresponding to the initial image.

2. The method according to claim 1, characterized in that, The step of randomly offsetting the pixel position of the first pixel to obtain the offset position corresponding to the first pixel includes: Generate the first and second random numbers; The second coordinate value is obtained based on the first random number and the first coordinate value, wherein the first coordinate value is the horizontal axis coordinate value of the pixel position of the first pixel. A fourth coordinate value is obtained based on the second random number and the third coordinate value, wherein the third coordinate value is the vertical coordinate value of the pixel position of the first pixel. The offset position corresponding to the first pixel is obtained based on the second coordinate value and the fourth coordinate value.

3. The method according to claim 2, characterized in that, The step of obtaining the second coordinate value based on the first random number and the first coordinate value includes: calculating the product of the first random number and the first preset coefficient to obtain a first calculated value; and summing the first coordinate value and the first calculated value to obtain the second coordinate value. The step of obtaining the fourth coordinate value based on the second random number and the third coordinate value includes: calculating the product of the second random number and the second preset coefficient to obtain a second calculated value; and summing the third coordinate value and the second calculated value to obtain the fourth coordinate value.

4. The method according to claim 1, characterized in that, The step of blurring the offset pixel corresponding to the first pixel to obtain the blurred color value corresponding to the first pixel includes: Based on a preset sampling step size and a preset neighborhood range, multiple sampling points corresponding to the offset pixel point corresponding to the first pixel point are determined; The blurred color value corresponding to the first pixel is obtained based on the color value of each sampling point and the weight coefficient of each sampling point.

5. The method according to claim 4, characterized in that, The step of obtaining the blurred color value corresponding to the first pixel based on the color value of each sampling point and the weight coefficient of each sampling point includes: The color values ​​of each sampling point are weighted and summed according to the weight coefficient of each sampling point to obtain the total color value; Sum the weight coefficients of each sampling point to obtain the total weight coefficient; Calculate the ratio of the total color value to the total weight coefficient to obtain the blurred color value corresponding to the first pixel.

6. The method according to claim 4, characterized in that, The step of determining multiple sampling points corresponding to the offset pixel point corresponding to the first pixel point based on a preset sampling step size and a preset neighborhood range includes: Determine whether the first pixel region is located within the initial image. The first pixel region is the region within a preset neighborhood range of the offset pixel corresponding to the first pixel. If at least one pixel in the first pixel region is located outside the initial image, then the at least one pixel is assigned a value according to the initial image, and sampling is performed in the first pixel region based on the preset sampling step size to determine the plurality of sampling points.

7. The method according to claim 4, characterized in that, The step of determining multiple sampling points corresponding to the offset pixel point corresponding to the first pixel point based on a preset sampling step size and a preset neighborhood range includes: Determine whether the first pixel region is located within the initial image. The first pixel region is the region within a preset neighborhood range of the offset pixel corresponding to the first pixel. If at least one pixel in the first pixel region is located outside the initial image, a second pixel region is determined based on the first pixel region and the initial image, wherein the second pixel region is the region in the first pixel region that is located within the initial image. Based on the preset sampling step size, samples are taken within the second pixel region to determine the plurality of sampling points.

8. An image processing apparatus, characterized in that, include: The acquisition unit is used to acquire the pixel position of the first pixel in the initial image; The first pixel is any pixel in the initial image that needs to be blurred; An offset unit is used to randomly offset the pixel position of the first pixel to obtain the offset position corresponding to the first pixel. The determining unit is used to determine the offset pixel corresponding to the first pixel based on the offset position corresponding to the first pixel. The processing unit is used to perform blurring processing on the offset pixel corresponding to the first pixel to obtain the blurred color value corresponding to the first pixel. The generation unit is used to assign the color value of the first pixel to the blurred color value corresponding to the first pixel, so as to generate a blurred image corresponding to the initial image.

9. An electronic device, characterized in that, include: A memory and a processor, the memory being used to store a computer program and the processor being used to cause the electronic device to implement the image processing method according to any one of claims 1-7 when executing the computer program.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a computing device, causes the computing device to implement the image processing method according to any one of claims 1-7.