Image edge detection method, device, electronic device and storage medium

Through the combination of eight-direction convolution templates and adaptive thresholds, the problems of low efficiency and poor accuracy of traditional image edge detection are solved, and more efficient and accurate image edge detection is achieved.

CN114581472BActive Publication Date: 2024-11-12XIAN YUWEI SEMICONDUCTOR TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210236032.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-03-11
Publication Date
2024-11-12
Estimated Expiration
2042-03-11

AI Technical Summary

Technical Problem

Traditional image edge detection algorithms are inefficient, difficult to meet the needs of high speed and high accuracy, and can easily lead to incomplete edge points and inaccurate threshold settings, resulting in information loss.

Method used

The eight-direction convolution template is used to detect the image edge, and the gradient amplitude is determined through the convolution operation of the local image target matrix and the convolution template, and the adaptive threshold is used to replace the global threshold, improving detection efficiency and accuracy.

Benefits of technology

Improves the efficiency and accuracy of image edge detection, reduces noise impact and false edges, and enhances edge continuity and detail richness.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114581472B_ABST
    Figure CN114581472B_ABST
Patent Text Reader

Abstract

The embodiment of the present invention discloses an image edge detection method, device, electronic device and storage medium. The method includes: obtaining a local image target matrix, and saving the central pixel point of the local image target matrix as a local image threshold; performing a convolution operation on the local image target matrix and a convolution template to determine the gradient amplitude in each direction, and determining the target gradient amplitude based on the gradient amplitude results in each direction; wherein the convolution module includes convolution templates in eight directions; comparing the target gradient amplitude with the local image threshold to determine the local image grayscale value result. The technical solution of the embodiment of the present invention is adopted to expand the two-directional convolution template into an eight-directional convolution module, and at the same time adopt an adaptive threshold to replace the global threshold, thereby improving the accuracy of image edge detection and improving the efficiency of image edge detection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present invention relate to the field of digital image recognition, and in particular to an image edge detection method, device, electronic device and storage medium. Background Art

[0002] Edge detection is a key technology in digital image processing. It is the basis of defect detection, pattern recognition, target tracking and image segmentation. Its recognition accuracy and speed will directly affect the effect of subsequent image analysis algorithms. Most traditional image edge detection algorithms rely on software programs to extract edges using the first-order derivative extreme values ​​of image pixels (such as Prewitt operator, Roberts operator, Sobel operator, etc.) or second-order derivative zero-crossing information (such as Laplacian operator, LOG operator, DOG operator, etc.). However, it is easy to cause incomplete image edge points. At the same time, the edge information extracted by manually setting the threshold is quite different. Inaccurate threshold setting can easily lead to the loss of key edge details. In addition, the serial execution of detection using software programs is inefficient and frame loss is common. Therefore, it is difficult to meet the current high-speed and high-precision requirements.

[0003] Therefore, how to improve the efficiency of image edge detection is a technical problem that needs to be solved urgently by those skilled in the art. Summary of the invention

[0004] The embodiments of the present invention provide an image edge detection method, an apparatus, an electronic device and a storage medium to improve the efficiency of image edge detection.

[0005] In a first aspect, an embodiment of the present invention provides an image edge detection method, comprising:

[0006] Obtaining a local image target matrix, and saving a central pixel point of the local image target matrix as a local image threshold;

[0007] The local image target matrix is ​​convolved with a convolution template to determine the gradient amplitude in each direction, and the target gradient amplitude is determined according to the gradient amplitude results in each direction; wherein the convolution module includes convolution templates in eight directions;

[0008] The target gradient magnitude is compared with the local image threshold to determine the local image grayscale value result.

[0009] In a second aspect, an embodiment of the present invention further provides an image edge detection device, comprising:

[0010] A local image threshold determination module is used to obtain a local image target matrix and save the central pixel point of the local image target matrix as a local image threshold;

[0011] A target gradient amplitude determination module, used for performing a convolution operation on the local image target matrix and a convolution template to determine the gradient amplitude in each direction, and determining the target gradient amplitude according to the gradient amplitude results in each direction; wherein the convolution module includes convolution templates in eight directions;

[0012] The grayscale value result determination module is used to compare the target gradient amplitude with the local image threshold to determine the local image grayscale value result.

[0013] In a third aspect, an embodiment of the present invention further provides an electronic device, the electronic device comprising:

[0014] one or more processors;

[0015] A storage device for storing one or more programs;

[0016] When the one or more programs are executed by the one or more processors, the one or more processors implement the image edge detection method described in any embodiment of the present invention.

[0017] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the image edge detection method described in any embodiment of the present invention.

