## Abstract

Scratches on the surface of optical components have serious impacts on optical system such as imaging quality of lens and/or mirrors in optical imaging systems, light-collecting abilities of laser fusion and solar concentrator systems. The size of the scratches is a key issue for analyzing and assessing the impacts quantitatively. Most of the available testing methods for scratches depend on human visual inspection (HVI) with naked eyes by workers, which leads to low efficiency and accuracy. This paper presents an automatic detecting method for the scratches on optical surface with machine vision inspection (MVI) method. The microscopic dark-field scattering imaging system is used as the front end of the detection system. A dedicated algorithm is designed for non-closing scratch detection. The core merits of this algorithm lies in three folds: 1) automatic processing capabilities, which includes positioning, clustering, and precise estimation of the length of the scratches; 2) high efficiency, which is characterized by a short time interval, i.e., about 0.138 second per binary image with 2724 × 2724 pixels in our experiments; 3) high accuracy, where the error rate of the total length of the scratches detected is less than 5% when compared with the nominal visual measurement result obtained via HVI method. The proposed scratch detecting algorithm can be used for non-destructive testing (NDT) of the glass-like surfaces.

© 2019 Optical Society of America under the terms of the OSA Open Access Publishing Agreement

## 1. Introduction

Machine vision is widely utilized to detect the surfaces of the materials of interest in the field of non-destructive testing (NDT) [1–3]. Most of the available approaches are designed to deal with metal [4], wood [5], textured materials [6] or living tissue in medicine and biology [7]. However, optical components, such as lenses and mirrors, are rarely involved.

Scratches, the major defects on optical surface, have serious impacts on optical system since they can not be cleaned or removed with NDT methods. The optical parameters such as refractive index, light transmittance will be changed by scratches [8]. According to the international standard of surface imperfection tolerances [9], the length of the scratch is an important indicator of the quality of optical systems or elements. Thus, the measurement precision of scratches is essential for the quality evaluation of optical system, which leads to the key problem of analyzing the scratches quantitatively. At present, for manufacturing optical components, scratch testing is mainly dominated by the naked-eyes visual testing, which is also named with *human visual inspection* (HVI). However, the detecting efficiency of the HVI method is very low since the workers’ visual acuity is seriously decreased by fatigue or high strength workload, and the subjective evaluation is arguable due to the acuity of the workers’ eyesight and experiences [10]. In addition, scratches have different directions and depths. In the process of detection, workers need to not only frequently change the incident angle of light but also move the glass-like surface itself, which leads to a fact that the visual inspection of scratches is the most time-consuming step when manufacturing optical components.

There are several conventional optical techniques for surface defect detection. Germer [11] and Gu [12] proposed the defect detecting method based on the polarization of light. In their method, the emphasis is put on the qualitative analysis of the existence of defects. However, there is lack of quantitative evaluation for the results of detection. Schneider et al. [13] proposed a fast defect detection method with the help of single sided diffraction. However, the imaging quality is still needed to be analysed even if the defects are highlighted successfully. Sanchez-Brea [14] proposed a wire surface defect detection method stimulated by the fact of intensity variations on the scattering cone generated. Unfortunately, the detection device needed is expensive and complex, which limits its applications.

Images of dark field are much easier to be processed and the information for quantitative defect analysis can be obtained directly. A perfect or ideal optical surface is a smooth glass-like surface, thus the scattering light at the defect will enter into the imaging system (camera). On the contrary, the light reflected by the defect-free surface will not enter into the aperture of the imaging system. In consequence, the image regions corresponding to the defects or dusts on the optical surface appear as bright white pixels. On the contrary, the dark gray pixels corresponds to the defect-free or clean region of the surface. Here we remark that the path of the light ray in dark field system is easy to be designed and verified with optical design software such as CODE V and ZEMAX.

In recent decade, lots of researches on defect detection on optical surface appeared with the birth of dark field imaging system. In 2007, Yang [15, 16] not only designed a *microscopic dark field scattering imaging* (MDSI) system to capture the candidate images with scratches of interest, but also designed a detection algorithm for detecting strong scratches. However, this imaging system introduces noise inevitably while it works. The algorithm may miss a lot of weak or non-notable scratches and the estimation of the length of scratches fluctuates apparently. In 2015, Li [17] proposed the image filtering and difference scheme for scratch extraction. For this method, the noise in the images can be efficiently removed. However, some weak scratches may also be removed unexpectedly. Thus the accuracy of scratches detection is not satisfactory for the practical purpose. In 2016, Tao [18] proposed a binarization method for dark field images by combining the LSD method and Hough transform directly. However, there are two disadvantages for Tao’s method: the detection result is not accurate enough and it is very sensitive to threshold parameters.

