Image processing method, device, electronic device and storage medium

By generating masks and performing straight line fitting and gradient value correction, the problem of poor edge protrusion elimination in images is solved, achieving smoother edges and more efficient image processing effects.

CN114494058BActive Publication Date: 2024-09-24HEFEI YUQIANG INFORMATION TECHNOLOGY CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202210078688.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-01-24
Publication Date
2024-09-24
Estimated Expiration
2042-01-24

AI Technical Summary

Technical Problem

When the existing technology eliminates edge protrusions of objects to be identified in images, the accuracy and effect are poor, resulting in insufficient smooth edges and affecting the image processing effect.

Method used

By generating masks, perform straight line fitting and gradient value acquisition, correct edges, and generate new masks to eliminate protrusions and ensure smooth edges.

Benefits of technology

Effectively eliminate the protrusions on each edge of the target object in the image, making the edges smoother and improving the image processing effect.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114494058B
    Figure CN114494058B
Patent Text Reader

Abstract

The embodiment of the present application discloses an image processing method, device, electronic device and storage medium, which can effectively eliminate the protrusions on each edge of the target object in the image to be processed, so that each edge is relatively smooth, and the image processing effect is improved. The method of the embodiment of the present application includes: generating a mask corresponding to the image to be processed, the mask is used to mark the image position corresponding to the target object in the image to be processed; performing straight line fitting on each edge of the target object in the mask to obtain the slope corresponding to each fitted straight line, and obtaining the gradient value corresponding to each pixel point on each edge of the target object in the image to be processed; using the slope corresponding to each straight line and the gradient value corresponding to each pixel point on each edge, each edge of the target object in the mask is corrected to obtain a new mask; according to the new mask and the image to be processed, the target image is obtained.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

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

[0002] In order to improve the recognition accuracy of the image, the object to be recognized in the image will be processed, such as eliminating the protrusions on the edge of the object to be recognized. At present, the morphological algorithm of the image is generally used to eliminate the protrusions on the edge of the object to be recognized in the image, such as an opening operation or a closing operation. Specifically, the opening operation refers to first performing an erosion operation on the image and then performing an expansion operation, while the closing operation refers to first performing an expansion operation on the image and then performing an erosion operation. Among them, the erosion operation refers to expanding the highlight area or white part of the image, and the brightness area of ​​the obtained erosion map is larger than the brightness area of ​​the image, while the expansion operation refers to reducing and refining the highlight area or white part of the image, and the brightness area of ​​the obtained expansion map is smaller than the brightness area of ​​the image.

[0003] Whether it is an opening operation or a closing operation, to a certain extent, it is impossible to accurately and effectively eliminate the protrusions generated on the edge of the object to be identified, so that the edge of the object to be identified is not smooth enough. Summary of the invention

[0004] The embodiments of the present application provide an image processing method, device, electronic device and storage medium, which can effectively eliminate the protrusions on each edge of the target object in the image to be processed, so that each edge of the target object is smoother, thereby improving the image processing effect.

[0005] A first aspect of the embodiments of the present application provides an image processing method, which may include:

[0006] Generate a mask corresponding to the image to be processed, where the mask is used to mark the image position corresponding to the target object in the image to be processed;

[0007] Performing straight line fitting on each edge of the target object in the mask to obtain the slope corresponding to each fitted straight line, and obtaining the gradient value corresponding to each pixel point on each edge of the target object in the image to be processed;

[0008] Using the slope corresponding to each straight line and the gradient value corresponding to each pixel point on each edge, each edge of the target object in the mask is corrected to obtain a new mask;

[0009] A target image is obtained according to the new mask and the image to be processed.

[0010] Optionally, the slope corresponding to each straight line and the gradient value corresponding to each pixel point on each edge are used to correct each edge of the target object in the mask to obtain a new mask, including: if it is determined that the slope corresponding to the first straight line is not infinite, then according to the slope corresponding to the first straight line and a preset threshold, the slope range corresponding to the first straight line is determined, and the first straight line is any straight line among each straight line; using the slope range corresponding to each straight line and the gradient value corresponding to each pixel point on each edge, each edge of the target object in the mask is corrected to obtain a new mask.

[0011] Optionally, the slope range corresponding to each straight line and the gradient value corresponding to each pixel on each edge are used to correct each edge of the target object in the mask, including: if it is determined that the first gradient value corresponding to the first pixel is not within the slope range corresponding to the first straight line, the pixel value corresponding to the first pixel in the mask is set to a preset pixel value; wherein the first pixel is any pixel among each pixel on the first edge corresponding to the first straight line, and the preset pixel value is used to indicate that the pixel belongs to the background image area.

[0012] Optionally, the slope corresponding to each straight line and the gradient value corresponding to each pixel on each edge are used to correct each edge of the target object in the mask, including: if it is determined that the slope corresponding to the first straight line is infinite, then judging whether the first gradient direction corresponding to the first pixel in the image to be processed is a vertical direction of the first straight line, the first straight line is any straight line among each straight line, and the first pixel is any pixel among each pixel on the first edge corresponding to the first straight line; if the first gradient direction is a vertical direction of the first straight line, then setting the pixel value corresponding to the first pixel in the mask to a preset pixel value, and the preset pixel value is used to indicate that the pixel belongs to the background image area.