[0018] The embodiment of the present invention provides an image edge detection method, device, electronic device and storage medium, which obtains a local image target matrix and saves the central pixel of the local image target matrix as the local image threshold; performs convolution operation on the local image target matrix and a convolution template to determine the gradient amplitude in each direction, and determines the target gradient amplitude based on the gradient amplitude results in each direction; wherein the convolution module includes convolution templates in eight directions; compares the target gradient amplitude with the local image threshold to determine the grayscale value result of the local image. The technical solution of the embodiment of the present invention is adopted to expand the two-direction convolution template into an eight-direction convolution module, and after the local image is subjected to eight-direction convolution parallel operation and size comparison judgment, the optimal gradient direction of the local image can be obtained; at the same time, an adaptive threshold is used instead of a global threshold to improve the accuracy of image edge detection and the efficiency of image edge detection. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] Other features, objects and advantages of the present invention will become more apparent by reading the detailed description of non-limiting embodiments made with reference to the following drawings. The drawings are only for the purpose of illustrating preferred embodiments and are not to be considered as limiting the present invention. Also, the same reference symbols are used throughout the drawings to represent the same parts. In the drawings:

[0020] Figure 1Ais a flow chart of an image edge detection method provided by Embodiment 1 of the present invention;

[0021] Figure 1B Schematic diagram of an image matrix convolution template of a traditional Sobel operator provided in an embodiment of the present invention;

[0022] Figure 1C is a schematic diagram of an eight-directional convolution module provided in an embodiment of the present invention;

[0023] Figure 2A A flowchart of an image edge detection method provided in Embodiment 2 of the present invention;

[0024] Figure 2B It is a flow chart of a median filtering algorithm provided by an embodiment of the present invention;

[0025] Figure 2C is a schematic diagram of an image pixel arrangement provided by an embodiment of the present invention;

[0026] Figure 2D is a schematic diagram of an edge detection algorithm flow provided in an embodiment of the present invention;

[0027] Figure 2E is a schematic diagram of an image edge detection test result provided in an embodiment of the present invention;

[0028] Figure 3A A flowchart of an image edge detection method provided in Embodiment 3 of the present invention;

[0029] Figure 3B is a block diagram of an image edge detection system provided in an embodiment of the present invention;

[0030] Figure 3C is a schematic diagram of an algorithm structure of an image detection system provided in an embodiment of the present invention;

[0031] Figure 3D is a schematic diagram of an SDRAM ping-pong operation structure provided in an embodiment of the present invention;

[0032] Figure 3E is a schematic diagram of edge detail comparison provided in an embodiment of the present invention;

[0033] Figure 4 is a structural schematic diagram of an image edge detection device provided by Embodiment 4 of the present invention;

[0034] Figure 5 It is a structural schematic diagram of an electronic device provided in Example 5 of the present application. DETAILED DESCRIPTION

[0035] The present invention will be further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the present invention, rather than to limit the present invention. It should also be noted that, for ease of description, only parts related to the present invention, rather than all structures, are shown in the accompanying drawings.

[0036] Before discussing the exemplary embodiments in more detail, it should be mentioned that some exemplary embodiments are described as processes or methods depicted as flow charts. Although the flow charts describe the operations (or steps) as sequential processes, many of the operations (or steps) therein can be implemented in parallel, concurrently or simultaneously. In addition, the order of the operations can be rearranged. The process can be terminated when its operation is completed, but can also have additional steps not included in the accompanying drawings. The process can correspond to a method, function, procedure, subroutine, subprogram, etc.

[0037] Embodiment 1

[0038] Figure 1A This is a flow chart of an image edge detection method provided by Embodiment 1 of the present invention. This embodiment is applicable to the case of edge detection of an image. The method of this embodiment can be executed by an image edge detection device, which can be implemented in hardware and / or software. The device can be configured in a server for image edge detection.

[0039] Edges usually refer to a set of pixels where the grayscale value of an image changes dramatically. In theory, they are caused by an instantaneous jump in the grayscale value. However, in actual image areas, the change from light to dark or from dark to light is a gradual process, and the grayscale curve has a certain slope. Traditional edge detection uses differential form to measure the size of this slope. Through the convolution operation of a specific differential operator and the local area of ​​the image, the operation result is compared with the threshold to obtain the image edge information. Figure 1B is a schematic diagram of an image matrix convolution template of a traditional Sobel operator provided in an embodiment of the present invention, see Figure 1B ,like Figure 1B As shown in (a) and (b), the traditional Sobel operator is divided into two directions, x and y, where the x direction is used for horizontal edge detection and the y direction is used for vertical edge detection. In order to improve the accuracy of image detection and the richness of edge details, 3x 3 convolution templates in the directions of 45°, 135°, 180°, 225°, 270° and 315° are added to the traditional Sobel operator. The method specifically includes the following steps:

[0040] S110, obtaining a local image target matrix, and saving a central pixel point of the local image target matrix as a local image threshold.

[0041] The local image target matrix may refer to using an image acquisition device to obtain a partial image of the image to be detected as a local image, and generating the local image target matrix based on the local image data. The local image target matrix may refer to a 3×3 image matrix.