The key objective of scratch detection is locating the scratches and evaluating them. The evaluation includes counting the number of scratches and determining the length of the scratches. In machine vision, the fundamental strategy for scratches detection is to convert the detection task into line detection problem. There are some typical general line detection (GLD) algorithms based on Hough transform [19–21], LSD [22] and ED lines [23].

These GLD algorithms are not appropriate for continuous straight line segments because of three deficiencies:

- they locate the scratches well but the output of detection consists of broken lines in most cases;
- some extra process need to be applied to connect these line segments according to semantics;
- the weak scratches are difficult to be distinguished since the values of intense of pixels in a given scratch regions may be slightly different from those in non-scratch regions.

Therefore, GLD algorithms can not be used for quantitative analysis and we can not use them directly when evaluating the glass-like surfaces with *machine vision inspection* (MVI) methods.

In our application, the surfaces of interest are those of neodymium glasses. This optical component is used for laser fusion system and the optical component is quite large. The dimension of the tested surface is 810 mm × 460 mm. Scratches are generated during the process of grinding, polishing and translating the optical components. The MDSI system is used as a front end for capturing digital images, which provide original information for detecting scratches on optical surface fast and accurately. The system consists of a ring light source, a zoom microscope, XY-DOF translation stage and a high resolution CCD. The ring light source allows the imaging system to capture scratches in all directions. The images collected by the microscope are clear and weak scratches can be highlighted. Since the field of view (FOV) of the microscope is small (14.42 mm × 14.42 mm), the large-scale optical component is placed on a translational platform, which allows the microscope to scan the entire surface for complete inspection. For more details about MDSI, please see Liu [24].

In this paper, an accurate and efficient algorithm is designed, implemented, verified and evaluated for detecting the scratches on the optical surface. Our scratch detection algorithm includes four consecutive steps:

- Coarse Locating — determine the coarse position of the scratches;
- Classifying the seeds for each scratch;
- Collecting all of the points belong to scratches;
- Accurate Locating — determine the accurate position of scratch endpoints.

- The scratches and abstract line segments on binary image are modelled and represented mathematically.
- A procedure is designed to connect the broken segments (the output of the GLD algorithm).
- The key information, which includes location, numbers and length with satisfied accuracy, that specifying the scratches are generated automatically for evaluation.

The contents of this paper are organized as follows: Section 2 gives the fundamental notations and concepts for modelling the scratches; Section 3 describes the modules of the scratch detection algorithm with details; Section 4 gives the verification and validation of the algorithm via concrete examples; and finally conclusions are made in Section 5.

## 2. Notations and concepts about scratches

#### 2.1. Image captured from MDSI system

A grayscale image is specified by a function defined on a 2-dimensional finite region. Mathematically, we have

*W*is the width and

*H*is the height of the image

*ℐ*. We use

**= [**

*p**x*,

*y*]

^{⊤}to denote the image point or pixel at location (

*x*,

*y*) and

*ℐ*(

*x*,

*y*) =

*ℐ*(

**) to denote the intensity of the grayscale image at image point**

*p***.**

*p*In this paper, the grayscale images of large scale optical components are generated by the MDSI system and *W* = *H* = 2724 as demonstrated in Fig. 1. For easier processing, these grayscale images are binarized via an operation

*t*such that

#### 2.2. Representation of line segment and scratch

A line segment in an image is determined by its endpoints. Formally, let *p** _{s}* = [

*x*,

_{s}*y*]

_{s}^{⊤}∈ Ω be the start point and

*p**= [*

_{e}*x*,

_{e}*y*]

_{e}^{⊤}∈ Ω be the end point, the corresponding line segment can be represented by

*S*⊂

*ℐ*, in which a length attribution

_{b}*ℓ*is added if compared with the line segment

*L*. Usually, for a scratch

*S*= 〈

*ℓ*;

*p**,*

_{s}

*p**〉 we have since it may be a line segment or curve.*

_{e}The data structures of the line segment *L* and scratch *S* used in this paper is summarized in Table 1.

For two line segments ${L}_{i}=\u3008{\mathit{p}}_{s}^{i},{\mathit{p}}_{e}^{i}\u3009$ and ${L}_{j}=\u3008{\mathit{p}}_{s}^{j},{\mathit{p}}_{e}^{j}\u3009$ as illustrated in Fig. 3, let *θ _{ij}* be the included angle of them, then we have

**,**

*a***]) =**

*b**a*

_{1}

*b*

_{2}−

*a*

_{2}

*b*

_{1}for

**= [**

*a**a*

_{1},

*a*

_{2}]

