A method for extracting edge of image objects

By calculating the grayscale value ratio and traversal direction of two pixels in the image that are a certain step apart, the edge region binary map is generated, which solves the problem of poor blur edge detection in the prior art, and achieves more accurate edge extraction and robustness.

CN116012402BActive Publication Date: 2025-09-02GUANGDONG AIKEXIN TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

The existing image object edge extraction operator has poor detection effect when the object edge transitions to the background are not obvious, especially for the extraction of blurred edges.

Method used

By calculating the grayscale value ratio of two pixels apart at a certain step, we determine the pixels of the edge area of ​​the object, combine different traversal directions and grayscale transition methods, an edge area binary map is generated, and edge contour points are extracted using openCV's findContours operator.

Benefits of technology

More precise extraction of the edges of fuzzy objects is achieved, with good robustness and insensitivity to image brightness, and improves the accuracy and adaptability of edge detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116012402B_ABST
    Figure CN116012402B_ABST
Patent Text Reader

Abstract

The present invention discloses a method for extracting the edge of an image object, which belongs to the field of computer vision technology. The method comprises the following steps: S1: parameter preset: before calculating the edge area, preset detection parameters: comparison step size step, minimum grayscale ratio value r0 of pixels in the edge area of ​​the object, traversal direction d, and grayscale transition mode m; S2: setting the width of the image to be detected to w and the height to h, creating a result storage image with the same size as the image to be detected, and setting all grayscale values ​​of the result storage image to 0; S3: extracting the edge of the image to be detected. Compared with the existing technology, the present method extracts the edge of the object by calculating the grayscale value ratio of two pixels with a certain step size to determine whether a certain pixel is a pixel in the edge area of ​​the object in the image. The extraction result of the edge of the blurred object in the image will be more accurate than the existing technology; it is not sensitive to the brightness of the image and has good robustness and adaptability.
Need to check novelty before this filing date? Find Prior Art

Description

Technical field:

[0001] The present invention belongs to the technical field of computer vision, and in particular relates to a method for extracting edges of image objects. Background technology:

[0002] Image object edge extraction belongs to the field of computer vision technology and is used to preserve areas of an image with drastic grayscale changes. The open-source computer vision operator library, openCV, provides a variety of edge extraction operators. These operators exploit the sudden change in grayscale values ​​between the edges of objects and the background image to separate the target area from the image and then extract the object's edges.

[0003] These image object edge extraction operators are mainly divided into two categories:

[0004] 1. First-order operators: First, edge strength is calculated using the first-order derivative. The direction of the gradient is then used to find the local direction of the edge. The maximum value of the local gradient modulus is then found based on this direction to locate the edge. These operators include Roberts, Prewitt, Sobel, Kirsch, and Canny. At the edge of an image, pixel values ​​may "jump" in the x or y direction. The derivative of these pixels is calculated, and the first-order derivative is extreme at the edge.

[0005] 2. Second-order operators: Locate and detect edges by finding the zero-crossing point of the second-order derivative obtained from the image, such as the Laplacian operator and the LOG operator. If the second-order derivative of the pixel value is calculated, the derivative value at the edge will be 0.

[0006] However, whether it is a first-order operator or a second-order operator, when the transition between the edge of the object and the background is not obvious (edge ​​blur), the edge detection effect is not very good, and the blurrier the edge, the worse the effect. Summary of the invention:

[0007] To solve the above problems, the primary purpose of the present invention is to provide a method for extracting object edges in an image, which can extract the object edges by calculating the object edge area. The extraction results of the edges of blurred objects in the image will be more accurate than the existing technology. At the same time, this technology is insensitive to the brightness of the image and has good robustness and adaptability.

[0008] To achieve the above object, the technical solution of the present invention is as follows:

[0009] The present invention provides an image object edge extraction method, comprising the following steps:

[0010] S1: Parameter preset: Before calculating the edge area, preset detection parameters: comparison step step, minimum grayscale ratio r0 of pixels in the edge area of ​​the object, traversal direction d, grayscale transition mode m;

[0011] S2: Set the width of the image to be detected to w and the height to h, create a result storage image with the same size as the image to be detected, and set all grayscale values ​​of the result storage image to 0;

[0012] S3: Extract the edges of the objects in the image to be detected.

[0013] Furthermore, in step S1, when the grayscale value ratio of two pixels actually spaced apart by step is greater than or equal to r0, it may indicate that there is a pixel in the edge region of the object, and the preset value of r0 is usually greater than 1.0.