[0042] If the acquired local image does not contain noise, the central pixel of the local highlight target matrix is ​​saved as the local image threshold. Figure 1B As shown, the center pixel point of the target matrix is Figure 1B Pixel b in (c) 2 .

[0043] S120, performing a convolution operation on the local image target matrix and a convolution template to determine the gradient amplitudes in each direction, and determining the target gradient amplitude according to the gradient amplitude results in each direction.

[0044] The convolution template may refer to a 3x 3 convolution template with 45°, 135°, 180°, 225°, 270° and 315° directions added to the traditional Sobel operator x and y directions. It is an eight-direction convolution template. Figure 1C Schematic diagram of an eight-directional convolution module provided in an embodiment of the present invention. Compared with the 5x 5 template, this size template can effectively reduce the number of convolution operations inside the FPGA, shorten the operation time and save a lot of memory resources. Other size templates are also applicable, and the embodiment of the present invention does not make specific restrictions. Figure 1C The weight in each template is determined by the distance to the center pixel and the angle. Other methods for determining the weight are also applicable, and the embodiment of the present invention does not make specific limitations.

[0045] Convolution operation can refer to the weighted summation process, where each pixel in the image area is multiplied by each element of the convolution module, and the sum of all products is used as the new value of the center pixel of the image area. For example, each pixel of the local image target matrix is ​​multiplied by Figure 1C Each element of the convolution module in each direction is multiplied correspondingly, and the sum of the products is used as the latest pixel value of the central pixel of the local image target matrix.

[0046] The gradient magnitude may refer to the latest pixel value of the central pixel of the local image target matrix in each direction obtained by convolution operation. For example, each pixel of the local image target matrix is ​​respectively Figure 1C Each element of the convolution module in each direction is multiplied to determine the gradient amplitude in each direction. The gradient amplitude with the largest absolute value in each direction is selected as the target gradient amplitude. The gradient amplitude in each direction is calculated according to the following formula:

[0047]

[0048] The local image gradient magnitude uses the vector [G 0° ,G 45° ,G 90° ,G 135° ,G 180° ,G 225° ,G 270° ,G 315° ] T The norm of the image is expressed, and the infinite norm is used to simplify the gradient calculation, as shown in the following formula: ∞ ;

[0049] M ∞ =max{|G 0° |,|G 45° |,|G 90° |,|G 135° |,|G 180° |,|G 225° |,|G 270° |,|G 315° |}

[0050] S130: Compare the target gradient amplitude with the local image threshold to determine the local image grayscale value result.

[0051] Wherein, the target gradient amplitude is compared with the local image threshold. If the target gradient amplitude is greater than the local image threshold, the pixel value of the local image is set to a preset value, such as 255, to set the local image pixel value to white; if the target gradient amplitude is less than or equal to the local image threshold, the pixel value of the local image is set to a preset value, such as 0, to set the local image pixel value to black. The local image threshold Med can be automatically set according to the distribution of pixel gray values ​​in different image areas, and the threshold is adjusted in real time as the pixel gray values ​​of the image area change. The determination of the gray value of each pixel point of the local image is completed adaptively according to the local image threshold and the target gradient amplitude.

[0052] The embodiment of the present invention provides an image edge detection method, which obtains a local image target matrix and saves the central pixel point of the local image target matrix as the local image threshold; performs convolution operation on the local image target matrix and a convolution template to determine the gradient amplitude in each direction, and determines the target gradient amplitude based on the gradient amplitude results in each direction; wherein the convolution module includes convolution templates in eight directions; compares the target gradient amplitude with the local image threshold to determine the grayscale value result of the local image. The technical solution of the embodiment of the present invention is adopted to expand the two-direction convolution template into an eight-direction convolution module, and after the local image is subjected to eight-direction convolution parallel operation and size comparison judgment, the optimal gradient direction of the local image can be obtained; at the same time, an adaptive threshold is used instead of a global threshold to improve the accuracy of image edge detection and improve the efficiency of image edge detection.

[0053] Embodiment 2

[0054] Figure 2A The flowchart of an image edge detection method provided by the second embodiment of the present invention. The embodiment of the present invention further optimizes the above embodiment on the basis of the above embodiment, and the embodiment of the present invention can be combined with various optional solutions in one or more of the above embodiments. Figure 2A As shown, the image edge detection method provided in the embodiment of the present invention may include the following steps:

[0055] S210: If the local image contains noise, preprocess the local image and determine a local image preprocessing result.

[0056] Among them, although the image data transmitted by the image acquisition device has been pre-processed inside the camera, if it is directly output without other processing, there will still be a lot of noise, which will have a huge impact on the edge detection of the image and may cause a large number of false edges. Algorithms for removing image noise include but are not limited to median filtering, mean filtering, and Gaussian filtering.