^{⊤},

**= [**

*b**b*

_{1},

*b*

_{2}]

^{⊤}. Furthermore, the

*degree of proximity*(DOP) of these two line segments is defined by

*L*and

_{i}*L*.

_{j}#### 2.3. Dark points

The set of *dark points 𝒟* in the image *ℐ _{b}* is specified by

In the presence of dusts on optical components, the grayscale images generated by the MDSI system are always polluted by noises. Obviously, this impact will be propagated to the binary images, as the random noise points illustrated in Fig. 2. Usually, The scratches are represented as line segments in the images, thus the line detection algorithms can be used to detect them. It should be noted that the concept of endpoint for a scratch is different from that of a line segment since the former is not well-defined. For a physical scratch, an “endpoint” must be definite instead of some possible points. However, for its representation in the binary image, it may be some points in a set of co-linear points and/or noise points, as shown in Fig. 2 (a). It is easy to find that the dark points may be generated from noise or scratches, viz.,

*𝒟*∩

^{S}*𝒟*= ∅. A direct result of this phenomena is that the GLD algorithm may fail because of the difficulty of distinguishing endpoints from the noise points.

^{N}#### 2.4. Performance parameter of scratch detection

Although the HVI is criticized for its low efficiency, its detecting results are widely accepted. Let *ℓ*_{hvi} be the total length of all scratches obtained by the HVI method and *ℓ*_{mvi} be the counterpart by the MVI method.

For the purpose of evaluating the detecting results, we define the error rate of scratch detection by

If the error rate*E*<

*E*

_{max}= 5% for a sufficiently large amount of samples of optical surface components, then the detector is Accepted as a reliable detector, otherwise it will be Rejected.

## 3. Scratch detecting algorithm

For the purpose of automatic and rapid processing, we designed a flowchart for scratches detecting with the help of computer vision, see Fig. 4. There are four key modules in our MVI method:

- coarse locating of scratches,
- classifying scratches,
- removing noise point and
- positioning proper endpoints.

We now give some necessary interpretations. Firstly, we take the LSD for initial or coarse positioning the scratches after loading the binary images. Then, a classification is used to find “seeds” for each scratch. After that, the RANSAC algorithm [25] is utilized to select the points belonging to the scratches. Finally, a search algorithm is applied to determine the endpoints of the scratches, calculate and output the scratch information of interest.

#### 3.1. Coarse locating of scratches with LSD algorithm

LSD is a fast algorithm based on computing grayscale gradient with sub-pixel accuracy for detecting line segments in digital images. Compared with the line detection algorithms based on the Hough transformation, LSD algorithm have three merits: it is more faster, more accurate and does not depend on tuning parameters. The output of LSD algorithm is a set of line segments denoted by

- it usually detects several line segments for a given scratch since it relies on gradient computation heavily;
- the line segments detected may be distributed on both sides of the scratch and may have different slopes, see Fig. 6.

The method of eliminating these unexpected phenomena depends on tuning the parameters of LSD algorithm.

Although there are seven built-in parameters in the LSD algorithm, we found that not all of them play important roles in our application. Our experiments show some fascinating results:

- Only two parameters are essential: one is the moderate scaling parameter
*s*, the other one is the standard deviation*σ*of Gaussian filter. - We may not find any line segment with default parameters in the LSD, thus it is necessary to tune the parameters carefully. Once these two parameters are well-tuned, the impact of noise can be reduced and the detection accuracy can be improved significantly.
- For each scratch
*S*, the set*ℒ*contains 3 ∼ 5 line segments and the positions of these line segments give a coarse localization of*S*.

#### 3.2. Classifying segments from different scratches

To distinguish the line segments of different scratches, we propose a line segment classification algorithm to classify the line segments, see Algorithm 1.

For the design of this algorithm, there are three key elements of significance for the line segments *L _{i}* and

*L*:

_{j}- included angle
*θ*of_{ij}*L*and_{i}*L*,_{j} - degree of proximity DOP
of_{ij}*L*and_{i}*L*, and_{j} - scratch account ratio
*r*of_{ij}*L*and_{i}*L*._{j}

For the first element, we calculate the sine of the included angle sin *θ _{ij}* between two LSD output line segments ${L}_{i}=\u3008{\mathit{p}}_{s}^{i},{\mathit{p}}_{e}^{i}\u3009$ and ${L}_{j}=\u3008{\mathit{p}}_{s}^{j},{\mathit{p}}_{e}^{j}\u3009$ by (6). Let

*θ*

_{max}∈ [0,

*π*) be a critical angle, then we can set a threshold value sin

*θ*

_{max}. If |sin