[0013] Optionally, obtaining the target image according to the new mask and the image to be processed includes: multiplying the pixel value of each pixel in the new mask with the pixel value of the pixel at the same image position in the image to be processed to obtain the target image.

[0014] Optionally, generating a mask corresponding to the image to be processed includes: extracting color features of the image to be processed and / or various shape features contained in the object in the image to be processed; identifying the target object included in the image to be processed according to the color features and / or the shape features, and generating a mask corresponding to the image to be processed.

[0015] Optionally, the target object is a regular polygonal object or an irregular polygonal object.

[0016] A second aspect of the embodiments of the present application provides an image processing device, which may include:

[0017] A processing module, used to generate a mask corresponding to the image to be processed, where the mask is used to mark the image position corresponding to the target object in the image to be processed;

[0018] An acquisition module is used to perform straight line fitting on each edge of the target object in the mask to obtain the slope corresponding to each fitted straight line, and to obtain the gradient value corresponding to each pixel point on each edge of the target object in the image to be processed;

[0019] The processing module is also used to correct each edge of the target object in the mask using the slope corresponding to each straight line and the gradient value corresponding to each pixel point on each edge to obtain a new mask; and obtain the target image based on the new mask and the image to be processed.

[0020] Optionally, the processing module is specifically used to determine the slope range corresponding to the first straight line based on the slope corresponding to the first straight line and a preset threshold if it is determined that the slope corresponding to the first straight line is not infinite, and the first straight line is any straight line among each straight line; and use the slope range corresponding to each straight line and the gradient value corresponding to each pixel point on each edge to correct each edge of the target object in the mask to obtain a new mask.

[0021] Optionally, the processing module is specifically used to set the pixel value corresponding to the first pixel point in the mask to a preset pixel value if it is determined that the first gradient value corresponding to the first pixel point is not within the slope range corresponding to the first straight line; wherein the first pixel point is any pixel point among each pixel point on the first edge corresponding to the first straight line, and the preset pixel value is used to indicate that the pixel point belongs to the background image area.

[0022] Optionally, the processing module is specifically used to determine whether a first gradient direction corresponding to a first pixel point in the image to be processed is a vertical direction of the first straight line if it is determined that the slope corresponding to the first straight line is infinite, the first straight line being any straight line among each straight line, and the first pixel point being any pixel point among each pixel point on a first edge corresponding to the first straight line; if the first gradient direction is a vertical direction of the first straight line, the pixel value corresponding to the first pixel point in the mask is set to a preset pixel value, and the preset pixel value is used to indicate that the pixel point belongs to the background image area.

[0023] Optionally, the processing module is specifically configured to multiply the pixel value of each pixel point in the new mask by the pixel value of the pixel point at the same image position in the image to be processed, so as to obtain the target image.

[0024] Optionally, the processing module is specifically used to extract color features of the image to be processed and / or various shape features contained in the object in the image to be processed; identify the target object included in the image to be processed according to the color features and / or the shape features, and generate a mask corresponding to the image to be processed.

[0025] Optionally, the target object is a regular polygonal object or an irregular polygonal object.

[0026] A third aspect of the embodiments of the present application provides an electronic device, which may include:

[0027] A memory storing executable program code;

[0028] and a processor coupled to the memory;

[0029] The processor calls the executable program code stored in the memory, and when the executable program code is executed by the processor, the processor implements the method described in the first aspect of the embodiment of the present application.

[0030] Another aspect of the embodiments of the present application provides a computer-readable storage medium having executable program code stored thereon. When the executable program code is executed by a processor, the method described in the first aspect of the embodiments of the present application is implemented.

[0031] Yet another aspect of the embodiments of the present application discloses a computer program product. When the computer program product is run on a computer, the computer is enabled to execute any one of the methods disclosed in the first aspect of the embodiments of the present application.

[0032] Another aspect of an embodiment of the present application discloses an application publishing platform, which is used to publish a computer program product. When the computer program product runs on a computer, the computer executes any one of the methods disclosed in the first aspect of the embodiment of the present application.

[0033] It can be seen from the above technical solutions that the embodiments of the present application have the following advantages:

[0034] In an embodiment of the present application, a mask corresponding to the image to be processed is generated, and the mask can accurately mark the image position corresponding to the target object in the image to be processed; then, a straight line fitting is performed on each edge of the target object in the mask to obtain the slope corresponding to each edge, and the gradient value corresponding to each pixel point on each edge of the target object in the image to be processed is obtained; then, each edge of the target object in the mask is corrected using the slope corresponding to each straight line and the gradient value corresponding to each pixel point on each edge to obtain a new mask; finally, based on the new mask and the image to be processed, the target image is obtained, which can effectively eliminate the protrusions on each edge of the target object in the image to be processed, so that each edge of the target object in the target image is smoother, thereby improving the image processing effect. BRIEF DESCRIPTION OF THE DRAWINGS

[0035] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments and the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application, and other drawings can be obtained based on these drawings.

[0036] Figure 1 A schematic diagram of an embodiment of an image processing method in an embodiment of the present application;

[0037] Figure 2a This is a schematic diagram of an embodiment of an image to be processed in an embodiment of the present application;

