Characterization of the Surface Finish of Machined Parts Using Artificial Vision and Hough Transform

The surface finish of machined parts is of the utmost importance in determining their quality. This is not only for aesthetic purposes. Since in several industrial applications the machined parts have to be in contact with other parts, surface finish is also a determining factor in defining the capacity of wear, lubrication, and resistance to fatigue (i.e. service life). To determine the quality of machined parts, the roughness is analyzed to be a representation of the surface texture. Therefore, mathematical techniques have been developed to measure this criterion; such as the roughness meter, X-ray diffraction, ultrasound, electrical resistance, and image analysis (Alabi et al., 2008; Xie, 2008; Bradley & Wong, 2001).

that are not part of the lines to be segmented. Another contribution has been introduced in stage 4, where the reconstruction is undertaken using the straight lines that form the image without projection, up to the edges of the image. These modifications were implemented to optimize the developed application.
The Hough transform is a mathematical method that uses an edge detector to locate points that could form a perceptible edge. The method determines if the points are specific components of a parameterized curve. This was developed in 1962 by Paúl Hough (Davies, 1990) in order to find, in nuclear physics, the straight paths of high energy particles in a bubble chamber; but not until 1969 was the Rosenfeld (Illingworth & Kittler, 1988) proposed algorithm introduced for use in the image processing area.

The hough transform
The Hough transform is a method used for line segmentation. It is based on the transformation of a straight line in an x-y plane (eq.(1)) into a point in an m-b plane (eq. (2)). The line equation (eq. (1)) defines each one of the lines in the x-y plane by means of a slope (m) and a y-axis intersection (b).
The points that form the line in the x-y plane are represented by one point in the new m-b plane, as shown in Fig. 1. In this, the line of the x-y plane has a slope value equal to the unit and an intersection equal to two. One can see that this line is represented by only one point in the m-b plane, whose coordinates correspond to the parameter values (m,b) that define the straight line in the x-y plane (Leavers, 1993).
a) x-y p l a n e b ) m-b plane When using the Hough transform to solve the problem of locating straight lines and then searching for points with greater frequency in the m-b plane, the following routines and elements need to be created and evaluated: 1. Acummulator: A table whose cells are initialized to zero. The number of rows and columns in the accumulator are determined by the maximum values of the parameters www.intechopen.com (m,b) of the lines to be segmented. For example: a line in the x-y plane is defined by two points and the points that are found between these two points belong to a straight line, as the points shown in Fig. 2a. The expected slope of the straight line formed by these three points is in the interval 0 < m < 3, while its intersection with the y axis is in the interval 0 < b < 5. Thus, the accumulator has to be constructed with four columns and six rows to accommodate the expected values of m and b, for the line defined by these three collinear points. 2. Evaluation of points and registration in the accumulator. Eq. (2)  parameters manifests itself when lines perpendicular to the x axis are to be segmented. In such a case, m tends to infinity. To solve this indefinition, Duda and Hart (Duda & Hart, 1972) propose to use the parameters (θ, ρ) of a vector starting at the origin and oriented perpendicular to the line to be segmented. In this parameterization, θ is the angle sustained by the vector and the x axis, and ρ is the distance measured from the origin to the intersection between the vector and the line (see Fig. 3). This parameterization is described by eq. (3); it is known as the Standard Hough Transform (SHT).
ii xy s i n cos In this new space, each point with parameters (θ,ρ) is mapped into a sinusoid when its coordinates i x and i y are kept constant (see eq. (3)), and the value of θ is varied within the specified interval (Duda & Hart, 1972).
The process used to identify straight lines with the SHT is presented in Fig. 3, where we can see four points ( Fig. 3a). Three of the describe the straight line with greater length. Each one of these points is to be projected into a different sinusoid in the θ-ρ space (see Fig. 3b). These projections are registered in the accumulator (Fig. 3c), whose dimensions are obtained according to the expected intervals for θ and ρ. The interval for ρ is defined as (Duda & Hart, 1972): where a is the width and h is the height of the x-y plane, respectively.
www.intechopen.com Expression 4 is used to obtain the possible lengths of the parameterization or radius vector, from its origin to the line. When the points are collinear the cells with greater values provide the parameters of the lines to be identified. In Fig. 3c we can see the maximum value of three, this corresponds to the greatest number of collinear points that define the line of Fig.  3a having the greatest length. By plotting the values of the intersections in the accumulator on a coordinate system with three dimensions (θ, ρ, fr) (where fr indicates the number of registered intersections in each cell), one can discriminate, in the accumulator, the cells with a high frequency of intersection, as shown in Fig. 3c. In the third axis, corresponding to the frequency of intersection, the value of the highest frequency occurs only once; that is, there is only one maximum point. Accordingly, there is only one set of points with the highest possible collinearity (see Fig. 3a), and therefore a line of greater length in the x-y plane of the image.
The reconstruction of the lines located with the standard Hough Transform is carried out by evaluating the values of x in eq.  The straight line located from the four points processed is shown in Fig. 3d; it is used to evaluate the points and parameters in (Duda & Hart, 1972): The Hough transform is an efficient method in detecting lines, circles, and ellipses, but with a high computational cost. With the objective of improving its efficiency, several proposals have been done (Xie, 2008;Illingworth & Kittler, 1988). The methods to improve the performance of the Hough transform are basically in the lines segmentation, and these are classified into two groups (Genswein & Yang, 1999) The NPHTs propose methods to optimize the discretization of the accumulator as well as the identification of the cells with the larger number of intersections or records. The PHTs conduct, in an iterative manner, the random selection of small sets of points until a cell in the accumulator exceeds a defined limit in line identification. The points that define the line in the image are deleted and the selection of new points starts again, this process is done in an iterative manner until the processing of all points in the image is accomplished.
Yun-Seok et. al. (Lee, Yoo & Jeong, 2006), stated that the developed techniques in the nonprobabilistic Hough transformations decrease the complexity of finding the maximum point in the accumulator. However, in these methods, all the possible orientations of θ must be considered. Meanwhile, with the probabilistic Hough transformations, the number of points to be processed in order to avoid incorrect results must be carefully selected.

