# Fashion Product Classification through Deep Learning and Computer Vision
## 4 Logo Detection
### Logo Detection through Standard Computer Vision Approaches
The punctual equation of PCC, applied to images, is as follows:  
\[pcc(I,T,x,y)=\frac{\sum_{j,k}\left(I_{xy}(j,k)-\mu_{I_{xy}}\right)\left(T\left( j,k\right)-\mu_{T}\right)}{\sqrt{\sum_{j,k}\left(I_{xy}(j,k)-\mu_{I_{xy}} \right)^{2}\sum_{j,k}\left(T\left(j,k\right)-\mu_{T}\right)^{2}}}, \tag{1}\]  
where \(j\) spans from \(-T_{w}/2\) to \(T_{w}/2\), and \(k\) from \(-T_{h}/2\) to \(T_{h}/2\), given \(T_{w}\) and \(T_{h}\) as the width and the height of the template \(T\), respectively. \(I_{xy}\) is a portion of the image \(I\) with the same size of \(T\) and centered around \(p=(x,y)\). Scalars \(\mu_{I_{xy}}\) and \(\mu_{T}\) are the average values of \(I_{xy}\) and \(T\), respectively. \(T(j,k)\) (and, therefore, \(I_{xy}(j,k)\)) is the pixel value of that image at the coordinates \(j,k\) computed _from the center_ of that image. It is worth noting that the numerator is the covariance between \(I\) and \(T\), and the denominator is the product of their standard deviations. Hence, the equation is invariant to affine transformations. This means that PCC is a robust method in case of varying light conditions, showing independence from several real-world lighting issues, since the main lighting contribution from objects is linear. Rearranging the Equation (1) allows us to gain a simplified equation that does not depend directly on the averages of the image and the template. This is useful to apply a mask \(M\) to the template, as follows:  
\[pcc(I,T,M,x,y)=\frac{n\sum_{j,k}I_{xy}MT-\sum_{j,k}I_{xy}\sum_{j,k}MT}{\sqrt{n \sum_{j,k}I_{xy}-\left(\sum_{j,k}I_{xy}\right)^{2}}\sqrt{n\sum_{j,k}MT-\left( \sum_{j,k}MT\right)^{2}}}, \tag{2}\]  
where indexes \(j,k\) are omitted for the sake of brevity. The value of PCC obtained in this way is still invariant to affine transformations. The relevant region of the input image consists initially in the entire visible area of the garment in the image, obtained in the preprocessing phase: in fact, the binary image that represent the shape of the apparel product has value 0 on the background, and 1 otherwise. The initial template matching is performed on a downsampled grayscale version of the input image. The initial downsampling factor is 16. Equation (2) is computed for each pixel of coordinates \((x,y)\) in the search region, for each transformation of the template. It is worth noting that \(-1\leq PCC\leq 1\). Such a score has an immediate interpretation: a value close to 1 means a strong correlation between the portion of the input image and the template, whilst a value close to \(-1\) an inverse correlation. Since logos could have different backgrounds and colors, both correlation and inverse correlation denote a good match. In our approach, the PCC value is then transformed into a probability, between 0 and 1. A threshold is applied to find the most probable matching. Applying a threshold returns a set of regions, and these regions are used in the following step of the algorithm to perform the successive matching. Simultaneously, the downsampling on the input image is reduced to a factor of 8 in the second iteration and 4 in the third. Such an iterative process is repeated no more than three times in our system, in order to avoid high computational times. At the end of the iterative process, the remaining search regions become the regions where the logo was found, and a circle is drawn over it to indicate its position. Figure 8 shows the procedure for finding a small logo using PCC. Only the matching with the right-hand side of the logo is detailed, but the last image shows the results of both searches (LHS and RHS). In this case, the logo is clearly visible, but it could be confused with the background pattern: in fact, the first iteration of PCC in Figure 8 retrieves several false positives. Figure 8: An example of logo detection using template matching. This approach is also applicable to other kinds of logos if other types of templates and masks are provided, giving very accurate results if appropriate template transformations are performed.