Research and Implementation of Signature Detection Based on Matching Algorithm

Errors such as wrong signature or upside down signature occur mostly during gathering in a bookbinding production line, and affect the quality of bookbinding. This paper presents a new algorithm for signature detection to detect these errors rapidly and accurately. The algorithm constructs scale space firstly by making use of pyramid method in morphology, then creates a region of interest by selecting a appropriate Pyramid image, extracts features from regions of interest, and make them matching templates, furthermore, filters the sample image and extracts the contour, finally selects the appropriate similarity coefficient for template matching, and obtain the matching results. This algorithm is implemented with MVtec Haclon software. Experiments show that the algorithm can anti-rotation, has strong robustness. The matching accuracy is 100%, meanwhile, the low time consumption of the algorithm can meet the demand of high-speed production.


Introduction
In recent years, the development trends in packaging and printing industry are providing variety of printed media as well as higher printing and binding quality. At the same time, customers' requirements for high quality printed matter increase. So, issues of quality inspection have drawn more and more attention from printing enterprises [1]. In the binding process of books, collating signatures are detected to improve binding quality by preventing errors such as wrong signatures, upside down signatures, double signatures and missing signatures.
At present most of collating machines are equipped with a detection device for detecting double signatures and missing signatures, but no good detection methods for detecting wrong signatures and upside down signatures. There are some collating machines which detect wrong signatures and upside down signatures by using machine vision technology for image recognition, but due to the position of the signature changes during the collating process, the accuracy rate of detection is relatively low. The way to improve accuracy rate of detection is to increase the amount of image data, which will increase the complexity of the detection algorithms, and the time required for detection also increases greatly. So, when the bookbinding production line runs at high speed, missed detection may occur, and quality control can't achieve.
A solution of image matching based on Halcon operator is proposed in this paper, which can solve the problems of low accuracy rate of detection and large number of time for detection.

Algorithm overview
The algorithm is implemented by using the Haclon operator. The algorithm consists of the extraction of sensitive regions (ROI, region of interest), Image preprocessing, extraction of contour points, template matching and affine transformation. This algorithm has the advantages of short running time, accurate matching and strong robustness. The basic flow of the algorithm is shown in figure 1. First, This algorithm first extracts a ROI from the template image, and the ROI and the sample image are preprocessed ,this can make the match faster, and then in the pre-processed ROI contour feature extraction as a template, and finally in the sample image search template to match.

The creation of ROI
The creation of ROI is the basis of image matching. To ensure the accuracy of template matching, the ROI region should contain the unique feature of the signatures, for example the size of the font, the font, the arrangement, the shape in the ROI different from other regions. The creation of ROI includes ROI extraction and ROI preprocessing. ROI area size is set to 100 * 100 pixels, the scale space is two layers.

Template extraction
The first step of the image matching algorithm based on local feature is to extract the unique feature set from the template image, which includes the extraction of the feature points and the extraction of the feature regions within the adjacent area of the feature points. First you have to open a custom size template image window, then use the reduce domain operator to set an ROI ,marked with a gray rectangle, as shown in Figure 2; this experiment to create the region of interest in the arrangement, font, and font size to ensure its uniqueness.

Fig.2 sets the template area of interest
In order to facilitate the subsequent construction of the scale space of ROI and the extraction of ROI contours, it is necessary to binarize the template image [2], and the mathematical model of binarization, the mathematical model of binarization is shown in formula(1).

Construction of ROI Scale Space
The core of the scale space is to extract the scale space of the different scales by repeating the scale transformation of the ROI image several times [3], and then extract the main contours in these scale spaces. The extracted main contour is the feature vector, Through the detection of edges and corners, That only Gauss can produce nuclear multi-scale space nuclear [4]under the present theory , people use x, y, σ represents an image scale space L, the mathematical expression is that the sample image I (x, y) is convolution with a two-dimensional Gauss function G (x, y, σ) that can be changed by a scale. Formula see formula (2); Among them, the Gauss function is shown in formula (3); The upper type (x, y) represents the position of a pixel in the original image, andσis the scale space factor, and its value mainly affects the smoothness of the image.
Gauss Pyramid's application is to reduce the image resolution, and thus reduce the matching time, one image of Pyramid is a collection of progressively reduced resolutions arranged in Pyramid. The aim is to directly select one of the images in order to improve the overall efficiency. The steps are as follows: (1) smoothing the image; (2) sampling the image. After the drop sampling, the Gauss filter is added to reflect the scale continuity.

Template contour extraction
In the multi-scale space constructed by ROI, according to the precision and time overhead needs to choose a layer of image multi-scale space as the processing object, and then return to the XLD (eXtended Line Descriptions) profile, and are normalized to match with sample pictures of more accurate and rapid.
The extraction of the XLD contour first uses the least squares method to fit the contour points set at the pixel level to f (x) [5], so that the minimum variance of the point set (x i , y i ) is minimum, and the mathematical model ; In the case that the mean square error between the guaranteed contour sets (X i , Y i ) is minimum, the function f (x) is determined Coefficient term. If there is a curve f(x)=c 0 +c 1 x+c 2 x 2 , Suppose the number of the contour points is m, and the coefficients of the function are n, At m≥n, Solvable equations BC=Y; The coefficients of the fitting function can be obtained by solving the equations, thus the minimum error XLD contour curve you are obtained in the sub-pixel.
The processed contour template ModelContours is shown in Figure 3.