[0057] In the embodiment of the present invention, a median filter algorithm is used to remove image noise. The median filter algorithm adopts a pipeline design concept to perform a 3x 3 matrix center data (b 2 ) for filtering, Figure 2B is a flow chart of a median filtering algorithm provided by an embodiment of the present invention, see Figure 2B , 13 16-bit registers are defined inside the FPGA to store the comparison results generated in each step. The algorithm logic is as follows: Steps A1-A3:

[0058] A1: For the three data in the first row of the matrix (a 1 , a 2 , a 3) and store them in the three defined registers in order of size; the second and third rows are calculated in parallel with the first row, thereby obtaining the maximum value (Max), middle value (Mid) and minimum value (Min) of each row, and the results are stored in 9 registers respectively;

[0059] A2: Compare the three maximum values, middle values, and minimum values, obtain the minimum value among the maximum values ​​(Minof Max), the middle value among the middle values ​​(Mid of Mid), and the maximum value among the minimum values ​​(Max of Min), and store the results in three registers respectively;

[0060] A3: Sort the three values ​​obtained in the second step again to obtain the required image median (Med), and store the result in the median register.

[0061] Use the median value (Med) obtained after filtering to replace the center pixel b of the original 3x 3 image matrix 2 , that is, completing the single pixel filtering process. Figure 2C is a schematic diagram of an image pixel arrangement provided by an embodiment of the present invention, see Figure 2C , the remaining pixels are filtered in the same way, and finally a complete filtered image except for the outermost pixels is obtained.

[0062] S220 , generating at least two local image target matrices according to the local image preprocessing result, and caching the local image preprocessing result as a local image threshold.

[0063] The local image preprocessing result may refer to the median of each pixel point of the local image obtained after the image is subjected to median filtering, and the filtered image median Med is passed to the shift register to obtain each filtered 3x 3 image matrix.

[0064] S230, performing a convolution operation on the local image target matrix and a convolution template to determine the gradient amplitudes in each direction, and determining the target gradient amplitude according to the gradient amplitude results in each direction.

[0065] The step of performing a convolution operation on the local image target matrix and a convolution template to determine the gradient amplitudes in each direction, and determining the target gradient amplitude according to the gradient amplitude results in each direction, includes:

[0066] Performing a convolution operation on the target image matrix and the convolution template to determine the gradient amplitude in each direction;

[0067] Perform infinite norm operation on the gradient amplitude in each direction, and determine the target gradient amplitude based on the operation result;

[0068] Among them, the eight-directional convolution module includes 3x 3 convolution templates in the directions of 0°, 45°, 90°, 135°, 180°, 225°, 270° and 315°.

[0069] Figure 2D is a schematic diagram of an edge detection algorithm flow provided in an embodiment of the present invention, see Figure 2D , the specific edge detection algorithm logic is as follows:

[0070] B1: Concatenate each matrix (image matrix after median filtering) with the eight-directional Sobel convolution template (see Figure 1C ) performs convolution operation to obtain the gradient amplitude G in each direction 0° , G 45° , G 90° , G 135° , G 180° , G 225° , G 270° , G 315° ;

[0071] B2: Take the absolute value of the gradient amplitude in each direction, and get G 0° _abs, G 45° _abs, G 90° _abs, G 135° _abs, G 180° _abs, G 225° _abs, G 270° _abs, G 315° _abs;

[0072] B3: Sort the absolute values ​​of the gradient amplitudes in each direction, get the maximum value and record it as M ∞ .

[0073] After the above process, the local image after median filtering is subjected to eight-directional convolution parallel operation and size comparison judgment, and the local image target gradient amplitude M can be obtained. ∞ .

[0074] S240: Compare the local image threshold with the target gradient amplitude to determine the local image grayscale value result.

[0075] The step of comparing the local image threshold with the target gradient amplitude to determine the local image grayscale value result includes:

[0076] If the target gradient amplitude is greater than the local image threshold, the local image grayscale value result is white;

[0077] If the target gradient amplitude is less than or equal to the local image threshold, the local image gray value result is black;

[0078] The local image grayscale value result is displayed in real time through an image display device.

[0079] The median Med output by the median filter module is cached in the defined image threshold register. The local image threshold will change in real time with the change of the image data matrix, thus achieving an adaptive effect. ∞ At the same time, the cached local image threshold (i.e., median filter result Med) is read and combined with M ∞ A comparison is made and, according to the following formula, if the target gradient amplitude is greater than the local image threshold, the grayscale value result of the local image is white; if the target gradient amplitude is less than or equal to the local image threshold, the grayscale value result of the local image is black, and the image edge information Edge can be output synchronously in real time.

[0080]