[0038] Figure 2b This is a schematic diagram of an embodiment of a mask in an embodiment of the present application;

[0039] Figure 2c A schematic diagram of an embodiment of a new mask in an embodiment of the present application;

[0040] Figure 2d A schematic diagram of an embodiment of a target image in an embodiment of the present application;

[0041] Figure 3 A schematic diagram of an embodiment of an image processing device in an embodiment of the present application;

[0042] Figure 4 This is a schematic diagram of an embodiment of an electronic device in an embodiment of the present application. DETAILED DESCRIPTION

[0043] The embodiments of the present application provide an image processing method, device, electronic device and storage medium, which can effectively eliminate the protrusions on each edge of the target object in the image to be processed, so that each edge of the target object is smoother, thereby improving the image processing effect.

[0044] In order to make the technical personnel in the technical field better understand the scheme of the present application, the technical scheme in the embodiment of the present application will be described below in conjunction with the drawings in the embodiment of the present application. Obviously, the described embodiment is only a part of the embodiment of the present application, not all of the embodiments. Based on the embodiments in the present application, they should all fall within the scope of protection of the present application.

[0045] like Figure 1 FIG. 1 is a schematic diagram of an embodiment of an image processing method in an embodiment of the present application, which may include:

[0046] 101. Generate a mask corresponding to the image to be processed.

[0047] The image to be processed refers to an image including a target object.

[0048] The target object refers to an object of interest in the image to be processed, such as a foreground object in the image to be processed, or a specified object (such as a person, a specific object, etc.) in the image to be processed. Further, the target object may be a polygonal object. Optionally, the target object may be a regular polygonal object or an irregular polygonal object, which is not specifically limited here.

[0049] The mask can be used to mark the image position corresponding to the target object in the image to be processed. In the mask, since the target object is a foreground object, the area image outside the target object is the background image area.

[0050] It is understandable that the mask can be a grayscale image or a binary image. The mask involved in the embodiment of the present application is a binary image, which is an image composed of pixel values ​​of 0 and pixel values ​​of 1, wherein the pixel value of 0 represents black and the pixel value of 1 represents white. Optionally, in the mask, when the pixel value corresponding to the pixel point of the target object is 0, the pixel value corresponding to the pixel point of the background image area is 1; when the pixel value corresponding to the pixel point of the background image area is 1, the pixel value corresponding to the pixel point of the target object is 0, and no specific limitation is made here.

[0051] For example, Figure 2a FIG. 1 is a schematic diagram of an embodiment of an image to be processed in an embodiment of the present application. Figure 2a, the image to be processed 200a includes a target object 201a and a background image area 202a. The target object 201a is composed of an irregular multi-pentagonal object and a regular quadrilateral object. The pentagonal object includes five vertices, namely point A, point B, point C, point D and point E, and the pentagonal object includes five edges, namely edge AB, edge BC, edge CD, edge DE and edge EA. In addition, edge DE has a protrusion F. The quadrilateral object includes four vertices, namely point G, point H, point I and point J, and the quadrilateral object includes four edges, namely edge GH, edge HI, edge IJ and edge JG.

[0052] like Figure 2b FIG. 1 is a schematic diagram of an embodiment of a mask in an embodiment of the present application. Figure 2b The mask 200b shown is Figure 2a The image to be processed 200a shown corresponds to: In the mask 200b, the pixel value corresponding to the pixel point of the target object 201b is 1, and the pixel value corresponding to the pixel point of the background image area 202b is 0.

[0053] Optionally, the electronic device generates a mask corresponding to the image to be processed, which may include: the electronic device extracts color features of the image to be processed and / or various shape features contained in the object in the image to be processed; the electronic device identifies the target object included in the image to be processed based on the color features and / or the shape features, and generates a mask corresponding to the image to be processed.

[0054] It should be noted that the electronic device has an image recognition function, and can identify the target object corresponding to the color features and / or the various shape features contained in the object based on the color distribution extracted in the image to be processed, that is, the color features and / or the various shape features contained in the object (for example, irregular quadrilaterals or regular hexagons, etc.); the electronic device then extracts the target object and generates a mask corresponding to the image to be processed, so that the electronic device can subsequently correct each edge of the target object to effectively eliminate the protrusions on the corresponding edges of the target object in the image to be processed.

[0055] Optionally, the electronic device generating a mask corresponding to the image to be processed may include: the electronic device inputting the image to be processed into an image recognition model to obtain the mask corresponding to the image to be processed output by the image recognition model.

[0056] The image recognition model is trained by a historical set of images to be processed and a historical set of masks.

[0057] It can be understood that since the image recognition model is trained with a large number of historical images to be processed and a large number of historical masks, when the electronic device inputs the image to be processed into the image recognition model, the image recognition model can quickly output the mask corresponding to the image to be processed, so that the electronic device can quickly acquire the mask, which can effectively save the power consumption of the electronic device while improving the mask acquisition efficiency.

[0058] 102. Perform straight line fitting on each edge of the target object in the mask to obtain a slope corresponding to each fitted straight line, and obtain a gradient value corresponding to each pixel point on each edge of the target object in the image to be processed.