Template matching
The template matching is divided into searching and matching template, first select a suitable search strategy to match a set of templates in the internal storage, The template is then affine transformed to (2) (3) compare with the standard template. If the standard template is found in the sample picture, the match is considered successful.

Selection of search strategy
Based on the Pyramid image, you can use the hierarchical search strategy [6] as described below. First of all, the appropriate number of gold towers is calculated for sample images and template images. Then, make a global match on the top floor of Pyramid. Of course, a proper termination criterion can also be added here. Because each layer of the Pyramid image is added, the image, pixel, and template pixels are reduced by 4 times. That is, each additional layer of Pyramid can speed up 16 times. So, if you perform a global match on the fourth floor in Pyramid, the number of calculations is reduced by 4096 times as compared with the original image.The basic steps of this process are: 1. first you should calculate the appropriate number of Pyramid layers for sample pictures and template images; 2. You're going to have a global matching at the top of the Pyramid and search for the area to which the template is registered; 3. The algorithm mapped the registration region to the next layer in Pyramid, and identified the area around the registration results as a new search area; 4. This algorithm performs a new registration in the new search region of this layer and maps the registration results to the next layer of Pyramid; 5. Then, duplicate search until it reaches the bottom of the Pyramid. Because the search area of each layer is very small, it can greatly reduce the amount of computation and save the matching time.
In the actual match process, because the image will have some very messy edges, it is not possible to find the correct template in the sample picture. This is due to errors, so it is necessary to set thresholds for the similarity of the algorithms and accept the matching results only when their similarity is less than or higher than a threshold. The results are shown in Figure 4 and figure 5;

Affine transformation
Once the template of the sample image is found, match it with the target template. Because the template may have translation, rotation and other changes, so the affine transformation of the template of the sample image should be carried out by using the two-dimensional transformation matrix [7]. In computer graphics, coordinate transformation is usually not a single one. In order to reduce the computational complexity, we usually obtain a matrix with the final change by adding the sub matrixes. So we need to translate translation as a variation matrix. Therefore, the experiment can only introduce homogeneous coordinate system.  Point (Px, Py) is a fixed point of transformation, namely the algorithm when using HomMat2DRotate conversion, in order to make the coordinates of the point position will remain unchanged, the first to enter the transformation matrix the origin fixed point moves to the global coordinate system. Then, add the rotation matrix, and finally add the 2D transform matrix HomMat2D to move the fixed point back to its original position. Transform as follows: HomMat2DTranslate adds the 2D transform moment HomMat2D to the vector t = (Tx, Ty) matrix, and obtains the new moment HomMat2DTranslate. The HomMat2DTranslate is translated relative to the global coordinate system; the transformation matrix as follows: 1 0 2 T a n 0 1 2 After a series of affine transformations, the matching template can match the template more accurately, thus improving the matching accuracy of the sample images.

Template creation
The creation of ROI is implemented with the create shape model, which comes with halcon. It includes the number of towers, the rotation angle of the template, the step size, the feature points, the contrast, and other parameter settings.
In create shape model, the parameter NumLevels is the parameter that sets the number of plies in Pyramid. The bigger the NumLevels, the less information the top Pyramid has, and no template information will be found. If Pyramid's progression is too small, the matching speed will slow down. Because the picture collected in this experiment is black and white, with less space occupation and higher matching efficiency, the number of layers in Pyramid should not be too large. The number of layers defined in this experiment is 2 in Pyramid.
General image matching differs from image matching of signature, because there will be appear upside down situation in the process of printing books, In order to effectively avoid the situation upside down, so choosing the image rotation range allows for positive and negative 50 degrees rotation of the image matching algorithm for arbitrary resistance in general in the experiment can not match the angle.
The parameter Contras determines the contrast of the template pixels [8]. The choice of Contrast should ensure that the main features of the template are used in the sample picture.

Template search
In the find shape model operator, the arguments AngleStart and AngleExtent define the starting angle and range at which the template search begins. AngleStep defines the step size of the search angle. The settings of the three parameters match the parameters in the create shape model.
The number of gold towers used in the search should match the number of gold towers NumLevels when creating the template. NumLevels should be within the number of layers defined by create shape model [9].
The parameter Greediness is the setting of the threshold when searching. If Greediness=0, use a more secure search method. As long as the template exists in the sample image, it can be found, but searching in this mode is waisting time. If Greediness=1, the search method is unsafe, so even if the template exists in the image, the template may not be found, but the probability of occurrence is very small. Searching in this mode can save a lot of time. In the experiment, because the template is unique and the experimental environment is stable, Greediness=0.8 is set up.

Results of experiments
To test the algorithm, 100 bitmap images of 300KB are selected as sample images for testing. Matching each sample image with template image, The results show that under the Halcon environment, the accuracy of the matching algorithm can reach 100%. Running on a computer with 32 bit operating system, 4GB memory , Intel Core I3 processor, and 2.30GHz CPU, the average time needed for an image matching is 42.5ms. Figure 6 is a display of the matching result.

Conclusion
The experimental results show that the algorithm for signature detection can extract a ROI region of arbitrary size, and then fast and accurate registration of signature. Compared with the traditional detection technology, the algorithm can detect wrong signatures and upside down signature more effectively, shorten the matching time greatly, anti-rotation, and is robust against illumination and rotation. The algorithm improves the speed and accuracy of Bookbinding quality inspection. With the improvement of production automation and the expansion of production scale, machine vision technology will be more widely used and developed in the quality inspection of printed matter.