# A Multi-Stage Method for Logo Detection in Scanned Official Documents Based on Image Processing
## 3 Materials and Methods  
Our logo-detection approach is based on an extension to the feature rectangles method (FR) proposed by [24]. As defined by their work, an FR is a rectangle with a minimum inner area that surrounds at least one foreground pixel, and its four edges consist of background pixels. The process of computing FRs can be summarized in the following list of steps:  
* Extract a set of every foreground pixel in the input image.
* Place a 3 \(\times\) 3 window around each pixel.
* If not all pixels in the top window border are background pixels, expand the top edge by one pixel and repeat this step. If every pixel is a background pixel, go to step 4.
* If not all pixels in the bottom window border are background pixels, expand the bottom edge by one pixel and repeat this step. If every pixel is a background pixel, go to step 5.
* If not all pixels in the left window border are background pixels, expand the left edge by one pixel and repeat this step. If every pixel is a background pixel, go to step 6.
* If not all pixels in the right window border are background pixels, expand the right edge by one pixel and repeat this step. If every pixel is a background pixel, the region is considered a candidate region  
Our main enhancements with respect to this method reside in two aspects. First, we do not scan the entire document looking for logotypes, so the number of false positives is reduced. Instead, we segment the document into regions with a high probability of containing a logotype, and we only expand the rectangles from those regions. Second, documents are pre-classified according to their level of image noise, and we apply specific morphological operations to those whose noise exceeds a given threshold. This reduces the number of FRs without impacting recognition, providing a look-ahead value, which we will introduce later, used before closing a rectangle.  
One of the situations where the standard FR method does not perform well is when the logo is formed by two or more components separated by a small margin. Typically, one of those components is the logotype itself, and the other is the name of the company, organization, or group that the logo represents. The standard FR method has problems detecting these X-Y separated logos, as mentioned by [24]. With that method, only one part of the logo is detected, the graphical part, with no text, as we can see in Figure 1a. With our method, the full logo (image, picture, and text) is detected. We accomplish this by proposing that a region edge does not stop expanding when it is formed exclusively by background pixels. Instead, it may expand from one or many or its sides, depending on the initial shape of the region. Figure 1b is an example of the result of the modified extended rectangle method. Using the modified extended rectangle method, the logotype includes its text label, whereas in the original method, only the graphical part of the logotype is included. This is our main modification to the FR method, which we will describe along with the rest of our proposed detection framework in the following subsections.  
In short, our method consists of the following steps:  
* **Binarization:** Images are binarized using the Otsu method [29].
* **Noise estimation and image enhancement:** document noise level estimation and reduction.
* **Computation of regions of interest (ROIs):** extraction of consecutive image rows with a very low number of foreground pixels at the top and bottom.
* **Extended feature rectangles with look-ahead:** a modified feature rectangles expansion method.
* **Region feature vectors:** A C4.5 decision tree is applied to train and test the system against a collection of documents.  
The complete workflow is depicted in the flow diagram of Figure 2, and a detailed explanation of each stage of our method is presented next.  
Figure 1: Feature rectangles method applied to a document. (**a**) Original result. (**b**) Our modified method.  
Figure 2: Workflow of our proposed method.