*θ*| > sin

_{ij}*θ*

_{max}, we label these two line segments as different categories of scratches. Otherwise, we regard them as “co-linear” segments, see Fig. 5. Fig. 5(a) shows two scratches

*S*

_{1}and

*S*

_{2}and Fig. 5(b) simulates the detecting result of LSD. The included angles are

*θ*

_{24}=

*θ*(

*l*_{2},

*l*_{4}) and

*θ*

_{25}=

*θ*(

*l*_{2},

*l*_{5}) respectively. Obviously, |sin

*θ*

_{24}| < |sin

*θ*

_{25}|, thus

*l*_{2}and

*l*_{5}belong to different scratches. It is necessary to verify whether

*L*

_{2}and

*L*

_{4}belong to the same scratch.

In order to verify whether these “co-linear” line segments belong to the same scratch, we calculate the DOP of them according to (7). Let DOP_{max} be the maximum DOP, i.e., a threshold value. If DOP* _{ij}* < DOP

_{max}, we regard them as the same category, as shown in Fig. 6. Fig. 6(a) shows two scratches

*S*

_{3}and

*S*

_{4}and Fig. 6(b) simulates the detection result of LSD. We can see that the |sin

*θ*

_{15}| is small, thus we need to calculate ${\text{DOP}}_{15}=\Vert {\mathit{p}}_{e}^{1}-{\mathit{p}}_{s}^{5}\Vert $. Similarly, we compute the distance ${\text{DOP}}_{13}=\Vert {\mathit{p}}_{e}^{1}-{\mathit{p}}_{s}^{3}\Vert $ between

*L*

_{1}and

*L*

_{3}. Obviously, DOP

_{13}< DOP

_{15}. Hence, compared with the threshold, we find that

*L*

_{1}and

*L*

_{3}belong to the same scratch. We need further verification to see whether

*L*

_{1}and

*L*

_{5}belong to different scratches. Otherwise, we need to check whether there is a real scratch between these two “co-linear” segments.

Firstly, we choose a rectangle *R _{ij}* which contain the line segment

*L*: one of its symmetric axis is the direction vector

_{i}

*l**with length*

_{i}*ℓ*and width 5 pixels, as illustrated in Fig. 7. Fig. 7(a) simulates the detecting result of LSD.

_{i}*L*

_{1}and

*L*

_{5}are “co-linear”, but DOP

_{15}> DOP

_{max}. We need to verify whether there are scratches in the rectangular area specified by the points ${\mathit{p}}_{e}^{1}$ and ${\mathit{p}}_{s}^{5}$. We determine a rectangular area in binary image and calculate the scratches ratio

*r*

_{15}. Fig. 7(b) shows that

*r*

_{15}= 30% <

*r*

_{min}= 50%. Thus, the

*L*

_{1}and

*L*

_{5}belong to different scratches. We then divide

*R*into

_{ij}*n*equal parts along

_{t}

*l**, see Fig. 7 (b). Formally, we have*

_{i}*n*be the number of small rectangles which have dark points, viz., We now define the scratch account ratio for the rectangle

_{s}*R*as In our detection problem, we set

_{ij}*n*= 10 as the default value. Let

_{t}*r*

_{min}= 50% be the threshold. If

*r*≥

_{ij}*r*

_{min},

*L*and

_{i}*L*are considered to be part of the same scratch category. Otherwise, they belong to different categories, as illustrated in Fig. 7.

_{j}Once the classification is finished, each category represents a scratch, and we regard each category as a scratch *seed*. Then, we can find the two endpoints of each scratch seed. However, as Fig. 8 shows, if we only use one certain set of the built-in parameters of LSD, the closure of scratch seed may not relates with the corresponding scratch. Fig. 8(a)∼(c) are the original binary images, they all have at least one scratch. The red parts in Fig. 8(d)∼(f) are the LSD detection results, the scratch seeds. We can see that LSD can not cover the whole scratches clearly. In consequence, it is difficult to find the proper endpoints of the scratches. This disadvantage has serious impact on the detection performance which is characterized by the total length *ℓ _{mvi}* of all scratches.

#### 3.3. Removing noise points with RANSAC method

In order to overcome the disadvantage mentioned above, we expand the search grid according to the output of Algorithm 1 (Line Segment Classification Algorithm). We create a rectangular region of interest (ROI), denoted by Σ, to contain the whole scratch: it covers the part detected by LSD and its extended part is along the direction of the line segment. The set of dark points *𝒟*_{Σ} in this ROI will be