[0081] In order to verify the effectiveness of the eight-direction Sobel adaptive threshold algorithm for image edge detection proposed in the embodiment of the present invention, the system is tested based on the FPGA hardware platform. Figure 2E is a schematic diagram of an image edge detection test result provided in an embodiment of the present invention, see Figure 2E , where (a) is the grayscale image after median filtering; (b) is the binarized image with a global threshold set, and it can be seen that there are many noise points and false edges in the image; (c) is the traditional Sobel edge detection result in the x and y directions, and it can be seen that some edge information in the non-x and y directions of the image is lost or discontinuous, and there are many false edges in the image; (d) is the detection result of the embodiment of the present invention, and it can be seen that both the edge continuity and the image detail richness are better than the traditional Sobel algorithm, and the local noise points and false edges of the image are effectively controlled, and the edge continuity is better.

[0082] The embodiment of the present invention provides an image edge detection method. If the acquired local image contains noise, the local image is preprocessed and the local image preprocessing result is determined; at least two local image target matrices are generated according to the local image preprocessing result, and the local image preprocessing result is cached as the local image threshold; the local image target matrix is ​​convolved with a convolution template to determine the gradient amplitude in each direction, and the target gradient amplitude is determined according to the gradient amplitude results in each direction; the local image threshold is compared with the target gradient amplitude to determine the local image grayscale value result. The technical solution of the embodiment of the present invention is adopted, the acquired local image is subjected to median filtering to remove image noise, and the median Med output by the median filtering module is cached in a defined image threshold register, and the local image threshold will change in real time with the change of the median value of the image data matrix, thereby achieving an adaptive effect. The image edge detection algorithm provided by the embodiment of the present invention is adopted, so that the local noise points and false edges of the image are effectively controlled, the continuity of the image edge is improved, and the efficiency of image edge detection is improved.

[0083] Embodiment 3

[0084] Figure 3A The flowchart of an image edge detection method provided by the third embodiment of the present invention. The embodiment of the present invention further optimizes the above embodiment on the basis of the above embodiment, and the embodiment of the present invention can be combined with various optional solutions in one or more of the above embodiments. Figure 3A As shown, the image edge detection method provided in the embodiment of the present invention may include the following steps:

[0085] S310, setting the timing and configuring the internal register parameters of the image acquisition device through the SCCB bus to obtain a partial image.

[0086] Among them, the serial camera control bus protocol (Serial Camera Control Bus, SCCB) may refer to the image acquisition device performing timing setting and internal register parameter configuration on the image acquisition device through the SCCB bus, so that the image acquisition device outputs an adaptive image resolution and data format. For example, in an embodiment of the present invention, the timing setting and internal register parameter configuration of the OV5640 camera are performed through the SCCB bus, so that the camera outputs an image resolution of 1024x 720 pixels and the data format is 16bit RGB565. The image acquisition device in the embodiment of the present invention includes but is not limited to a camera and a camera. The embodiment of the present invention does not specifically limit the camera model, image resolution and data format.

[0087] Optionally, the method further includes:

[0088] The control signal in the clock domain makes the rate at which the image acquisition device acquires image data consistent with the rate at which the image display device displays images.

[0089] In the embodiment of the present invention, an OV5640 camera is used to acquire a local image, an OV5640 driver module is used to configure the parameters of the OV5640 camera, and image data is supplemented through an asynchronous FIFO. The rate of data collected from the camera is different from the rate to be displayed on the VGA display, and data loss will occur. When displayed on the VGA display, faults or tears will be displayed, and rate matching is required. In the embodiment of the present invention, FIFO is used to supplement data, maintaining the integrity of the data, and the rate at which the image acquisition device acquires image data is kept consistent with the rate at which the image display device displays images through the control signal of the clock domain. Figure 3B is a block diagram of an image edge detection system provided in an embodiment of the present invention, see Figure 3B , where the main logic modules defined inside the FPGA system are: OV5640 driver module, asynchronous FIFO control module, SDRAM control module, shift register control module, median filter module, Sobel module and VGA display module. The embodiment of the present invention uses the SDRAM control module and the asynchronous FIFO control module to perform data cross-clock domain processing between the OV5640 camera and the VGA display, which can effectively reduce the risk of metastable state and ensure data reliability.

[0090] S320, receiving local image data, and generating at least two local image target matrices according to the local image data.

[0091] In an optional solution of the embodiment of the present invention, if the acquired image data does not contain noise data, at least two local image target matrices are generated according to the local image data.

[0092] In an optional solution of the embodiment of the present invention, Figure 3C is a schematic diagram of an image detection system algorithm structure provided in an embodiment of the present invention, see Figure 3C If the acquired image data contains noise data, the local image needs to be preprocessed to remove image noise, which may include steps C1-C3:

[0093] C1: transfers the synchronized image data to the shift register control module and outputs a 3x 3 image matrix;

[0094] C2: Pass the 3x 3 image matrix into the median filter module, output the matrix median through pipeline design, and cache the median as the local image threshold;

[0095] C3: The output median data is passed to the shift register control module, and the 3x 3 filtered image matrix is ​​output as the local image target matrix.

[0096] S330, obtaining a local image target matrix, and saving the central pixel point of the local image target matrix as a local image threshold.