Edge detection and binarization of the image
The creation of a binary version of the original image is carried out as a pre-processing stage; this provides a significant decrease in the number of points to be processed. Through this preprocessing stage, only the points that form part of the objects of interest in the image are considered for further analysis, while those that belong to the bottom are discarded.

Edge detection
Edge detection is based on the abrupt variation of pixel intensity between the borders and the background, where the borders define the edges of the objects that form the image. This permits definition of false edges due to noise in the image. Techniques to identify edges based on discontinuities in the pixels' intensity are based on the gradient obtained in the image f(x,y) at (x,y), where the point (x,y) is defined as a vector perpendicular to the edge (Szeliski, 2008): where G is the maximum variation in the intensity of f (which corresponds to the intensity and position of each pixel in the image) in the (x,y) point per unit of distance, with magnitude and direction given by (Szeliski, 2008): ,a r c t a n       .
Several gradient operators have been divided into two groups, the first-derivative operators and the second-derivative operators. In the first group are the Sobel, Prewitt, Roberts, Kirsch, Robinson, and Feid-Chen operators. In the second group are the Laplacian and Gaussian Laplacian operators. In this work, we focus on the Sobel operator to detect edges and smooth the image, thereby minimizing the noise due to false edge resulting from the noise enhancement produced by the derivative operators (Gonzalez & Woods, 2008).
The Sobel operator computes the intensity values change approximation at a point when it is considered to be a neighborhood of a 3×3 size, taking the point as the center. The Sobel mask is shown in Fig. 4.
Edge detection using the Sobel operator implies the computation of the sum of the coefficient of the gray scale levels of the pixels contained in the region enclosed by the mask: An example of the resulting image applying the Sobel methodology is shown in Fig. 5b.
A threshold is applied for the construction of the binary image. This threshold is used in the gradient image to identify and separate the pixels which belong to the edges of the image from those that form the background: The binary image shown in Fig. 5c is obtained after the application of the threshold (T=32) to the gradient image in Fig. 5b. In the binary image ( Fig. 5c) one notices the presence of discontinuous edges. A process that significantly reduces the discontinuous edges is the algorithm developed by Canny (Canny, 1986); which is implemented in the edge extraction stage.
The Canny algorithm detects the edges applying error criteria, location, and response; these conditions can be broken down into three modules. In the first module, the image is processed using a Gaussian filter, with the purpose of smoothing both the image and the existing noise (Fig. 6): After the image is smoothed, the Sobel operator is applied to obtain the magnitude and direction of the gradient. These values are employed as criteria in the second module in order to construct a new image, whose edges must have a width of one pixel. In the third module, the false modules are determined by applying two thresholds (T1 and T2, T1 being less than T2) to the last image obtained. These values are derived from the intensity of the pixels, by which it is expected that the edges of objects in the image will be found. The intensities of the pixels that are greater than T2 form part of the edges of the binary image, as do the pixels whose intensities are greater than T1, and which also have at least one neighbor with intensity greater than T2. Figure 7 shows the binary image of Fig. 5a obtained with the Canny edge detector (to be compared with Fig. 5). www.intechopen.com