[0059] Optionally, the electronic device performs straight line fitting on each edge of the target object in the mask to obtain the slope corresponding to each fitted straight line, which may include: the electronic device performs straight line fitting on each edge of the target object in the mask through a random sample consensus (RANSAC) algorithm to obtain the slope corresponding to each fitted straight line.

[0060] The slope may be infinite or not infinite, and is not specifically limited here.

[0061] It should be noted that the RANSAC algorithm estimates the parameters of the straight line model from a set of pixels containing outliers in the mask in an iterative manner.

[0062] Take the first edge as an example. In a group of pixels containing outliers, some pixels belong to the first edge, and some pixels do not belong to the first edge. If the electronic device determines the first straight line corresponding to the first edge based on the group of pixels containing outliers, it is necessary to determine the first straight line corresponding to the first edge based on the pixels belonging to the first edge. Since a straight line model requires two data to uniquely determine a straight line equation, that is, a straight line model requires two pixels to uniquely determine a straight line, the electronic device randomly selects two pixels from all the pixels belonging to the first edge, and uses the pixel coordinates of the two pixels to calculate the first straight line model equation Y=aX+b represented by the two pixels, where a represents the slope of the first straight line corresponding to the first edge, and b represents a constant; then, the pixel coordinates of the pixels on the first edge are all applied to the first straight line model equation Y=aX+b, and the distance value between each pixel and the first straight line is calculated, and then the distance value between each pixel and the first straight line is compared with the preset distance threshold, and the pixel whose distance value is less than the preset distance threshold is determined as the target pixel. After repeating the above steps for a preset number of iterations, the first straight line model equation with the most target pixels is selected, and the slope of the first straight line corresponding to the first edge can be accurately obtained.

[0063] Specifically, the preset number of iterations is two. The electronic device determines the first straight line model equation Y according to the pixel coordinates of the first pixel point and the pixel coordinates of the second pixel point. 1 =a 1 X 1 +b 1 The electronic device calculates the distance value between each pixel point on the first edge and the first straight line, and then compares each distance value with a first preset distance threshold, and determines the pixel point whose distance value is less than the first preset distance threshold as the first target pixel point, and then obtains the first number of the first target pixel point;

[0064] The electronic device determines the second straight line model equation Y according to the pixel coordinates of the third pixel point and the pixel coordinates of the fourth pixel point. 2 =a 2 X 2 +b 2 The electronic device calculates the distance value between each pixel point on the first edge and the second straight line, and then compares each distance value with a second preset distance threshold, and determines the pixel point whose distance value is less than the second preset distance threshold as the second target pixel point, and then obtains the second number of the second target pixel points;

[0065] Finally, the electronic device compares the first number with the second number, and if the first number is greater than the second number, a 1 is determined as the slope of the first straight line corresponding to the first edge; if the second number is greater than the first number, a 2 is determined as the slope of the first straight line corresponding to the first edge; if the first quantity is equal to the second quantity, then a 1 or a 2 The slope of the first straight line corresponding to the first edge is determined.

[0066] It should be noted that the preset distance threshold and the preset number of iterations may be set before the electronic device leaves the factory, or may be customized by the user according to the needs of the target object, and are not specifically limited here.

[0067] Exemplarily, the electronic device uses the RANSAC algorithm to Figure 2b By performing straight line fitting on the edge of the pentagonal object in the mask 200 b shown, it can be obtained that the slope of the straight line corresponding to the edge CD is 1 / 2.

[0068] Optionally, the electronic device obtains the gradient value corresponding to each pixel point on each edge of the target object in the image to be processed, which may include: the electronic device obtains the pixel coordinates corresponding to each pixel point on each edge of the target object in the image to be processed; and the electronic device determines the gradient value corresponding to each pixel point based on the pixel coordinates of each pixel point.

[0069] It should be noted that the gradient refers to a vector, which is a vector. The gradient value corresponding to the gradient can represent the maximum value of the directional derivative of the pixel point in the image to be processed by the electronic device along the gradient direction, that is, it can represent the value at which the pixel point changes fastest and at the largest rate of change along the gradient direction at the pixel point. That is, the gradient value corresponding to the gradient is the modulus of the gradient.

[0070] Take the first pixel as an example. The process of the electronic device determining the gradient value G(x, y) corresponding to the first pixel according to the pixel coordinates I(i, j) of the first pixel is as follows: the electronic device obtains the derivative dx(i, j) of the first pixel in the first direction and the derivative dy(i, j) of the first pixel in the second direction according to the pixel coordinates (i, j) of the first pixel; and then obtains the gradient value G(x, y) corresponding to the first pixel according to dx(i, j) and dy(i, j).

[0071] Specifically, the electronic device calculates the derivative dx(i, j) of the first pixel point in the first direction according to the first derivation formula; the electronic device calculates the derivative dy(i, j) of the first pixel point in the second direction according to the second derivation formula; the electronic device calculates the gradient value G(x, y) corresponding to the first pixel point according to the gradient value formula.

[0072] Wherein, the first derivative formula is dx(i, j)=[I(i+p, j)-I(i, j)] / p;

[0073] The second derivative formula is dy(i, j)=[I(i, j+p)-I(i, j)] / p;

[0074] The gradient value formula is G(x, y)=dx(i, j)+dy(i, j).