- Firstly, we sort these points by their coordinates in the slope direction.
- Secondly, we divide them into
*n*parts such that each part contains $\lceil {n}_{r}^{-1}\left|{\mathcal{D}}_{\mathrm{\Sigma}}^{S}\right|\rceil $ dark points where |_{r}*A*| denotes the number of elements in a finite set*A*and ⌈*x*⌉ denotes the the ceiling of real number*x*, i.e.,$$\lceil x\rceil =k,\hspace{0.17em}\hspace{0.17em}\hspace{0.17em}\hspace{0.17em}\hspace{0.17em}\hspace{0.17em}\hspace{0.17em}\hspace{0.17em}k-1<x\le k,\hspace{0.17em}\hspace{0.17em}\hspace{0.17em}\hspace{0.17em}\hspace{0.17em}\hspace{0.17em}\hspace{0.17em}\hspace{0.17em}\hspace{0.17em}\hspace{0.17em}\hspace{0.17em}k\in \mathbb{Z}.$$Fig. 9 illustrates the partition of dark points in ${\mathcal{D}}_{\mathrm{\Sigma}}^{S}$, in which we set*n*= 3 as the default value. Fig. 9(a) emulates the detecting result of LSD. We define the rectangular area surrounded by_{r}*L*_{1}and*L*_{2}. In Fig. 9(b), we collect all the points in this area from binary image. And, according to the number of points, we divide the region into three equal parts. In Fig. 9(c), we use RANSAC in each part. In Fig. 9(d), with the result of RANSAC, we can obtain the more precise area which contain all the scratches with less noise. Therefore, each part of the ROI*𝒟*_{Σ}can be modeled well by a line segment even if the scratch has a little curvature since the length of each part is small enough. - Thirdly, we take the RANSAC method to fit the scratch with the line model by choosing two points randomly in each part and removing the noise points automatically.

At the same time, we also get the candidate lines *L _{n}* as the output of RANSAC procedure. Our experiments show that three parts are enough to present the existing curved scratches, as demonstrated in Fig. 10.

Once the dark points caused by noise is removed successfully, we can determine the structure of *𝒟 ^{S}*. Suppose there are

*K*scratches in an image

*ℐ*, then (9) and (17) imply that

_{b}*K*is unknown and it can be determined automatically in Algorithm 1.

#### 3.4. Positioning proper endpoints

Once the noise points are removed, we sort the points in *𝒟*^{Sn} by a strategy of two steps:

- Compute the slope coefficient
*α*of_{n}*L*;_{n} - Sort the dark points: If |
*α*| > 1, then the dark points ${\left\{{\mathit{p}}_{i}={\left[{x}_{i},{y}_{i}\right]}^{\top}\right\}}_{i=1}^{N}$ in_{n}*𝒟*^{Sn}are sorted with increasing order by the vertical coordinates*y*, viz.,_{i}$$\begin{array}{ll}{\text{Order}}_{y}\hfill & :{\mathcal{D}}^{{S}_{n}}\times {\mathcal{D}}^{{S}_{n}}\to \{\text{True},\text{False}\}\hfill \\ \hfill & ({\mathit{p}}_{i},{\mathit{p}}_{j})\mapsto \{\begin{array}{ll}\text{True},\hfill & \text{if}\hspace{0.17em}\hspace{0.17em}{\mathit{p}}_{i}.y<{\mathit{p}}_{j}.y;\hfill \\ \text{False},\hfill & \text{otherwise}.\hfill \end{array}\hfill \end{array}$$Otherwise, these points are sorted by the horizontal coordinates*x*similarly,_{i}$$\begin{array}{ll}{\text{Order}}_{x}\hfill & :{\mathcal{D}}^{{S}_{n}}\times {\mathcal{D}}^{{S}_{n}}\to \{\text{True},\text{False}\}\hfill \\ \hfill & ({\mathit{p}}_{i},{\mathit{p}}_{j})\mapsto \{\begin{array}{ll}\text{True},\hfill & \mathbf{if}\hspace{0.17em}\hspace{0.17em}{\mathit{p}}_{i}.x<{\mathit{p}}_{j}.x;\hfill \\ \text{False},\hfill & \text{otherwise}.\hfill \end{array}\hfill \end{array}$$

Then, we apply Algorithm 2 to obtain the endpoints as follows.

In Algorithm 2, the two endpoints are found one by one. Firstly, we begin with the first point *p*_{1} as start endpoint candidate *p** _{sc}*. The distance between

*p**and*

_{i}

*p*_{i+1}are computed by

*p**,*

_{i}

*p*_{i+1}) ≤

*d*

_{max}, where

*d*

_{max}is the maximum acceptable separation between

*p**and*

_{i}

*p*_{i+1}, then we regard that these two points are not separable and continue to calculate dist(

*p*_{i+1},

*p*_{i+2}). Otherwise, such as the case where dist(

*p**,*

_{j}

*p*_{j+1}) >

*d*

_{max}, we calculate the distance dist(

*p**,*

_{sc}

*p**) between*

_{j}

*p**and*

_{j}

*p**. This distance has two possibilities: it may be the length of a part of scratch which consists of “adjacent” points, or the diameter of a lump of noise points. It depends on the value of this distance:*

_{sc}- If the distance is less than
*ℓ*_{min}and the minimum length of the scratch should be recorded. We just abandon these points and set the*p*_{j+1}with*p*, and then repeat previous steps._{sc} - Otherwise we find the start point
*p*, which is the last endpoint candidate_{s}*p*, see Fig. 11. In Fig. 11(a), we assume_{sc}*p*_{1}as*p*. Since dist(_{sc}*p*_{11},*p*_{12}) >*d*_{max}, we have to calculate dist(*p*,_{sc}*p*_{11}) = dist(*p*_{1},*p*_{11}). This value is shorter than*ℓ*_{min}, therefore we abandon the points on the line segment $\overline{{\mathit{p}}_{1}{\mathit{p}}_{11}}$, and regard*p*_{12}as*p*. In Fig. 11(b), since dist(_{sc}*p*_{39},*p*_{40}) >*d*_{max}, we calculate dist(*p*,_{sc}*p*_{39}) = dist(*p*_{12},*p*_{39}). This value is greater than*ℓ*_{min}, hence we have*p*=_{s}*p*=_{sc}*p*_{12}.

Secondly, we determine the other endpoint similarly. However, this time we begin with the last point of the sorted points *p** _{N}*.

The time complexity of Algorithm 2 is *𝒪*(*n _{d}*), thus the two endpoints can be determined quickly.

#### 3.5. Implementation of scratch detecting algorithm

With four modules constructed above, the complete scratch detecting algorithm is described in Algorithm 3, which corresponds to the flowchart in Fig. 4. To locate the scratches, we use the LSD algorithm. After classifying the scratches, we use a RANSAC procedure to collect the points in scratches. Finally, we found the endpoints of the scratches as accurately as possible. As mentioned in Algorithm 3, there are five parameters need to be set. Actually, for any similar problem, these parameter can be set easily by following process. First, according to the detection requirement, *ℓ*_{min} (the minimum length of the scratch to be recorded) is determined. Then, the degree of proximity DOP_{max} and the maximum acceptable separation *d*_{max} are determined based on *ℓ*_{min}. Actually, we can set

The scratch account ratio *r _{min}* is similar with the duty ratio, which indicates the proportion of area that may be scratched through, thus 50% is a reasonable threshold. The last parameter

*θ*

_{max}is used to distinguish scratch categories by computing the difference of angle. Since the LSD results can be located at both sides of scratch, the setting of this parameter is related to

*ℓ*

_{min}and the width of scratch

*w*will be

*θ*

_{max}= 13° = 0.22689 rad,

*r*

_{min}= 50%, DOP

_{max}= 50 pixels,

*d*

_{max}= 30 pixels,

*ℓ*

_{min}= 15 pixels.

## 4. Experiment and result analysis

#### 4.1. Experiment results

To evaluate the performance, we applied Algorithm 3 on about 1700 images (2724 × 2724 pixels), which are generated from 7 different optical surfaces (810 mm × 460 mm for each).

During the experiment, we found that the connection between scratches plays a very important role in the final results. If several co-linear segments correspond to the same scratch, then it is necessary to connect and merge them into a long scratch. Otherwise, the length of the scratch will probably be calculated as less than the actual length. Thanks to the judging condition in Algorithm 1, we have our own standard to decide the attribution different line segments. This phenomena is clearly demonstrated in Fig. 12. This figure shows the original images, LSD test results and our test results. Fig. 12(a)∼(c) are the images with LSD detection results. The rectangular areas in Fig. 12(d)∼(f) are the area that include scratches and the black line segment is the scratch that we found. In Fig. 12(c), the middle area of the scratch is too weak, thus, the corresponding area in Fig. 12(f) is shown in co-linear points, which cannot be detected by LSD. For our algorithm, it can not only determine the position relationship between the found strong scratches successfully but also can connect them very well via Algorithm 3.

Fig. 13 shows that our algorithm can find the scratches’ endpoints which coincides with the realistic situation very well. Fig. 13(a)∼(c) are the images with LSD detection results. The rectangular areas in Fig. 13(d)∼(f) are the area that include scratches and the black line segment is the scratch that was found. Due to the fact that the contrast of original image is too low, see Fig. 13(a)∼(c), the scratch (especially for the head and tail area) is discontinuous, see Fig. 13(d)∼(f). For this case, LSD can only find the *seeds* on the scratches. The length of these *seeds* is far less than the length of the scratch. In Algorithm 2, a pixel-level linear search algorithm is used to find true endpoints of scratch. Actually, Fig. 13(a)∼(c) show that there is no clear standard for the endpoint selection by the HVI method. That means for the same image but different people, an inspector person may mark different endpoints. However, by using our algorithm, the stability of the scratch detection results is good, which can be said that this is one of the advantage over human vision detection. This process also improves the accuracy of determining the total length of the scratch concerned.

Actually, the LSD algorithm just works well for the straight scratches (line segments) whose curvatures are near zero. However, there exists *large curvature scratches*. Fig. 14 indicates that the algorithm can deal with large curvature scratches. Fig. 14(a)∼(c) are the images with LSD detection results shown in red. The rectangular area in Fig. 14(d)∼(f) are the area that include scratches and the black line segment is the scratch that was found.

For these kind of scratches, the LSD algorithm treat them as a collection of small independent straight scratches. In this way, it breaks the continuity of the scratches and increases the difficulty of calculating the length of the scratch. Physically and geometrically, a large curvature scratch can be considered as several linked long scratches whose ends connects each other. For more original images with acceptable resolution, please see the images on the web site https://github.com/PaperImageData/ScratchDetector shared by the authors.

#### 4.2. Comparison of detecting algorithms

We compared our scratch algorithm with LSD [22] and the algorithm in [18]. Table 2 shows the results by different detection algorithms. We use 5 group of images data and collect the detection results. Compared with the GLD such as LSD [22], our algorithm can detect the correct number of scratches in most cases. Meanwhile, the total length of scratches detected with LSD algorithm is far less than its counterpart obtained with HVI method. Compared with the algorithm in [18], our method is more stable and reliable, since for all experiments, we have a small error rate *E* < 5%. Obviously, the accuracy of our MVI result is satisfactory when compared with that of HVI.

We implemented the detection algorithm with the C++ programming language and the open source software OpenCV-3.2 [26] on a Ubuntu 16.04 GNU/Linux operating system with Intel i7-6700K CPU and 32GB DDR4 RAM. The processing speed is about 0.138 second per binary image with 2724 × 2724 pixels in scratch detection.

## 5. Conclusions

Scratches detection on optical surface is a challenging problem in optics engineering. In this paper, we proposed an algorithm for detecting scratch defects on precise optical component surfaces. This algorithm can deal with the cases that GLD algorithms are not suitable for, such as the scratch has punctiform in the head and tail area, discontinuous scratches segments and etc.. Particularly, compared with LSD algorithm, our algorithm can give a semantic scratch detection and provide higher accuracy in quantitative analysis. Compared with the HVI method, our MVI method is much more accurate, fast, convenient and economical. Due to the physics characters of the surface, we believe this algorithm can also be used in other glass-like surface scratch detection.

## Funding

Hainan Provincial Natural Science Foundation of China (HPNSFC) (2019CXTD405); National Natural Science Foundation of China (NSFC) (61201085, 61562023, 61502127).

## References

**1. **L.-X. Yuan, Z.-T. Zhang, and X. Tao, “The development and prospect of surface defect detection based on vision measurement method,” in World Congress on Intelligent Control and Automation, (2016), pp. 1382–1387.

**2. **P. Mariño, V. Pastoriza, and M. Santamaría, “Machine vision method for online surface inspection of easy open can ends,” in Proc. SPIE, vol. 6382 (2006), pp. 638206. [CrossRef]

**3. **H.-H. Jiang and G.-F. Yin, “Surface defect inspection and classification of segment magnet by using machine vision technique,” Adv. Mat. Res. **339**, 32–35 (2011).

**4. **J.-W. Dong, Q.-J. Wu, W.-W. Jiang, and Q. Xu, “The review of new NDT methods of metal material fatigue monitoring,” Int. J. Hybrid Inf. Technol. **8**, 225–232 (2015). [CrossRef]

**5. **S. Radovan, P. George, M. Panagiotis, and G. Manos, “An approach for automated inspection of wood boards,” in Proc. 2001 ICIP (Cat. No.01CH37205), vol. 1 (2001), pp. 798–801.

**6. **G.-H. Hu, G.-H. Zhang, and Q.-H. Wang, “Automated defect detection in textured materials using wavelet-domain hidden markov models,” Opt. Eng. **53**, 093107 (2014). [CrossRef]

**7. **E. H. Shortliffe and M. S. Blois, “The computer meets medicine and biology: emergence of a discipline,” Biomed. Infor. pp. 3–45 (2006). [CrossRef]

**8. **P. Cormont, A. Bourgeade, S. Cavaro, T. Doualle, G. Gaborit, L. Gallais, J.-L. Rullier, and D. Taroux, “Process for repairing large scratches on fused silica optics,” in Proc. SPIE, vol. 9633 (2015), p. 9633A.

**9. **“Optics and Photonics — Preparation of Drawings for Optical Elements and Systems — Part 7: Surface Imperfection Tolerances,” Standard, IOS (2008).

**10. **X. Tao, Z.-T. Zhang, F. Zhang, and D. Xu, “A novel and effective surface flaw inspection instrument for large-aperture optical elements,” IEEE Trans. Instrum. Meas. **64**, 2530–2540 (2015). [CrossRef]

**11. **T. A. Germer, “Angular dependence and polarization of out-of-plane optical scattering from particulate contamination, subsurface defects, and surface microroughness,” Appl. Opt. **36**, 8798–8805 (1997). [CrossRef]

**12. **Z.-H. Gu, “Detection of a small defect on a rough surface,” Opt. Lett. **23**, 494–496 (1998). [CrossRef]

**13. **V. M. Schneider, M. Meljnek, and K. T. Gahagan, “*Fast detection of single sided diffracted defects in display glass*,” (OSA, 2009), pp. 638–644.

**14. **L. M. Sanchez-Brea, P. Siegmann, M. A. Rebollo, and E. Bernabeu, “Optical technique for the automatic detection and measurement of surface defects on thin metallic wires,” Appl. Opt. **39**, 539–545 (2000). [CrossRef]

**15. **L. Li, D. Liu, P. Cao, S. Xie, Y. Li, Y. Chen, and Y. Yang, “Automated discrimination between digs and dust particles on optical surfaces with dark-field scattering microscopy,” Appl. Opt. **53**, 5131–5140 (2014). [CrossRef] [PubMed]

**16. **D. Liu, Y.-Y. Yang, L. Wang, Y.-M. Zhuo, C.-H. Lu, L.-M. Yang, and R.-J. Li, “Microscopic scattering imaging measurement and digital evaluation system of defects for fine optical surface,” Opt. Commun. **278**, 240–246 (2007). [CrossRef]

**17. **C. Li, Y.-Y. Yang, H.-L. Xiong, D. Liu, S.-B. Xie, Y. Li, J. Bai, Y. Shen, H.-Z. Jiang, and X. Liu, “Dual-threshold algorithm study of weak-scratch extraction based on the filter and difference,” High Power Laser Part. Beams **27**, 1–8 (2015). In Chinese.

**18. **X. Tao, D. Xu, Z. T. Zhang, F. Zhang, X. L. Liu, and D. P. Zhang, “Weak scratch detection and defect classification methods for a large-aperture optical element,” Opt. Commun. **387**, 390–400 (2016). [CrossRef]

**19. **J. Illingworth and J. Kittler, “The adaptive Hough transform,” IEEE Trans. PAMI **9**, 690–698 (1987). [CrossRef]

**20. **N. Kiryati, Y. Eldar, and A. M. Bruckstein, “A probabilistic Hough transform,” Pattern Recogn. **24**, 303–316 (1991). [CrossRef]

**21. **N. Guil, J. Villalba, and E. L. Zapata, “A fast Hough transform for segment detection,” IEEE Trans. IP **4**, 1541–1548 (1995).

**22. **R. G. von Gioi, J. Jakubowicz, J.-M. Morel, and G. Randall, “LSD: a fast line segment detector with a false detection control,” IEEE Trans. PAMI **32**, 722–732 (2010). [CrossRef]

**23. **C. Akinlar and C. Topal, “EDLines: A real-time line segment detector with a false detection control,” Pattern Recogn. Lett. **32**, 1633–1642 (2011). [CrossRef]

**24. **D. Liu, S. Wang, P. Cao, L. Li, Z. Cheng, X. Gao, and Y. Yang, “Dark-field microscopic image stitching method for surface defects evaluation of large fine optics,” Opt. Express **21**, 5974–5987 (2013). [CrossRef] [PubMed]

**25. **M. A. Fischer and R. C. Bolles, “Random sample consensus: a paradigm for model fitting with applications to image analysis and automated cartography,” Commun. ACM **24**, 381–395 (1981). [CrossRef]

**26. **A. Kaehler and G. Bradski, *Learning OpenCV 3: Computer Vision in C++ with the OpenCV Library* (O’Reilly Media, 2017).