Histogram modification
Image enhancement using intensity distribution is now undertaken. To do this, a histogram equalization is proposed. The procedure used to conduct the histogram equalization is as follows. The histogram of an image is a discrete function defined as: where  Pg is the probability that a given gray value (intensity) occurs in the image, M is the total number of pixels in the image, and N(g) is the number of pixels with intensity g. Redistribution or transformation of intensities during the histogram equalization is expressed as (Shanmugavadivu & Balasubramanian, 2010): where ki V is the new intensity value for the i-th pixel in the equalized image, L is the number of gray levels in the image, S k i s t h e n u m b e r o f a c c u m u l a t e d p i x e l s w i t h a determined value of the i-th intensity, S k min is the smallest number of frequencies accumulated that are greater than zero, and S k max is the largest number of frequencies accumulated from pixels.
For detection of straight lines in the surface of a polished-finish cutting tool using the Hough transform, a binary image of the tool's surface must be obtained from the original grayscale image. To preserve the characteristics of the straight lines, the histogram equalization defined by Eq. (12) is used.
In the proposed framework, instead of predicting the values for the θ parameter in the , the binary image is processed with the Sobel mask, in order to find the direction of the straight lines and to determine the value of θ. Knowing the directions of the straight lines reduces the size of the accumulator. Also, the number of iterations in the SHT to straight-line segmentation is decreased, compared with previously published methods (Illingworth & Kittler, 1988;Leavers, 1993). Next, the pixels that retain the zero value in the binary image are selected. The selected points are processed with the SHT. The (θ,ρ) cell values with the largest number of intersections in the accumulator define the parameters that describe the number of straight lines on the tool's surface, as well as the width of each one. This allows for quantifying the straight lines on the machined surface. The width measurements of the straight lines on the tool's surface can be related to its quality.

Cutting tool
A cutting tool has two characteristics to be taken into account, the material and the geometry of the tool. The second characteristic may lead to defective machining due to www.intechopen.com gradual wear and even loss of the tool's shape by, for example, tearing at the radius of the nose, as shown in Fig. 8. This damage requires a reworking of the surface or possibly discardation of the piece. The damage can be avoided if the cutting tool is changed before a catastrophic failure of the edge or cutting edge happens. The images processed to assess the quality of the finish of the studied surfaces are obtained from a round bar of a 6061 T6 aluminum with a diameter of 38.1mm (1 ½ inches). This bar was machined by a process of hammering without coolant, utilizing a QNMG 432 TF cutting tool with a depth of cut at 0.5mm, a cutting speed of 300 mm/min, and a spindle speed of 700 RPM. The process was carried out on a CNC lathe, with a Model DMC 1820 Galil ® driver (Fig. 9). Fig. 9. CNC lathe use to produce the test cylinders.

Framework
The proposed stages to identify the straight line characteristics of the machined surface's finish by applying the SHT line segmentation procedure, is shown in Fig. 10

Image capture
The image acquisition of the surface of the pieces machined on the CNC lathe was carried out using a 16X optical microscope (LEICA, Model EZ4D with an integrated 3 megapixel digital camera), in BMP format. Pixel intensity was recorded in gray scale with an 8 bits-perpixel resolution.