[0014] Furthermore, in step S1, the values ​​of the traversal direction d include but are not limited to 1, 2, 4, and 8, where 1 indicates the traversal direction from top to bottom, 2 indicates the traversal direction from bottom to top, 4 indicates the traversal direction from left to right, and 8 indicates the traversal direction from right to left; if you want to obtain the entire outline of the object, combine the traversal directions, and the value of the traversal direction d should be set to 7 (corresponding to 1111 in binary).

[0015] Furthermore, in step S1 , the grayscale transition mode m can take values ​​of 1 and 2, where 1 represents transition from light to dark and 2 represents transition from dark to light, and needs to be set according to actual conditions.

[0016] Furthermore, in step S2, for example, if it is determined by calculation that the pixel (x1, y1) is a pixel in the edge area of ​​the object, the grayscale value of the pixel at the corresponding position (x1, y1) of the result storage image is set to 255 (completely white).

[0017] Furthermore, step S3 includes:

[0018] Step S31: Calculate the binary image of the left edge area of ​​the image to be detected: take d=4, m=1, traverse from the first row of the image to the end of the hth row, and traverse each row from the first column to the end of the w-step column, find the pixels in the left edge area of ​​the object, and set the grayscale value of the pixel at the corresponding position of the result storage image to 255 (all white), and obtain the binary image of the left edge area in the result storage image. Assuming that the current traversal is to the yth row and the xth column, that is, the coordinates are (x, y), then the pixel coordinates to be compared are (x+step, y). If gray(x, y) / gray(x+step, y)>=r0, it means that the pixel at the coordinate (x+step, y) is the edge point of the object, and the grayscale value of the corresponding coordinate of the result storage image is set to 255, that is, dst_gray(x+step, y)=255. The results are as follows:

[0019] Step S32: Calculate the binary image of the right edge area of ​​the image to be detected, take d=8, m=1, traverse from the first row of the image to the hth row, and traverse each row from the wth column to the stepth column, find the pixels in the right edge area of ​​the object, and set the grayscale value of the pixel at the corresponding position of the result storage image to 255 (completely white), and obtain the binary image of the right edge area in the result storage image. Assuming that the current traversal is to the yth row and the xth column, that is, the coordinates are (x, y), then the pixel coordinates to be compared are (x-step, y), if gray(x, y) / gray(x-step, y)>=r0, it means that the pixel at the coordinate (x-step, y) is the edge point of the object, and the grayscale value of the corresponding coordinate of the result storage image is set to 255, that is, dst_gray(x-step, y)=255

[0020] Step S33: Calculate the binary image of the upper edge area of ​​the image to be detected, take d=1, m=1, traverse from the first row of the image to the h-step row, and each row is incremented from the first column to the w-th column to find the pixels in the upper edge area of ​​the object, and set the grayscale value of the pixel at the corresponding position of the result storage image to 255 (all white), and obtain the binary image of the upper edge area in the result storage image. Assuming that the current traversal is to the yth row and the xth column, that is, the coordinates are (x, y), then the pixel coordinates to be compared are (x, y+step), if gray(x, y) / gray(x, y+step)>=r0, it means that the pixel at the coordinate (x, y+step) is the edge point of the object, and the grayscale value of the corresponding coordinate of the result storage image is set to 255, that is, dst_gray(x, y+step)=255

[0021] Step S34: Calculate the binary image of the lower edge area of ​​the image to be detected, take d=2, m=1, start from the hth row of the image and traverse in descending order to the stepth row, and then traverse in ascending order from the 1st column to the wth column for each row, find out the pixels in the lower edge area of ​​the object, and set the grayscale value of the pixel at the corresponding position of the result storage image to 255 (all white), and obtain the binary image of the lower edge area in the result storage image. Assuming that the current traversal is to the yth row and the xth column, that is, the coordinates are (x, y), then the pixel coordinates to be compared are (x, y-step), if gray(x, y) / gray(x, y-step)>=r0, it means that the pixel at the coordinate (x, y-step) is the edge point of the object, and the grayscale value of the corresponding coordinate of the result storage image is set to 255, that is, dst_gray(x, y-step)=255

[0022] Step S35: Merge the edge region binary images of the four grayscale transition results of the result storage images in steps S31 to S34 to obtain a complete edge region binary image.

[0023] Step S36: The edge region binary image obtained in S35 is extracted using the findContours operator of openCV to obtain edge contour points, and the edge contour points are drawn on the image to be detected to form the edge of the object.