[0097] S340, performing a convolution operation on the local image target matrix and a convolution template to determine the gradient amplitudes in each direction, and determining the target gradient amplitude according to the gradient amplitude results in each direction.

[0098] Among them, see Figure 3C The filtered image data is passed into the eight-directional Sobel module, the gradient amplitude in each direction is determined by convolution operation, the gradient amplitude in each direction is compared, and the local image target gradient amplitude is output.

[0099] S350: Compare the target gradient amplitude with the local image threshold to determine the local image grayscale value result.

[0100] The target gradient amplitude is compared with the local image threshold, and the result is subjected to grayscale binarization processing; the binarization result is displayed in real time on a VGA display through a VGA display module.

[0101] In an optional solution of the embodiment of the present invention, Figure 3D is a schematic diagram of an SDRAM ping-pong operation structure provided in an embodiment of the present invention, see Figure 3D , mark a certain frame of the image, and switch the bank at the mark; for example, write the image data into Bank1 through OV5640, switch the bank at the image frame number flag, and output the image data from Bank2; the next frame of image data can be written into Bank2 and read out from Bank1. The embodiment of the present invention uses ping-pong operation to switch two blocks (Banks) in SDRAM according to the image frame number flag (flag_frame) to complete the storage and reading of image data respectively, which can effectively avoid data conflicts that may occur when writing data into SDRAM and reading data from VGA, thereby causing image frame breakage. When a frame of image data of the OV5640 camera has been completely stored in a Bank, the frame of image can be read and displayed through VGA, and at the same time, it can be switched to another Bank of SDRAM to continue writing. In this way, the read and write data operations are switched, so that the OV5640 write data and the VGA display read data are always distributed in two different Banks, thereby achieving stable and correct transmission of image data.

[0102] Figure 3Eis a schematic diagram of edge detail comparison provided in an embodiment of the present invention. In order to deeply compare the effects of different algorithms, Figure 2E The details of the images (c) and (d) are magnified and compared. The original grayscale images of the local areas of the two images, the results of the traditional algorithm and the algorithm of the present invention are shown in Figure 2. Figure 3E As shown in (a), (b) and (c) in the figure. Comparing the area shown at "1" in the two figures, it can be seen that the processing results of the traditional Sobel algorithm have the phenomenon of edge discontinuity, while the algorithm of the embodiment of the present invention uses multi-directional simultaneous detection of image gradients, and can accurately display the actual edge of the image after determining the target gradient direction; the traditional algorithm at "2" identifies the image noise as a false edge, and the algorithm result of the embodiment of the present invention basically filters it out; the traditional algorithm result at "3" shows that the electronic components have no obvious edge features, and each component is blurred into a mass, with extremely low recognition, while the algorithm result of the embodiment of the present invention shows that the edges of each device are clear and there are no false edges around, and the detection effect is significantly better, which proves the feasibility and effectiveness of the embodiment of the present invention.

[0103] The embodiment of the present invention provides an image edge detection method, which uses the SCCB bus to set the timing of the image acquisition device and configure the internal register parameters to obtain a local image; if the acquired image data does not contain noise data, at least two local image target matrices are generated based on the local image data; if the acquired image data contains noise data, the local image needs to be preprocessed to remove image noise; the local image target matrix is ​​generated from the image data with the noise removed; the local image target matrix is ​​convolved with a convolution template to determine the gradient amplitude in each direction, and the target gradient amplitude is determined based on the gradient amplitude results in each direction; the target gradient amplitude is compared with the local image threshold to determine the grayscale value result of the local image. Using the technical solution of the embodiment of the present invention, the present invention proposes an image adaptive threshold eight-direction Sobel edge detection algorithm, and implements the algorithm on FPGA. The feasibility of the system is verified through board experiments. Compared with traditional algorithms and software implementation methods, the recognition accuracy and operation speed of the present invention are better, and it has high practical value in the field of high-speed image processing such as defect detection.

[0104] Embodiment 4

[0105] Figure 4 4 is a schematic diagram of the structure of an image edge detection device provided by the fourth embodiment of the present invention. This embodiment is applicable to the case of edge detection of an image. The device includes: a local image threshold determination module 410, a target gradient amplitude determination module 420 and a gray value result determination module 430. Among them:

[0106] A local image threshold determination module 410 is used to obtain a local image target matrix and save the central pixel point of the local image target matrix as a local image threshold;

[0107] A target gradient amplitude determination module 420 is used to perform a convolution operation on the local image target matrix and a convolution template to determine the gradient amplitude in each direction, and determine the target gradient amplitude according to the gradient amplitude results in each direction; wherein the convolution module includes convolution templates in eight directions;

[0108] The grayscale value result determination module 430 is used to compare the target gradient amplitude with the local image threshold to determine the local image grayscale value result.

[0109] Based on the above embodiment, optionally, the target gradient amplitude determination module includes:

[0110] Performing a convolution operation on the target image matrix and the convolution template to determine the gradient amplitude in each direction;

[0111] Perform infinite norm operation on the gradient amplitude in each direction, and determine the target gradient amplitude based on the operation result;

[0112] Among them, the eight-directional convolution module includes 3x 3 convolution templates in the directions of 0°, 45°, 90°, 135°, 180°, 225°, 270° and 315°.

[0113] Based on the above embodiment, optionally, the gray value result determination module includes:

[0114] If the target gradient amplitude is greater than the local image threshold, the local image grayscale value result is white;

[0115] If the target gradient amplitude is less than or equal to the local image threshold, the local image gray value result is black;

[0116] The local image grayscale value result is displayed in real time through an image display device.

[0117] Based on the above embodiment, optionally, the device further includes:

[0118] The image preprocessing module is used to preprocess the local image and determine the local image preprocessing result if the local image contains noise.

[0119] Based on the above embodiment, optionally, the device further includes:

[0120] generating at least two local image target matrices according to the local image preprocessing result, and caching the local image preprocessing result as a local image threshold;

[0121] Performing a convolution operation on the local image target matrix and the convolution template to determine the gradient amplitude in each direction, and determining the target gradient amplitude according to the gradient amplitude results in each direction;

[0122] The local image threshold is compared with the target gradient amplitude to determine the local image grayscale value result.

[0123] Based on the above embodiment, optionally, the device further includes:

[0124] The timing of the image acquisition device is set and the internal register parameters are configured through the SCCB bus to obtain a local image;

[0125] Local image data is received, and at least two local image target matrices are generated according to the local image data.

[0126] Based on the above embodiment, optionally, the device further includes:

[0127] The control signal in the clock domain makes the rate at which the image acquisition device acquires image data consistent with the rate at which the image display device displays images.

[0128] The above-mentioned device can execute the image edge detection method provided by any embodiment of the present invention, and has the corresponding functional modules and beneficial effects for executing the image edge detection method.

[0129] Embodiment 5

[0130] Figure 5 Schematic diagram of the structure of an electronic device provided in Embodiment 5 of the present application. The present application embodiment provides an electronic device, in which the interactive device for image edge detection provided in the present application embodiment can be integrated. Figure 5 As shown, this embodiment provides an electronic device 500, which includes: one or more processors 520; a storage device 510, which is used to store one or more programs. When the one or more programs are executed by the one or more processors 520, the one or more processors 520 implement the image edge detection method provided in the embodiment of the present application. The method includes:

[0131] Obtaining a local image target matrix, and saving a central pixel point of the local image target matrix as a local image threshold;

[0132] The local image target matrix is ​​convolved with a convolution template to determine the gradient amplitude in each direction, and the target gradient amplitude is determined according to the gradient amplitude results in each direction; wherein the convolution module includes convolution templates in eight directions;

[0133] The target gradient magnitude is compared with the local image threshold to determine the local image grayscale value result.

[0134] Of course, those skilled in the art can understand that the processor 520 also implements the technical solution of the image edge detection method provided in any embodiment of the present application.

[0135] Figure 5 The electronic device 500 shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0136] like Figure 5 As shown, the electronic device 500 includes a processor 520, a storage device 510, an input device 530, and an output device 540; the number of the processor 520 in the electronic device can be one or more. Figure 5 A processor 520 is taken as an example; the processor 520, the storage device 510, the input device 530 and the output device 540 in the electronic device can be connected via a bus or other means. Figure 5 The connection via bus 550 is taken as an example.

[0137] The storage device 510 is a computer-readable storage medium that can be used to store software programs, computer executable programs, and module units, such as program instructions corresponding to the image edge detection method in the embodiment of the present application.

[0138] The storage device 510 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system and at least one application required for a function; the data storage area may store data created according to the use of the terminal, etc. In addition, the storage device 510 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some instances, the storage device 510 may further include a memory remotely arranged relative to the processor 520, and these remote memories may be connected via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0139] The input device 530 may be used to receive input numbers, character information or voice information, and generate key signal input related to user settings and function control of the electronic device. The output device 540 may include electronic devices such as a display screen and a speaker.

[0140] The electronic device provided by the embodiment of the present application can achieve the technical effect of improving the accuracy of image edge detection and improving the efficiency of image edge detection.

[0141] Embodiment 6

[0142] Embodiment 6 of the present invention further provides a storage medium containing computer executable instructions, wherein the computer executable instructions are used to execute an image edge detection method when executed by a computer processor, the method comprising:

[0143] Obtaining a local image target matrix, and saving a central pixel point of the local image target matrix as a local image threshold;

[0144] The local image target matrix is ​​convolved with a convolution template to determine the gradient amplitude in each direction, and the target gradient amplitude is determined according to the gradient amplitude results in each direction; wherein the convolution module includes convolution templates in eight directions;

