Research on Key Technology of Diamond Particle Detection Based on Machine Vision

Most traditional methods for detecting the quality of tiny particles are manually detected by measurement tools. Manual detection has the limitations of low efficiency, high false detection rate and low detection accuracy, and is gradually replaced by non-contact measurement. In this paper, a new denoising algorithm based on median and mean filtering is proposed in diamond particle image analysis. Dynamic threshold segmentation is combined with the Canny algorithm for edge extraction. In the edge extraction process of the particle edge, it will lead to non-closed problems. A contour edge location method based on Hough transform is proposed. Thereby, parameters such as particle size, roundness and ellipticity of the diamond particles are measured.


Introduction
Diamond particles has high hardness and good wear resistance and can be widely used in cutting, grinding and drilling. It is an ideal raw material for grinding and polishing high hardness materials such as cemented carbide, ceramics, gemstones and optical glass. Diamond particles are relatively small and difficult to measure. Industrial requirements are the particle size, perimeter and area of these particles. A prerequisite for obtaining these parameters is the accurate detection of the edge closure profile. Because the domestic diamond particles mainly rely on the manual measurement of the characteristic parameters of the diamond particles for the evaluation of the diamond particle grade, there are problems such as large grading load, strong subjectivity and low efficiency [1]. In addition, with the mature application of digital image processing technology in various industries, the recognition and measurement method based on machine vision has become an important development direction of diamond particles quality detection and control. The machine vision system uses the machine instead of the human eye to achieve measurement and judgment. The processing speed is fast, the real-time and stability are good, and the disadvantages caused by manual measurement can be overcome. With the development of information technology and fieldbus technology, machine vision has become an indispensable emerging technology in modern processing and manufacturing. It has been widely used in industries such as industry, transportation, agriculture, medicine, etc. These are diamond particles shape detection. The development of the system laid a solid foundation. Diamond particles have the characteristics of small particle size, high surface reflection, and many characteristic parameters. For high surface reflection problems, the image obtained by LED single-sided illumination is better [3]. In this paper, a new denoising algorithm based on median filtering and mean filtering is proposed to remove the noise of diamond particles, and the edge of the filtered image is extracted by Canny edge detection algorithm based on dynamic segmentation. Based on the original edge curve of the pre-processed diamond particle image, the determined edge contour of the diamond particle is obtained by the modified Hough line detection algorithm, and the obtained edge contour is fitted. The particle size, roundness and ellipticity of the diamond particles are finally obtained. The purpose of this paper is to detect the area, perimeter, particle size and other indicators of diamond particles on the basis of digital image processing.

Image Denoising
According to the median filtering and mean filtering algorithms, a new denoising algorithm based on median and mean filtering is proposed, The denoising process is implemented as follows: (1)Within the 3 × 3 window centered on the current pixel j i f , , define all pixels to form a set as (2)For other pixels in the non-center position, after removing the noise pixels with the gray value of 0 or 255, the remaining non-noise points constitute the set A is empty, it is not executed, and the process proceeds to step (1).