Preprocessing
The preprocessing stage consists of two processes: histogram equalization and gradient angle computation. During the equalization of the histogram, the binary image of the surface is obtained. At the gradient angle computation stage, the θ information is obtained.

Binary image construction
This process begins with the computation of the frequency and cumulative histograms of the original grayscale image. To accomplish this, the process described in Fig. 11.
Upon obtaining the records in the cumulative histogram, the cells with the highest and lowest registrations other than zero are sought, assigning them values of S Kmax and S Kmin , respectively. The new intensity values are found from in the image pixels by evaluating each register of the table S K of Fig. 11 in eq. (12). Having established the new intensity values V k , the shift in intensity of each pixel is made as follows:  The intensity of the pixel is obtained.  This intensity points to the entry in the table of the V k s, whose value indicates the new intensity to be assigned to the pixel.
The binary image shown in Fig. 12 was obtained, using a threshold value of 128. The pixels with intensity values that are less than or equal to an established value are assigned a zero for its intensity value, while those pixels with an intensity greater than the threshold value are assigned a 255 magnitude value.

The gradient angle
To define the values of the θ angle, the information from the gradient is employed during the processing of the original grayscale image. In this chapter, the gradient information is used to obtain the angle of the edges having more frequency than in the binary image obtained.
Equation (7) describes the magnitude and gradient angle. These values are gathered using the Sobel mask on the binary image obtained by means of the histogram equalization of the original image, evaluating each point that does not form part of the background.
In Fig. 13a, the binary image is observed and in Fig. 13b, the edges are observed. Here, the pixels' intensity within the segment of the specified edge is taken as a reference for the angle gradient computation described below. With edges highlighted by the gradient magnitude, the following steps are undertaken to determine the angle magnitude, obtained by the process described as follows:  A table is constructed, consisting of a single column and 361 rows for each of the expected angles; that is, 0, 1, 2,…,360. Within these cells, the registration corresponding to the angle value is noted. Negative entries correspond to not-yet-evaluated angles.  The edge angle is estimated and registered taking only those points that comply with the condition that its value in the binary image is zero, and the magnitude of the gradient is other than zero.  In the algorithm, the angles registered are entered into a table, where the times that the angles are given are accumulated to obtain the global information of the edge direction.
Based on the angles registrations, the interval of the θ parameter of the Hough transform is determined. This interval is obtained from the cumulative frequency indicated in Fig. 14, in the range proposed (0, 1-45, 46-89, 90, 271-315, 316-359), which corresponds to all of the possible angle values of the gradient of the image in such a way that, in the interval where the greatest frequency is registered, the interval for θ is determined.
As an example, the result of this angle grouping scheme is shown in Fig. 14  The definition of all the angles of the detected edges is shown in To conclude, the preprocessing stage is conducted by filtering the points in the binary image with the gradient magnitude, decreasing the width of the straight lines due to the histogram equalization process. The filtering process is carried out as follows: only the pixels having a value of zero are selected. For each one of these pixels, its intensity in the table of gradient values is checked to ascertain that it is equal to or greater than 255. If this is the case, a value of 255 is assigned to the pixel. This way, we have a binary image with fewer points without affecting the straight lines of the surface finish during the filtering process. This helps to improve the performance of the Hough transform.

Characterization
The

Parameter interval definition
For the ρ parameter, the expected values are defined by the diagonal of the image obtained from the width a and height b values of the image by utilizing eq. (4). Values for the θ interval are obtained from the proposed stage in the angle gradient computation, whose processes are quantified from the angle frequencies observed in Fig. 14. In this registration, the highest value must be located in order to define the values to be assigned to the θ parameter. These values can be observed in the first row (indicated by the second column value), by which the θ parameter will take the zero value, as described in Table 1.

