Image edge detection method, device, equipment and storage medium
By using Gaussian filtering and gradient information processing, edge images are directly generated from the initial image, solving the problems of poor reusability and low efficiency caused by parameter dependence in existing algorithms, and achieving efficient edge detection.
Patent Information
- Application Number
- CN202211667529.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-23
- Publication Date
- 2025-12-09
- Estimated Expiration
- 2042-12-23
AI Technical Summary
Existing image edge detection algorithms rely on parameter inputs, resulting in poor reusability and low efficiency.
By applying Gaussian filtering to the initial image, the gradient information of the Gaussian image is obtained, the target edge threshold is determined, edge points are filtered out, and the edge points are connected to generate an edge image. The entire process does not require any parameters to be input in advance.
It achieves efficient image edge detection without human intervention, improving the efficiency and adaptability of edge detection.
Smart Images

Figure CN115861354B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer vision, and particularly relates to an image edge detection method and device, equipment and a storage medium. BACKGROUND
[0002] An edge is the most basic visual feature in an image and is one of the most important contents of image processing. In order to more accurately obtain important structural properties in an image, edge detection is generated. With the rapid development of artificial intelligence, edge detection is widely applied in many fields, such as pedestrian tracking, face recognition, assisted driving and other fields with 2D image processing requirements.
[0003] At present, there are many effective edge detection algorithms, such as a Canny operator. The Canny operator has the advantages of obtaining weak edges and suppressing the generation of false edges. On the basis of a simple gradient operator, a single-pixel edge expansion strategy with good anti-noise performance and high positioning accuracy is introduced. On the basis of first-order differentiation, non-maximum suppression and double-threshold detection are added, which brings advantages and also has a disadvantage that cannot be ignored, that is, it is severely dependent on the prior input of parameters, such as the output image position, the upper threshold, the lower threshold, the size of the image template and other parameters, resulting in poor reusability in different scenes, and the parameter input also reduces the efficiency of edge detection to some extent. SUMMARY
[0004] The main purpose of the present application is to provide an image edge detection method, device, equipment and storage medium, which aims to solve the technical problem of low efficiency of current image edge detection.
[0005] To achieve the above purpose, the present application provides an image edge detection method, which comprises the following steps:
[0006] If an initial image input by a user is received, the initial image is subjected to Gaussian filtering to obtain a Gaussian image;
[0007] Gradient information of each pixel point in the Gaussian image is obtained, and a target edge threshold corresponding to the Gaussian image is determined according to each gradient information;
[0008] Each edge point is screened out from each pixel point according to the target edge threshold;
[0009] Each edge point is connected to obtain an edge image of the initial image.
[0010] Optionally, the gradient information comprises a target gradient value and a gradient direction.
[0011] The step of obtaining the gradient information of each pixel point in the Gaussian image comprises:
[0012] obtaining a gradient absolute value sum of each of the pixel points, and taking the gradient absolute value sum as the target gradient value;
[0013] determining a gradient direction of each of the pixel points by comparing the vertical gradient value and the horizontal gradient value.
[0014] Optionally, the step of determining the target edge threshold corresponding to the Gaussian image according to the gradient information comprises:
[0015] obtaining a width and a height of the initial image, and calculating a ratio between a product of the width and the height and each of the target gradient values;
[0016] aggregating each of the ratios based on a preset threshold weight to obtain the target edge threshold.
[0017] Optionally, the step of screening out each of the edge points from each of the pixel points according to the target edge threshold comprises:
[0018] calculating a target gradient value difference between each of the pixel points and a neighboring pixel point based on the gradient direction;
[0019] if each of the target gradient value differences is detected to be greater than or equal to the target edge threshold, taking each of the pixel points as the edge point.
[0020] Optionally, the gradient direction comprises a horizontal direction and a vertical direction, and the step of calculating a target gradient value difference between each of the pixel points and a neighboring pixel point based on the gradient direction comprises:
[0021] if the gradient direction is the horizontal direction, calculating a target gradient value difference between each of the pixel points and a horizontally neighboring pixel point;
[0022] if the gradient direction is the vertical direction, calculating a target gradient value difference between each of the pixel points and a vertically neighboring pixel point.
[0023] Optionally, the step of connecting each of the edge points to obtain an edge image of the initial image comprises:
[0024] detecting a growth direction of each of the edge points according to the gradient direction corresponding to each of the edge points, wherein the growth direction refers to a direction in which each of the edge points extends;
[0025] traversing each of the target edge points satisfying a preset termination condition based on the growth direction, connecting each of the edge points and the corresponding target edge point to obtain the edge image.
[0026] Optionally, the step of detecting the growth direction of each edge point according to the gradient direction corresponding to each edge point comprises:
[0027] if the gradient direction is vertical, determining that the growth direction of each edge point is upward or downward growth;
[0028] if the gradient direction is horizontal, determining that the growth direction of each edge point is leftward or rightward growth.
[0029] In addition, in order to achieve the above-mentioned purpose, the present application also provides an image edge detection device, which comprises:
[0030] a Gaussian filtering module, configured to perform Gaussian filtering on an initial image received by a user to obtain a Gaussian image;
[0031] a gradient calculation and edge threshold determination module, configured to obtain gradient information of each pixel point in the Gaussian image, and determine a target edge threshold corresponding to the Gaussian image according to the gradient information;
[0032] an edge point screening module, configured to screen each edge point from each pixel point according to the target edge threshold;
[0033] an edge image obtaining module, configured to connect each edge point to obtain an edge image of the initial image.
[0034] Optionally, the gradient calculation and edge threshold determination module is further configured to:
[0035] obtain the gradient absolute value sum between the vertical gradient value and the horizontal gradient value of each pixel point, and take the gradient absolute value sum as the target gradient value;
[0036] determine the gradient direction of each pixel point by comparing the vertical gradient value and the horizontal gradient value.
[0037] Optionally, the gradient calculation and edge threshold determination module is further configured to:
[0038] obtain the width and the height of the initial image, and calculate the ratio between the product of the width and the height and each target gradient value;
[0039] aggregate each ratio based on a preset threshold weight to obtain the target edge threshold.
[0040] Optionally, the edge point screening module is further configured to:
[0041] calculate a target gradient value difference between each pixel point and an adjacent pixel point based on the gradient direction of each pixel point;
[0042] If the difference between the target gradient values of each of the target gradient values is greater than or equal to the target edge threshold, each of the pixel points is regarded as the edge point.
[0043] Optionally, the edge point screening module is further configured to:
[0044] If the gradient direction is horizontal, a target gradient value difference between each of the pixel points and a horizontally adjacent pixel point is calculated.
[0045] If the gradient direction is vertical, a target gradient value difference between each of the pixel points and a vertically adjacent pixel point is calculated.
[0046] Optionally, the edge image obtaining module is further configured to:
[0047] According to the gradient direction corresponding to each of the edge points, a growth direction of each of the edge points is detected, wherein the growth direction refers to a direction in which each of the edge points extends.
[0048] Based on the growth direction of each of the edge points, each of the target edge points satisfying a preset termination condition is traversed, and each of the edge points and the corresponding target edge point is connected to obtain the edge image.
[0049] Optionally, the edge image obtaining module is further configured to:
[0050] If the gradient direction of each of the edge points is vertical, the growth direction of each of the edge points is determined to be upward or downward growth.
[0051] If the gradient direction of each of the edge points is horizontal, the growth direction of each of the edge points is determined to be leftward or rightward growth.
[0052] The present application also provides an image edge detection device, which comprises a memory, a processor, and an image edge detection program stored in the memory and executable on the processor, and the image edge detection program, when executed by the processor, implements the steps of the image edge detection method.
[0053] The present application also provides a readable storage medium, which stores an image edge detection program, and the image edge detection program, when executed by a processor, implements the steps of the image edge detection method.
[0054] The present application also provides a computer program product, which comprises a computer program, and the computer program, when executed by a processor, implements the steps of the image edge detection method.
[0055] The application provides an image edge detection method, device, equipment and storage medium. Compared with the current edge detection method which needs to input parameters, if the initial image input by the user is received, the initial image is subjected to Gaussian filtering, image noise suppression is performed, a smooth Gaussian image is obtained, each pixel point in the Gaussian image is acquired, gradient information of each pixel point in the Gaussian image is acquired, a target edge threshold corresponding to the Gaussian image is determined according to the gradient information, each edge point is screened out from each pixel point according to the target edge threshold, and the edge image of the initial image is obtained by connecting each edge point. The pixel value of each pixel point is input into a preset gradient function to acquire gradient information, and the corresponding target edge threshold is calculated according to the gradient information, so that the edge point is screened out according to the target edge threshold, each edge point is connected to obtain the edge image, the purpose of obtaining the edge image through the continuous calculation process of the gradient and the edge point is achieved, any parameter does not need to be input in advance, and manual intervention is not needed, the technical defects that the current edge detection algorithm generally needs to input parameters in advance, the reusability of the edge detection algorithm is not strong, and the efficiency of the edge detection is low are overcome, and the efficiency of the image edge detection is improved. BRIEF DESCRIPTION OF DRAWINGS
[0056] Figure 1 The figure is a flowchart of the first embodiment of the image edge detection method of the application.
[0057] Figure 2 The figure is an initial image related to the image edge detection method of the application.
[0058] Figure 3 The figure is a Gaussian image related to the image edge detection method of the application.
[0059] Figure 4 The figure is an edge point image related to the image edge detection method of the application.
[0060] Figure 5 The figure is an edge image related to the image edge detection method of the application.
[0061] Figure 6 The figure is a schematic diagram of an image edge detection device related to the image edge detection method of the application.
[0062] Figure 7 The figure is a schematic diagram of the device structure of the hardware running environment related to the image edge detection method of the application.
[0063] The implementation, functional features and advantages of the application will be further described with reference to the embodiments and the accompanying drawings. DETAILED DESCRIPTION
[0064] In order to make the above objectives, characteristics and advantages of the present application more apparent, clear and easier to understand, the technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by a person of ordinary skill in the art without creative work fall within the protection scope of the present application.
[0065] Embodiment one
[0066] At present, there are many effective edge detection algorithms, such as Canny operator. The advantage of Canny is that weak edges can be obtained while the generation of false edges is suppressed. On the basis of a simple gradient operator, a single-pixel edge expansion strategy with good anti-noise performance and high positioning accuracy is introduced. On the basis of first-order differentiation, non-maximum suppression and double-threshold detection are added, which brings advantages and also makes it have a disadvantage that cannot be ignored, that is, it is heavily dependent on the advance input of parameters, such as the output image position, the upper threshold, the lower threshold, the size of the image template and other parameters, resulting in poor reusability in different scenes, and the parameter input also reduces the efficiency of edge detection to some extent.
[0067] The embodiment of the present application provides an image edge detection method. In the first embodiment of the image edge detection method of the present application, referring to Figure 1 , the image edge detection method comprises the following steps.
[0068] In step S10, if an initial image input by a user is received, the initial image is subjected to Gaussian filtering to obtain a Gaussian image.
[0069] In step S20, gradient information of each pixel point in the Gaussian image is obtained, and a target edge threshold corresponding to the Gaussian image is determined according to each gradient information.
[0070] In step S30, each edge point is screened out from each pixel point according to the target edge threshold.
[0071] In step S40, each edge point is connected to obtain an edge image of the initial image.
[0072] In the embodiment, it should be noted that the initial image is an image that needs to be subjected to edge detection, which can be a color image or a grayscale image. The Gaussian image refers to an image obtained after Gaussian filtering. The gradient information can include the target gradient value and the gradient direction. The target gradient value refers to the sum of the gradient absolute values of the horizontal gradient value and the vertical gradient value of each pixel point, which is used to represent the gradient value of each pixel point in the overall image. The target edge threshold is used to screen out each edge point from each pixel point.
[0073] As an example, steps S10 to S40 include: if an initial image input by a user is received, performing Gaussian filtering on the initial image by any one of a direct convolution method, a repeated convolution method, an FFT (fast Fourier transform) implementation method, or a recursive implementation method, to obtain a Gaussian image, wherein the Gaussian image includes at least one pixel point, and in this embodiment, a Gaussian kernel can be set as [5, 5], or can be set according to actual detection conditions; obtaining pixel values corresponding to each of the pixel points, inputting each of the pixel values into a preset gradient function, and calculating a target gradient value and a gradient direction of each of the pixel points, wherein the preset gradient function can include a preset gradient value function and a preset gradient direction function, the preset gradient value function is used to calculate a horizontal gradient value and a vertical gradient value of each of the pixel points, and the target gradient value is calculated by summing the absolute values of the gradient values in the two directions, and the preset gradient direction function is used to determine the corresponding gradient direction according to the horizontal gradient value and the vertical gradient value of each of the pixel points; obtaining a width and a height of the initial image, calculating a product of the width and the height, and calculating a ratio between the product and the target gradient value of each of the pixel points, and finally aggregating each of the ratios based on a preset threshold weight to obtain the target edge threshold, wherein the preset threshold weight is an empirical value and can be set according to actual detection conditions; and filtering out edge points that meet conditions from each of the pixel points according to the target edge threshold, wherein the condition means that a target gradient value difference between each of the pixel points and two adjacent pixel points is calculated according to each of the gradient directions, and each of the edge points is detected by comparing each of the target gradient value differences with the target edge threshold; determining a growth direction of each of the edge points according to the gradient direction of each of the edge points, performing edge point traversal in the growth direction of each of the edge points, and stopping growth and connecting each of the edge points with a corresponding target edge point when each of the target edge points that meet a preset termination condition is detected, to finally obtain a complete edge image.
[0074] For example, as Figure 2 For an initial image, Gaussian filtering is performed on A to obtain a smooth Gaussian image Figure 2 The gradient value and the gradient direction of each of the pixel points in B are calculated, the target edge threshold is calculated, and the edge points are filtered out according to the target edge threshold, to generate an edge point image Figure 4 Each of the edge points in Figure 4 is connected according to the corresponding growth direction, and finally a complete edge image Figure 5 is obtained.
[0075] The step of obtaining gradient information of each pixel point in the Gaussian image comprises:
[0076] In step S21, an absolute gradient sum of a vertical gradient value and a horizontal gradient value of each pixel point is obtained, and the absolute gradient sum is taken as the target gradient value.
[0077] In step S22, a gradient direction of each pixel point is determined by comparing the vertical gradient value and the horizontal gradient value.
[0078] In the embodiment, it is to be noted that a general gradient direction calculation method is to calculate an arctangent function between the vertical gradient value and the horizontal gradient value, and an angle value is obtained to represent the gradient direction. However, there are eight neighborhoods corresponding to each edge point, i.e. up, down, left, right, upper left, upper right, lower left and lower right, which are the positions immediately adjacent and the positions diagonally adjacent, and there are eight directions. In actual application, only the neighborhood direction corresponding to the edge point is needed to be known, and the specific angle value is not needed to be taken. Therefore, in the embodiment, the gradient direction is only divided into two items, i.e. horizontal and vertical, and the specific growth direction is further selected in the horizontal and vertical directions according to the gradient value of each pixel point. In this way, the calculation amount can be greatly reduced, and a good edge detection effect can be achieved.
[0079] As an example, steps S21 to S22 comprise: obtaining pixel values of each pixel point at each coordinate point, inputting each pixel value into a preset gradient function, calculating a vertical gradient value, a horizontal gradient value and an absolute gradient sum of each pixel point, taking the absolute gradient sum as the target gradient value; inputting an absolute value of the horizontal gradient value and an absolute value of the vertical gradient value into the preset gradient direction function, comparing the two absolute values, if the absolute value of the horizontal gradient value is greater than the absolute value of the vertical gradient value, determining that the gradient direction of the corresponding pixel point is 0, i.e. horizontal, if the absolute value of the horizontal gradient value is less than or equal to the absolute value of the vertical gradient value, determining that the gradient direction of the corresponding pixel point is 1, i.e. vertical.
[0080] In an implementable manner, the preset gradient size function is as follows:
[0081] G x = f(i, j) - f(i + 1, j + 1)
[0082] G y = f(i, j + 1) - f(i + 1, j)
[0083] G = |G x | + |G y |
[0084] wherein f(i,j) represents a pixel value of an i,j coordinate point in an image, G x represents a horizontal gradient value, G y represents a vertical gradient value, and G represents a target gradient value.
[0085] The preset gradient direction function is as follows:
[0086]
[0087] wherein 0 represents a horizontal gradient direction, and 1 represents a vertical gradient direction.
[0088] The step of determining the target edge threshold corresponding to the Gaussian image according to the gradient information includes:
[0089] In step S23, the width and the height of the initial image are obtained, and a ratio between a product of the width and the height and each target gradient value is calculated.
[0090] In step S24, each ratio is aggregated based on a preset threshold weight to obtain the target edge threshold.
[0091] As an example, steps S23 to S24 include: when the user inputs the initial image, the width and the height of the initial image are obtained, the product of the width and the height is calculated, and the ratio between the product and each target gradient value is calculated; the ratio is input into a preset edge function and multiplied by the preset threshold weight to aggregate each ratio, thereby obtaining the target edge threshold, wherein the aggregation refers to calculating the average value of all ratios, and the preset edge function is used to obtain the target edge threshold of a subsequent selected edge point. Since the function only involves parameters of the initial image itself and does not require additional input of other parameters, the function has self-adaptability, thereby improving the simplicity of image edge detection.
[0092] In an implementable manner, the preset edge function is as follows:
[0093]
[0094] wherein k represents the preset threshold weight, H represents the height of the initial image, W represents the width of the initial image, and G(i,j) represents the target gradient value of a pixel point at coordinate (i,j).
[0095] The step of screening each edge point from each pixel point according to the target edge threshold includes:
[0096] In step S31, a target gradient value difference between each pixel point and an adjacent pixel point is calculated based on each gradient direction.
[0097] Step S32, if the difference of each target gradient value is greater than or equal to the target edge threshold, each pixel point is regarded as the edge point.
[0098] As an example, steps S31 to S32 include: if the gradient direction is horizontal, calculating the difference of target gradient value between each pixel point and horizontally adjacent pixel points, if the gradient direction is vertical, calculating the difference of target gradient value between each pixel point and vertically adjacent pixel points; inputting each target gradient value difference into a preset edge point judgment function to detect whether each target gradient value difference is greater than or equal to the target edge threshold, if yes, determining the corresponding pixel point as the edge point, if no, determining the corresponding pixel point is not the edge point.
[0099] In an implementable manner, the preset edge point judgment function is as follows:
[0100] ang = 1, and G(i,j)-G(i,j-1) ≥ T, G(i,j)-G(i,j+1) ≥ T, then the pixel point of coordinate (i,j) is an edge point.
[0101] ang = 0, and G(i,j)-G(i-1,j) ≥ T, G(i,j)-G(i+1,j) ≥ T, then the pixel point of coordinate (i,j) is an edge point.
[0102] Wherein, ang represents the gradient direction, and T represents the target edge threshold.
[0103] Wherein, the step of calculating the difference of target gradient value between each pixel point and adjacent pixel points based on each gradient direction includes:
[0104] Step S311, if the gradient direction is horizontal, calculating the difference of target gradient value between each pixel point and horizontally adjacent pixel points;
[0105] Step S312, if the gradient direction is vertical, calculating the difference of target gradient value between each pixel point and vertically adjacent pixel points.
[0106] As an example, steps S311 to S312 include: if the gradient direction is horizontal, calculating the difference of target gradient value between each pixel point and two pixel points adjacent in horizontal direction; if the gradient direction is vertical, calculating the difference of target gradient value between each pixel point and two pixel points adjacent in vertical direction, and detecting whether each target gradient value difference is greater than or equal to the target edge threshold, if yes, determining each pixel point as the edge point.
[0107] For example, assuming that the gradient direction of the pixel point A(i, j) is 1, i.e. vertical, the first target gradient value difference between the target gradient values of A and the adjacent two pixel points B(i, j+1) and C(i, j-1) in the vertical direction is calculated, i.e. G y1 =G(i, j)-G(i, j+1) and G y2 =G(i, j)-G(i, j-1), assuming that the target edge threshold is T, whether G y1 and G y2 are both greater than or equal to T is detected, if yes, A is determined as an edge point; similarly, assuming that the gradient direction of A is 0, i.e. horizontal, the second target gradient value difference between the target gradient values of A and the adjacent two pixel points M(i+1, j) and N(i-1, j) in the horizontal direction is calculated, i.e. G x1 =G(i, j)-G(i-1, j) and G x2 =G(i, j)-G(i+1, j), whether G x1 and G x2 are both greater than or equal to T is detected, if yes, A is determined as an edge point.
[0108] The step of connecting the edge points to obtain the edge image of the initial image comprises:
[0109] In step S41, the growth direction of each edge point is detected according to the gradient direction corresponding to each edge point, wherein the growth direction refers to the direction in which each edge point extends;
[0110] In step S42, based on the growth direction of each edge point, each target edge point satisfying a preset termination condition is traversed, and each edge point and the corresponding target edge point are connected to obtain the edge image.
[0111] In this embodiment, it should be noted that the preset termination condition refers to the condition under which each edge point stops growing, which can be set as encountering other edges generated by other seed points or the surrounding having no gradient information, i.e. G(i, j)=0.
[0112] As an example, the steps S41 to S42 include: detecting a growth direction of each of the edge points according to a gradient direction corresponding to each of the edge points, wherein when the gradient direction is horizontal, the corresponding growth direction can include left growth and right growth, and when the gradient direction is vertical, the corresponding growth direction includes upward growth and downward growth; performing edge point traversal according to the growth direction of each of the edge points, stopping growth when the target edge point satisfying the preset termination condition is detected, connecting each of the edge points and the corresponding target edge point, and then taking the target edge point as a base point, continuing to perform traversal according to the gradient direction and the growth direction of the target edge point, detecting a next target edge point corresponding to the target edge point, and connecting the next target edge point, to obtain a complete edge image through the above-mentioned cycle.
[0113] The step of detecting the growth direction of each of the edge points according to the gradient direction corresponding to each of the edge points includes:
[0114] If each of the gradient directions is vertical, the growth direction of each of the edge points is determined to be upward growth or downward growth.
[0115] If each of the gradient directions is horizontal, the growth direction of each of the edge points is determined to be left growth or right growth.
[0116] As an example, the steps S411 to S412 include: if each of the gradient directions is vertical, the growth direction of each of the edge points is determined to be upward growth or downward growth; and if each of the gradient directions is horizontal, the growth direction of each of the edge points is determined to be left growth or right growth, and further, according to a target gradient value of each of the edge points, it can be determined whether to grow left upward, left downward, right downward or right upward.
[0117] For example, assuming that the target gradient value of the edge point D(i, j) is G(i, j), the target gradient values of E(i-1, j-1), F(i-1, j) and J(i-1, j+1) are calculated, that is, G(E), G(F) and G(J), and it is detected whether G(E) is greater than G(F) and whether G(E) is greater than G(J), if both are greater, it is determined that D grows left downward; similarly, the target gradient value of H(i-1, j+1) is calculated, that is, G(H), and it is detected whether G(H) is greater than G(F) and whether G(H) is greater than G(E), if both are greater, it is determined that D grows left upward; if neither is satisfied, it is determined that D grows left, and similarly, right downward growth and right upward growth can be detected.
[0118] The embodiment provides an image edge detection method, device, equipment and storage medium. Compared with the current edge detection method which needs to input parameters, if the initial image input by the user is received, the initial image is subjected to Gaussian filtering, image noise suppression is performed, a smooth Gaussian image is obtained, each pixel point in the Gaussian image is acquired, gradient information of each pixel point in the Gaussian image is acquired, a target edge threshold corresponding to the Gaussian image is determined according to the gradient information, each edge point is screened out from each pixel point according to the target edge threshold, and the edge image of the initial image is obtained by connecting each edge point. The pixel value of each pixel point is directly input into a preset gradient function to acquire gradient information, the corresponding target edge threshold is calculated according to the gradient information, the edge point is screened out according to the target edge threshold, each edge point is connected to obtain the edge image, the purpose of obtaining the edge image through the gradient and the continuous calculation process of the edge point by only inputting the initial image is achieved, any parameter does not need to be input in advance, and manual intervention is not needed, the technical defects that the current edge detection algorithm generally needs to input parameters in advance, the reusability of the edge detection algorithm is not strong, and the efficiency of the edge detection is low are overcome, and the efficiency of the image edge detection is improved.
[0119] In addition, the embodiment of the application further provides an image edge detection device, as shown in the following Figure 6 The image edge detection device comprises:
[0120] A Gaussian filtering module 10 is configured to perform Gaussian filtering on the initial image if the initial image input by the user is received, so as to obtain a Gaussian image.
[0121] A gradient calculation and edge threshold determination module 20 is configured to acquire gradient information of each pixel point in the Gaussian image, and determine a target edge threshold corresponding to the Gaussian image according to the gradient information.
[0122] An edge point screening module 30 is configured to screen each edge point from each pixel point according to the target edge threshold.
[0123] An edge image obtaining module 40 is configured to connect each edge point to obtain the edge image of the initial image.
[0124] Optionally, the gradient calculation and edge threshold determination module 20 is further configured to:
[0125] acquire the gradient absolute value sum between the vertical gradient value and the horizontal gradient value of each pixel point, and take the gradient absolute value sum as the target gradient value.
[0126] The gradient direction of each pixel point is determined by comparing the vertical gradient value and the horizontal gradient value.
[0127] Optionally, the gradient calculating and edge threshold determining module 20 is further configured to:
[0128] acquire a width and a height of the initial image, and calculate a ratio between a product of the width and the height and each of the target gradient values;
[0129] aggregate each of the ratios based on a preset threshold weight to obtain the target edge threshold.
[0130] Optionally, the edge point screening module 30 is further configured to:
[0131] calculate a target gradient value difference between each of the pixel points and an adjacent pixel point based on each of the gradient directions;
[0132] if each of the target gradient value differences is greater than or equal to the target edge threshold, each of the pixel points is determined as the edge point.
[0133] Optionally, the edge point screening module 30 is further configured to:
[0134] if the gradient direction is horizontal, a target gradient value difference between each of the pixel points and a horizontally adjacent pixel point is calculated;
[0135] if the gradient direction is vertical, a target gradient value difference between each of the pixel points and a vertically adjacent pixel point is calculated.
[0136] Optionally, the edge image obtaining module 40 is further configured to:
[0137] detect a growth direction of each of the edge points according to the gradient direction corresponding to each of the edge points, wherein the growth direction refers to a direction in which each of the edge points extends;
[0138] based on each of the growth directions, traverse each of the target edge points satisfying a preset termination condition, and connect each of the edge points and the corresponding target edge point to obtain the edge image.
[0139] Optionally, the edge image obtaining module 40 is further configured to:
[0140] if each of the gradient directions is vertical, the growth direction of each of the edge points is determined as upward or downward growth;
[0141] if each of the gradient directions is horizontal, the growth direction of each of the edge points is determined as leftward or rightward growth.
[0142] The image edge detection device provided in the present application adopts the image edge detection method in the above embodiments, and solves the technical problem of low image edge detection efficiency. Compared with the prior art, the image edge detection device provided in the embodiments of the present application has the same beneficial effects as the image edge detection method provided in the above embodiments, and other technical features in the image edge detection device are the same as the features disclosed in the above embodiments, which will not be repeated here.
[0143] The present application provides an electronic device, referring to Figure 7 , the electronic device comprises at least one processor, and a memory connected with the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the image edge detection method in the above embodiment one.
[0144] Figure 7 It shows a structural schematic diagram of an electronic device suitable for implementing the embodiments of the present disclosure. The electronic device in the embodiments of the present disclosure can include but is not limited to mobile terminals such as mobile phones, notebook computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablets), PMPs (portable multimedia players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), and the like, and fixed terminals such as digital TVs, desktop computers, and the like. Figure 7 The electronic device shown is only an example, and should not impose any limitation on the functions and use range of the embodiments of the present disclosure.
[0145] As shown in Figure 7 , the electronic device can include a processing device (such as a central processor, a graphics processor, etc.) that can perform various appropriate actions and processes according to programs stored in a read-only memory (ROM) or loaded into a random access memory (RAM) from a storage device. In the RAM, various programs and data required for the operation of the electronic device are also stored. The processing device, the ROM, and the RAM are connected to each other through a bus. An input / output (I / O) interface is also connected to the bus.
[0146] Generally, the following systems can be connected to the I / O interface: input devices including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; output devices including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices including, for example, a magnetic tape, a hard disk, etc.; and communication devices. The communication devices can allow the electronic device to communicate wirelessly or wiredly with other devices to exchange data. Although the electronic device with various systems is shown in the figure, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be alternatively implemented or provided.
[0147] In particular, the processes described above with reference to the flowcharts can be implemented as a computer software program according to embodiments of the present disclosure. For example, embodiments of the present disclosure include a computer program product comprising a computer program carried on a computer readable medium, the computer program comprising program code for performing the methods illustrated by the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device, or installed from a storage device, or installed from a ROM. When the computer program is executed by a processing device, the above-mentioned functions defined in the methods of embodiments of the present disclosure are performed.
[0148] The electronic device provided by the present application adopts the image edge detection method in the above-mentioned embodiments, and solves the technical problem of low image edge detection efficiency. Compared with the prior art, the electronic device provided by the embodiments of the present application has the same beneficial effects as the image edge detection method provided by the above-mentioned embodiments, and other technical features in the electronic device are the same as the features disclosed in the above-mentioned embodiments, which will not be repeated here.
[0149] It should be understood that parts of the present disclosure can be realized by hardware, software, firmware or a combination thereof. In the description of the above-mentioned embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0150] The above is merely specific implementation of the present application, but the protection scope of the present application is not limited thereto, any person skilled in the art can easily think of changes or replacements within the technical range disclosed by the present application, which should be covered in the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.
[0151] The present embodiment provides a computer readable storage medium having stored thereon computer readable program instructions for performing the image edge detection method in the above-mentioned embodiment one.
[0152] The computer readable storage medium provided by the embodiments of the present application may, for example, be a U disk, but is not limited to an electric, magnetic, optical, electromagnetic, infrared, or semiconductor system, system, or device, or any combination thereof. More specific examples of the computer readable storage medium may include, but are not limited to, an electric connection with one or more conductive wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the embodiments, the computer readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, system, or device. The program code contained on the computer readable storage medium can be transmitted by any suitable medium, including but not limited to: electric wires, optical cables, RF (radio frequency), etc., or any suitable combination thereof.
[0153] The above computer readable storage medium may be contained in an electronic device, or may exist separately without being assembled into an electronic device.
[0154] The above computer readable storage medium carries one or more programs, which, when executed by an electronic device, cause the electronic device to: if an initial image input by a user is received, perform Gaussian filtering on the initial image to obtain a Gaussian image; obtain gradient information of each pixel point in the Gaussian image, and determine a target edge threshold corresponding to the Gaussian image according to each gradient information; according to the target edge threshold, screen out each edge point from each pixel point; and connect each edge point to obtain an edge image of the initial image.
[0155] Computer program code for carrying out operations of the present disclosure can be written in one or more programming languages or combinations thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" language or similar programming languages. Program code can be executed entirely on a user computer, partially on a user computer, as a separate software package, partially on a user computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer can be connected to the user computer through any kind of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (for example, through the Internet by using an Internet service provider).
[0156] The flow and block diagrams in the drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present application. In this regard, each block in the flow and block diagrams can represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical functions. It should also be noted that in some alternative implementations, the functions noted in the blocks can occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently or the blocks may be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and / or flowchart illustrations, and combinations thereof, can be implemented by special purpose hardware-based systems that perform the specified functions or operations, or combinations of special purpose hardware and computer instructions.
[0157] The modules involved in the embodiments of the present disclosure can be implemented in the form of software or in the form of hardware. In some cases, the name of the module does not constitute a limitation on the unit itself.
[0158] The computer readable storage medium provided by the present application stores computer readable program instructions for executing the image edge detection method described above, and solves the technical problem of low image edge detection efficiency. Compared with the prior art, the beneficial effects of the computer readable storage medium provided by the embodiments of the present application are the same as those of the image edge detection method provided by the above embodiments, and are not described here.
[0159] The present application also provides a computer program product, comprising a computer program, which is executed by a processor to implement the steps of the image edge detection method as described above.
[0160] The computer program product provided by the present application solves the technical problem of low image edge detection efficiency. Compared with the prior art, the beneficial effects of the computer program product provided by the embodiments of the present application are the same as those of the image edge detection method provided by the above embodiments, and are not described here.
[0161] The above is only the preferred embodiment of the present application, and does not limit the patent scope of the present application, and any equivalent structure or equivalent flow transformation using the content of the specification and drawings, or direct or indirect application in other related technical fields, are also included in the patent processing scope of the present application.
Claims
1. An image edge detection method characterized by, The image edge detection method comprises: if an initial image input by a user is received, performing Gaussian filtering on the initial image to obtain a Gaussian image; obtaining gradient information of each pixel point in the Gaussian image, and determining a target edge threshold corresponding to the Gaussian image according to each gradient information; calculating a target gradient value difference between each pixel point and a neighboring pixel point based on each gradient direction; if each target gradient value difference is detected to be greater than or equal to the target edge threshold, regarding each pixel point as an edge point; connecting each edge point to obtain an edge image of the initial image; the gradient information comprises a target gradient value and a gradient direction; the step of obtaining the gradient information of each pixel point in the Gaussian image comprises: obtaining a gradient absolute value sum between a vertical gradient value and a horizontal gradient value of each pixel point, and taking the gradient absolute value sum as the target gradient value; determining the gradient direction of each pixel point by comparing the vertical gradient value and the horizontal gradient value; the step of determining the target edge threshold corresponding to the Gaussian image according to each gradient information comprises: obtaining a width and a height of the initial image, and calculating a ratio between a product of the width and the height and each target gradient value; aggregating each ratio based on a preset threshold weight to obtain the target edge threshold.
2. The image edge detection method of claim 1, wherein, the gradient direction comprises a horizontal direction and a vertical direction; the step of calculating the target gradient value difference between each pixel point and a neighboring pixel point based on each gradient direction comprises: if the gradient direction is the horizontal direction, calculating a target gradient value difference between each pixel point and a horizontally neighboring pixel point; if the gradient direction is the vertical direction, calculating a target gradient value difference between each pixel point and a vertically neighboring pixel point.
3. The image edge detection method of claim 1, wherein, the step of connecting each edge point to obtain an edge image of the initial image comprises: detecting a growth direction of each edge point according to a gradient direction corresponding to each edge point, wherein the growth direction refers to a direction in which each edge point extends; based on each growth direction, traversing each target edge point satisfying a preset termination condition, connecting each edge point and a corresponding target edge point to obtain the edge image.
4. The image edge detection method of claim 3, wherein, the step of detecting a growth direction of each edge point according to a gradient direction corresponding to each edge point comprises: if the gradient direction is the vertical direction, determining that the growth direction of each edge point is upward growth or downward growth; if the gradient direction is the horizontal direction, determining that the growth direction of each edge point is leftward growth or rightward growth.
5. An image edge detection apparatus characterized by comprising: The image edge detection device comprises: a Gaussian filtering module configured to, if an initial image input by a user is received, perform Gaussian filtering on the initial image to obtain a Gaussian image; The gradient calculation and edge threshold determination module is configured to obtain gradient information of each pixel point in the Gaussian image, and determine a target edge threshold corresponding to the Gaussian image according to the gradient information. The gradient information includes a target gradient value and a gradient direction. The gradient calculation and edge threshold determination module is further configured to obtain a gradient absolute value sum between a vertical gradient value and a horizontal gradient value of each pixel point, and take the gradient absolute value sum as the target gradient value. The gradient direction of each pixel point is determined by comparing the vertical gradient value and the horizontal gradient value. The gradient calculation and edge threshold determination module is further configured to obtain a width and a height of the initial image, and calculate a ratio between a product of the width and the height and each target gradient value. The target edge threshold is obtained by aggregating each ratio based on a preset threshold weight. The edge point screening module is configured to screen each edge point from each pixel point according to the target edge threshold. The edge point screening module is further configured to calculate a target gradient value difference between each pixel point and an adjacent pixel point based on each gradient direction. If each target gradient value difference is detected to be greater than or equal to the target edge threshold, each pixel point is taken as an edge point. The edge image obtaining module is configured to connect each edge point to obtain an edge image of the initial image.
6. An electronic device, comprising: The electronic device includes: at least one processor; and a memory connected with the at least one processor in communication; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the steps of the image edge detection method in any one of claims 1 to 4.
7. A readable storage medium, characterized by, The readable storage medium stores a program for implementing an image edge detection method, and the program is executed by a processor to implement the steps of the image edge detection method in any one of claims 1 to 4.
Citation Information
Patent Citations
Non-maximum suppression, dynamic threshold calculation and image edge detection method
CN109816673A