[0075] Wherein, (i, j) is the pixel coordinate of the first pixel point; I(i, j) is the first pixel value corresponding to the first pixel point. Optionally, p is 1.

[0076] 103. Using the slope corresponding to each straight line and the gradient value corresponding to each pixel point on each edge, each edge of the target object in the mask is corrected to obtain a new mask.

[0077] It should be noted that since there may be protrusions on the edge of the target object in the image to be processed, resulting in the edge not being smooth enough, if the electronic device does not process the protrusions on the edge, it may affect the subsequent image processing. Therefore, after obtaining the image to be processed and the mask corresponding to the image to be processed, the electronic device can use the slope of the straight line corresponding to each edge of the target object in the mask and the gradient value corresponding to each pixel point on each edge of the target object in the image to be processed to correct each edge of the target object in the mask, so as to effectively eliminate the protrusions on the edge of the target object, so that each edge on the target object is smoother, and then a new mask can be obtained.

[0078] Optionally, the electronic device uses the slope corresponding to each straight line and the gradient value corresponding to each pixel point on each edge to correct each edge of the target object in the mask to obtain a new mask, which may include but is not limited to the following implementations:

[0079] Implementation method 1: If the electronic device determines that the slope corresponding to the first straight line is not infinite, then the slope range corresponding to the first straight line is determined according to the slope corresponding to the first straight line and a preset threshold; the electronic device uses the slope range corresponding to each straight line and the gradient value corresponding to each pixel point on each edge to correct each edge of the target object in the mask to obtain a new mask.

[0080] The first straight line is any straight line among straight lines obtained by the electronic device performing straight line fitting on each edge of the target object in the mask.

[0081] It can be understood that since the target object may include multiple edges, each edge corresponds to a straight line, that is, the target object may include multiple straight lines, and the first straight line is any straight line among the multiple straight lines, the electronic device only needs to fit the straight line corresponding to each edge according to the method of the above-mentioned implementation method 1 to obtain the slope corresponding to each straight line.

[0082] The preset threshold value may be set before the electronic device leaves the factory, or may be customized by the user according to actual needs, and is not specifically limited here.

[0083] The electronic device can determine whether the slope corresponding to the first straight line is infinite, that is, it can determine whether the first straight line is a straight line perpendicular to the horizontal. If it is determined that the slope corresponding to the first straight line is not infinite, it is determined that the first straight line is not a straight line perpendicular to the horizontal; if it is determined that the slope corresponding to the first straight line is infinite, it is determined that the first straight line is a straight line perpendicular to the horizontal.

[0084] Optionally, the electronic device determines the slope range corresponding to the first straight line based on the slope corresponding to the first straight line and a preset threshold, which may include: the electronic device subtracts the preset threshold from the slope corresponding to the first straight line to obtain a first slope threshold corresponding to the first straight line; the electronic device adds the preset threshold to the slope corresponding to the first straight line to obtain a second slope threshold corresponding to the first straight line; the electronic device uses the first slope threshold as the lower limit value of the slope range corresponding to the first straight line, and uses the second slope threshold as the upper limit value of the slope range to obtain the slope range corresponding to the first straight line.

[0085] It should be noted that the timing for the electronic device to obtain the first slope threshold and the second slope threshold is not limited.

[0086] Furthermore, the electronic device determines a first slope threshold corresponding to the first straight line according to the first formula; the electronic device determines a second slope threshold corresponding to the first straight line according to the second formula; the electronic device uses the first slope threshold as the lower limit value of the slope range corresponding to the first straight line, and uses the second slope threshold as the upper limit value of the slope range, to obtain the slope range corresponding to the first straight line.

[0087] Wherein, the first formula is m=a-th, and the second formula is n=a+th; m represents the first slope threshold, n represents the second slope threshold, a represents the slope corresponding to the first straight line, and th represents the preset threshold. In addition, the slope range can be expressed as (m, n).

[0088] Optionally, the electronic device uses the slope range corresponding to each straight line and the gradient value corresponding to each pixel point on each edge to correct each edge of the target object in the mask, which may include: if it is determined that the first gradient value corresponding to the first pixel point is not within the slope range corresponding to the first straight line, the electronic device sets the pixel value corresponding to the first pixel point in the mask to a preset pixel value.

[0089] The first pixel point is any pixel point among each pixel point on the first edge corresponding to the first straight line, and the preset pixel value is used to indicate that the pixel point belongs to the background image area.

[0090] It should be noted that when the electronic device determines that the slope corresponding to the first straight line is not infinite, the slope range corresponding to the first straight line exists. The electronic device can obtain the pixel points whose gradient values ​​of the pixel points on the first edge corresponding to the first straight line are within the slope range corresponding to the first straight line. Since the pixel points within the slope range corresponding to the first straight line are also the pixel points in the target object, the electronic device does not need to adjust the pixel values ​​corresponding to the pixel points in the target object, so the electronic device can retain the pixel values ​​of the pixel points within the slope range corresponding to the first straight line. At the same time, when the electronic device determines that the first gradient value corresponding to the first pixel point is not within the slope range corresponding to the first straight line, it can be determined that the first pixel point is a pixel point in the protrusion on the first edge. In order to eliminate the first pixel point in the protrusion, the electronic device can set the pixel value corresponding to the first pixel point in the mask to a preset pixel value, which can be 0 or 1, so that the pixel value corresponding to the first pixel point is the same as the pixel value corresponding to the pixel point in the background image area.

