# Automatic Defect Detection for Web Offset Printing Based on Machine Vision
## 2 Methodology
### Determining First Row in Web Offset Images
#### 2.1.2 Search Method Based on Image Projection  
Generally, the common method for determining first row of web offset images is the method of template matching based on normalized cross-correlation (NCC). For the template matching method, a sub-image with a discriminative feature from reference image should first be selected, and then search the corresponding region in the initial frame image. However, searching for the position of a sub-image in a large image is computationally expensive [1]. Moreover, selecting a sub-image with a discriminative feature is not an easy job if done manually, and in some cases a sub-image with a discriminative feature does not exist in the reference image. In this subsection, a fast searching algorithm based on image projection is given, which can convert 2D searching into 1D searching using NCC. Figure 3: Illustration of determining the first row in captured web offset images. (**a**) continuous captured printing image; (**b**) reference image; (**c**) an initial frame image captured at the start time. Figure 2: Illustration of different installation methods of a rotary encoder for image capturing. (**a**) the usual method; (**b**) our proposed method. Inspired by the idea of searching for the first row only in the row direction, a 2D image can be converted into a 1D feature descriptor by projecting a 2D image along the row's horizontal direction, and then the search process can be executed in 1D space. Figure 4 gives two gray average projection curves of Figure 3b,c. From Figure 4, we can see the projection curves of a reference image and an initial frame are similar except having a shift in the horizontal direction, which means the first row can be found when the two projection curves overlap simply by moving one of the projection curves. Thus determining first row in web offset images becomes a matching problem in 1D feature space. Considering the periodicity of the captured image, the projection curve of an initial frame is extended by a period as shown in Figure 5, where the projection curve of the reference image is matched with the extended projection curve of the initial frame image. Suppose the reference image and initial frame are represented as \(R(m,n)\) and \(F(m,n)\) with the size of \(w*h\), where \(w\) is the image width and \(h\) is the image height. The projection average gray values  
Figure 4: Gray projection curve. Figure 5: Extend gray projection curve of initial frame image. of \(R(m,n)\) and \(F(m,n)\) along with row direction are denoted by \(r(n)\) and \(f(n)\), which are given in Equations (1) and (2). \[r(n)=\frac{1}{w}\sum_{m=1}^{w}R(m,n)\quad n=1,2,\cdots,h \tag{1}\]  
\[f(n)=\frac{1}{w}\sum_{m=1}^{w}F(m,n)\quad n=1,2,\cdots,h \tag{2}\]  
For convenience, we rewrite \(r(n)\) as \(t=(t_{i})_{i=1}^{h}=(r(1),r(2),\cdots,r(h))\), the extend \(f(n)\) as \(d=(d_{i})_{i=1}^{2h}=(f(1),f(2),\cdots,f(h),f(1),f(2),\cdots,f(h))\). Then, NCC is employed for searching the first row as follows. \[NCC(r)=\sum_{i=1}^{h}\frac{(t_{i}-\overline{t})(d_{i+r}-\overline{d}_{r})}{ \sqrt{\sum_{i=1}^{h}(t_{i}-\overline{t})^{2}\sum_{i=1}^{h}(d_{i+r}-\overline{ d}_{r})^{2}}} \tag{3}\]  
where \(\overline{t}\) and \(\overline{d}_{r}\) are the means of \(t\) and \(d\) and range from \(d_{r+1}\) to \(d_{r+h}\), respectively, which are given by:  
\[\overline{t}=\frac{1}{h}\sum_{i=1}^{h}t_{i}\quad\text{and}\quad\overline{d}_{r }=\frac{1}{h}\sum_{i=1}^{h}d_{i+r}\]  
To speed up the search process, two strategies are imported into the proposed algorithm. The first is to select some columns which have obviously changing data as the projected ROI, as shown in Figure 6 marked with blue color, for reducing projection time. While the other is to construct a pyramid with one-dimension as shown in Figure 7, where searching process goes from the top layer to the first layer. The process of constructing the pyramid and searching first row is as follows:  
1. Smooth the initial projection average gray value by three-point average and set it as the first layer of the pyramid. 2.