Accumulator construction and points' evaluation in the straight line normal equation
A With the binary image of the surface finish, the pixels that do not correspond to the background are evaluated using eq. (13), where the θ value is equal to zero (the value assigned in the definition stage of the parameters' interval). If the value of ρ is found within the interval defined, it is registered in the accumulator. Fig. 15 shows the registers in the accumulator that correspond to the binary image of Fig. 13b. The θ-ρ parameters are located in the x-y axis; in the z axis, the frequency of the points that are collinear are shown (those registering more than a single occurrence within the same cell of the accumulator). In this way, the straight lines of the surface finish are identified by the higher frequencies in the graphic. In the graphic of Fig. 15, only a single peak is observed; this describes the straight line observed in the surface finish of Fig. 12a. Fig. 15. Peak of the straight line in the surface finish of Fig. 12a. www.intechopen.com

Location of the maximum in the Hough space
The accumulator table is now explored in order to locate the cell or cells that have the highest registration. This is used to obtain the θ and ρ values, which allows for the positioning and orientation of the straight lines of the surface finish.
In Fig. 15, corresponding to the space frequency of the parameters, we can see only one point at the top. That point in the Hough transform represents the straight line that is observed in Fig. 16. The values shown in the θ-ρ figure of this cell describe the orientation and position thereof. Fig. 16. θ-ρ parameters illustrating maximum frequency.

Image acquisition
The captured image of the surface finish of a piece machined on a CNC lathe is presented in BMP format, with 640×480 pixels in gray scale with 8 bits per pixel. From this, a sub-image of 256×256 pixels was used to segment the straight lines of the surface finish. This image is used to segment the eight straight lines observed, which are characteristic of the surface finish of machined pieces using a sharp tool. The purpose of this stage is to achieve the construction of the binary image and to compare the obtained results with the algorithm based on the Sobel mask and the Canny edge detector.
Straight lines in the surface finish www.intechopen.com

Construction of the binary image
To build the binary image of the surface finish using the Sobel mask (see Fig. 18b) and the Canny algorithm (see Fig. 18c), it is observed that both images present fewer points to be processed, but both lose information. This is because the binary image constructed with the Sobel mask presents discontinuous straight lines of the surface finish, wherein none of these present continuity from the beginning to the end of the straight lines observed in the image of the surface finish (Fig. 18a). The image constructed with the Canny algorithm preserves the continuity in the majority of the straight lines, but they are seen to be distorted. The image constructed with the proposed method (Fig. 18d) does not lose information since all of the straight lines of the surface finish preserve their continuity and definition.

The θ y ρ parameters interval definition
The method to obtain the orientation description of the edges is applied on the binary images constructed with the gradient by applying the Sobel mask and the Canny algorithm.
The tables with the computed angle frequencies are presented in Fig. 19. Here one can see that the tables of the frequencies that describe the straight line orientation of the surface www.intechopen.com finish, starting from the interval with the greatest frequency are the binary images constructed with the Sobel mask and the proposed equalization method. Therefore, the θ parameter can be defined in both images using only one value.
On the contrary, the binary image constructed with the Canny algorithm does not permit the description of straight line orientation with the information from the gradient angle, because the interval presenting the highest frequency corresponds to the orientations in the interval [0,45]. For this reason, the θ parameter must be defined in the interval indicated to make the correct segmentation of the straight lines observed on the surface finish. 22      , which has been reduced by applying the proposed method of grouping frequencies in the edges' orientation on the intervals utilizing the information obtained from the gradient angle. Since the angle identification of the predominant edges corresponds to zero, the straight lines to be segmented are perpendicular. Therefore, the magnitude of the radius vector is found in the width dimensions of the image. From this conclusion, the values expected for the ρ parameter are reduced to 82%.

Processed points in the equalized image
The image constructed using the proposed equalization method renders a greater percentage of points than the 50% found in the original image. This value is reduced by eliminating the isolated points, while the distance is increased between the straight line edge segments that are not part of the straight lines on the surface finish. The aim of this is to Equalization www.intechopen.com reduce false segmentations due to points that are collinear, but that are not necessarily part of straight lines on the surface finish.
In Fig. 20b, a fragment of the binary image constructed is shown. In this image, a couple of isolated points can be observed, as well as a fragment of the straight edge that does not form part of the actual straight lines on the finish. The intensities of these pixels and the magnitude of the gradient are shown in the tables presented in Fig. 20c and Fig. 20d, respectively. An example worthy of consideration is the point located in Column 217, Row 102. Its intensity value is equal to zero, but the magnitude of the gradient is other than zero, so the pixels are considered to be part of the background image, changing its intensity to 255, as can be seen in Fig. 20e. Accordingly, this point is not seen in the image fragment shown in Fig. 20f. This criterion is applied to all of the pixels in the image and a new image is constructed, as shown in Fig. 20g, which contains 48% of the points in the original image.
Once the point-filtering process is applied, we can see, in Fig. 20g, how isolated points are eliminated and the distances are incremented between segments of the edges that do not belong to the straight lines on the surface finish, without affecting the definition and continuity of them. The accumulator tables of the binary images constructed are shown in Fig. 21. Here we can observe that, for the binary image constructed with the Sobel mask and the proposed method of equalization, the gradient information can be employed. This decreases the accumulator dimensions by 99% with respect to the accumulator constructed for the binary image formed by the Canny algorithm. The Canny accumulator also does not allow for defining the orientations of the straight lines of the surface finish by the frequency of the angles obtained. Fig. 21. Accumulator dimensions for the binary images constructed. Fig. 22 presents the registration in the accumulator of the images constructed in order to filter the points with the proposed algorithm employing the gradient magnitude and the pixels' intensity from the binary images. This decreases the number of iterations through the reduction of the number of processed points. Note that the greatest percentage in the reduction of iterations in the constructed image, with respect to iterations realized in the images without filtering, is with the Sobel mask (70%), followed by the Canny algorithm (29%), and finally the creation of the image by means of the equalization algorithm (18%). In addition to reducing the iterations in the processing of binary images filtered with the Hough transform, the filtering process provides the reduction of collinear points that are not necessarily part of a continuous straight line. This factor is reflected in the location stage of the maximum in the parameters space, as described below.

Evaluation of points into the equation of the straight line and its accumulator registration
The time employed to process the image of the surface finish by means of the algorithm developed in Mathcad version 14 (on a computer with a 1.66 GHz processor and 1GB RAM, running Windows XP) was 15.23 s. without point filtering and 9.17 s. with point filtering. This processing time was spent to obtain the segmented straight lines on the surface finish image observed in Fig. 22. Accumulator

Maximum frequencies location in the parameters space
In Fig. 23, the maximum-frequency points located in the accumulators are shown. One can notice that for the points of the binary images constructed with the Sobel mask, the maximum value is 244, while for the Canny algorithm the value is 176; presenting a singular point in the upper part of their respective graphics. Although the values of the cells describe the parameters within the expected values, they offer only the parameters of one of the eight straight lines in the image. The threshold value can be decreased to obtain the parameters of more straight lines. This would implicate an additional process to define an optimum threshold value. On the contrary, with the method proposed here to obtain the image and accumulator, the maximum frequency value is high enough to allow for the segmentation The discontinuity observed in the segmented straight line widths in the binary image obtained by means of the equalization method is due to the surface finish dimension not being constant along each one of the straight lines' widths. This characteristic can be observed in the parameters space of the Hough transform. These values are presented in groups in Fig. 24, where the straight line describes the obtained parameters.  Is important to underline that the intervals quantity in which the cells are grouped with the highest frequency correspond to the number of straight lines in the images. The information for each one of them is obtained from the parameters space, using the maximum frequency taken from the accumulator.

Conclusion
By equalizing the histogram of the surface finish image, a binary image is constructed without losing the characteristics of the straight lines in the image.
The proposed method defines the θ and ρ parameters and the selection of the pixels to be processed. Gradient-information processing reduces the number of iterations in the standard Hough transform.
With the proposed method, the necessary data can be determined to describe the length, width, and straight line numbers of the surface finish from the corresponding parameter values of the cells having the highest frequency in the accumulator table of the Hough transform without an additional algorithm being needed.
The number of pixels to be processed is directly related to the number of iterations used to segment the lines with the standard Hough transform. Therefore, larger images require a higher number of iterations, increasing the processing time for the segmentation of straight lines on machined surfaces.