METHODS FOR DETECTION ANALYSIS IN QUALITY CONTROL SYSTEM

The article contains a description of the quality control system based on optical detection algorithms. It plays an increasingly important in the production process. The development of new systems based on the technology of optical detection methods to a large degree can improve the production process at different stages.


Introduction
Analysis of the data may be used for a process optimization in different ways and it can affect many aspects of a process management. We can detect disturbances in the process, find the causes affecting problems with a quality, and choose optimal settings for the process, comparing different preparation procedures and many others [1,[4][5][6][7][8][9]. The presented application of a image processing concern two problems. Bottle caps and rectangular dark objects were used. Caps are cheap, easy to access and are available in various colours. The rectangle is a shape often found in products as well as squares, circles and ellipse and can be qualified and measured in similar way. In the testing setting there is a camera located over the conveyor belt. Axis of the camera view is perpendicular to the plane of the belt. The speed of the belt was about 16.5 cm per second.
First part of the paper is about detecting caps and determined their orientations. To detected objects set of pictures with an empty scene were used to define common colours of the background. To determine orientation of a cap the algorithm uses the Canny edge segmentation and the image is processed using the discrete convolution trying to match the cap oval pattern to the best extent -this is how the outer cap oval is located and then the interior of the oval is analysed.
Next part is about detecting and measuring rectangular dark objects. Two methods were presented to track the object location. The type of the method is determined by modality of a scene histogram. Whereas to measure the object rotate and translation invariant geometrical moments where used.
The main goal of the research was to find fast segmentation (in the real time) methods due to the requirements of the production processes.

Brightness regularization
Due to a lightening condition in the working space before an analysis of the scene there was applied a regularization of a brightness across the frame. Because the irregularity had stationary character i.e. it does not change over time, used method was based on the least square fitting of a plane to the brightness of the referential image of the empty conveyor belt treated as points in the three dimensional Euclidean space and next subtracting this plane from analysed scenes. The Fig. 1 shows a visualisation of the mentioned irregularity as a tilt in the brightness of the empty belt scene treated as a three dimensional surface, and the Fig. 2 presents the same scene after the regularisation. Removing of the tilt improve significantly global thresholding methods robustness without any additional computational expensive operations.

Fast localisation of objects on the scene
In optical algorithms we often make an assumption that there is at most one object to analyse on the scene. To ensure that assumption in general conditions we have to split the initial scene, which can contain more than one object, to subscenes where the assumption is fulfilled. Thus we require the segmentation method that can be very inaccurate but has to be fast in splitting the scene, for that task we adapted the Code Book algorithm [2] changing the colour space from RGB to HSV. Because HSV has separated channels for the saturation and the brightness therefore the hue (H channel) is quite resist to lightening conditions and is essential for colours distinguishing. Thus change of the colour space allow to use the absolute value of differences between pixels to distinguish colours and is computationally cheaper than the Euclidean norm. The further most important change concerned the number of analysed pixels. Instead of checking all points on the frame we select just a grid with a distance of thirty pixels between checking points, and about fifteen pixels from edge of the picture to ensure that the grid is centred on the scene. The general purpose of the experiment was to determine how much information we can remove from the original scene and still be able to locate objects on the picture to split the whole image for sub-images containing only one object. The minimum number of points in the grid can be determined in two ways. First of all the minimum number of checking points is bounded by the degradation of entropy of the scene. Graph 4 show the curve of entropy of the scene after reducing it by taking every second pixel from original image (first point on graph) or previously reduced image (for rest of the points ). We can see that after fifth point on the graph (where fifth point corresponds to taking every thirty-two pixel of the original image) the entropy decreases drastically due to degeneration of information on the scene. The second way of determination of the number of checking point correspond to the Nyquist-Shannon sampling theoremradius of caps was about 65 pixels, so the 30 pixels space between checking points met the minimum value of samples (at least two checking point match a cap if it appear on scene) needed to restore the information about location of a cap. It is worth to notice that this is also the theoretical boundary for the spaces between objects, smaller gaps cause that separated objects are detected as one. Due to introduced changes, developed algorithm generate location marks map at the speed of about 1500 frames per second which meets our requirements for execution time. Fig. 3 shows example scene with the grid of analysed points. Location markers plot on the right show which points of the grid were recognized as a foreground. Based on that markers the rectangular sub-scenes with exactly one object are extracted and are shown on the bottom of the Fig. 3. Figure 4 presents the entropy degradation in the reduced scene. Using the method for splitting the scene for the sub-scenes we create an application to define which side of a cap laying on the conveyor belt is visible.
Algorithm take sub-scene and (using the two-dimensional convolution) search for an oval of a cap on a scene of edges segmented by the Canny detector. Next the space inside the founded oval is analysed: if the number of pixels inside the oval do not exceed the fixed threshold then its mean that a cap is thread down. If the threshold is exceeded then it is mean that a cap is thread up. Figure 5 shows an example result of a sub-scene processing. In the upper left there are edges obtained by Canny detector and marked rectangle points place of the strongest response to the searched oval. In upper right there is shown the shape of oval mask. Bottom left presents extracted interior of the oval and the bottom right shows original image. The header REVERSED mean that a cap was recognised as thread up. Tested effectiveness of method was 94% (From 500 tested caps 19 was classified wrong as reversed and one was wrong classified as not reversed).

Segmentation of dark objects and measurements of dimensions based on rotate invariant geometrical moments
The next algorithm that we develop can be used to black object segmentation and also assuming that it has a shape of the rectangle the application measures dimensions of that object. For testing we used rectangular black phantoms printed by a 3D printer (in the case of bimodal histogram) and phantoms made of a black rubber (in the uni-modal case).

The case of bimodal histogram
If the histogram of the scene is bimodal then for the segmentation process we can use two global thresholds. The lower one is fixed on some small value to separate far too dark objects. The higher threshold is variable and it is adapting to the position of local maximum of the histogram of analysed scene that correspond to the mode of the searching object. To determine the value of that threshold we use a histogram of referential image of empty conveyor belt and the higher threshold is defined as (1) where H i and H ref are smoothed histograms of the current scene and the referential image respectively, α is a fixed scalar bigger than 1 where a typical value is in the interval [1.5;2.1], S c (X) is a cumulative sum of the vector X.
Comparison of thresholding methods are shown in the Fig. 6. There are three different scenes binarized by: the Otsu's algorithm (first column), the iterative algorithm proposed by Gonzalez and Woods [3] (second column) and presented method before any additional filtering (last column of the figure). To remove noises after initial thresholding (middle plot of the Fig. 7) we scale down the binary mask (with the scale factor 2) and then we use standard morphological operation like opening (for further noise reduction ) and closing (to obtain more convex shape on the mask). Bottom plot of the Fig. 7 shows the final mask, a boundary of a founded object is marked by the green line in the original grey-scale image in the top plot of the Fig. 7. When the segmentation process is complete we treated the founded shape as a set of points on the two dimensional plane and compute second order geometrical moments invariant to translations and rotations and base of that moment we can determine the dimensions of the object assuming that it is approximately rectangleshaped according to the equations (2) for a < b. Where ϕ 1 and ϕ 2 are rotate and translation invariant moments [3] of a segmented shape and a parameter k is a scalar depending on the measured shapes. For rectangles but for example for ellipses .

Segmentation in a case of uni-modal histogram
The method presented in the previous section is not suitable for the situation when the histogram of the analysed scene is unimodal. In that case we cannot use the global thresholding even the adaptive one and we have to use some methods of local segmentation. In our method we computed morphological gradient of the image and applied median filter. After filtering we used the watershed segmentation (Matlab 2015b implementation of Meyer algorithm). Due to the shape of the segmented object we could scale down the picture with the factor of 5 without degradation of the entropy and process far less pixels which speed up watersheding and decrease the number of regions to inspect, moreover after downscaling distribution of the regions are more consistent due to degradation of gaps between belt plates to boundaries of regions. For segmentation the regions we use just a fixed threshold for the mean brightness within the region. After thresholding we scale up the mask back to the original size of the picture obtaining the fine approximation of the minimal region containing the searched object. Example of result is shown in the Fig. 8. Upper image is a visualisation of watershed segmentation, segmented regions are shown in the bottom part and in the middle there is the original scene, marked green line is the boundary of merged (by morphological closure) regions from the bottom mask rescaled to the original resolution, red line is the same region boundary but with the additional padding. Founded boundaries can be next used for example as the initial contour for the level set method if the accuracy of the segmentation is more desired than its speed.

Conclusion
Presented algorithm and methods show that the problems of detection and localisation of objects on the production line can be solved with the relatively easy way and according to that simplicity the systems of optical detection can be cheap and very fast. Another noticeable fact is that we can perform some mathematical operations to the scene to improve quality of detection without modifying conditions of the production environment. Used methods show also the advantages of applying reductions to the analysed frames for relevant acceleration of computations without decreasing the quality of detection results.