An Efficient Method for Stamps Recognition Using Histogram Moment with Haar Wavelet Sub-bands

One major problem facing some environments, such as insurance companies and government institutions, is when a massive amount of documents has to be processed every day. Thus, an automatic stamp recognition system is necessary. The extraction and recognition of a general stamp is not a simple task because it may have various shapes, sizes, backgrounds, patterns, and colors. Moreover, the stamp can be printed on documents with bad quality and rotation with various angles. Our proposed method presents a new approach for the preprocessing and recognition of color stamp images. It consists of four stages, which are stamp extraction, preprocessing, feature extraction, and matching. Stamp extraction is achieved to isolate complex background and remove unwanted data or noise that is surrounding the stamp area. The preprocessing stage is necessary to improve the stamp brightness and eliminate the rotation that occurs during the stamping process. In feature extraction, the extracted information will be representing the desirable feature vector in order to discriminate between stamps using local distribution of statistical features and Haar wavelet with histogram moment. Finally, each extracted feature vector will be saved in the dedicated system database for matching purpose. The test results indicate that the proposed system provides a high recognition rate for two sets of the proposed features (i.e., 99.29% recognition rate for the local distribution of statistical features and 96.01% recognition rate for the Haar wavelet transform with histogram and moment).

consists of the following steps; firstly, the chromatic portion of the image is isolated from the text and background which are roughly achromatic. Secondly, color clustering is applied for getting various cluster images, each containing only some elements that have the same color. Finally, in order to obtain candidate solutions, the cluster images are cleaned from noise and segmented by the XY-cut algorithm. The test results indicated that recall is 83% and precision is 84% [5]. Pawel and Dariusz proposed a method for solving the problem of identifying the stamp types extracted from digital images, which is separated into two principal phases. In the first phase, the stamp is represented using Point Distance Histogram method depending on the shape descriptor. Principal Component Analysis Transform was utilized in the second phase, with an additional reduction based on Linear Discriminant Analysis. The dimensionality reduction conducted using PDH-calculated descriptors showed that, for classification purposes, only the four first performance components are useful. The test results indicated that the best recognition rate is 89% [10]. Sheraz et al. proposed a new method of segmenting stamps from document images. The system can be considered as a general way to segment the single/multicolored, monochrome, and even black stamps. It is also capable of segmenting invisible stamps as well as those in some arbitrary shapes. In addition, for feature extraction, the authors used part-based / local features merged with geometric features. The test results achieved values for recall and precision of 73% and 83%, respectively [11]. Junaid et al. presented a common approach to segmenting stamps from scanned document images, based on utilizing Fully Convolutional Neural Network (FCNs). This approach provided the so called D-StaR, which is able to detect invisible stamps of any shape, color, scale, or orientation. In addition, D-StaR can also detect overlapping stamps. A Completed Convolutional Network was also used to separate stamp masks from scanned document images. The test results indicated precision and recall values of 87% and 84%, respectively [12]. Gantuya et al. suggested a method to detect official stamps from scanned documents and learn about historical stamps. The method included the next stages: Firstly, they identified the official stamps in the document scanned, depending on the partitioning of the red color and the document standard. They also implemented processing algorithms to remove noise, resize, and reshape, etc. In the end, a new static classification algorithm was suggested to classify stamps by shapes, by utilizing PCA and KNN algorithms (nearest neighbour). The test indicated that, when KNN was used to classify stamps by shapes into classes, the ratio of training to testing data was 70:30 respectively, with a recognition ratio of 86.46 [13].

Research Method 3.1 Gamma Correction
The image of the stamp might occasionally be unclear and this may affect the process of extracting good features for the image. Therefore, we needed to improve the image brightness by applying nonlinear gamma correction. In order to enhance the degree of whiteness in bright regions or the degree of blackness in dark regions, gamma correction is accomplished [14]. The following steps describe the process of enhancement using gamma correction:

1.
The mean (µ) and standard deviation (σ) values for the gray scale image were computed by applying equations 1 and 2, respectively [14].

2.
The lowest (Min) and highest (Max) gray values found in the stamp region were computed using the following equations (3 and 4) [15].
where μ and σ are the mean and standard deviation values, respectively, of the image. The α 1 and α 2 parameters are used to control the strength of the linear extent. The optimal values of these parameters are determined by testing different potential values, until reaching the value that gives the best result. In this work, the α 1 and α 2 values were set to 0.5 and 3.5, respectively. These values were tested randomly from the experiment and the best values that led to an increase in the contrast were selected.

3.
Nonlinear gamma stretching was applied using equation (5) [15]. In this work, the value of γ was set to 0.2 because this value has led to the best brightness stretching result and brighter output value.

{ ( )
where Gry(x,y) is the gray image and I G (x,y) is the resulted image after applying gamma stretching.

Rotation Compensation
Also, images can suffer from rotation at different angles, which is due to the fact that the stamps are not always placed with the horizon line because of the process of stamping. Consequently, one of the most important challenges facing the process of recognition is estimating the value of the angle that the image needs to return to the original point or estimating the value of the angle that is approximately close to the point of origin. The dataset also contains stamps that are in different classes, thus the problem facing rotation compensation is how to estimate the angle of rotation. In this work, we utilized the statistical tool of PCA to rotate the object. PCA was employed on white pixels in the binary image to determine how the object is rotated around the mean of the object pixels. To determine the rotation angle value for each stamp image, the following steps were applied [16]:

1.
Determine The center point of the binary stamp image, which is the average of coordinates of the stamp image points, was determined.

2.
Depending on PCA, the compensation angle (θ R ) of rotation stamp was determined to utilize the two dimensional matrix of the binary stamp image. This angle was determined using the following equation [17]: where x c and y c are center coordinates and θ R is the compensation angle value.

3.
To perform rotation compensation on the 2D stamp image based on the corresponding angle value, the rotation was computed using the following rotation transform equations [17]: where X n and Y n are the new coordinates of the rotated pixel (x,y) in the Rot_Img (x,y), while θ R is the value of angle rotation.

Local Distribution of Statistical Features
This method includes the definition of some significant mathematical equations relevant to the feature values which is applied for each block. Three local features were used to extract features from each block. These features are: density, average for x and y coordinates, and standard deviation for x and y coordinates. The following equations describe each of these statistical local features [17].

1.
Density was computed for each block of stamp image, as shown in the equation (9) [17].

∑ ∑
where Den(x,y) is the density for each block, while x s and y s represent the starting point for each block and x e and y e represent the endpoint for each block. BlkOvr_ Img(x,y) is the partitioning overlapping stamp image.

2.
The average of x and y coordinates was computed for each block, as shown in equation (10) [17].

3.
Standard deviation (σ) of x and y coordinates was computed for each block, as shown in equation (11) [17].

Haar Wavelet Transform with Histogram and Moment
Wavelet transformation is a method for signal analysis that can be used in many fields and disciplines, such as image processing, pattern recognition, and many other fields. In this proposed system, wavelet transformation was used as a tool to extract features, as it has proven effective in extracting the best features. In the wavelet transform, the image can be divided into a set of bands that have limited components, which are called sub bands. In the proposed system, a one-level 2D Haar Wavelet Transform (HWT) was accomplished. HWT decomposes the image into four sub-bands (LL, LH, HL, HH), where LL represents the approximation or average sub-band, while other sub-bands represent detail or change sub-bands [18]. It is important to notice that these sets of features are not extracted directly from these sub-bands. Thus, to extract a set of features from the stamp image, the following steps were implemented: 1. Partitioning the image into overlapping blocks and applying the 2D Haar wavelet transform on each block, for one level. Each block was decomposed into four sub-bands (i.e., LL, LH, HL, and HH).

2.
The histogram for each band from the block was computed by counting the number of pixels for each gray level. 3. The proposed moment equation was computed for each histogram band to extract features from each band, as shown in equation (12). The proposed system focuses on the values of the moment for sub-bands. The main idea of this method is to determine the moment of the histogram of each subband that is utilized to establish the feature vector.

∑
where Mom His represents the moment of the histogram for each sub-band, while His L represents the histogram length, and Mean His represents the mean of the histogram.

The Proposed System
This section describes the steps implemented in the proposed system, which are shown in Algorithm 1 and comprises the following phases: (i) stamp extraction, (ii) preprocessing, (iii) feature extraction, and (iv) matching. The steps involved in these phases are further explained in the following phases. Figure-1

Stamp Extraction Phase
In this phase, the stamp can be placed on the complex background and surrounded by unwanted data, such as words, text, patches, and other types of noise which are formed as objects at the nearest to the stamps. Thus, we need to isolate background clusters from stamp clusters and remove noise. This phase consists of six steps that are briefly explained in the following.

Loading the Stamp Image
The stamp image is the image file in the bitmap format (i.e., .bmp). The stamp image color resolution is 24 bit / pixel. Loading the image data (i.e., components R, G, and B).

K-Means Clustering Algorithm
K-Means clustering algorithm aims to group a set of data objects into k clusters based on the Euclidean distance measured between the data objects and the selected k centroids. Thus, a huge number of clusters for each image is created. The k-means algorithm for the proposed system includes the following steps: 1. Select an initial random centroid for each cluster. The initial step for k-means in the proposed method is to select four initial random centroids for each band of image (i.e. RGB). In this case, the number of probabilities for the values of the random centroids will become equal to L=4 3 =64. 2. Compute the difference between each data point (i.e. pixel) for each band of the image with each centroid. 3. Apply the Euclidean distance to compute the summation of the squares of the differences between each pixel and its assigned centroid for each band of the image. 4. Find the minimum distance between clusters. 5. Group data points which have similar colors, depending on the minimum distance, to assign the clusters. 6. When clustering is finished, compute the mean of the clusters and determine the nearest centroid. At the time, compute the mean color in each cluster to be remapped onto the image.

ISODATA Clustering Algorithm
The ISODATA clustering algorithm is similar in its principle to the K-means algorithm. However, in the ISODATA algorithm, the number of clusters is determined automatically through the iteration, by merging similar clusters and splitting clusters based on thresholding value. Hence, this algorithm will reduce the number of clusters by merging the same clusters. It is considered as the development

Rajab and George
Iraqi Journal of Science, 2021, Vol. 62, No. 9, pp: 3182-3195 3188 step for k-means, which includes reducing the number of clusters for each image. This step starts after a limited number of iterations of k-means, and this number is determined by the user.

Computing the Minimum Distance
The distance between all the remaining clusters must be determined. After that, the determination between the two clusters is conducted to find out the lowest distance, and they are combined according to the color value of the cluster pixels selected for merging. This method will be continued until combining all clusters that have the lowest distance. Hence, the number of clusters will be greatly decreased.

Computing the Mean and Standard Deviation
This step aims to isolate background clusters from stamp clusters by computing the mean and standard deviation values for the remaining clusters. Then, the larger clusters will have lower standard deviation values than the other clusters. The largest cluster is the background cluster, which is not bounded to the central region and may have wide variation. Then, we have to determine which of the remaining clusters part of the background are. This is achieved by measuring the dominant color value for each cluster and keeping the value of the largest repetition, because it is considered the background cluster. From experience, it can be noted that the background cluster is the cluster which contains the highest repetition value, which exceeds 10, but if the value is lower than 10 then it is known as a stamp clusters. As a result, the numbers of background and stamp clusters are determined. These clusters will combine to produce one image for both the background and the stamp.

Extracting the Stamp and Remove Object
The stamp clusters are isolated from the background and other unwanted information (noise patches that appear as isolated areas). Thus, we need to remove this information. This process is performed by segmenting the stamp cluster using a region that is growing to a number of segments and calculating the main and the secondary diagonals for each segment to produce four points of the two diagonals, so that, the segment that contains four points is considered as the stamp, otherwise it is considered as a noise area. A binary mask is generated from the connected segment and multiplies with the original image, after isolating the background, to obtain a stamp image that is free from noise. Figure-2 shows the results of each step of the first phase (i.e., stamp extraction) of two images chosen randomly from the stamps dataset.

Preprocessing Phase
The primary stage in any recognition system is the preprocessing stage. It is established to manipulate the image data and make it more convenient to the task of extracting features. In the preprocessing stage, a set of tasks were conducted to improve the quality of the image. These tasks are covered in the following steps.

Gray Image Preparation
The RGB color stamp image format was converted to gray scale image, where each pixel value was represented by one byte instead of three bytes, because it carries only the intensity information. Figure-3 shows the result of converting color stamp image to gray scale image for two tested images.  Figure-4 illustrates the effect of applying gamma stretching for two tested images.

Binarization (Global Thresholding)
Global thresholding is the most common method used in image segmentation. It is performed by comparing the image values with a threshold value T. The pixels which have an intensity value of 1 correspond to objects, while those with a value of 0 correspond to the background. The selected thresholding value was 150. Figure Figure-6 illustrates the result of applying the rotation compensation for two tested images.

Region of Interest Extraction (Clipping)
The clipping is the process of allocating the stamp in the image. This step can be done by performing four separate scans (i.e., scanning each side of the image boundary until reaching the row or column holding the stamp pixel). Figure-7 illustrates the result of applying the clipping process for two tested images.

Image Partitioning with Overlapping
The main aim of this step is to divide the image into overlapping blocks to describe the local feature for each block. The block dimensions (i.e., Block width and Block heigh ) can be determined by dividing the image dimensions (i.e., Img width and Img heigh ) into the number of blocks (N x and N y ). The overlapping ratio is the parameter that controls the degree of overlapping between blocks, which can be considered as the ratio between the extended block length and the original block. The number of blocks and overlapping ratio values is tested to discover the appropriate value, which leads to better recognition rate. It is necessary to note that the image dimensions (width and height) were not equal; consequently, the block dimensions also differed. Figure-8 illustrates the result of applying the partitioning process with overlapping for two tested images.

Features Extraction Phase
The most important phase in any recognition system is feature extraction. The main purpose of feature extraction is to extract important information from the stamp image. The extracted information will be representing the desirable feature vectors in order to discriminate between stamps. Each extracted feature vector will be saved in the database for the matching stage. Two various sets of distinguished features were used in the proposed system, as described in sections 3.3 and 3.4.

Matching Phase
This phase was used to compute the degree of similarity between the feature vectors extracted from the stamp image. To perform the matching process, the computed discriminating feature vectors for each class were used to produce the template. The particular template consists of the mean feature vector of each class and the standard deviation feature vector, which is stored in the database. This stage was performed by comparing the feature vector of the stamp image with all template vectors stored in the database.

Similarity Measure
The degree of similarity utilized in the proposed method was determined using an Euclidean distance measure, named as the Normalized Mean Square Distance (NMSD), as defined by equation (13) [17].
where, F i represents the tested i th feature vector extracted from the stamp input image, T j represents the j th template feature vector registered in the database, while T µj and T σj represent the mean and standard deviation template vectors, respectively, which are loaded from the database. The recognition rate (RR), referred to as the ratio between the number of correct recognition decisions and the totals number of tried tests, was used to evaluate the recognition system performance, as defined by equation (14):

Results and Discussion
One dataset (i.e., Stamps Dataset) was used for evaluating the performance of the proposed stamp recognition system. The dataset was taken from Mendeley Data 2020 [19]. This dataset consists of different samples belonging to 173 classes. Each class is a subset that consists of nine samples of stamps. The stamp images are BMP 24 bit/pixel (bit depth). Initially, the recognition performance of the Local Distribution of Statistical Features method was tested for the three feature vectors (i.e., density only 'Den', average only 'Avr', standard deviation only 'σ') as well as four feature set combinations (i.e. density + average 'Den_Avr', density + standard deviation 'D_σ', average + standard deviation 'Avr_σ', and density + average + standard deviation 'Den_Avr_σ') with similarity measures (i.e. NMSD). Dividing the image into blocks of different sizes and overlapping ratios facilitates the process of obtaining the distinctive features that reflect a huge amount of image information, as well as searching for the best vectors that lead to the best recognition rate. We first performed experiments on all the seven feature sets mentioned above against different block sizes (3×3, 3×5, 5×5, 5×7, 7×7, 7×9, and 9×9) and different overlapping ratios of 0.1, 0.2, and 0.3. The results shown in Tables-2, 3, and 4 illustrate the effects of the number of blocks and different overlapping ratios r on the recognition rate of the above seven feature sets, by using NMSD similarity measure. As a result of the above tables, it is clear that the recognition rate generally varies according to the block size and overlapping ratios, where a small block size has a smaller recognition rate, and as the block size increases the recognition rate also increases. The best attained recognition rate (i.e. 99.29%) was achieved when the number of blocks was taken as 7×7and 7×9 blocks, with overlapping ratio values of 0.2 and 0.3, respectively, using NMSD similarity measure.
Also, the recognition results of Haar wavelet transform, with histogram and moment feature sets, are presented. Features were extracted from the moment of the histogram in the one-level 2D Haar wavelet transform. In essence, it is simply based on the partition of the image into blocks and decomposing each block to four sub-bands (LL, LH, HL, and HH) to compute the histogram for each sub-band. Thus, features were extracted from applying moment in the histogram sub-bands.
Also, we performed experiments on all the twelve feature sets mentioned above against different block sizes (3×3, 3×5, 5×5, 5×7, 7×7, 7×9, and 9×9) and different overlapping ratios of 0.1, 0.2, and 0.3. The results shown in Tables-5, 6, and 7 illustrate the effects of the number of blocks and different overlapping ratios on the recognition rate of the above three extracted groups of feature sets, using NMSD similarity measure. The important point we have to take into consideration to improve the overall success rate of the recognition system is the merge of more than two features. It can be noticed from test results listed in the above tables that the best attained recognition rate (i.e., 96.01%) is obtained when the number of blocks taken is 9×9, with an overlapping ratio of 0.1 and four merged features (F11(LL_LH_ LL_HL)), using NMSD similarity measure.

Comparison with Other Studies
We also evaluated the efficiency of the proposed system as opposed to other published studies (Table-8). The results demonstrated that our approach leads to a higher recognition rate as compared to other studies.

Conclusions
In this paper, we proposed a new approach that leads to the recognition of color stamp images. Until now this topic has not been widely discussed and resolved in the previous studies. The implemented system consisted of four stages, which were stamp extraction, preprocessing, feature extraction, and matching. The aims of the stamp extraction stage were to extract the stamp region and remove unwanted information that were closer to the stamp. The preprocessing stage was established to manipulate the image data and make it more convenient for the task of extracting features. The main purpose of feature extraction was to extract the desirable feature vector in order to discriminate between stamps. Finally, the matching stage was used to compute the degree of similarity between the feature vectors extracted from the stamp image. Also, this paper proposed a simple rotation compensation module and was designed to make the process more robust against facing rotation. Thus, the concept of local distribution was applied to the statistical features and Haar wavelet transform with histogram and moment which were used as discrimination features. The experimental results performed on one public dataset (i.e. Stamps Dataset) indicated that the performance of the proposed system in terms of recognition rate is very high (99.29% for the first feature set and 96.01% for the second feature set).