Edge extraction based on Canny algorithm
A good edge detection operator should have three indicators: ①Good detection performance, both less true edge loss and less non-edge edge; ② High positional accuracy. The detected edges should be on the true boundary; ③Has a unique response to each edge, and the resulting boundary is a single pixel wide.
The traditional Canny edge detection algorithm is as follows: ①Smoothing the image with Gaussian filter; ② Calculating the amplitude and direction of the gradient with the finite difference of the first-order partial derivative;③Suppressing the non-maximum value of the gradient amplitude; ④ Using the double-threshold algorithm detect and connect edge edges. In the detection of actual particle images, this original Canny algorithm can detect the edges of particles well, but it also brings some new problems. The images people get are not standard images, such as the effects of lighting. The edges of the image are blurred. Therefore, when edge detection is performed on an image, if the entire image adopts a fixed threshold, it is generally impossible to consider a specific condition of the image, thereby affecting the edge detection effect. One way to solve this problem is to divide the image into several sub-images in the pre-processing of the image and select a corresponding threshold for each sub-image. The entire image is divided into different thresholds. In order to enable the Canny algorithm to more accurately detect the boundary of the target in the image, when the image is preprocessed, it is first divided into several sub-images, then, for each case in the sub-image, select different thresholds, and finally select The threshold dynamically splits the sub-image [4].
The steps of the dynamic threshold algorithm are as follows: (1) Pre-processing the image. That is, for the obtained non-standard image, the edge of the entire image is sharpened first by linear sharpening filtering (linear high-pass filter), and then the image is divided into several sub-images for subsequent processing. There must be partial overlap between the segmented sub-images in order to eliminate the boundary effects present in the processed image [5].
(2)Select one of the sub-images in sequence and smooth them with a Gaussian smoothing filter. Let ] , [ j i I denote an image, then the operation can be represented as a convolution process: is a Gaussian smoothing filter function, and σ is a scatter parameter of a Gaussian function.
(3)Sub-image enhancement. Using the finite difference of the first-order partial derivative to calculate the magnitude and direction of the gradient. The amplitude and direction angle can be calculated from the conversion formula of Cartesian coordinates to polar coordinates: Select a threshold in the sub image. The dynamic threshold algorithm still uses a double threshold to detect the edges of the sub-image. However, since the gray value of the target and the background are partially interlaced, it is usually desirable to minimize the error after segmentation. Therefore, the algorithm uses the optimal threshold method to find one of the thresholds: The test results show that if the second threshold is taken as 40% of the threshold obtained by the optimal threshold method, there is a good segmentation and connection effect [6]. (5)Check if there are still sub-images that have not been processed? If yes, turn (2); otherwise, turn (6).
(6)Dynamically segment the entire image using a plurality of thresholds selected in (4).
Suppose that two thresholds are selected in a subimage, respectively 1 τ and 2 τ , and i T is obtained using a high threshold, it contains few false edges, but not continuous.
(7)Use non-maximum suppression to refine edges. Since the ridges are created at the boundary of the image during processing, in order to refine the edges, the algorithm needs to track along the top of the ridge belt, setting those points that are not the maximum to zero. This process is called non-maximum suppression.
The edges of the image processed by this algorithm are complete and there is no excessive noise. Experiments show that the dynamic threshold algorithm compensates for the lack of edge when the Canny method performs edge detection on grayscale uneven images, and has the ability to detect fuzzy edges. It is a practical edge detection algorithm.

Edge Extraction of Diamond Particles Based on Hough Transform
The principle of Hough transform detection edge: Hough line transformation connects the discrete pixels in the image through the global feature of the graph. The central idea is the duality principle of the point line, all points on any line in the image plane are in the parameter space. There are a plurality of intersecting lines corresponding to one-to-one, a plurality of straight lines intersecting at the same point in the parameter space have a collinear point corresponding to the image plane [7]. In summary, the Hough line transformation is to achieve the mapping of all the lines in the image plane to the parameter space, and then complete the detection by performing simple point accumulation statistics in the parameter space. For the problem that the slope of the straight line is perpendicular to the coordinate axis, the Hough transform is extremely sitting [8]. The equation is used to represent the line: The parameter ρ is the distance from the straight line L to the origin of the image space, and θ is the angle between the perpendicular line of the straight line L and the x-axis. From the equation (8), all the points in the image plane correspond to the parameter space θ ρ -. The middle is the sinusoidal set that meets at point P. Obviously, if the P point in the parameter space is determined, the corresponding straight line can be detected.  According to the Hough transform extraction principle is as follows: 1. Offline the parameter and set it to the corresponding accumulator, the initial value is set to zero.
2. Performing Hough transform on the pre-processed discrete edges such as morphological denoising, smoothing filtering and Canny edge detection, and storing the result in Hough transform accumulator.
3. Set an appropriate threshold and clear the accumulated value in the Hough transform accumulator that is less than the threshold. 4. In the parameter space, find all the points that satisfy the threshold value and search for the corresponding line in the image plane, which realizes the detection of the line in the image.
5. In the parameter space, find all the points that meet the threshold value and search for the corresponding line in the image plane, which realizes the detection of the line in the image [8].
The pseudo straight line is eliminated by fine-tuning the size of the polar range p and the polar angle e in the neighborhood [9]. First, arbitrarily select a straight line as the reference line, and count all the straight lines whose difference between the polar path p and the polar angle 0 is within a certain range, and merge these straight lines into a straight line in the middle (the straight line closest to the edge contour). Then all the traversed lines are cleared, and then all the lines are merged according to this algorithm.

Fitting of the edge contour of diamond particles
The basic principle of the contour fitting algorithm is: firstly, the contour line with the determined contour is divided into four categories according to its position relative to the center point of the image space, and then the straight line in each class is based on the size of the polar angle is sorted from small to large. All the straight lines are sorted according to a certain direction, and finally all the intersection points are obtained according to the order and connected in order to form a contour fitting.

Measurement and calculation of diamond particles
The characteristic parameters of the diamond particles are particle size, ellipticity and roundness. The particle size is the diameter of a circle equal to the surface area of the diamond being measured. The ellipticity of a diamond crystal is defined as the ellipticity of the ellipse closest to its projection. According to this definition, the ovality of the diamond crystal is greater than or equal to 11, and the closer to 1, the closer the crystal form is to the crystal form of the ideal diamond. Definition of roundness: The ratio of the circumference of the circumference of the diamond particle surface projection surface to the circumference of the diamond projection area is called the roundness. The closer the roundness is to 1, the better the crystal structure [10]. Using the pointPolygonTest() function in OpenCV, iterate through all the pixels in the image space, approximate the contour of the polygon according to the distance from the point to the contour, and finally return the position of the center of the circle and the diameter of the inscribed circle, thereby obtaining the maximum inscribed circle of the diamond particles that can be used to calculate the particle size of the particles.

Conclusion
In the environment of OpenCV and VC++ configuration, based on Canny algorithm, Hough transform realizes the measurement of diamond particles. Through image preprocessing of diamond particles, extraction and fitting of contour edges, the experimental results show that the Hough transform diamond particles proposed in this paper are proposed. The measurement method effectively solves the problem of image edge nonclosedness, and then quickly and accurately measures the diamond particle characteristic parameters.