[0024] Furthermore, in step S3 , the width w of the image to be detected is the same as the number of columns of the regional binary image of the result stored image, and the height h of the image to be detected is the same as the number of rows of the regional binary image of the result stored image.

[0025] Compared with the existing technology, the beneficial effects of the present invention are: this method extracts the edge of an object by calculating the grayscale value ratio of two pixels separated by a certain step length to determine whether a pixel is a pixel in the edge area of ​​an object in an image. The extraction result of the edge of blurred objects in the image will be more accurate than the existing technology; at the same time, this technology is not sensitive to the brightness of the image and has good robustness and adaptability. Description of the drawings:

[0026] Figure 1 It is the image to be detected in this embodiment.

[0027] Figure 2 It is a binary image of the left edge area of ​​the result storage image in this embodiment.

[0028] Figure 3 It is a binary image of the right edge area of ​​the result storage image in this embodiment.

[0029] Figure 4 It is a binary image of the upper edge area of ​​the result storage image in this embodiment.

[0030] Figure 5 It is a binary image of the lower edge area of ​​the result storage image in this embodiment.

[0031] Figure 6 It is a binary image of the edge area of ​​the entire result storage image in this embodiment.

[0032] Figure 7 It is a binary image of the edge region obtained on the image to be detected by using the method of this embodiment.

[0033] Figure 8 It is a binary image of the edge area obtained by processing the image to be detected using the Canny operator.

[0034] Figure 9It is a binary image of the edge area obtained by processing the image to be detected using the Laplacian operator with a convolution kernel size of 3.

[0035] Figure 10 It is a binary image of the edge area obtained by processing the image to be detected using the Laplacian operator with a convolution kernel size of 7. Specific implementation method:

[0036] In order to make the purpose, technical solutions and advantages of the present invention more clearly understood, the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.

[0037] The present invention is implemented as follows:

[0038] like Figure 1-10 As shown, this embodiment provides an image object edge extraction method, comprising the following steps:

[0039] S1: Parameter preset: Before calculating the edge area, preset detection parameters: comparison step step, minimum grayscale ratio r0 of pixels in the edge area of ​​the object, traversal direction d, grayscale transition mode m;

[0040] S2: Set the width of the image to be detected to w and the height to h, create a result storage image with the same size as the image to be detected, and set all grayscale values ​​of the result storage image to 0;

[0041] S3: Extract the edges of the objects in the image to be detected.

[0042] Furthermore, in step S1, when the grayscale value ratio of two pixels actually spaced apart by step is greater than or equal to r0, it may indicate that there is a pixel in the edge region of the object, and the preset value of r0 is usually greater than 1.0.

[0043] Furthermore, in step S1, the values ​​of the traversal direction d include but are not limited to 1, 2, 4, and 8, where 1 indicates the traversal direction from top to bottom, 2 indicates the traversal direction from bottom to top, 4 indicates the traversal direction from left to right, and 8 indicates the traversal direction from right to left; if you want to obtain the entire outline of the object, combine the traversal directions, and the value of the traversal direction d should be set to 7 (corresponding to 1111 in binary).

[0044] Furthermore, in step S1 , the grayscale transition mode m can take values ​​of 1 and 2, where 1 represents transition from light to dark and 2 represents transition from dark to light, and needs to be set according to actual conditions.

[0045] Furthermore, in step S2, for example, if it is determined by calculation that the pixel (x1, y1) is a pixel in the edge area of ​​the object, the grayscale value of the pixel at the corresponding position (x1, y1) of the result storage image is set to 255 (completely white).

[0046] Furthermore, in this embodiment, it is assumed that the width and height of the image to be detected are w and h respectively, the grayscale value of the pixel at the coordinate (x, y) of the image to be detected is src_gray(x, y), and the grayscale value of the pixel at the coordinate (x, y) of the result storage image is dst_gray(x, y). Figure 1 The image in the figure is used as an example to illustrate the process of extracting the edge of an object by calculating the edge area of ​​the object (extracting the edge of the dark rectangle in the image. The width and height of the image are w = 340 and h = 240. Based on this image, step = 10 and r0 = 1.1 can be set). Note: The upper and lower horizontal edges of the dark rectangle in the image are blurred. The specific implementation steps are as follows:

[0047] Step S31: Calculate the binary image of the left edge area of ​​the image to be detected: take d=4 (traversal direction is from left to right), m=1 (transition from light to dark), start traversing from the first row of the image to the hth row, and each row starts from the first column and traverses to the w-step column, find out the pixels in the left edge area of ​​the object, and set the grayscale value of the pixel at the corresponding position of the result storage image to 255 (all white), and obtain the binary image of the left edge area in the result storage image. Assuming that the current traversal is to the yth row and the xth column, that is, the coordinates are (x, y), then the pixel coordinates to be compared are (x+step, y), if gray(x, y) / gray(x+step, y)>=r0, it means that the pixel at the coordinate (x+step, y) is the edge point of the object, and the grayscale value of the corresponding coordinate of the result storage image is set to 255, that is, dst_gray(x+step, y)=255, and the result is as follows Figure 2 shown.

[0048] Step S32: Calculate the binary image of the right edge area of ​​the image to be detected, take d=8 (traversal direction is from right to left), m=1 (transition from light to dark), start traversing from the first row of the image to the hth row, and each row starts from the wth column and traverses in descending order to the stepth column, find out the pixels in the right edge area of ​​the object, and set the grayscale value of the pixel at the corresponding position of the result storage image to 255 (all white), and obtain the binary image of the right edge area in the result storage image. Assuming that the current traversal is to the yth row and the xth column, that is, the coordinates are (x, y), then the pixel coordinates to be compared are (x-step, y), if gray(x, y) / gray(x-step, y)>=r0, it means that the pixel at the coordinate (x-step, y) is the edge point of the object, and the grayscale value of the corresponding coordinate of the result storage image is set to 255, that is, dst_gray(x-step, y)=255, and the result is as follows Figure 3 shown.

[0049] Step S33: Calculate the binary image of the upper edge area of ​​the image to be detected, take d = 1 (traversal direction is from top to bottom), m = 1 (transition from light to dark), start traversing from the first row of the image to the h-step row, and each row starts from the first column and traverses incrementally to the w-th column, find out the pixels in the upper edge area of ​​the object, and set the grayscale value of the pixel at the corresponding position of the result storage image to 255 (all white), and obtain the binary image of the upper edge area in the result storage image. Assuming that the current traversal is to the yth row and the xth column, that is, the coordinates are (x, y), then the pixel coordinates to be compared are (x, y+step), if gray(x, y) / gray(x, y+step)>=r0, it means that the pixel at the coordinate (x, y+step) is the edge point of the object, and the grayscale value of the corresponding coordinate of the result storage image is set to 255, that is, dst_gray(x, y+step)=255, and the result is as follows Figure 4 As shown, it can be seen that although the upper edge of the rectangular box in the figure is blurred, a clear, continuous and uninterrupted binary image of the upper edge area block can still be obtained through this method.

[0050] Step S34: Calculate the binary image of the lower edge area of ​​the image to be detected, take d = 2 (traversal direction is from bottom to top), m = 1 (transition from light to dark), start from the hth row of the image and traverse in descending order to the stepth row, and each row starts from the 1st column and traverses in increasing order to the wth column, find out the pixels in the lower edge area of ​​the object, and set the grayscale value of the pixel at the corresponding position of the result storage image to 255 (all white), and obtain the binary image of the lower edge area in the result storage image. Assuming that the current traversal is to the yth row and the xth column, that is, the coordinates are (x, y), then the pixel coordinates to be compared are (x, y-step), if gray (x, y) / gray (x, y-step) > = r0, it means that the pixel at the coordinate (x, y-step) is the edge point of the object, and the grayscale value of the corresponding coordinate of the result storage image is set to 255, that is, dst_gray (x, y-step) = 255, and the result is as follows Figure 5 shown.

[0051] Step S35: Merge the edge region binary images of the four grayscale transition results of the result storage image in steps S31-S34 to obtain a complete edge region binary image. The result is as follows: Figure 6 As shown, it can be seen that the outer edge of the rectangular frame is continuous and smooth.

[0052] Step S36: The edge area binary image obtained in S35 is extracted using the findContours operator of openCV to obtain edge contour points. These contour points are drawn on the original image. The result is as follows: Figure 7 As shown, the gray line portion of the edge is the obtained rectangular frame edge.

[0053] Furthermore, in step S3 , the width w of the image to be detected is the same as the number of columns of the regional binary image of the result stored image, and the height h of the image to be detected is the same as the number of rows of the regional binary image of the result stored image.