[0091] It is understandable that, since each edge on the target object corresponds to a plurality of pixels, the electronic device only needs to calculate each pixel according to the above method to obtain the gradient value corresponding to each pixel.

[0092] Implementation method 2: If the electronic device determines that the slope corresponding to the first straight line is infinite, it determines whether the first gradient direction corresponding to the first pixel point in the image to be processed is the vertical direction of the first straight line; if the first gradient direction is the vertical direction of the first straight line, the electronic device sets the pixel value corresponding to the first pixel point in the mask to the preset pixel value.

[0093] It should be noted that when the electronic device determines that the slope corresponding to the first straight line is infinite, the electronic device cannot obtain the slope range corresponding to the first straight line, that is, the slope range corresponding to the first straight line does not exist. When the electronic device determines that the slope corresponding to the first straight line is infinite, the first straight line is a straight line perpendicular to the horizontal direction, so if the first gradient direction corresponding to the first pixel point is the horizontal direction of the first straight line, that is, the first gradient direction is parallel to the horizontal direction, then the electronic device can determine that the first pixel point is a pixel point on the edge corresponding to the first straight line, that is, it can be determined that the first pixel point is a pixel point in the target object, and the electronic device does not need to adjust the pixel value corresponding to the pixel point in the target object, so the electronic device can retain the pixel value of the first pixel point; if the first gradient direction corresponding to the first pixel point is the vertical direction of the first straight line, then it can be determined that the first pixel point is a pixel point in the protrusion on the first edge. In order to eliminate the first pixel point in the protrusion, the electronic device can set the pixel value corresponding to the first pixel point in the mask to a preset pixel value, so that the pixel value corresponding to the first pixel point is the same as the pixel value corresponding to the pixel point in the background image area.

[0094] For example, Figure 2c FIG. 1 is a schematic diagram of an embodiment of a new mask in an embodiment of the present application. Figure 2c In the new mask 200c, the new mask 200c includes the target object 201c and the background image area 202c. In the new mask 200c, there is no protrusion on each edge of the target object 201c.

[0095] It can be understood that both the above-mentioned implementation method 1 and implementation method 2 are for the purpose of more accurately determining which pixels in the mask are pixels on the edge of the target object and which pixels are pixels in the protrusions generated by the edge, so that the electronic device can accurately adjust the pixel values ​​corresponding to the pixels in the mask. Specifically, the electronic device can retain the pixel values ​​corresponding to the pixels on the edge of the target object, and adjust the pixel values ​​corresponding to the pixels in the protrusions to preset pixel values, so that the pixel values ​​corresponding to the pixels in the protrusions can be the same as the pixel values ​​corresponding to the pixels in the background image area, so as to effectively eliminate the pixels in the protrusions generated on the upper edge of the target object, thereby making each edge of the target object in the mask smoother.

[0096] 104. Obtain a target image according to the new mask and the image to be processed.

[0097] Since the new mask accurately defines the image position of the target object with the edge protrusions eliminated, the electronic device can adjust the pixel points of the target object in the image to be processed according to the new mask to obtain the target image, so that the pixel points of the edge protrusions belonging to the target object in the image to be processed are adjusted to be close to the pixel points of the background area.

[0098] Optionally, the electronic device obtains the target image based on the new mask and the image to be processed, which may include: the electronic device multiplies the pixel value of each pixel in the new mask with the pixel value of the pixel at the same image position in the image to be processed to obtain the target image.

[0099] It should be noted that, in the new mask, if the pixel value corresponding to the pixel of the target object is 1, and the pixel value corresponding to the pixel of the background image area is 0, then the electronic device multiplies the pixel value of each pixel in the new mask with the pixel value of the pixel at the same image position in the image to be processed. In the target image obtained, the pixel value corresponding to the pixel that actually belongs to the target object is retained, and the pixel value corresponding to the pixel that produces protrusions on the edge of the target object is adjusted to the pixel value corresponding to the pixel in the background image area, which effectively eliminates the protrusions on the edge, so that each edge of the target object in the target image is smoother.

[0100] For example, Figure 2d FIG. 1 is a schematic diagram of an embodiment of a target image in an embodiment of the present application. Figure 2d In the target image 200d, the target image 200d includes a target object 201d and a background image area 202d. The pixel values ​​corresponding to the pixels of the target object 201d are retained, while the pixel values ​​corresponding to the pixels of the background image area 202d are 0. In the target image 200d, there is no protrusion on each edge of the target object 201d.

[0101] In an embodiment of the present application, a mask corresponding to the image to be processed is generated, and the mask can accurately mark the image position corresponding to the target object in the image to be processed; then, a straight line fitting is performed on each edge of the target object in the mask to obtain the slope corresponding to each edge, and the gradient value corresponding to each pixel point on each edge of the target object in the image to be processed is obtained; then, each edge of the target object in the mask is corrected using the slope corresponding to each straight line and the gradient value corresponding to each pixel point on each edge, which can effectively eliminate the protrusions on each edge of the target object in the image to be processed, so that each edge of the target object in the target image is relatively smooth, thereby improving the image processing effect.

