Also at]Goethe University, Frankfurt am Main.

Combinational neural network using Gabor filters for the classification of handwritten
digits
N. Joshi∗

arXiv:1709.05867v1 [cs.CV] 18 Sep 2017

Frankfurt Institute for Advanced Studies (FIAS),
600438 Frankfurt, Germany and
[
(Dated: September 10, 2017)
A classification algorithm that combines the components of k-nearest neighbours and multilayer
neural networks has been designed and tested. With this method the computational time required
for training the dataset has been reduced substancially. Gabor filters were used for the feature
extraction to ensure a better performance. This algorithm is tested with MNIST dataset and it will
be integrated as a module in the object recognition software which is currently under development.
PACS numbers: 07.05.Mh,42.30.Tz, 42.30.Sy

I.

INTRODUCTION

Deep learning algorighms are gaining fame with its
performance on the large datasets. They rely on the
availability of huge data, thereby minimizing the influence of few irregular samples from dataset. A classification algorithms that combines the k-nearest nearest
neighbours and multi layer perceptron (MLP) network
has been designed and tested. A fusion of parametric
and non-parametric approach produces better learning
results with a few trainning examples. With this combinational approach, we have also managed to reduced
a substancial amount dataset required to train the network. This algorithm has been tested on the well known
dataset of handwritten digits from MNIST [1]. This approach is known as meta learning [2].

II.

envelope and γ is the spatial aspect ratio of the Gabor
function. A Gabor filter bank is created by the choice of
different parameters. In this case three values of σ and
λ were chosen with eight rotations (θ ’s) equally spaced
between [0, π] (Total 3×3×8 = 72 ). Fig.1 shows pictures
of different gabor filters in 2D with false colour coded
intensities.

GABOR FILTERS AND FEATURE
EXTRACTION

Gabor filters are the natural choice to extract features
as they produce a respose similar to the human visual
system [3]. A two-dimentional Gabor function is written
as

FIG. 1: Gabor filter bank created by varying σ, frequency
(ν = 2π/λ) and rotation (θ). The intensities are false colour
coded for better visual purpose.

Each of the gabor filter is convolved with the sample
 x02 + γ 2 y 02 



x0
image (see example Fig.2) to get the respose matrix. All
g x, y; λ, θ, ψ, θ, γ = exp −
exp
i
2π
+ψ
,
2σ 2
λ
of these response matrices then converted to form a fea(1)
ture vector.
where
x0 = x cos(θ) + y sin(θ),
y 0 = −x sin(θ) + y cos(θ),
and λ is the wavelength, θ is the orientation, ψ is the
phase offset, σ is the standard deviation of the Gaussian

∗ Electronic

address: njoshi@fias.uni-frankfurt.de

III.

COMBINED NETWORK MODEL

Gabor filter can be used for boundary detection or
texture segmentation. In the case of handwritten digits recognition the inner structure is ignored. Only frequencies (ν = 2π/λ) and the values of Gaussian spread
σ responsible for detecting the form of figure were used
[4, 5]. One should adjust these values according to image

2
IV.

EXPERIMENTS AND RESULTS

It was observed that the efficiency of the algorithm depends on the number of elements including the Gabor
parameters as well as standard deviation allowed to update weights of the network. In the first stage, the Gabor
parameters were varied in such a way that the distances
between vectors generated from model digits were optimized.

FIG. 2: An example of four Gabor filters applied to the sample
image.

properties like the size and depth. Please also note that,
each image manipulation library uses different methods
to read the raw data from the image file, giving rise to
conflicting results. In this case, an image was imported as
a float array and normalized to avoid any floating point
errors. A feature vector can be formed by calculating local energy, mean amplitude, entropy or phase amplitude.
We used the information entropy and the energy to form
a vector of [1×144] dimension. The Shannon information
entropy is defined as

H=−

X

pk log2 (pk ),

(2)

FIG. 4: Minkowski distances distributed over invervals for
different values of frequency and σ.

Fig.4 shows the normalized distribution of Minkowski
distances between each digits. The Minkowski distance
between two points x1 and x2 of order p is defined as

k

where k is the number of gray levels and pk is the
probability associated with gray level k [6].

d=

n
X

p 1/p

(|x1 − x2 |)

.

(3)

i=1

For p = 2, it reduces to the Euclidean distance.
It is desired that for best classification the centroids
should be as far as possible with equal distances between
them. Inspite of that, one observes that the distance
between digits 1 and 7 is much less than the distance
between 1 and 8 due to their similarity. When frequencies
and σ are optimized we get the distribution depicted by
blue solid line (see Fig.4). The number of interval denotes
the vector distance formed by digits
FIG. 3: Schematics of neural network model.

Fig.3 shows the scheme of the algorithm. Models of
digits were created by taking an average of a certain number of randomly chosen images from the MNIST dataset.
The feature vector extracted from this model was used to
initialize an MLP network. Then a batch of dataset from
trainning set was fed. When the cost function exceeds
the pre-determenined value calculated from covariance
matrix, a newly calulated centroid was used to update
the weights of the neural network. Thus, with this strategy, a faster recognition of particular image was achieved
using lesser number of trainning samples.

d0 =distance(x0 , x1 )
d1 =distance(x0 , x2 )
.. ..
..
. .
.
di =distance(x3 , x7 )
.. ..
..
. .
.
dk =distance(x8 , x9 )
In the second stage the algorithm is devided into two
branches. The feature set with labels from the model

3
digit is fed directly to the MLP network and the weights
are initialized. The trainning set is devided into batches
and using nearest neighbor algorithm, centroid and covariance matrix is calculated by

FIG. 6: Accuracy as a function of batches for two different
values of sigma deviation.

n

S=


0
1 X
Xi − X̄ Xi − X̄ ,
n − 1 i=1

(4)

from which the standard deviation is derived i.e. the
square roots of the eigenvalues of the covariance matrix
along the principal component. The centroid is simply
the mean of the vectors. if the distribution is spread, far
more than the previously calculated standard deviation,
the weights of neural network is updated and varified
against the testing set; consequently the accuracy over
the test set is calculated.
Fig. 5 shows the evolution of the separation between
feature vectors as the weights are updated with trainning batches. The separation between feature set grows
more distant during the trainning phase and increasing
the accuracy.

FIG. 5: Evolution of distribution of distances between intervals as a function of number of batches fed to the network.

MNIST provides large data set for testing hence one
can calculate accuracy with a low uncertainty. In this
case it was observed that the accuracy on testing data
set depends on weight updating. If we allow for a larger
Gaussian spread, the accuracy rises quickly over number
of batches but does not reach its heighest value. Whereas
for smaller values about 98% accuracy was acheived at
the cost of larger number of batches.

The calculations were performed using computer cluster with 8 nodes consisting 2 CPUs each. The module
called mpi4py was used for parallel processing [7]. The
calculation of Centroid and standard deviation was done
using Scikit-learn along with Numpy library Scikit-learn.
The neural network was designed with the module known
as Multi layer Perceptron under Scikit-learn.

V.

CONCLUSIONS

A model fusing two different methods is presented here.
The performance of Gabor filter in image segmentation
is also investigated and proved useful, though substantial
amount of efforts were required to fine-tune filter parameters for the output consistancy. With this method we
have achieved about 98% accuracy. A sub-module is proposed to manipulate the images in order to align properly
a distrorted image. Early results have have shown increased efficiency of 99.2%. Although this code is tested
only with the MNIST dataset, the ongoing efforts will
use the other datasets like Omniglot character sets and
other abstract objects.

[1] http://yann.lecun.com/exdb/mnist/

[2] Maudsley, D.B. “ A Theory of Meta-Learning and Princi-

4
ples of Facilitation: An Organismic Perspective”, University of Toronto, 1979.
[3] John Daugman, “Complete Discrete 2-D Gabor Transforms by Neural Networks for Image Analysis and Compression”, IEEE Trans on Acoustics, Speech, and Signal
Processing. Vol. 36. No. 7. July 1988, pp. 11691179.
[4] R.Mehrotra, K.R.Namuduri, N.Ranganathan, “Gabor
filter-based edge detection”, Volume 25, Issue 12, December 1992, Pages 1479-1494.
[5] A.G. Ramakrishnan, S. Kumar Raja and H.V. Raghu
Ram, “Neural network-based segmentation of textures us-

ing Gabor features”, Proc. 12th IEEE Workshop on Neural Networks for Signal Processing, pp. 365 - 374, 2002.
[6] C.E. Shannon, “A Mathematical Theory of Communication”, Bell System Technical Journal, vol. 27, pp. 379423,
623-656, July, October, 1948
[7] L. Dalcin, P. Kler, R. Paz, and A. Cosimo, “Parallel Distributed Computing using Python”, Advances in Water
Resources, 34(9):1124-1139, 2011
[8] Pedregosa et al., “Scikit-learn: Machine Learning in
Python”, JMLR 12, pp. 2825-2830, 2011.

