Detecting shape defects in ferrite cores Dmitry Chetverikov and Judit Verestoy Computer and Automation Research Institute Budapest, Kende u.13-17, H-1111 Hungary mitya@leader.ipan.sztaki.hu Abstract In the framework of a European technological research project [2], a general method is presented for shape measurement and defect detection of industrially produced objects using the characteristic 2D projections of the objects. The method is applied to the visual inspection and dimensional measurement of ferrite cores. An optical shape gauge system is described, based on rotation-invariant shape matching. A novel shape representation is introduced that facilitates the invariant matching. Special attention is paid to nding the optimal reference position and orientation (pose) of the measured shape for invariant comparison to the reference shape. This problem arises because shape defects may deteriorate any of the dimensions. 1 Introduction The study presented in this paper covers a part of the COPERNICUS technological research project CIPA-CT94 0153 CRASH (for CRAck and SHape defect detection in ferrite cores) which has been in progress since 1995 [2]. The aim of the project is to develop a non-contact system for automated quality inspection of industrially produced objects, in particular ferrite cores. Ferrite cores are used, among others, in measuring systems, and their quality is essential for assuring the required precision. The system being developed should be able to detect dimensional, surface and inner (sub-surface) defects which can greatly a ect the quality of the cores, and to classify di erent ferrite cores assigning a grade to each one depending on the quality. The project serves as a contribution to the standards of IEC (International Electrotechnical Commission) for quality assessment of ferrite cores and to the standardisation schemata of the quality system ISO 9000 IEC-Q. Producers expect an increase of reliability by decreasing the classi cation error rate by 50% with respect to the currently used manual quality control. The main defects to be detected and measured are surface and sub-surface cracks, roughness of the surfaces, shape defects such as missing parts, chips, bending, de ection or dimension inconsistencies. In order to detect these defects the project partners use two types of sensors: optical sensors and electromagnetic (EM) sensors. The optical system is suitable for the detection of the shape defects and for the classi cation of the ferrite cores. Special illumination helps in detection of surface roughness and surface cracks as well. The sub-surface defects can only be detected using an EM sensor. This paper describes the methods developed and used for detection, measurement and classi cation of shape defects in ferrite cores. The current practice to control the core production is to select sample cores and measure their dimensions with a mechanical gauge that either accepts or rejects the core. Also, the distributions of the dimensional measurements are obtained to monitor the production parameters. The standard and the acceptable values of the dimensions refer to the basic views (projections) of the objects: the lateral, the upper and the transversal. These basic views are assumed to be sucient for shape inspection. To comply with this practice, an optical shape gauge system was developed in order to quickly reject the obviously defective cores and then measure the less obvious but still critical dimensional deviations from the standard values speci ed by the producer. These standard values and the allowable deviations are represented by two images, the reference image and the tolerance image. Both are generated based on the speci cation of the core and compared to the shape being measured. An important feature of the shape gauge system is its capability to handle arbitrarily oriented projections of the 3D objects. We assume that a core will be inspected in any of its stable positions at arbitrary orientation. Therefore, the comparison of the measured and the reference shape should be shift and rotation invariant. To = Appeared in: Proc. 10th Scandinavian Conference on Image Analysis, Lappeenranta, Finland, 1997, pp.731-737. determine the orientation of an arbitrary shape, a rotation-invariant shape matching procedure was used. A novel shape representation, the polar run-length code (PRLC), was introduced that is particularly suitable for this purpose. A speci c problem arises when one tries to nd the optimal reference pose of the measured shape for comparison to the reference shape. There is no obvious, `natural' solution as shape defects may a ect any of the dimensions. Consequently, no reference baseline can be speci ed. We propose a solution based on a hierarchy of criteria that may be of interest for invariant shape gauging in general. The task of ferrite core shape measurement and dimensional defect detection is introduced in section 2. The problem of the invariant comparison of a reference and a test shape for shape gauging is discussed in section 3. The polar run-length coding of a 2D shape is proposed in section 4 where the PRLC based shape matching procedure is also described. Section 5 presents the main steps of the shape analysis procedure. Finally, the conclusions are drawn. 2 Shape measurement of ferrite cores Figure 1 shows three views of an E-core. A great variety of cores, both in shape and size, is being produced rendering the task of automatic visual measurement quite dicult, at least if a universal tool is expected to be developed. Additionally, there are no internationally accepted standards that would regulate the quality of ferrite cores as far as their shape defects are concerned. In our current study we rely on the initial recommendations that refer to the basic views of the so called E-shaped core, or E-core, whose sample is demonstrated in gure 1. This speci c core type was selected because of its relative complexity and relevance to core production by one of the project partners. The standard dimensions as well as the tolerance limits were speci ed by this partner. The company also provided a set of sample E-cores necessary for the initial testing of the algorithms developed. Figure 1: Three views of an E-core. The task of ferrite core shape measurement and defect detection is formulated as follows. Given a particular E-core with the speci ed dimensions and allowable deviations, consider each of the basic views of the core. This results in 2D shapes whose dimensions should be measured, gauged and classi ed. The scale of the images, i.e. its resolution in millimeters, is given. The pose of the shape is arbitrary. Only a single shape is present in the image. For geometrical correction of the image, four reference points forming a reference rectangle are shown in the corners. Under these conditions, the system should: (a) reject the core if the overall deviation from any of the reference shapes is above a threshold; (b) measure the dimensions of the core; (c) detect and measure selected types of shape defect; (d) keep track of the major statistics for production control. The overall check and rejection are necessary because one can readily discard the de nitely defective cores for which measuring the individual deviations makes no sense as these deviations either fall beyond the measurement range or cannot be de ned at all. 3 Invariant shape comparison for shape gauging The operation of the shape gauge system is based on the comparison of a test shape to a reference shape generated from the standard dimensions. To compare a test shape to a reference shape for arbitrary pose one needs a shiftand rotation-invariant matching procedure whose aim is to normalise the pose of the shape. This should be done under a proper optimisation criterion since the two shapes may di er in both large and small details. 2 At the rst glance, the comparison criterion seems to be straightforward. The two shapes should be superimposed so that the defective segments of the test shape di er from, while the `good' segments coincide with the corresponding segments of the reference shape. This means, however, that the defects should be recognised prior to the comparison that itself aims at defect recognition. The solution proposed in this study is based on the feedback between shape comparison and defect detection. This feedback allows for a gradual correction of the reference pose starting from an initial guess and using a hierarchy of matching criteria. To obtain the initial reference pose, several options for shape di erence measures were considered. Finally, we have selected as the initial matching criterion the largest area overlap of the two shapes. Any local feature based criterion, e.g. the coincidence of the baselines of the shapes, would be neither universal nor stable, as defects may signi cantly distort that particular local feature. The initial matching criterion would require optimisation with three parameters (the two coordinates of the centroid and the rotation angle) which is not feasible in practice. As the centroid is less sensitive to local defects, we can normalise the position by superimposing the centroids of the two shapes. This solution is often used in the industrial machine vision practice. (See e.g. [3].) When a large defect occurs in the test shape, the shift of its centroid results in a greater deviation from the reference shape. This is acceptable since in this case the goal is to detect the overall deviation and reject the test core as completely wrong. In the case of smaller defects that do not result in the overall rejection, the initial pose is corrected for more precise measurement of individual defects. The correction procedure is presented in section 5. 4 The polar run-length code and rotation-invariant shape matching Once the optimisation criterion for nding the initial reference pose has been de ned, one needs an accurate shape representation that facilitates the matching procedure. The angular precision of matching must be high since this precision sets the accuracy limits of the whole gauging system because the correction of the initial pose is timeconsuming and limited in both position and orientation. Di erent classes of representations have been developed to date (e.g. [3]). Several rotation invariant shape matching algorithms are described in [1], including those that can signi cantly speed up the matching by using a multiresolution shape representation. The traditional shape representations considered as candidates for precise core shape matching were discarded as either computationally demanding, or only applicable to limited classes of shapes, or less ecient at ne angular resolutions. For example, the traditional radial (polar) representation, i.e. radius as a function of angle, can only be applied to star-shaped objects, while many non-radial contour representations face the problem of non-uniform angular sampling. We have designed and implemented a simple shape representation, the polar run-length code (PRLC), which is suitable for precise rotation-invariant matching. The PRLC is similar to the conventional run-length code (RLC), in the sense that it is also formed by the parameters of the runs measured across the binary image of the shape. Each run is represented by the starting point and the length. The main di erence between the RLC and the PRLC is that, instead of the conventional line-by-line scans, the shape is scanned radially, with a given angular resolution. The initial point of the radial scans in the centroid. The PRLC is a lossy coding, as the shape can only partially be reconstructed from the code. The precision of the reconstruction increases with the angular resolution. Figure 2 illustrates the amount of information contained in PRLC, depending on the angular resolution. A major advantage of the PRLC is that it is well-suited for shape rotation around the centroid since this rotation amounts to the rotational shift of the code. Its usage is not limited to star-shaped objects. Another advantage is that the overlap area is easily computed from the PRLC as the sum of the run overlaps. The PRLC based matching procedure nds the rotation angle that minimises the symmetric area di erence of the two shapes which is equivalent to nding the maximum overlap. An alternative option is the use of the major axis of the test shape [3]. This option is not as general as the matching solution, but it is faster and may have higher precision as the angle is not quantised. 5 The core shape analysis The steps of the core shape analysis are given below. The key steps are described later in more detail. 3 (a) (b) (c) Figure 2: Shape reconstruction from the PRLC: (a) original image; (b) reconstructed image, angular resolution 2 degrees; (c) reconstructed image, angular resolution 0.5 degrees. 5.1 The structure of the method (1) Acquire the initial grayscale image, apply the geometrical correction, then binarise the resulting image to obtain the test shape image TEST. (2) From the speci ed core dimensions and their tolerances, generate two properly scaled images: the reference shape image REF and the tolerance image TOL. (3) Compute the PRLC codes of the reference and the test shapes and rotationally shift the PRLC of the test shape to nd the angle that minimises the symmetric di erence between the reference shape and the rotated test shape. (4) Superimposing the centroids of reference and test shapes, rotate the test shape around the centroid by the rotation angle found in the previous step. The result is the normalised test shape NORM. (5) Compute the di erence image DIFF as the symmetric di erence of REF and NORM. (6) Compute the deviation image DEV as the di erence between the DIFF and TOL. (7) Measure the DEV area. Reject the core if the DEV area is greater than a preset overall threshold. (8) Divide the DIFF image into zones using edge boxes assigned to the edges of the shape. Correct the initial reference pose of the test shape and nd the nal pose. (9) For the nal pose, evaluate the zones and compute the dimensions and the shape features speci ed. 5.2 Description of the key procedures In this section we describe in more details the main algorithms of the core shape analysis system. 5.2.1 Obtaining the TEST image Images taken by a camera may su er geometrical distorsions arising from several factors such as non-orthogonality of the camera axis to the core support plane, non-square pixels and nonlinearities of camera optics. The geometrical correction procedure used is based on the reference measurement of four points in the plane. (See [3].) This warping algorithm maps four reference points onto the corners of the image. The four points are the centroids of four small circular markers placed in the corners of the view eld. The test shape image is obtained by binarising the geometrically corrected grayscale image. The well-known thresholding algorithm by Otsu (e.g. [3]) is applied. 5.2.2 Generating the REF and the TOL images The reference image and the tolerance image are generated using the scaled standard dimensions and tolerance values of the E-core. The tolerance image shows the tolerance area. The di erence between the normalised test shape and the reference shape is acceptable when this di erence is entirely within the tolerance area. Figure 3 exempli es REF and TOL images. The scaling factor converting the length from millimeters to pixels depends on the camera magni cation and is speci ed by the operator. The program that generates the REF and the TOL images requires as the input the lengths (in mm-s) of those critical E-core dimensions that completely de ne the core. The positive and the negative tolerances of these parameters are given separately as the tolerances are not symmetric. During the binary image generation, the pixel coordinates obtained are rounded to the nearest integer. This is one of the factors that may in uence the precision of the method under insucient resolution. 4 Figure 3: A reference shape and a tolerance image. 5.2.3 Measuring the di erences The di erence image DIFF contains those points which appear either in the NORM image or, exclusively, in the REF image: = . The deviation image DEV consists of those pixels which appear in the di erence image but do not appear in the tolerance image: = n . Figure 4 shows examples of DIFF and DEV images. DI F F N ORM RE F DE V DI F F T OL Figure 4: Measuring a defective core: the normalised test shape, the di erence image and the deviation image. The DEV image is used to determine whether the core has intolerable shape defects. The overall deviation is the number of pixels in the DEV image. A threshold is set for the overall deviation to reject completely defective shapes. 5.2.4 Correcting the initial reference pose The di erence image is covered by edge boxes, i.e. divided into characteristic zones that are analysed separately. The edge boxes are used to correct the initial reference pose and to measure the characteristic dimensions and defects. Figure 5 illustrates the necessity to correct the initial reference pose. The centroid of a defective shape is shifted compared to the position needed for proper comparison. The test shape is rotated with respect to the desired position. Di erences are measured in all dimensions although the real defects are only located on the upper (mating) surface. (a) (b) (c) (d) Figure 5: In uence of shape defects on the reference pose. (a) The ideal shape and its centroid. (b) The defective shape and its centroid. (c) The desired reference pose. (d) The reference pose obtained using the maximum area overlap criterion. The initial reference pose is re ned by rst slightly varying the orientation, then the position. The following hierarchy of matching criteria is used to correct the initial5 pose: (1) The cumulative angular deviation between the measured and the ideal edges is minimised. The actual edges are approximated by the least square method and the angular di erences between the corresponding actual and ideal edges are accumulated. The least cumulative angular deviation, i.e. the most parallel alignment gives the best reference orientation. This eliminates the e ect of defect interference because of biased orientation. Figure 6 shows an example of the initial and the corrected orientation. (2) For the best reference orientation, the centroid position is perturbed to minimise the cumulative intolerable deviation. Figure 7 illustrates the application of the minimum deviation criterion. (a) (b) Figure 6: Correcting the reference orientation. (a) The initial di erence image obtained using the maximum area overlap criterion. (b) The corrected di erence image obtained with the criterion of parallelism. (a) (b) (c) Figure 7: Correcting the reference position using the minimum deviation criterion. The intolerable deviations are shown in dark. (a) The original position obtained after the area-based matching and the angular correction. (b) Shifting the centroid to the relative position (1 1) yields a zero intolerable deviation. (c) An alternative shift (?1 ?1) leading to a larger deviation. ; ; 5.2.5 Measuring shape dimensions and features Once the test shape has been matched, the edge pieces appearing in the edge boxes are used for precise measurement of shape dimensions and features. The critical dimensions of an E-core are shown in gure 8. As the positions of the boxes are known, after the least squares approximation the de nitions and the measurements are straightforward. Figure 8 also exempli es one of the typical shape features introduced to measure a characteristic defect due to the curvature of the baseline. In this case, the height is measured for the three baseline points shown and the concavity is de ned as ( l + r ) 2 ? c . h h h = h 6 Conclusion Measurements have been made using 24 sample cores from the test core set provided by the core producer. Four of them were labelled as defective with di erent degrees of intolerable deviations, the other 20 cores were acceptable. Three of the defective cores were correctly rejected as having global defects, while the fourth one was rejected after measuring the critical dimensions. The acceptable cores passed the test. 6 A C h D h2 h1 hl (a) hc ∆ hr (b) Figure 8: Measuring shape dimensions and features. (a) The critical dimensions of E-core being measured. (b) The baseline concavity feature. In addition, 50 E-cores of another size were measured to obtain the statistics of selected shape features such as skewness of the mating surface, de ection of legs and curvature of the baseline. The statistics obtained were in good correspondence with the distributions of the manually measured values. The shape gauge system is able to detect the required defects provided the conditions speci ed for its operation are met. The following factors may decrease the precision of the optical shape gauge: (1) inaccuracies in the reference rotation angle, as the di erence image is sensitive to orientation; (2) binarisation of gray-scale images, since the edges of the shapes may become less precise; (3) using discrete rather than real co-ordinates while generating the REF and the TOL images and superimposing the centroids of the reference and the test shapes. We are currently considering several possibilities to improve the accuracy of the system. Modi cations may be necessary to apply the program to other types of cores. For example, in the case of circular-shaped cores the most parallel alignment of a test and a reference shape can be de ned using edge orientations obtained with an edge detector. The main features of the system, however, are believed to be universal enough to deal with a variety of ferrite cores of di erent shapes and sizes. Acknowledgments This work is supported by the EU COPERNICUS grant CIPA-CT94 0153. References [1] D. Chetverikov. A multiresolution algorithm for rotation-invariant matching of planar shapes. Pattern Recognition Letters, Vol. 13, 1992, pp. 669{676. [2] The CRASH Consortium. CIPA-CT94 0153 CRASH Project. Technical report, EU COPERNICUS Programme, Brussels, 1997. [3] R. M. Haralick and L. G. Shapiro. Computer and Robot Vision, volumes I|II. Addison-Wesley, 1992|1993. 7