[0102] like Figure 3 FIG. 1 is a schematic diagram of an embodiment of an image processing device in an embodiment of the present application, which may include:

[0103] The processing module 301 is used to generate a mask corresponding to the image to be processed, and the mask is used to mark the image position corresponding to the target object in the image to be processed;

[0104] An acquisition module 302 is used to perform straight line fitting on each edge of the target object in the mask to obtain a slope corresponding to each fitted straight line, and to obtain a gradient value corresponding to each pixel point on each edge of the target object in the image to be processed;

[0105] The processing module 301 is also used to modify each edge of the target object in the mask using the slope corresponding to each straight line and the gradient value corresponding to each pixel point on each edge to obtain a new mask; and obtain the target image based on the new mask and the image to be processed.

[0106] Optionally, in some embodiments of the present application,

[0107] The processing module 301 is specifically used to determine the slope range corresponding to the first straight line according to the slope corresponding to the first straight line and a preset threshold if it is determined that the slope corresponding to the first straight line is not infinite, and the first straight line is any straight line among each straight line; and to correct each edge of the target object in the mask by using the slope range corresponding to each straight line and the gradient value corresponding to each pixel point on each edge to obtain a new mask.

[0108] Optionally, in some embodiments of the present application,

[0109] The processing module 301 is specifically used to set the pixel value corresponding to the first pixel point in the mask to a preset pixel value if it is determined that the first gradient value corresponding to the first pixel point is not within the slope range corresponding to the first straight line; wherein the first pixel point is any pixel point among each pixel point on the first edge corresponding to the first straight line, and the preset pixel value is used to indicate that the pixel point belongs to the background image area.

[0110] Optionally, in some embodiments of the present application,

[0111] The processing module 301 is specifically used to determine whether the first gradient direction corresponding to the first pixel point in the image to be processed is the vertical direction of the first straight line if it is determined that the slope corresponding to the first straight line is infinite, the first straight line is any straight line among each straight line, and the first pixel point is any pixel point among each pixel point on the first edge corresponding to the first straight line; if the first gradient direction is the vertical direction of the first straight line, the pixel value corresponding to the first pixel point in the mask is set to a preset pixel value, and the preset pixel value is used to indicate that the pixel point belongs to the background image area.

[0112] Optionally, in some embodiments of the present application,

[0113] The processing module 301 is specifically configured to multiply the pixel value of each pixel point in the new mask by the pixel value of the pixel point at the same image position in the image to be processed, so as to obtain a target image.

[0114] Optionally, in some embodiments of the present application,

[0115] The processing module 301 is specifically used to extract the color features of the image to be processed and / or the various shape features contained in the object in the image to be processed; identify the target object included in the image to be processed according to the color features and / or the shape features, and generate a mask corresponding to the image to be processed.

[0116] Optionally, the target object is a regular polygonal object or an irregular polygonal object.

[0117] like Figure 4 As shown, it is a schematic diagram of an embodiment of an electronic device in an embodiment of the present application, which may include: a memory 402 and a processor 401, the processor 401 and the memory 402 are coupled, and the processor 401 can call the executable program code stored in the processor 401;

[0118] The processor 401 included in the image processing device has the following functions:

[0119] Generate a mask corresponding to the image to be processed, where the mask is used to mark the image position corresponding to the target object in the image to be processed;

[0120] Performing straight line fitting on each edge of the target object in the mask to obtain the slope corresponding to each fitted straight line, and obtaining the gradient value corresponding to each pixel point on each edge of the target object in the image to be processed;

[0121] Using the slope corresponding to each straight line and the gradient value corresponding to each pixel point on each edge, each edge of the target object in the mask is corrected to obtain a new mask;

[0122] A target image is obtained according to the new mask and the image to be processed.

[0123] Optionally, the processor 401 further has the following functions:

[0124] If it is determined that the slope corresponding to the first straight line is not infinite, then the slope range corresponding to the first straight line is determined according to the slope corresponding to the first straight line and a preset threshold, and the first straight line is any straight line among each straight line; using the slope range corresponding to each straight line and the gradient value corresponding to each pixel point on each edge, each edge of the target object in the mask is corrected to obtain a new mask.

[0125] Optionally, the processor 401 further has the following functions:

[0126] If it is determined that the first gradient value corresponding to the first pixel point is not within the slope range corresponding to the first straight line, the pixel value corresponding to the first pixel point in the mask is set to a preset pixel value; wherein the first pixel point is any pixel point among each pixel point on the first edge corresponding to the first straight line, and the preset pixel value is used to indicate that the pixel point belongs to the background image area.

[0127] Optionally, the processor 401 further has the following functions:

[0128] If it is determined that the slope corresponding to the first straight line is infinite, then determine whether the first gradient direction corresponding to the first pixel point in the image to be processed is the vertical direction of the first straight line, the first straight line is any straight line among each straight line, and the first pixel point is any pixel point among each pixel point on the first edge corresponding to the first straight line; if the first gradient direction is the vertical direction of the first straight line, then the pixel value corresponding to the first pixel point in the mask is set to a preset pixel value, and the preset pixel value is used to indicate that the pixel point belongs to the background image area.