[0054] Furthermore, in actual use, you may sometimes only need to obtain certain specific edges. In this case, you can select only some of the traversal directions, for example, only select the left edge of the object to do something (such as straight line fitting, etc.); you can also merge multiple traversal directions together and use a specific traversal algorithm to generate a merged result graph of multiple traversal directions at one time, depending on the specific needs.

[0055] Furthermore, as a comparison with this method, the results of processing the above image using other openCV edge extraction operators are roughly as follows:

[0056] A. Processing results of the canny operator, a typical representative of first-order operators Figure 8 As shown, it can be seen that the upper and lower edges are blurred, resulting in the extracted upper and lower edges being jagged.

[0057] B. The processing results of the Laplacian operator, a typical representative of the second-order operators, are as follows Figure 9-10 As shown:

[0058] The result of convolution kernel size 3 is as follows Figure 9 As shown in the figure, it can be seen that the upper and lower edges are blurred, resulting in a lot of noise in the extracted upper and lower edges, and the positions of the four corner points of the rectangular frame are unclear.

[0059] The result of convolution kernel size 7 is as follows Figure 10 As shown, it can be seen that there are noise points and the four corners of the rectangular frame are unclear.

[0060] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.

Claims

1. A method for extracting edge of an image object, characterized in that: The following steps are included: S1: Parameter preset: Before calculating the edge area, preset detection parameters: comparison step step, minimum grayscale ratio r0 of pixels in the edge area of ​​the object, traversal direction d, grayscale transition mode m; S2: Set the width of the image to be detected to w and the height to h, create a result storage image with the same size as the image to be detected, and set all grayscale values ​​of the result storage image to 0; S3: Extract the edge of the image object to be detected; When the grayscale value ratio of two pixels with a distance of step is greater than or equal to r0, it means that there is a pixel in the edge area of ​​the object; The values ​​of traversal direction d include 1, 2, 4, and 8. 1 means the traversal direction is from top to bottom, 2 means the traversal direction is from bottom to top, 4 means the traversal direction is from left to right, and 8 means the traversal direction is from right to left. The grayscale transition mode m can take values ​​of 1 and 2, where 1 represents the transition from light to dark and 2 represents the transition from dark to light. Step S3 includes: Step S31: Calculate the binary image of the left edge area of ​​the image to be detected: set d=4, m=1, traverse from the first row of the image to the hth row, and traverse from the first column of each row to the w-step column, find the pixels in the left edge area of ​​the object, and set the grayscale value of the corresponding pixel at the result storage image to 255, and obtain the binary image of the left edge area in the result storage image; Step S32: Calculate the binary image of the right edge area of ​​the image to be detected, set d=8, m=1, traverse from the first row of the image to the hth row, and traverse each row from the wth column to the stepth column in descending order, find the pixels in the right edge area of ​​the object, and set the grayscale value of the pixel at the corresponding position in the result storage image to 255, and obtain the binary image of the right edge area in the result storage image; Step S33: Calculate the binary image of the upper edge area of ​​the image to be detected, set d=1, m=1, traverse from the first row of the image to the h-step row, and then traverse each row incrementally from the first column to the w-th column, find the pixels in the upper edge area of ​​the object, and set the grayscale value of the pixel at the corresponding position in the result storage image to 255, and obtain the binary image of the upper edge area in the result storage image; Step S34: Calculate the binary image of the lower edge area of ​​the image to be detected, set d=2, m=1, start from the hth row of the image and traverse in descending order to the stepth row, and then traverse in ascending order from the 1st column of each row to the wth column, find the pixels in the lower edge area of ​​the object, and set the grayscale value of the pixel at the corresponding position in the result storage image to 255, and obtain the binary image of the lower edge area in the result storage image; Step S35: merging the edge region binary images of the four grayscale transition results of the result storage images in steps S31 to S34 to obtain a complete edge region binary image; Step S36: The edge region binary image obtained in S35 is extracted using the findContours operator of openCV to obtain edge contour points, and the edge contour points are drawn on the image to be detected to form the edge of the object.

2. The image object edge extraction method according to claim 1, wherein: In step S3 , the width w of the image to be detected is the same as the number of columns of the regional binary image of the result stored image, and the height h of the image to be detected is the same as the number of rows of the regional binary image of the result stored image.

Citation Information

Patent Citations

  • HSV-based vehicle license plate shadow detection and removal method

    CN107292898A

  • Human face sketching system based on improved Sobel operator and human face contour extraction method based on improved Sobel operator

    CN108363986A