Image-Based Inspection Technique of a Machined Metal Surface for an Unmanned Lapping Process

This paper presents a new machine vision framework for the efficient examination and classification of surface textures on medium- and large-sized mold products, such as used for automobiles, TVs, and refrigerators. Existing techniques, which are based on the hands and eyes of skilled workers, are inconsistent and time-consuming. Although there are many types of precise surface inspection and measurement methods, most are difficult to apply at industrial sites or by finishing robots due to problems such as speed, setup limitations, and robustness. This paper proposes two techniques based on image processing that aims to automate surface inspection during an unmanned lapping process that is mainly employed to eliminate milling tool marks. First, both the shape of the reflected light and the intensity of the captured near-field contrast image right after the reflected specular are used to determine the machined surface state, and the presence of tool marks as the line light source scans counter-clockwise. Second, the photometric stereo technique is used to detect surface scratches through the normal map that recovers the surface. The proposed techniques show localized machined patterns and classify them with high accuracy.


Introduction
A crucial issue in manufacturing, when accurate inspection and rapid production are necessary, is the designation and inspection of machined metal surfaces. The automatic inspection and detection of defects using image processing is an area of machine vision that is widely adopted in many industrial fields. It is used for high-throughput quality control in production systems, such as the detection of flaws on manufactured surfaces of automobiles or mobile phones [1,2]. The idea is to design autonomous devices that automatically examine and improve the performance of traditional inspection systems that depend heavily on human inspectors during the lapping process for a mold product surface. This task is usually repetitive and labor intensive, and it might also involve exposure to radiation, high noise levels, metal dust, and chemical environments, leading to health problems such as musculoskeletal and lung diseases. Therefore, robotic finishing for automation is highly necessary from the perspective of productivity, cost, time, and uniformity of surface quality [3,4].
The finishing performance of a surface depends on the dimensional characteristics of the surface irregularities. These characteristics vary considerably according to the surface material and the manufacturing process.
Conventionally, surface roughness and waviness are measured using a stylus, laser scanners, etc. However, these methods are rather slow and time consuming since they measure the surface profile at every point on the surface. In practice, many circumstances exist in which such detailed information about the metal surface is unnecessary. Moreover, the methods create limitations to the setup. Because of these problems, it is difficult to apply a stylus to real industrial sites or robotic finishing [4][5][6].
Alternatively, non-contact optical metrology techniques can be employed to overcome these problems. These techniques include confocal microscopy; various interferometry methods; optical profiling; and methods using reflection, scattering, and speckle patterns [4][5][6][7][8]. Although many methods are available, the use of these techniques is limited at industrial sites because of the working environment and special issues for measurement. Hence, a surface inspection is required that is 1 3 high speed, robust, low cost, and applicable to both industrial sites and robot finishing [4,[9][10][11][12].
There are two types of roughness in the lapping mold surface. The purpose of this research is not only to detect the machining induced tool marks that are regularly distributed, but the unexpectedly appeared scratches that are very thin and irregular type. This paper compares two major image-based surface techniques. First, machined surfaces are evaluated using tool mark detection and classification of the surface state based on the characteristics of the different reflected light according to the residual tool mark. The second proposed method is inspecting the entire machined surface at once and detecting scratches from the extracted normal map image based on a photometric stereo.
Captured near-field contrast images right after the reflected specular light made by an individual point light provide highly sensitive and reliable image data so that they can be processed through grayscale.

Reflection Property of Machined Surface [13]
After machining, multiple tool marks are created on the metal surface by machining tools performing milling and grinding. When a point light source is used to illuminate the surface, reflected light is generated in a direction perpendicular to the tool mark. The reflected light is indicated by the yellow arrows in Fig. 1 and is called a specular highlight.
The reflected light can be expressed as Eq. (1) in relation to the tool mark and the normal vector of the surface: where r h : the specular highlight by tool mark, ŝ : the tool mark direction of surface, n : the surface normal.
Equation (2) is satisfied when the intensity is maximum: where n′ : the bisector between camera and light source.

Reflection of the Milled Surfaces
In the case of milled surfaces, the highlight is made by gathering the reflected light in a small groove, as magnified by the red circle in Fig. 2.
The milling tool pattern is circular and has various diameters. Because of this, different reflected light patterns are created depending on the tool diameter, as shown in Fig. 3.
Using the tool mark radius from a point P, the direction vector of the milling tool mark is given by Eq. (3): where r : the radius of milling tool, P : a point on the milled surface, P x : the point depending on the x-coordinate.
The below equation is derived by substituting Eq. (3) for the maximum intensity condition:   From the reflection property and maximum intensity condition, the relationship between the milling tool radius and the reflected light is derived at P x on the surface, as shown in Eq. (4). It can be seen in Eq. (4) that the larger the diameter of the milling tool, the larger the P x . This reduces the range in which the reflected light occurs:

System Overview
There are many types of surface textures in machined metal parts. These textures can be attributed to one of the following causes: • milling tool marks • flaws produced during grinding • material defects such as cracks • chatter marks due to tool vibration • scratches due to processing and handling In order to meet all requirements, the system mainly includes a camera and an LED light source. There are limitations to using laser measuring equipment and precision measuring equipment in real environment conditions [14]. Therefore, the inspection system is tested in a dark space to minimize the effects of external noises. Figure 4 shows the setup for the inspection.
a. Camera A SONY RX10 m3 mirrorless camera with built-in CMOS sensor. It runs an ISO sensitivity of 100-12,800 with maximum resolution 20.1 (5472 × 3648). For surface inspection, the maximum ISO sensitivity is used and the distance of the camera zoom is set at 83 mm. The actual resolution used is about 0.02 (mm/ pixel).
As shown in Fig. 4, the camera is fixed vertically to the specimen, and 19 images are taken from 0° to 180° at intervals of 10° as the workpiece rotates. The light source obtains the image when moving only in the horizontal direction while being fixed at 45° in the vertical direction. As the line light source scans the surface counter-clockwise, the nearfield contrast appears distinctly right after the specular reflected light. The camera captures the images with 50 frame speed.

Machined Metal Surfaces
For this inspection, four types of machined surfaces are prepared ( Fig. 5) which have a size of 50 × 50 × 20 mm 3 The material is KP4M.
A total of nine specimens are used for statistical analysis. For these nine surfaces, surfaces were each machined by face mill, a turbo lap linear, a grinding machine, and a hand grinding.
The hand-ground surface is ground three times in the direction perpendicular to the arc of the milling tool mark. The machined surface is ground until the tool mark is not visible during a visual check. In the case of the hand grinder, the tool mark was removed according to a visual inspection at the third grinder.

Milled Surface
The reflected light is perpendicular to the milling tool mark, as shown in Fig. 1. The white line in the image shown in Fig. 6 is a specular highlight or reflected light. As the diameter of the face mill increases, the range of reflected light becomes narrower (Table 1). For a 50 mm face-milled specimen (Fig. 6a), the tool passed twice through the surface because the specimen size and diameter were the same. Thus, reflected light due to two tool marks appears. In the case of 125 mm (Fig. 6d), the depth of the tool mark is uneven due to chatter vibration during machining. Except for the 50 mm case, the overall intensity is dark. However, the intensity in the case of 125 mm is higher than in the 80 mm ( Fig. 6b) and 100 mm (Fig. 6c) cases due to chatter marks. The surface roughnesses R a and R z are indicated in Table 1.

Lapped and Ground Surface
As seen in Table 2, regardless of the grit size of the tool, reflected light by lapping occurs only in the picture when the light source position is 40°-140°. In addition, the shape of the reflected light by lapping and grinding is linear and wider than the reflected light from the milling tool mark since milling and grinding are performed manually. In the case of #600 (Fig. 7a1-a3), there are two types of reflected light. One is by lapping, and the other is by a milling tool mark. It is possible to check whether the milling tool mark has been removed with the raw image. The total intensity of #600 is lower than in the case of #800 (Fig. 7b) and #1200 (Fig. 7c), 3because the surface roughnesses R a and R z improve from #600 to #1200. As the lapping step proceeds, the surface becomes like a mirror surface. The intensity shape of the ground surface is brighter Fig. 5 Machined metal surfaces: a milled surface by a face mill with diameters 50, 80, 100, and 125 mm; the shape of the tool mark is a circular arc; b lapped surface by the turbo-lap linear which has grit sizes #600, #800, and #1200; the shape of the tool mark is straight; c ground surface by grinding machine and hand grinder

Characterization of the Machined Surfaces
When the raw images and surfaces are examined normally, the intensity differs depending on the machining process. Hence, the image processing in MATLAB was adopted to verify the relationship between the intensities seen with the naked eye and those of the image. As determined by a histogram using 19 images of each machined surface, the gray level with the maximum number of pixels was seen to be different. This dominant gray level or intensity is shown in Fig. 8.
The milled surface inspections showed a similar gray level for all 19 images, regardless of the diameter of the face mill. This means that the reflected light does not affect the intensity of the entire surface.
The lapped and ground surfaces have a maximum value of 255 gray levels in the region where the reflected light occurs. This means that the intensity of the reflected light dominates the entire intensity. Therefore, this result implies that the intensity and the reflected light indicate surface characteristics that distinguish the machined surface state. However, for lapping, the intensity of #800 is revealed to be higher than that of #1200, which is caused by scratches during the lapping process.
The mean and standard deviation values can represent the intensity in image processing. Figure 9 shows the mean and standard deviation of eight images outside this range.
It is confirmed that the intensities of the individual surfaces are distinguished within the range of the histogram without being influenced by the reflected light.
As in the case of the three brown circle areas, surfaces made by milling, grinding, and lapping can be distinguished by the intensity difference.
The mean and standard deviation values of the milled surface occur in one area, except for 125 mm of the three milling cases, since chatter marks exist. In the case of plane grinding, the area of the circles is also very small, because the reflected light forms narrow and uniform on the entire surface.
For the lapping process, the intensities of #800 becomes brighter than those of #1200, as shown in the histogram.

Determination of the Machined Surface State Based on Intensity
Classification and statistical analyses with the 30 milling, plane grinding, and hand lapping surfaces were carried out. The machined surface state can be determined using the intensity of the surface image. The T test and ANOVA results for the mean and standard deviation data for the intensity of the machined surfaces in Table 3, which show that the milled and two ground surfaces are independent because the T-test shows that the P-value is less than 0.05, which is clearly distinguished in the Fig. 10. On the other hand, manually hand lapped surfaces after milling machining show much wider distribution in the figure, of which standard deviation is much larger than 0.05.

Quantification of Machined Surface Condition
To quantify the machined surface condition such as milling, grinding, chatter and remained tool mark, cluster analysis was adopted. The clustering results are evaluated by the clustering accuracy and statistical analysis, and these can easily evaluate the clustering result using a confidence ellipse [15]. For drawing the confidence ellipse, the Mahalanobis distance is defined as the distance between two variables and the covariance, as in Eq. (5). Covariance is defined as Eq. (6), which indicates the degree of correlation between two variables: where D_M: Mahalanobis distance, X, Y: set of observations (mean and standard deviation), C: covariance matrix where C: covariance matrix, Var: variance of variable, σ: standard deviation of variable.
Also, the confidence ellipse can be defined as Eq. (7) using eigenvalues and eigenvectors of the covariance matrix and the standard deviation. The maximum and minimum eigenvalues represent the maximum and minimum radius of the confidence ellipse: where S: the value of the probability table (size of ellipse) where λ: maximum and minimum eigenvalue of covariance matrix. Figure 10 depicts the confidence ellipse using the Mahalanobis distance. The three different ellipse groups are independent of each other and also show whether the data in each group are trustworthy. Table 4 shows the covariance matrix of the machined surfaces.
The longest axis of the milling confidence ellipse represents the large standard deviation, because reflected light  occurs in almost all areas and the influence on the orientation is larger than the magnitude of the intensity. On the other hand, all data exist in the confidence ellipse except one outlier among 80 data points using 8 images per surface.
In the case of plane grinding, the width of the ellipse is small because the range of the specular highlight is narrower than that of the other two machined surfaces. The hand grinder case becomes wider because the reflected light is split, and the surface has various intensities due to the non-uniformity. These results support that intensity-based clustering could be a good indication for distinguishing the machined surface state.

Detection of Tool Mark Using Specular Highlight
The use of the specular highlight is possible for determining the residual amount of tool mark for the surface inspection of each finishing step.
After converting the original image to a gray image, the reflected light image is removed as depicted in Fig. 11. Next, the tool marks and non-parts are separated through thresholding, leaving only tool marks. Since the boundaries and areas of tool marks are partial and ambiguous, expansion of the boundaries is necessary. Through the dilation technique, the edges of the tool mark are filled with blank parts to sharpen the boundary [17].
Next, the areas that are too small are removed for accurate tool mark detection and the boundary part of the remaining area is indicated by yellow. Figure 12 shows that the tool mark around the reflected light is clearly visible, since the reflected light is the brightest part of the entire surface. By employing this technique, the residual tool marks around the reflected light can be detected by scanning the entire surface of image 19. But the scratch detection is unclear except for the tool marks when there is reflected light. Only scratches deeper than the depth of the residual tool marks can be detected.
In the case of 125 mm (Fig. 12c), a wide range of tool marks is detected due to the chatter marks. In the case of the hand lapped surface with #600 ( Fig. 12d1-d3), milling tool marks that have not been removed yet are detected.
However, tool marks from lapping at the reflected light area are also detected. Therefore, the tool mark detection algorithm should be improved to distinguish between milling and lapping tool marks. Moreover, an algorithm capable of simultaneously detecting a scratch is also required.

Photometric Stereo
This technique was popularly employed in computer vision applications to estimate the surface normal of objects with observations under different lighting conditions [16]. It is formally defined by the surface normal from the reflected light between the object and the light source and the observed intensities, as given by Eq. (8): where I: vector of observed intensities, L: normalized light directions, n: surface normal, k: albedo reflectivity.
The intensity and the position of the light source, surface normal vector is derived from Eq. (8) through Eqs. (9) and (10). The surface normal is obtained through light modeling from images along the light source at different locations from Eq. (10):

Setup for the Inspection
This setup is the same as the inspection configuration in Sect. 3.1 (Fig. 4), except for using two reflective balls and the light source position. This is because the reflective ball is an absolute reference for modeling the position of the moving light source. Iron balls were used in this study as the two reflective balls. Images are obtained at six locations of the optimized light source that do not cause specular highlight.

Optimization of Light Position for Removing Specular Highlight
The normal map is obtained as shown on the left of Fig. 13. This normal map does not recover the entire surface, and the left of Fig. 13 shows the surface information lost. That means that the photometric stereo is unsuitable for metal surfaces due to reflected light. If the normal map is acquired using the position of the light source where no reflected light is generated, a normal map that can recover the entire surface can be obtained, as shown on the right side of Fig. 13. Table 5 indicates the results of the horizontal angle region where reflected light occurs in Sect. 3.3 as well as the result of a region where no reflected light occurs. In this table, the common range of 13no reflected light is − 40° to 0° (40°) and − 140° to 180° (40°). As a result, six light source locations were set at 0°, − 20°, − 40°, − 140°, − 160°, and 180° as the common angle for six minimum images that can be recovered, using the opposite direction of Fig. 4b.

Normal Map Results of Machined Surfaces
As can be seen in Fig. 14, normal maps are acquired by inverting the z-direction of the original normal map and adopting it at 1.2 times the weight. The reason for using the z-direction normal map is that, since the machined surface is close to 2D, there is hardly any surface information in the x-and y-direction normal maps. The normal maps show the entire machined surfaces at once. But the middle region is relatively dark, because images near 90° and the opposite side are not considered in order to exclude specular highlight.
In the 125 mm milling case (Fig. 14a2), bright chatter tool marks are shown on both sides of the top, because there is faint reflected light even in the range where reflection should not occur due to chatter marks. For lapped with #600 ( Fig. 14b1) or plane grinder ground surfaces (Fig. 14c1, c2), it looks noticeably better for deep scratches than for tool marks. In the case of hand lapping, there is the tool mark  ig. 14 Normal map results: a1, a2 milled surfaces; respectively diameters of 100 mm, 125 mm; b1, b2 lapped surfaces; respectively grit size #600, #800; c1, c2 grinded surfaces; respectively plane grinder, hand grinder of the grinder itself and there are several highlights. This is also because the reflected light is generated in a range where it should not occur due to irregular tool marks by manual work.

Scratch Detection in the Machined Surface
In Sect. 4.4, since the tool mark around the reflected light was brightly captured, it was easy to find. However, it was difficult to detect scratches because of the bright characteristics of the reflected light. Therefore, adopting a normal map technique, it reflects the entire surface. The procedure is similar to that of the process in Sect. 4.4. As shown in Fig. 15 for the scratch detection, the inverted image was used in the original z-direction normal map.
This facilitates banalization for leaving only scratches. Then, as in the process of Sect. 4.4, the edges of the scratch are expanded to sharpen the boundary through the dilation technique. Next, the areas that are too small are removed for accurate scratch detection, and the boundary parts of the remaining area are shown in blue.
In Fig. 16, the dark yellow boxes show where scratches are detected, and the yellow ellipses show where the milling tool mark, which could not be removed with #600 hand lapping (Fig. 16b), was detected.
The lapped and ground surfaces may include unexpected scratches caused by handling. This scratch is rather deeper and clearer than tool marks such as the milling tool mark. To resolve this problem, a robust detection algorithm is needed to distinguish between scratches caused by external factors and the tool itself.
Significant improvements were made using the proposed method. The non-detection rate of scratches was very small and the improved inspection is superior to that from a human operator.

Conclusion
An image-based machined surface inspection based on an image processing technique was developed for applications in the process of unmanned lapping. In this paper, two methods are proposed. The first is an inspection method that utilizes reflected light characteristics by a tool mark on a machined surface. This distinguishes the machined surface state by using the shape of the reflected light and the intensity of the image according to the tool mark, and the tool mark can be also detected. The second is a normal map by the photometric stereo technique, which shows the entire surface at one time and can detect scratches much clear.
Consequently, if only the two methods are integrated, only six images can provide the classification of the machined surface state such as remained tool mark, waviness and scratch at once. This method can be applied to automate detection of the state of machined metal surfaces. This will widen the inspection method for robotic machining system as well as for unmanned machining processes.