[0129] Optionally, the processor 401 further has the following functions:

[0130] The pixel value of each pixel in the new mask is multiplied by the pixel value of the pixel at the same image position in the image to be processed to obtain the target image.

[0131] Optionally, the processor 401 further has the following functions:

[0132] Extracting the color features of the image to be processed and / or the shape features of the object in the image to be processed; identifying the target object included in the image to be processed according to the color features and / or the shape features, and generating a mask corresponding to the image to be processed.

[0133] Optionally, the target object is a regular polygonal object or an irregular polygonal object.

[0134] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware or any combination thereof. When implemented by software, all or part of the embodiments may be implemented in the form of a computer program product.

[0135] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transmitted from a website site, a computer, a server, or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, server, or data center. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a server or a data center that includes one or more available media integrations. The available medium may be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk Solid State Disk (SSD)), etc.

[0136] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0137] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.

[0138] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0139] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

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

[0141] As described above, the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.

Claims

1. An image processing method, characterized in that: include: Generate a mask corresponding to the image to be processed, wherein the mask is used to mark the image position corresponding to the target object in the image to be processed; Performing straight line fitting on each edge of the target object in the mask to obtain a slope corresponding to each fitted straight line, and obtaining a gradient value corresponding to each pixel point on each edge of the target object in the image to be processed; Using the slope corresponding to each straight line and the gradient value corresponding to each pixel point on each edge, each edge of the target object in the mask is corrected to obtain a new mask; A target image is obtained according to the new mask and the image to be processed.

2. The method according to claim 1, characterized in that The method of modifying each edge of the target object in the mask by using the slope corresponding to each straight line and the gradient value corresponding to each pixel point on each edge to obtain a new mask includes: If it is determined that the slope corresponding to the first straight line is not infinite, determining a slope range corresponding to the first straight line according to the slope corresponding to the first straight line and a preset threshold, the first straight line being any straight line among each of the straight lines; Each edge of the target object in the mask is corrected by using the slope range corresponding to each straight line and the gradient value corresponding to each pixel point on each edge to obtain a new mask.

3. The method according to claim 2, characterized in that The method of modifying each edge of the target object in the mask by using the slope range corresponding to each straight line and the gradient value corresponding to each pixel point on each edge includes: If it is determined that the first gradient value corresponding to the first pixel point is not within the slope range corresponding to the first straight line, setting the pixel value corresponding to the first pixel point in the mask to a preset pixel value; The first pixel point is any pixel point among each pixel point on the first edge corresponding to the first straight line, and the preset pixel value is used to indicate that the pixel point belongs to the background image area.

4. The method according to claim 1, characterized in that: The method of modifying each edge of the target object in the mask by using the slope corresponding to each straight line and the gradient value corresponding to each pixel point on each edge includes: If it is determined that the slope corresponding to the first straight line is infinite, determining whether a first gradient direction corresponding to a first pixel point in the image to be processed is a vertical direction of the first straight line, the first straight line being any straight line among each straight line, and the first pixel point being any pixel point among each pixel point on a first edge corresponding to the first straight line; If the first gradient direction is a vertical direction of the first straight line, the pixel value corresponding to the first pixel point in the mask is set to a preset pixel value, and the preset pixel value is used to indicate that the pixel point belongs to the background image area.

5. The method according to any one of claims 1 to 4, characterized in that The step of obtaining a target image according to the new mask and the image to be processed comprises: The pixel value of each pixel in the new mask is multiplied by the pixel value of the pixel at the same image position in the image to be processed to obtain a target image.

6. The method according to any one of claims 1 to 4, characterized in that The step of generating a mask corresponding to the image to be processed includes: Extracting color features of the image to be processed and / or shape features of each object contained in the image to be processed; The target object included in the image to be processed is identified according to the color feature and / or the shape feature, and a mask corresponding to the image to be processed is generated.

7. The method according to any one of claims 1 to 4, characterized in that The target object is a regular polygonal object or an irregular polygonal object.

8. An image processing device, characterized in that: include: A processing module, used to generate a mask corresponding to the image to be processed, wherein the mask is used to mark the image position corresponding to the target object in the image to be processed; An acquisition module, used for performing straight line fitting on each edge of the target object in the mask to obtain a slope corresponding to each fitted straight line, and obtaining a gradient value corresponding to each pixel point on each edge of the target object in the image to be processed; The processing module is also used to correct each edge of the target object in the mask by using the slope corresponding to each straight line and the gradient value corresponding to each pixel point on each edge to obtain a new mask; and obtain the target image according to the new mask and the image to be processed.

9. An electronic device, characterized in that: include: A memory storing executable program code; and a processor coupled to the memory; The processor calls the executable program code stored in the memory, and when the executable program code is executed by the processor, the processor implements the method according to any one of claims 1 to 7.

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

Citation Information

Patent Citations

  • Unmanned aerial vehicle vision wire patrol method based on gradient constraint Radon transform

    CN106056619A

  • Bank card inclination correction detection method and device, readable storage medium and terminal

    CN112686812A

  • Method for measuring antenna downtilt based on linear regression fitting

    US20200410710A1