[0145] The target gradient magnitude is compared with the local image threshold to determine the local image grayscale value result.

[0146] The computer storage medium of the embodiment of the present invention may adopt any combination of one or more computer-readable media. The computer-readable medium may be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of computer-readable storage media include: an electrical connection with one or more 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), a flash memory, an optical fiber, a portable CD-ROM, an optical storage device, a magnetic storage device, or any suitable combination of the above. The computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, device or device.

[0147] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, which carry computer-readable program code. Such propagated data signals may take a variety of forms, including but not limited to: electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.

[0148] The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, radio frequency (RF), etc., or any suitable combination of the above.

[0149] Computer program code for performing the operations of the present invention may be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's 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 may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0150] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "examples", "specific examples", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.

[0151] Note that the above are only preferred embodiments of the present invention and the technical principles used. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present invention, and the scope of the present invention is determined by the scope of the appended claims.

Claims

1. A method for detecting an image edge, characterized in that: The method comprises: Obtaining a local image target matrix, and saving a central pixel point of the local image target matrix as a local image threshold; Performing a convolution operation on the local image target matrix and the convolution template to determine the gradient amplitude in each direction, and determining the target gradient amplitude according to the gradient amplitude results in each direction; wherein the convolution template includes convolution templates in eight directions; Compare the target gradient amplitude with the local image threshold to determine the local image grayscale value result; The step of performing a convolution operation on the local image target matrix and a convolution template to determine the gradient amplitudes in each direction, and determining the target gradient amplitude according to the gradient amplitude results in each direction, includes: Performing a convolution operation on the local image target matrix and the convolution template to determine the gradient amplitude in each direction; Perform infinite norm operation on the gradient amplitude in each direction, and determine the target gradient amplitude based on the operation result; The step of comparing the target gradient amplitude with the local image threshold to determine the local image grayscale value result includes: If the target gradient amplitude is greater than the local image threshold, the local image grayscale value result is white; If the target gradient amplitude is less than or equal to the local image threshold, the local image gray value result is black; The local image grayscale value result is displayed in real time through an image display device, and the image edge information is output synchronously in real time.

2. The method according to claim 1, characterized in that: The convolution templates include 3x 3 convolution templates in directions of 45°, 135°, 180°, 225°, 270° and 315°.

3. The method according to claim 1, characterized in that Before performing a convolution operation on the local image target matrix and the convolution template to determine the gradient amplitudes in each direction, and determining the target gradient amplitude according to the gradient amplitude results in each direction, the method further includes: If the local image contains noise, the local image is preprocessed and a local image preprocessing result is determined.

4. The method according to claim 3, characterized in that If the local image contains noise, the method further includes: preprocessing the local image and determining the local image preprocessing result. generating at least two local image target matrices according to the local image preprocessing result, and caching the local image preprocessing result as a local image threshold; Performing a convolution operation on the local image target matrix and the convolution template to determine the gradient amplitude in each direction, and determining the target gradient amplitude according to the gradient amplitude results in each direction; The local image threshold is compared with the target gradient amplitude to determine the local image grayscale value result.

5. The method according to claim 1, characterized in that The method further comprises: The timing of the image acquisition device is set and the internal register parameters are configured through the SCCB bus to obtain a local image; Local image data is received, and at least two local image target matrices are generated according to the local image data.

6. The method according to claim 1, characterized in that The method further comprises: The control signal in the clock domain is used to keep the rate at which the image acquisition device acquires image data consistent with the rate at which the image display device displays images.

7. An image edge detection device, characterized in that: The device comprises: A local image threshold determination module is used to obtain a local image target matrix and save the central pixel point of the local image target matrix as a local image threshold; A target gradient amplitude determination module, used for performing a convolution operation on the local image target matrix and a convolution template to determine the gradient amplitude in each direction, and determining the target gradient amplitude according to the gradient amplitude results in each direction; wherein the convolution template includes convolution templates in eight directions; A gray value result determination module, used for comparing the target gradient amplitude with the local image threshold to determine the local image gray value result; Wherein, the target gradient amplitude determination module is configured to: Performing a convolution operation on the local image target matrix and the convolution template to determine the gradient amplitude in each direction; Perform infinite norm operation on the gradient amplitude in each direction, and determine the target gradient amplitude based on the operation result; Wherein, the gray value result determination module is configured to: If the target gradient amplitude is greater than the local image threshold, the local image grayscale value result is white; If the target gradient amplitude is less than or equal to the local image threshold, the local image gray value result is black; The local image grayscale value result is displayed in real time through an image display device, and the image edge information is output synchronously in real time.

8. An electronic device, characterized in that: include: one or more processors; A storage device for storing one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the image edge detection method described in any one of claims 1-6.

9. A storage medium containing computer executable instructions, characterized in that: The computer executable instructions are used to perform the image edge detection method according to any one of claims 1 to 6 when executed by a computer processor.