You are on page 1of 78

A Project Report

on

GENDER RECOGNITION FROM FACRS USING FUZZY


CLUSTERING AND NEAREST NEIGHBOR
CLASSIFIER
Submitted in partial fulfilment of the requirements for the award of the Degree of

MASTER OF TECHNOLOGY
in

COMPUTER SCIENCE AND ENGINEERING


by
M. MYTRI MADHURYA
(14FE1D5814)

Under the Guidance of

Mr. K. VIVEK, M. Tech.,


Assistant Professor
Department of Computer Science and Engineering

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


VIGNAN’S LARA INSTITUTE OF TECHNOLOGY AND SCIENCE
(Affiliated to Jawaharlal Nehru Technological University Kakinada, Kakinada)
(An ISO 9001:2008 Certified Institution, Approved by AICTE)
Vadlamudi-522213,
Guntur Dist., Andhra Pradesh,
November - 2016
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

VIGNAN’S LARA INSTITUTE OF TECHNOLOGY AND SCIENCE


(Affiliated to Jawaharlal Nehru Technological University Kakinada, Kakinada)
(An ISO 9001:2008 Certified Institution, Approved by AICTE)
Vadlamudi-522213

CERTIFICATE
This is to certify that the project report entitled “GENDER RECOGNITION FROM
FACES USING FUZZY CLUSTERING AND NEAREST NEIGHBOR
CLASSIFIER” is a bonafide work done by M. MYTRI MADHURYA
(14FE1D5814) under my guidance and submitted in partial fulfilment of the
requirements for the award of the degree of Master of Technology in COMPUTER
SCIENCE AND ENGINEERING from JAWAHARLAL NEHRU
TECHNOLOGICAL UNIVERSITY, KAKINADA. The work embodied in this
project report is not submitted to any University or Institution for the award of any
Degree or Diploma.

Project Guide Head of the Department


Mr. K.VIVEK Mr. N. RATNA KANTH

Assistant Professor Associate Professor

External Examiner
ACKNOWLEDGEMENT

While bringing out this project to its final form, I came across a number of
people whose contributions in various ways helped my field of explore and they deserve
special thanks. It is a pleasure to convey my gratitude to all of them.

First and foremost, I express sincere thanks to our respected Chairman


Dr. Lavu Rathaiah for providing support and stimulating environment for developing
the project.

I’m thankful to our beloved Principal Dr. K. Phaneendra Kumar for providing
great support in completing my project and giving the opportunity of doing the project.

At the same time I feel elated to thank our beloved Head of the
Department Mr. N. Ratna Kanth for inspiring all the way and arranging all the facilities and
resources needed for project. I profoundly convey thanks towards services rendered by him.

I’m thankful to our project Coordinator Mr. B. Balvinder Singh for supporting
in all the way to complete the project. His efforts in this respect are beyond the preview of
the acknowledgement.

This project presented here in the work accomplished under the enviable and
scholarly guidance of Mr. K. Vivek for his significant suggestion and help in every
aspect to accomplish the project work.

I also place my floral gratitude to the other teaching staff and lab technicians for
their constant support and advice throughout the project. I extend my thanks to non-
teaching staff for their assistantship during the project.

Last but not least I thank everyone who directly or indirectly helped me during the
successful completion of my project.

M. Mytri Madhurya

(14FE1D5814)
DECLARATION

I hereby declare that the project report entitled “Gender Recognition


from faces using Fuzzy Clustering and Nearest Neighbor Classifier”
submitted to the JNTUK Kakinada, is a record of an original work done by me under
the guidance of Mr K. VIVEK, Assistant Professor, of Computer science and
Engineering and this project report is submitted in partial fulfilment of the
requirements for the award of the Degree of Master of Technology in Computer
Science and Engineering. The results embodied in this project report are not
submitted to any other University or Institute for the award of any Degree or
Diploma.

M. Mytri Madhurya

(14FE1D5814)
ABSTRACT
The gender classification has attracted much attention in psychological
literature, relatively few machine vision methods have been proposed. However it has
been extensively studied in the context of surveillance applications and biometrics.
This project is mainly concern with offline gender classification using purely image
processing technique which using a database that was included in the system. The
way of doing this is by extracting the differences between male and female facial
features. Obviously the classification base on a single feature is not adequate since
humans share many facial properties even within different gender group. In the
existing systems, the feature extraction techniques like Principal component analysis,
Local binary patterns which worked on geometric methods. A geometric method does
not provide the accurate results.
Gender recognition is a standout amongst the most difficult issues in
computer vision. Facial gender identification of neonates and children is also known
as an extremely demanding issue for human spectators. This study propounds a novel
gender grouping technique using frontal facial pictures of individuals. The proposed
approach utilizes fuzzy clustering techniques and nearest neighbor, respectively, for
feature extraction and classification steps. Nearest neighbor can also apply to extract
the most suitable features from images as well as reducing the dimensionality of data.
The extracted components are then used to allocate the new pictures to proper classes
male or female in view of fuzzy clustering. The computational time and exactness of
the proposed method are examined together and the importance of the preferred
approach estimated to most of the other known competing methods is proved, chiefly
for younger faces. Experimental results indicate the significant classification
accuracies which have been gathered from FERET databases. Meanwhile, the
proposed algorithm is relatively easy; its computational time is viable and often less
than the other state-of-art gender classification methods.

i
TABLE OF CONTENTS

TOPIC PAGE NO

ABSTRACT i

List of Figures ii

1. INTRODUCTION 1 - 10

1.1 Introduction to Gender recognition 1

1.2 Basic Image Processing 3

1.3 Data Mining Techniques 9

1.3 Applications 10

2. LITERATURE SURVEY 11 - 21

2.1 Literature Survey Papers 11

2.2 Methods used in survey papers 15

3. CONCEPTS AND METHODS 22 - 30

3.1 Problem Definition 22

3.2 Architecture of Proposed system 23

3.3 Proposed Method 25

4. IMPLEMNTATION 31 - 56

4.1 Functional Requirements 31

4.2 Project Modules 31

4.3 Tools 33

4.4 Sample Code 45

5. TESTING 57 - 61

5.1 Testing 57

5.2 Types of Testing 61


6. RESULTS 62 - 66

7. CONCLUSION AND FUTURE SCOPE 67

REFERENCES 68

PUBLISHED PAPER 69
LIST OF FIGURES PAGE NO

Figure 1.1 RGB image 3

Figure 1.2 bit map image 3

Figure 1.3 color coding 4

Figure 1.4 transparency of colors 4

Figure 1.5 image representation 5

Figure 1.6 image format 5


Figure 1.7 image enhancement 7

Figure 1.8 image restoration 7

Figure 1.9 color image 8

Figure 1.10 image segmentation 8

Figure 2.1 hierarchal classifiers 17

Figure 2.2 implementation of hierarchal classifiers 18

Figure 2.3 image representation using WLD 19

Figure 2.4 Squared Symmetric Neighbourhood 20

Figure 3.1 Architecture of proposed system 23

Figure 3.2 Gender Recognition System 30

Figure 4.1 Parts of GUI 44

Figure 5.1 Test case Results 61

Figure 6.1 Basic GUI 62

Figure 6.2 Conversion of input image to gray scale image 63

Figure 6.3 Extraction of facial part from input image 63

ii
Figure 6.4 Cluster Formations 64

Figure 6.5 Face Detection 64

Figure 6.6 Feature Extraction 65

Figure 6.7 Classification 65

Figure 6.8 Gender Recognition 66

iii
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

CHAPTER 1
INTRODUCTION
1.1 Introduction to Gender recognition
This project is about gender recognition for classification based on the
frontal facial images. The classification using the frontal still facial image is not easy.
It is difficult mostly because of the inherent variability of the image formation process
in terms of image quality, images size, lighting condition, the angle of image and
photometry, geometry, and/or occlusion, change, and disguise. A successful gender
classification method has many potential applications such as human identification,
security system, smart human computer interface, computer vision approaches for
monitoring people, passive demographic data collection, etc. The interest on gender
recognition are discussed about the techniques that appearance based methods, that is
will learn the differential boundary between gender for male and female classes from
example images, without extracting any geometrical features such as distances, face
shape, face genetics and etc. Hopefully, in the 21st century now, there is a new system
that can implement or develop for solutions to similar face tasks as well.
The face is one of the most important biometric features of the human
beings and normally used as identification. Each person has their own innate face and
mostly a different face. As a human, to recognize the different faces without any
difficulty is more easily but it become difficulty to the system to recognize the human
faces. Face recognition is an active research area, and they can be used in wide range
applications such as surveillance and security, telecommunication and digital
libraries, human-computer intelligent interaction, and smart environment. Yet, it is a
challenging task to design and develop a robust computer system for face
identification thus classifies the gender of the human.
But, nowadays, the lack of automated face recognition systems is
especially apparent when compared to our own innate face recognition ability. Human
can perform face recognition, which is an extremely complex visual task, almost
instantaneously and our own recognition ability is far better and robust than any
computers can hope to be. Beside, a human also can recognize a familiar individual
under very adverse lighting conditions, from varying angles or viewpoints.
In the research for determination of features, such as, gender, race,
expression of a person, using facial features goes back to 1960s; it is only very

1
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

recently that acceptable results have been obtained. However, face recognition system
is still an area of active research since a completely successful approach or model has
not been proposed to solve the face recognition problem. For the next generation
surveillance systems are expected to take human frontal face as input pattern and
extract useful information such as gender information, emotion, race or age
information from the human face that soon it also can be used for the security system
or more than that.
Gender classification was first perceived as an issue in psychophysical
studies, which focuses on the efforts of understanding human visual processing
and identifying key features used to categorize between male and female
individuals. Research has shown that the disparity between facial masculinity and
femininity can be utilized to improve performances of face recognition
applications in biometrics, human-computer interaction, surveillance, and
computer vision. However, in a real-world environment, the challenge is how to deal
with the facial image being affected by the variance in factors such as illumination,
pose, facial expression, occlusion, background information and noise. This is then
also the challenge to the development of a robust face-based gender classification
system that has high classification accuracy and real-time performance.
This is then also the challenge to the development of a robust face-based
gender classification system that has high classification accuracy and real-time
performance. The conventional approach applied in face recognition, including face-
based gender recognition, typically involves the stages of image acquisition and
processing, dimensionality reduction, feature extraction, and classification, in that
order. Prior knowledge of the application domain is required to determine the best
feature extractor to design. In addition, the performance of the recognition system
is highly dependent on the type of classifier chosen, which is in turn
dependent on the feature extraction method applied. It is difficult to find a classifier
that combines best with the chosen feature extractor such that an optimal
classification performance is achieved. Any changes to the problem domain require a
complete re-design of the system.

2
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

1.2 Basics in Image Processing


1.2.1 Fundamentals of Digital Image

1.2.1.1 IMAGE:

An image is a two-dimensional picture, which has a similar appearance to


some subject usually a physical object or a person.

Image is a two-dimensional, such as a photograph, screen display, and as well


as a three-dimensional, such as a statue. They may be captured by optical devices—
such as cameras, mirrors, lenses, telescopes, microscopes, etc. and natural objects and
phenomena, such as the human eye or water surfaces.

The word image is also used in the broader sense of any two-dimensional figure
such as a map, a graph, a pie chart, or an abstract painting. In this wider sense, images
can also be rendered manually, such as by drawing, painting, carving, rendered
automatically by printing or computer graphics technology, or developed by a
combination of methods, especially in a pseudo-photograph.

Fig 1.1: RGB Image Fig 1.2: bitmap Image

An image is a rectangular grid of pixels. It has a definite height and a definite width
counted in pixels. Each pixel is square and has a fixed size on a given display.
However different computer monitors may use different sized pixels. The pixels that
constitute an image are ordered as a grid (columns and rows); each pixel consists of
numbers representing magnitudes of brightness and color.

3
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

Fig 1.3: Color Coding

Each pixel has a color. The color is a 32-bit integer. The first eight bits
determine the redness of the pixel, the next eight bits the greenness, the next eight bits
the blueness, and the remaining eight bits the transparency of the pixel.

Fig 1.4 Transparency of colors

1.2.1.2 Image File Sizes:

Image file size is expressed as the number of bytes that increases with the
number of pixels composing an image, and the color depth of the pixels. The greater
the number of rows and columns, the greater the image resolution, and the larger the
file. Also, each pixel of an image increases in size when its color depth increases, an
8-bit pixel (1 byte) stores 256 colors, a 24-bit pixel (3 bytes) stores 16 million colors,
the latter known as true color.

Image compression uses algorithms to decrease the size of a file. High


resolution cameras produce large image files, ranging from hundreds of kilobytes to
megabytes, per the camera's resolution and the image-storage format capacity. High
resolution digital cameras record 12 megapixel (1MP = 1,000,000 pixels / 1 million)
images, or more, in true color. For example, an image recorded by a 12 MP camera;
since each pixel uses 3 bytes to record true color, the uncompressed image would

4
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

occupy 36,000,000 bytes of memory, a great amount of digital storage for one image,
given that cameras must record and store many images to be practical. Faced with
large file sizes, both within the camera and a storage disc, image file formats were
developed to store such large images.

1.2.1.3 Image File Formats:

Image file formats are standardized means of organizing and storing


images. This entry is about digital image formats used to store photographic and other
images. Image files are composed of either pixel or vector (geometric) data that are
rasterized to pixels when displayed (with few exceptions) in a vector graphic display.
Including proprietary types, there are hundreds of image file types. The PNG, JPEG,
and GIF formats are most often used to display images on the Internet.

Fig 1.5: image representation formats

5
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

FUNDAMENTAL STEPS IN DIGITAL IMAGE PROCESSING:

Fig 1.6 Fundamental Steps In Digital Image Processing

Image Acquisition:

Image Acquisition is to acquire a digital image. To do so requires an image


sensor and the capability to digitize the signal produced by the sensor. The sensor
could be monochrome or color TV camera that produces an entire image of the
problem domain every 1/30 sec. the image sensor could also be line scan camera that
produces a single image line at a time. In this case, the objects motion past the line.

Scanner produces a two-dimensional image. If the output of the camera or


other imaging sensor is not in digital form, an analog to digital converter digitizes it.
The nature of the sensor and the image it produces are determined by the application.

Image Enhancement:

Image enhancement is among the simplest and most appealing areas of


digital image processing. Basically, the idea behind enhancement techniques is to
bring out detail that is obscured, or simply to highlight certain features of interesting
an image. A familiar example of enhancement is when we increase the contrast of an
image because ―it looks better.‖ It is important to keep in mind that enhancement is a
very subjective area of image processing.

6
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

Fig 1.7 Example of Image Enhancement

1.2.1.4 Image restoration:

Image restoration is an area that also deals with improving the appearance of
an image. However, unlike enhancement, which is subjective, image restoration is
objective, in the sense that restoration techniques tend to be based on mathematical or
probabilistic models of image degradation.

Fig 1.8: Example of Image Restoration

Enhancement, on the other hand, is based on human subjective preferences regarding


what constitutes a ―good‖ enhancement result. For example, contrast stretching is
considered an enhancement technique because it is based primarily on the pleasing
aspects it might present to the viewer, whereas removal of image blur by applying a
deblurring function is considered a restoration technique.

7
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

Color image processing:

The use of color in image processing is motivated by two principal factors.


First, color is a powerful descriptor that often simplifies object identification and
extraction from a scene. Second, humans can discern thousands of color shades and
intensities, compared to about only two dozen shades of gray. This second factor is
particularly important in manual image analysis.

Fig 1.9: Example of Color image processing

Segmentation: procedures partition an image into its constituent parts or objects. In


general, autonomous segmentation is one of the most difficult tasks in digital image
processing. A rugged segmentation procedure brings the process a long way toward
successful solution of imaging problems that require objects to be identified
individually.

Fig 1.10: Example of Segmentation

On the other hand, weak or erratic segmentation algorithms almost always


guarantee eventual failure. In general, the more accurate the segmentation, the more
likely recognition is to succeed.

Digital image is defined as a two dimensional function f(x, y), where x and y
are spatial (plane) coordinates, and the amplitude of f at any pair of coordinates (x,
y) is called intensity or grey level of the image at that point. The field of digital image

8
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

processing refers to processing digital images by means of a digital computer. The


digital image is composed of a finite number of elements, each of which has a
particular location and value. The elements are referred to as picture elements, image
elements, pels, and pixels. Pixel is the term most widely used.

1.3 Data mining Techniques

Fuzzy clustering:

The central idea in fuzzy clustering is the non-unique partitioning of the data into a
collection of clusters. The data points are assigned membership values for each of the
clusters and fuzzy clustering algorithm allow the clusters to grow into their natural
shapes. The fuzzy clustering algorithms can be divided into two types 1) Classical
fuzzy clustering algorithms 2) Shape based fuzzy clustering algorithms. Classical
fuzzy clustering algorithms can be divided into three types.1) The Fuzzy C-Means
algorithm 2) The Gustafson-Kessel algorithm 3) The Gath-Geva algorithm. Shape
based fuzzy clustering algorithm can be divided into 1) Circular shape based
clustering algorithm 2) Elliptical shape based clustering algorithm 3) Generic shape
based clustering algorithm. In this paper, represent a review on fuzzy c means, and
extended version of fcm such as pcm, fpcm and their advantages and disadvantages of
real time applications.

K- Nearest Neighbor Classifier:


The simplest classification scheme is a nearest neighbor classification in the image
space. Under this scheme an image in the test set is recognized by assigning to it the
label of the closest point in the learning set, where distance are measured in image
space. If all images have been normalized to be zero mean and have unit variance,
then this procedure is equivalent to choosing the image in learning set that best
correlates with the test image. Because of normalization process, the result is
independent of light source intensity and the effects of a videos cameras automatic
gain control. Feature selection is achieved using this learning algorithm by
constraining each classifier to depend on only a single feature .The Euclidean distance
metric is often chosen to determine the closeness between the data points in KNN.

9
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

1.4 Applications
Gender recognition is important because it finds its strong applications in fields of

• Authentication

• Demographic data collection

• Human computer interaction

• Access control and surveillance involving frontal facial images.

There are several large applications such as

• US VISIT (United States Visitor And Immigrant Status Indicator Technology)

• India’s UID (Unique Identification Authority of India) project that store face images.

10
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

CHAPTER 2

LITERATURE SURVEY

2.1 Literature Review and Survey Papers


[1] A Hybrid Approach to Gender Classification from Face Images Ziyi Xu, Li
Lu and Pengfei Shi
Description: Gender classification from face images has attracted a great deal of
attention. It can be useful in many places. In this paper, a novel hybrid face coding
method by fusing appearance features and geometry features is presented. We choose
Haar wavelets to represent the appearance features and use Adaboost algorithm to
select stronger features. Geometry features are regarded as a priori knowledge to help
improve the classification performance. Experimental results show the effectiveness
and robustness of the proposed approach regarding expression, illumination and pose
variation in some degree.
Method: In this method Haar-like features introduced by Viola and improved by
Lienhart to be the weak classifiers. Each rectangle feature computes the sum of the
pixels which lie within the white rectangles are subtracted from the sum of pixels in
the black rectangles. Within any image sub-window the total number of Rectangular
features is very large. Drawing an analogy between weak classifiers and features, the
AdaBoost algorithm is an effective procedure for searching out strong features. It
excludes a lot of ―useless‖ features, and focus on a small set of ―useful‖ features,
which contains much more gender information than the others.
Advantages
1. Hybrid method obtains a higher accuracy.
2. The novel classification method shows effectiveness and robustness regarding
expression, illumination and pose variation in some degree.
Limitations

1) Haar fails to detect face changes accurately due to down sampling.

2) Geometric methods are slow and complex and not providing an optimal result.

11
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

[2] Hyun- Chul Kim, Daijin Kim: Gender Classification with Bayesian Kernel
Methods

Description: We consider the gender classification task of discriminating between


images of faces of men and women from face images. In appearance-based
approaches, the initial images are preprocessed (e.g. normalized) and input into
classifiers. Recently, SVMs which are popular kernel classifiers have been applied to
gender classification and have shown excellent performance. We propose to use one
of Bayesian kernel methods which is Gaussian Process Classifiers (GPCs) for gender
classification. The main advantage of Bayesian kernel methods such as GPCs over
SVMs is that they determine the hyper parameters of the kernel based on Bayesian
model selection criterion. Our results show that GPCs outperformed SVMs with cross
validation.

Method: The EM-EP algorithm to learn Gaussian process classifiers for gender
classification. We expect that GPCs with the EM-EP algorithm work better than
SVMs with the cross validation and provide better hyper parameters for the kernels of
SVMs. In the experiments the hyper parameters obtained by GPC with the EM-EP
algorithm were even more suitable for SVMs than the ones obtained by cross
validation. GPCs worked better than SVMs and provided kernel hyper parameters to
make SVMs work better. We used Gaussian kernels in this paper.

Gaussian kernels do not seem to be ideal for image data since they do not
capture correlations between pixels. If we invent more proper kernels for face images,
we might improve the performance. It would also be interesting to perform
experiments on a larger face dataset.

Advantages

1. It preserves appearance of face images which can be considered to be naive


features

2. SVMs worked better than other classifiers such as ensemble of RBF networks,
classical RBF networks

Issues:

12
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

1) Limited performance in face feature representation.

2) Low accuracy in terms of illuminance detection and classification

[4] “Gender Recognition from Faces Using Bandlet and Local Binary Patterns”

In this paper, multi-scale bandlet and local binary pattern (LBP) based method for
gender recognition from faces is proposed. Bandlet is one of the multi-resolution
techniques that can adapt the orientation of the edges of the face images, and thereby
can better capture the texture of a face image. After extracting bandlet coefficients
from face images at different scales, LBP is applied to create a histogram, which is
used as the feature to a minimum distance classifier. The experiments are performed
using FERET gray scale face database, and the highest accuracy of 99.13% is
obtained with the proposed method.
Advantages
Better performance of the local binary pattern operator over other texture descriptors
is its tolerance to monotonic gray-scale changes.
Additional advantages are the computational efficiency of the LBP operator and that
no gray-scale normalization is needed prior to applying the LBP operator to the face
image.
Limitations

Geometric methods doesn’t provide the optimal results

[5] “Gender classification from face images based using Weber’s local descript
Gender Recognition from Face Pictures with Native WLD Descriptor and Neural
Network Approach”

In various biometric applications, gender recognition from facial images plays an


important role. In this paper, we investigate Weber’s Local Descriptor (WLD) for
gender recognition. WLD is a texture descriptor that performs better than other
similar descriptors but it is holistic due to its very construction. From WLD we will
obtain the significant properties of face images. Here an approach for developing an
automatic system to classify gender from a facial image using Neural Network
Classifier is presented. The significant features are allowed to feed as input to the
neural network.

13
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

Advantages

Robustness to noise and illumination changes

Low complexity

Better edge detection and image representation

Limitations

Occlusions in image representation

[6] “Facial Feature Extraction Using Geometric Feature and Independent


Component Analysis”

Automatic facial feature extraction is one of the most important and attempted
problems in computer vision. It is a necessary step in face recognition, facial image
compression. There are many methods have been proposed in the literature for the
facial feature extraction task. However, all of them have still disadvantage such as not
complete reflection about face structure, face texture. Therefore, a combination of
different feature extraction methods which can integrate the complementary
information should lead to improve the efficiency of feature extraction stage. In this
paper we describe a methodology for improving the efficiency of feature extraction
stage based on the association of two methods: geometric feature based method and
Independent Component Analysis (ICA) method.
Comparison of two methods of facial feature extraction: geometric feature
based method combined with PCA method (called GPCA) versus geometric feature
based method combined with ICA method (called GICA) on CalTech dataset has
demonstrated the efficiency of GICA method. Our results show that GICA achieved
good performance 80% compared to 88% of GPCA method. Furthermore, we
compare two methods mentioned above on our dataset, with performance of GICA
being 80% better 82% of GPCA method. The experiment results have confirmed the
benefits of the association geometric feature based method and ICA method in facial
feature extraction.
Limitations
1. Less accurate of features description because of whole image consideration
2. Poor edge detection and texture representation

14
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

2.2 Methods used in Survey Papers

2.2.1 Principal Component Analysis

PCA is a mathematical procedure that uses an orthogonal transformation to


convert a set of observations of possibly correlated variables into a set of values of
linearly uncorrelated variables called principal components. The number of principal
components is less than or equal to the number of original variables. This
transformation is defined in such a way that the first principal component has the
largest possible variance (that is, accounts for as much of the variability in the data as
possible), and each succeeding component in turn has the highest variance possible
under the constraint that it be orthogonal to (i.e., uncorrelated with) the preceding
components. Principal components are guaranteed to be independent only if the data
set is jointly normally distributed. PCA is sensitive to the relative scaling of the
original variables. Depending on the field of application, it is also named the discrete
Karhunen–Loève transform (KLT), the Hotelling transform or proper orthogonal
decomposition (POD).

Drawbacks
 Poor discriminatory power

 High computational load

2.2.2 Discrete Wavelet Transform:

In mathematics, a wavelet series is a representation of a square-


integrable(real-or complex-valued) function by certain orthonormal series generated
by a wavelet. This article provides a formal, mathematical definition of an
orthonormal wavelet and of the integral wavelet transform.

Definition A function   L2 R  is called an orthonormal wavelet if it can be used


to define a Hilbert basis, that is a complete orthonormal system, for the
Hilbert of square integrable functions.

 jk ,  lm =  jl , km

15
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

Where  jl is the Kronecker delta

Drawbacks

 Loss of edge details due to shift variant property.

2.2.3 Geometric Methods based Gender Recognition:

Hierarchical classifiers

Gender classification algorithms on well-aligned images perform quite well. For


multi-view facial images, however, the issue becomes much more complex. The
feature space is much larger, and designing an orientation-invariant feature is very
difficult. A commonly adopted solution is dividing the feature space into several
subspaces according to face orientations, which decomposes the multi-view problem
into easier classification tasks on simpler subspaces.

We adopted a two-layered structure. The first layer includes an orientation


classifier, which extracts feature vectors from the original image and classifies it into
several categories according to its orientation. Then the task of gender classification is
passed to the next layer where we make use of experts of gender classification for
certain orientations.

As errors in the first layer will propagate to the following steps, the accuracy
of the orientation classification is important for the whole problem. One source of
error is the boundary effect of hard assignment. For a face whose orientation lies on
the boundary of two categories, it is unreasonable to simply put it into one of them.
Therefore, we estimate the confidence that one face falls in each orientation category.
After obtaining the results from the gender classifiers in the following stage, we
compute the weighted-sum using the orientation confidence. In this paper, we use the
approach proposed by Huang and Shao for face pose classification.

 Symmetric trick

Human faces are bilaterally symmetrical. There may be some special characteristics
on someone’s face which could be the decisive evidence to recognize a certain person.
But in the area of gender classification, the special characteristics are not so

16
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

important. Thus, whether the characteristic is on the left cheek or right would not
affect the result of gender classification. In most cases, the face images are exactly
bilaterally symmetrical. We can identify a person in an image as a man or a women
according to the geometric measurements of the face and organs, the position of the
facial components, the style of hair, the texture of the skin, and many other details on
the face. A symmetric process will do no harm to the feature extraction of all the
above information. In fact, we cannot know if the face in the following image is
originally facing left or right.

Fig 2.1: Example For Hierarchical classifiers

The bilateral symmetry of the human face is one reason for us to select the
yaw rotation from the three possibilities. Because the space of the problem can be cut
to a half if we turn all the faces which face right to face left by a horizontal flip. If we
just take one of the other two rotations, the flip would not work. The limitation of the
facial symmetric trick is that we can only handle the various situations brought by the
yaw rotation but not all three possible rotations of the human face. The performance
also depends on the accuracy of the classification to tell wether the face is turned
toward left or right. Fortunately, this is an easy task (See Sect. 6.4). Suppose we just
consider the yaw rotation of the human face and all the faces are now facing left.

The feature space is obviously a half of the original one. As a result, the
scales of training data in the expert classifiers of the hierarchical framework increase
a lot and the number of the classes into which the first layer is going to classify is also
reduced to a half. Combination of facial component classifiers Even in the same
orientation category, the alignment of facial components is still a problem that cannot
be ignored when using holistic features. Thus, Takimoto et al. extracted the features
around the eyes and mouth to bypass the complexity of different facial component

17
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

placements. Motivated by psychological experiments which prove that individual


facial components can indicate the gender, we decided to use facial components rather
than the whole face. Similar to the bag-of-words framework, we discard the spatial
relationship between the components.

Fig 2.2: Implementation of Hierarchical classifiers

We adopt the active shape model (ASM), a statistical model of the shape of
a deformable object, to get the locations of eyes, nose, mouth, and chin, and then cut a
rectangle of facial components out of the facial image. SVMs with probabilistic
outputs are trained based on each facial component in a certain angle category (See
Fig. 3.2). There are many strategies for combination of classifiers. The strategies are
mainly divided into two approaches. One is to use the probabilistic outputs of the
classifiers as input to get the result according to some optimized rules. The other
receives the feature vectors which are the input of the individual classifiers in the
former approach and trains a classifier with all this information. Both of them achieve
better performance than the individual classifier does.

 Here, we mainly evaluate the following three approaches. Simple arithmetic


rules and fuzzy integral method are the former while multiple kernel learning
presents the later.

2.2.4. Weber’s Local Descriptors


WLD is based on Weber’s Law. It has several advantages, such as detecting
edges elegantly, robustness to noise and illumination change, and its powerful
representation ability. WLD is based on a physiological law. It extracts features from
an image by simulating a human sensing his/her surroundings. Specifically, as shown
in Fig 1, a WLD uses the ratio of the intensity differences 00 s v to 01 s v, motivated
by Weber’s Law. As expected, WLD gains powerful representation ability for
textures.

18
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

Fig 2.3 :Example image considered for WLD

The detected edges match the subjective criterion elegantly since WLD
depends on the perceived luminance difference. For example, as shown in (2), WLD
preserves the differences ( 00 s v ) between its neighbors and a centre pixel.
Sometimes 00 s v may be quite large. But if 00 s v / 01 s v is smaller than a noticeable
threshold, there is not a noticeable edge. In contrast, 00 s v may be quite small. But if
00 s v / 01 s v is larger than a noticeable threshold, there is a noticeable edge. In Fig.
5, we show some filtered images produced by WLD, from which one could conclude
that a WLD extracts the edges of images perfectly even with heavy noise.
Furthermore, the results of texture analysis show that much of the is discriminative
texture information is contained in high spatial frequencies such as edges. Thus, the
WLD works well to obtain a powerful feature for textures. WLD is robust to noise
appearing in a given image. Specifically, a WLD reduces the influence of noise, as it
is similar to the smoothing in image processing. As shown in Figure a differential
excitation is computed by a sum of its p-neighbor differences to a current pixel. Thus,
it reduces the influence of noisy pixels. Moreover, the sum of its p-neighbor
differences is further divided by the intensity of the current pixel, which also
decreases the influence of noise in an image. WLD has been developed to reduce the
effects of illumination change. On the one hand, it computes the differences 00 s v
between its neighbors and a current pixel. Thus, a brightness change in which a
constant is added to each image pixel will not affect the differences values. On the
other hand, WLD performs the division between the differences 00 s v and 01 s v .
Thus, a change in image contrast in which each pixel value is multiplied by a constant

19
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

will multiply differences by the same constant, and this contrast change will be
cancelled by the division. Therefore, the descriptor is robust to changes in
illumination. Furthermore, regrouping the differential excitation and orientation into a
2D histogram and then weighting the different frequency segments can improve
further the performance of the WLD descriptor.

Fig: 2.4: Squared Symmetric neighborhood for different (P,R)

For LBP, it computes the intensity differences between the centre pixel
xc and its neighbors in the first stage, and the responses of each neighbor are
thresholded at zero and are then concatenated to a binary string in the second stage.
Each binary string corresponding to each pixel is then used to compute a histogram
feature in the last stage. For SIFT, it computes the gradient magnitude and orientation
at each image sample point in a region around the keypoint location in the first stage.
The orientations are quantized to 8 dominant ones in the second stage. For the third
stage, the gradient magnitudes are weighted by a Gaussian window, and then
accumulated into orientation histograms by summarizing the contents over denoted
sub-regions.

Although WLD also computes the difference between the centre pixel xc
and its neighbors like LBP in the first stage, these differences are added together and
then divided by the centre pixel xc to obtain the differential excitation like the Weber
fraction. Different from LBP, WLD uses the gradient orientations to describe the
direction of edges. The gradient orientations are then quantized to 8 dominant
orientations in the second stage. Different from SIFT, we use the differential
excitation but not the weighted gradient to compute the histogram. Moreover,
differential excitations are not accumulated over denoted sub-regions around the
keypoint location. In contrast, we compute the frequency of the occurrence of
differential excitations for each bin of the histogram, the weighted object is the

20
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

frequency of each bin, and the weights are computed according to the recognition
performance based on the statistics, not weighting the values of gradients in terms of
the distances between the neighbours and the keypoint, as does SIFT. Furthermore,
we also compare the time complexity of WLD with LBP and SIFT theoretically.
Given an image in m×n, the time complexity for WLD is very low. It is as follows:

OWLD = C1m ,n , ,

where C1 is a constant. We use C1 for the computation of each pixel in WLD through
several additions, divisions and filtering with an arctangent function. Likewise, the
time complexity for LBP is also very simple:

OLBP = C 2 mn ,

where C2 is also a constant. We use C2 for the computation of each pixel in LBP
through several additions. However, the time complexity for SIFT is a little
complicated

Drawbacks

 In appearance based methods, less accurate of features description because of


whole image consideration

 In geometric based methods, the geometric features like distance between


eyes, face length and width, etc., are considered which not provides optimal
results

21
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

CHAPTER 3

CONCEPTS AND METHODS

3.1 Problem Definition


The problem of gender is rarely heard and less attention. This system uses
the still image as an input and would classify gender based on the still image.
The other problem is most face recognition systems had at most a few hundred faces.
This becomes a problem when the number of databases increased in a system. Larger
database means longer computational and processing time. Therefore, the
identification of gender can help to better face recognition system by focusing more
on identity-related features, and limit the number of entries to be searched in a large
database, thus improving the search speed. In other words, estimation will be done on
the input image and recognition of image is done only in the estimation group.
Theoretically, it will cut the processing time almost to half.

22
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

3.2 Architecture of the proposed System

The overall approach for gender detection block diagram is shown in Fig 3.1

Face Image

Preprocessing

Laplacian of Gaussian Filter

Feature Extraction

Computation Classifier

Database Verification

Display Output

Fig: 3.1 Architecture of proposed system

1. Considering the face images from the FERET dataset.


2. Preprocessing Technique
The pre-processing of face image undergoes several processes to acquire
the transformed face image, which will increase the quality of the image by keeping
prominent features. Noise reduction, color conversion and edge detection are some of
the pre-processing methods.
The edge detection algorithm is based on the following factors:

23
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

• Good detection - the algorithm used must point out as many real images as
possible.
• Minimal response - a given edge must mark only once in a possible way; the
noise, if any, in an image should not create false detection of an edge.
• Good localization - the marked edges should always be nearer to the real
image.
• Lighting compensation we adjust the locations of the lights to change the
lighting condition. The total energy of an image is the sum of the squares of
the intensity values.
3. Lapalacian of Gaussian Filter
Lapalacian of Gaussian Filter is used to filter noise before edge detection. This
method combines Gaussian filtering with the Laplacian for edge detection.
In Laplacian of Gaussian edge detection there are mainly three steps:
• Filtering
• Enhancement
• Detection
The LoG is a bandpass filter; we can therefore fold the spectrum of the image
(after low pass filtering) without loss of information, which is equivalent to reducing
the resolution.
The Laplacian of an image highlights regions of rapid intensity change and is
therefore often used for edge detection The Laplacian is often applied to an image that
has first been smoothed with something approximating a Gaussian smoothing filter in
order to reduce its sensitivity to noise. The operator normally takes a single graylevel
image as input and produces another graylevel image as output.
The Laplacian L(x,y) of an image with pixel intensity values I(x,y) is given by:
2I 2I
L ( x, y )  
x 2 y 2

• Laplacian is a measure of the second spatial derivative of an image


• Very useful in detecting abrupt changes
• In edge detection, Gaussian smoothing is done prior to Laplacian to remove
the effect of noise.

24
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

4. Facial region extraction: we adopt the face detection method. The method for
detecting and extracting the facial features in a gray-level image is divided into two
stages. First, the possible human eye regions are detected by testing all the valley
regions in an image. A pair of eye candidates is selected by means of the genetic
algorithm to form a possible face candidate. In our method, a square block is used to
represent the detected face region.

Computation

Compute the Euclidean distance matrix between pairs of feature vectors in the
training,

1. Set diagonal elements of this matrix to infinity,

2. Sort the distance matrix in ascending order,

3. Collect the class labels of the patterns located in the closest neighborhood of the
pattern,

4. Compute the membership grade to test class labels.

3.4 Proposed Method

Gender classification method using frontal facial images of people. The proposed
approach employs nearest neighbor classifier (NN) and fuzzy clustering technique,
respectively, for feature extraction and classification steps.

Fuzzy Clustering
FCM is a data clustering algorithm in which each data point associated with cluster
through a membership degree. This technique divides a group of N data points into r
fuzzy groups and finds a cluster center in each group, such that a cost of function of a
dissimilarity measure is minimized. Fuzzy clustering algorithm is used to reduce the
misclassified faces by excluding or modifying the low membership face images.

25
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

K-nearest neighbor (KNN)


This classifier is a simple algorithm that stores all available examples and classifies
new instances of the example language based on a similarity measure. It exploits lazy
learning [9]. For each test image ( to be predicted), locate the k closest members (the
K nearest neighbors) of the training data set.

Advantages
Fuzzy clustering approach outperforms the other methods for the datasets considered.
• Sensitivity variations in illumination and facial expression reduced
substantially.
• Fuzzy sets can efficiently manage the vagueness and ambiguity of face
images degraded by poor illumination component.

So far, many techniques have been proposed that can be used as a distinct
feature from facial images, which are given to binary classifier. The feature extraction
techniques are mainly based on geometric and appearance. Geometric features are
mainly based on distance between eyes, eye to ear, face length and face width; these
features are used by machine to classify a face image based on gender. Another
approach is appearance based approach that uses whole face image containing
thousands of pixels which is reduced to handful number of pixels by dimensionally
reduction schemes. For this image is transformed into other domain and features are
selected from that domain.

Clustering

In Clustering, one of the most widely used algorithms is fuzzy clustering


algorithms. Fuzzy set theory was first proposed by Zadeh in 1965 & it gave an idea of
uncertainty of belonging which was described by a membership function. The use of
fuzzy set provides imprecise class membership function. Applications of fuzzy set
theory in cluster analysis were early proposed in the work of Bellman, Zadeh, and
Ruspini This paper opens door step of fuzzy clustering [2]. Integration of fuzzy logic
with data mining techniques has become one of the key constituents of soft computing
in handling challenges posed by massive collections of natural data.

26
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

The central idea in fuzzy clustering is the non-unique partitioning of the data
into a collection of clusters. The data points are assigned membership values for each
of the clusters and fuzzy clustering algorithm allow the clusters to grow into their
natural shapes [3]. The fuzzy clustering algorithms can be divided into two types 1)
Classical fuzzy clustering algorithms 2) Shape based fuzzy clustering algorithms.
Classical fuzzy clustering algorithms can be divided into three types.1) The Fuzzy C-
Means algorithm 2) The Gustafson-Kessel algorithm 3) The Gath-Geva algorithm.
Shape based fuzzy clustering algorithm can be divided into 1) Circular shape based
clustering algorithm 2) Elliptical shape based clustering algorithm 3) Generic shape
based clustering algorithm. In this paper, represent a review on fuzzy c means, and
extended version of fcm such as pcm, fpcm and their advantages and disadvantages of
real time applications.

Fuzzy clustering is a class of algorithms for cluster analysis in which the allocation
of data points to clusters is not "hard" (all-or-nothing) but "fuzzy" in the same sense as fuzzy
logic. Data clustering is the process of dividing data elements into classes or clusters so that
items in the same class are as similar as possible, and items in different classes are as
dissimilar as possible. Depending on the nature of the data and the purpose for which
clustering is being used, different measures of similarity may be used to place items into
classes, where the similarity measure controls how the clusters are formed.
Some examples of measures that can be used as in clustering include distance,
connectivity, and intensity. In hard clustering, data is divided into distinct clusters, where
each data element belongs to exactly one cluster. In fuzzy clustering (also referred to as soft
clustering), data elements can belong to more than one cluster, and associated with each
element is a set of membership levels. These indicate the strength of the association between
that data element and a particular cluster.
Fuzzy clustering is a process of assigning these membership levels, and then using
them to assign data elements to one or more clusters. In fuzzy c-means clustering, each point
has a degree of belonging to clusters, as in fuzzy logic, rather than belonging completely to
just one cluster. Thus, points on the edge of a cluster, may be in the cluster to a lesser degree
than points in the center of cluster.

Ck 
 w ( x) x
x k
m

 w ( x)
x k
m

27
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

Any point x has a set of coefficients giving the degree of being in the kth cluster wk(x).
With fuzzy c-means, the centroid of a cluster is the mean of all points, weighted by their
degree of belonging to the cluster:
The degree of belonging, wk(x), is related inversely to the distance from x
to the cluster center as calculated on the previous pass. It also depends on a
parameter m that controls how much weight is given to the closest center.

Using a mixture of Gaussians along with the expectation-maximization


algorithm is a more statistically formalized method which includes some of these
ideas: partial membership in classes. Another algorithm closely related to Fuzzy C-
Means is Soft K-means. Fuzzy c-means has been a very important tool for image
processing in clustering objects in an image. In the 70's, mathematicians introduced
the spatial term into the FCM algorithm to improve the accuracy of clustering under
noise.
Fuzzy Clustering Means
In fuzzy clustering (also referred to as soft clustering), data elements can belong
to more than one cluster, and associated with each element is a set of membership
levels. These indicate the strength of the association between that data element and a
particular cluster. Fuzzy clustering is a process of assigning these membership levels,
and then using them to assign data elements to one or more clusters.

The algorithm employs fuzzy partitioning such that a given data point can belong
to several groups with a degree specified by membership grades between 0 and 2.

Fuzzy Clustering Algorithm

1. Choose a number of clusters.


2. Assign randomly to each point coefficient for being in the clusters.
3. Repeat until the algorithm has converged.
4. Compute the centroid for each cluster.
5. For each point, compute its coefficients of being in the clusters.

Gender recognition has been an active research topic since the early nineties.
There have been several advances in the past few years in terms of face detection and
tracking, feature extraction mechanisms and the related machine learning techniques.

28
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

Face recognition has drawn the attention of researchers in fields from image analysis
and processing, computer vision, to psychology and security [1]. In spite of more than
fifteen years of extensive re-search, large number of papers published in journals and
conferences dedicated to this area, we still cannot claim that automatic face
recognition is comparable to human performance [2]. The difficulty of automatic face
recognition is due to various effects like aging, facial expressions, occlusions, lighting
and viewpoint changes induced by body movement [3].
A successful face recognition mythology depends heavily on the particular
choice of the features, observation reduction and classification method. In this paper
four algorithms have introduced, modified and combined to enhance the face
recognition and detection [4]. The features are extracted using Fourier-Gabor filter
and selected by generalizing signal to noise equation. Modified fuzzy clustering
algorithm is used to reduce the misclassified faces by excluding or modifying the low
membership faces. Furthermore a new non-linear kernel is used to kernel the least
square method and the wild dog pack optimization is implemented to find the optimal
parameters. The suggested method is implemented by using four datasets: AT & T
database of faces (ATT), Indian Face Database (IFD), Faces95 from Essex university
database and Yale face database (Yale)

Feature Extraction and Selection There are several methods have been used to
extract the features from the face images, one among the best methods is Fourier-
Gabor filter which is introduced in [8]. Therefore the same method will be used in this
study to extract the features from the face images. However different size, orientation
and scale values are adopted in this study. The main steps are as following:
1) Resize the images to 40 × 40
2) Transform the images to frequency domain by applying Fourier transform in
Equation (3)
3) Use Equation (4) to prepare 8 Gabor filters for orientation and 10 filters for scaling.
Thus 80 different filters will be constructed
4) Multiply the result matrix in step 2 by each matrix in step 3.
5) Resize each matrix in step 4 as one row
6) construct the feature vector for each face by concatenation all the rows in step 5.

29
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

K-nearest neighbor (KNN).


This classifier is a simple algorithm that stores all available examples and classifies
new instances of the example language based on a similarity measure. It exploits lazy
learning [9]. For each test image ( to be predicted), locate the k closest members (the
K nearest neighbors) of the training data set. A Euclidean Distance mea sure is used to
calculate how close each member of the training set is to the test class that is being
examined. From this K nearest neighbor, we find their class labels and apply majority
voting to determine the class label of test image. The best choice of k depends upon
the data; generally, larger values of k reduce the effect of noise on the classification,
but make boundaries between classes less distinct.

Feature Extraction,
Face Detection Normalization

Decision
KNN Classifier
Male/Female

Fig: 3.2 Gender Recognition System

30
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

CHAPTER 4
IMPLEMENTATION
4.1 Functional Requirements

System Configuration:

Hardware System Configuration:-

Processor - Pentium –IV


Speed - 1.1 Ghz
RAM - 256 MB(min)
Hard Disk - 20 GB
Floppy Drive - 1.44 MB
Key Board - Standard Windows Keyboard
Mouse - Two or Three Button Mouse
Monitor - SVGA

Software System Configuration:-


Operating System : Windows95/98/2000/XP

Front End : MATLAB

4.2 Project Modules


Object recognition based on invariant features extraction with correlation
measurement

1. Test Image

2. Face Detection

3. Normalization

4. Features Extraction

5. Classification

6. Decision making

31
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

Test Image

Test image is nothing but an input image that to be compared with database
images for classification or authentication.

Face detection Face detection is a computer technology that determines the


locations and sizes of human faces in digital images. It detects facial features
and ignores anything else, such as buildings, trees and bodies.

Normalization

Removing the unwanted distortions which acquired from the input face images

Feature Extraction

Calculate the similar features of the given image by comparing the pixel
values and group them to form a cluster by using Fuzzy clustering.

Classification

The k-NN classifier is used to classify the different face images. The
Euclidean distance between the testing image feature and the training image
feature and a distance matrix is created.

In the distance matrix first k values are considered as and majority label of the
k value is considered as the correct label of the given testing image.

Detection

Based on the output of classifier, the test image will be classified as


male/female.

32
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

4.3 Tools

MATLAB

MATLAB is a high-performance language for technical computing. It integrates


computation, visualization, and programming in an easy-to-use environment where
problems and solutions are expressed in familiar mathematical notation. Typical uses
include:

 Math and computation

 Algorithm development

 Modeling, simulation, and prototyping

 Data analysis, exploration, and visualization

 Scientific and engineering graphics

 Application development, including graphical user interface building

MATLAB is an interactive system whose basic data element is an


array that does not require dimensioning. This allows you to solve many technical
computing problems, especially those with matrix and vector formulations, in a
fraction of the time it would take to write a program in a scalar noninteractive
language such as C or FORTRAN.

The name MATLAB stands for matrix laboratory. MATLAB was originally written
to provide easy access to matrix software developed by the LINPACK and EISPACK
projects. Today, MATLAB uses software developed by the LAPACK and ARPACK
projects, which together represent the state-of-the-art in software for matrix
computation.

MATLAB has evolved over a period of years with input from many
users. In university environments, it is the standard instructional tool for introductory
and advanced courses in mathematics, engineering, and science. In industry,
MATLAB is the tool of choice for high-productivity research, development, and
analysis.

33
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

MATLAB features a family of application-specific solutions called


toolboxes. Very important to most users of MATLAB, toolboxes allow you to learn
and apply specialized technology. Toolboxes are comprehensive collections of
MATLAB functions (M-files) that extend the MATLAB environment to solve
particular classes of problems. Areas in which toolboxes are available include signal
processing, control systems, neural networks, fuzzy logic, wavelets, simulation, and
many others.

The MATLAB System

The MATLAB system consists of five main parts:

Development Environment. This is the set of tools and facilities that help you use
MATLAB functions and files. Many of these tools are graphical user interfaces. It
includes the MATLAB desktop and Command Window, a command history, and
browsers for viewing help, the workspace, files, and the search path.

The MATLAB Mathematical Function Library. This is a vast collection of


computational algorithms ranging from elementary functions like sum, sine, cosine,
and complex arithmetic, to more sophisticated functions like matrix inverse, matrix
eigenvalues, Bessel functions, and fast Fourier transforms.

The MATLAB Language. This is a high-level matrix/array language with control


flow statements, functions, data structures, input/output, and object-oriented
programming features. It allows both "programming in the small" to rapidly create
quick and dirty throw-away programs, and "programming in the large" to create
complete large and complex application programs.

Handle Graphics®. This is the MATLAB graphics system. It includes high-level


commands for two-dimensional and three-dimensional data visualization, image
processing, animation, and presentation graphics. It also includes low-level
commands that allow you to fully customize the appearance of graphics as well as to
build complete graphical user interfaces on your MATLAB applications.

The MATLAB Application Program Interface (API). This is a library that allows
you to write C and FORTRAN programs that interact with MATLAB. It include

34
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

facilities for calling routines from MATLAB (dynamic linking), calling MATLAB as
a computational engine, and for reading and writing MAT-files.

4.3.1 DEVELOPMENT ENVIRONMENT

Introduction

This chapter provides a brief introduction to starting and quitting MATLAB, and
the tools and functions that help you to work with MATLAB variables and files. For
more information about the topics covered here, see the corresponding topics under
Development Environment in the MATLAB documentation, which is available online
as well as in print.

Starting and Quitting MATLAB

Starting MATLAB

On a Microsoft Windows platform, to start MATLAB, double-click the


MATLAB shortcut icon on your Windows desktop.

On a UNIX platform, to start MATLAB, type matlab at the operating system


prompt.

After starting MATLAB, the MATLAB desktop opens - see MATLAB Desktop.

You can change the directory in which MATLAB starts, define startup options
including running a script upon startup, and reduce startup time in some situations.

Quitting MATLAB

To end your MATLAB session, select Exit MATLAB from the File menu in
the desktop, or type quit in the Command Window. To execute specified functions
each time MATLAB quits, such as saving the workspace, you can create and run a
finish.m script.

MATLAB Desktop

35
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

When you start MATLAB, the MATLAB desktop appears, containing


tools (graphical user interfaces) for managing files, variables, and applications
associated with MATLAB.

The first time MATLAB starts, the desktop appears as shown in the
following illustration, although your Launch Pad may contain different entries.

You can change the way your desktop looks by opening, closing,
moving, and resizing the tools in it. You can also move tools outside of the desktop or
return them back inside the desktop (docking). All the desktop tools provide common
features such as context menus and keyboard shortcuts.

You can specify certain characteristics for the desktop tools by


selecting Preferences from the File menu. For example, you can specify the font
characteristics for Command Window text. For more information, click the Help
button in the Preferences dialog box.

Desktop Tools

This section provides an introduction to MATLAB's desktop tools.


You can also use MATLAB functions to perform most of the features found in the
desktop tools. The tools are:

 Current Directory Browser

 Workspace Browser

 Array Editor

 Editor/Debugger

 Command Window

 Command History

 Launch Pad

 Help Browser

36
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

Command Window Use the Command Window to enter variables and run functions
and M-files.

Command History

Lines you enter in the Command Window are logged in the Command
History window. In the Command History, you can view previously used functions,
and copy and execute selected lines. To save the input and output from a MATLAB
session to a file, use the diary function.

Running External Programs

You can run external programs from the MATLAB Command


Window. The exclamation point character! is a shell escape and indicates that the rest
of the input line is a command to the operating system. This is useful for invoking
utilities or running other programs without quitting MATLAB. On Linux, for
example,!emacs magik.m invokes an editor called emacs for a file named magik.m.
When you quit the external program, the operating system returns control to
MATLAB.

Launch Pad

MATLAB's Launch Pad provides easy access to tools, demos, and


documentation.

Help Browser

Use the Help browser to search and view documentation for all your Math
Works products. The Help browser is a Web browser integrated into the MATLAB
desktop that displays HTML documents.

To open the Help browser, click the help button in the toolbar, or type help
browser in the Command Window. The Help browser consists of two panes, the Help
Navigator, which you use to find information, and the display pane, where you view
the information.

Help Navigator

37
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

Use to Help Navigator to find information. It includes:

Product filter: Set the filter to show documentation only for the products you
specify.

Contents tab: View the titles and tables of contents of documentation for your
products.

Index tab: Find specific index entries (selected keywords) in the MathWorks
documentation for your products.

Search tab: Look for a specific phrase in the documentation. To get help for a
specific function, set the Search type to Function Name.

Favorites tab: View a list of documents you previously designated as favorites.

Display Pane

After finding documentation using the Help Navigator, view it in the display
pane. While viewing the documentation, you can:

Browse to other pages - Use the arrows at the tops and bottoms of the pages, or use
the back and forward buttons in the toolbar.

Bookmark pages : Click the Add to Favorites button in the toolbar.

Print pages - Click the print button in the toolbar.

Find a term in the page - Type a term in the Find in page field in the toolbar and
click Go.

Other features available in the display pane are: copying information, evaluating a
selection, and viewing Web pages.

Current Directory Browser

MATLAB file operations use the current directory and the search path as
reference points. Any file you want to run must either be in the current directory or on
the search path

38
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

Search Path

To determine how to execute functions you call, MATLAB uses a search path
to find M-files and other MATLAB-related files, which are organized in directories
on your file system. Any file you want to run in MATLAB must reside in the current
directory or in a directory that is on the search path. By default, the files supplied with
MATLAB and MathWorks toolboxes are included in the search path.

Workspace BrowserThe MATLAB workspace consists of the set of variables


(named arrays) built up during a MATLAB session and stored in memory. You add
variables to the workspace by using functions, running M-files, and loading saved
workspaces.

To view the workspace and information about each variable, use the
Workspace browser, or use the functions.

To delete variables from the workspace, select the variable and select Delete
from the Edit menu. Alternatively, use the clear function.

Array Editor

Double-click on a variable in the Workspace browser to see it in the Array


Editor. Use the Array Editor to view and edit a visual representation of one- or two-
dimensional numeric arrays, strings, and cell arrays of strings that are in the
workspace.

Editor/Debugger

Use the Editor/Debugger to create and debug M-files, which are programs you
write to run MATLAB functions. The Editor/Debugger provides a graphical user
interface for basic text editing, as well as for M-file debugging.

You can use any text editor to create M-files, such as Emacs, and can
use preferences (accessible from the desktop File menu) to specify that editor as the
default. If you use another editor, you can still use the MATLAB Editor/Debugger for
debugging, or you can use debugging functions, such as dbstop, which sets a
breakpoint.

39
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

MANIPULATING MATRICES

Entering Matrices

The best way for you to get started with MATLAB is to learn how to handle
matrices. Start MATLAB and follow along with each example.

You can enter matrices into MATLAB in several different ways:

 Enter an explicit list of elements.

 Load matrices from external data files.

 Generate matrices using built-in functions.

 Create matrices with your own functions in M-files.

Start by entering Dürer's matrix as a list of its elements. You have only to follow a
few basic conventions:

 Separate the elements of a row with blanks or commas.

 Use a semicolon, ; , to indicate the end of each row.

 Surround the entire list of elements with square brackets, [ ].

To enter Dürer's matrix, simply type in the Command Window

A = [16 3 2 13; 5 10 11 8; 9 6 7 12; 4 15 14 1]

MATLAB displays the matrix you just entered.

A=

16 3 2 13

5 10 11 8

9 6 7 12

4 15 14 1

40
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

This exactly matches the numbers in the engraving. Once you have entered the
matrix, it is automatically remembered in the MATLAB workspace. You can refer to
it simply as A.

Expressions Like most other programming languages, MATLAB provides


mathematical expressions, but unlike most programming languages, these expressions
involve entire matrices. The building blocks of expressions are:

Variables

MATLAB does not require any type declarations or dimension statements. When
MATLAB encounters a new variable name, it automatically creates the variable and
allocates the appropriate amount of storage. If the variable already exists, MATLAB
changes its contents and, if necessary, allocates new storage. For example,

num_students = 25

Creates a 1-by-1 matrix named num_students and stores the value 25 in its single
element.

Variable names consist of a letter, followed by any number of letters, digits,


or underscores. MATLAB uses only the first 31 characters of a variable name.
MATLAB is case sensitive; it distinguishes between uppercase and lowercase letters.
A and a are not the same variable. To view the matrix assigned to any variable, simply
enter the variable name.

Operators Expressions use familiar arithmetic operators and precedence rules.

+ Addition

- Subtraction

* Multiplication

/ Division

41
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

\ Left division (described in "Matrices and Linear Algebra" in


Using MATLAB)

^ Power

' Complex conjugate transpose

() Specify evaluation order

Functions

MATLAB provides a large number of standard elementary mathematical


functions, including abs, sqrt, exp, and sin. Taking the square root or logarithm of a
negative number is not an error; the appropriate complex result is produced
automatically. MATLAB also provides many more advanced mathematical functions,
including Bessel and gamma functions. Most of these functions accept complex
arguments. For a list of the elementary mathematical functions, type help elfun

For a list of more advanced mathematical and matrix functions,

type

help specfun

help elmat

Some of the functions, like sqrt and sin, are built-in. They are part of
the MATLAB core so they are very efficient, but the computational details are not
readily accessible. Other functions, like gamma and sin, are implemented in M-files.
You can see the code and even modify it if you want.

Figure

Figures are the windows that contain the GUI you design with the Layout
Editor. See the description of figure properties for information on what figure
characteristics you can control.

GUI

42
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

A graphical user interface (GUI) is a user interface built with graphical objects,
such as buttons, text fields, sliders, and menus. In general, these objects already have
meanings to most computer users. For example, when you move a slider, a value
changes; when you press an OK button, your settings are applied and the dialog box is
dismissed. Of course, to leverage this built-in familiarity, you must be consistent in
how you use the various GUI-building components.

Applications that provide GUIs are generally easier to learn and use since
the person using the application does not need to know what commands are available
or how they work. The action that results from a particular user action can be made
clear by the design of the interface.

The sections that follow describe how to create GUIs with MATLAB. This
includes laying out the components, programming them to do specific things in
response to user actions, and saving and launching the GUI; in other words, the
mechanics of creating GUIs. This documentation does not attempt to cover the "art"
of good user interface design, which is an entire field unto itself. Topics covered in
this section include:

Creating GUIs with GUIDE

MATLAB implements GUIs as figure windows containing various styles


of uicontrol objects. You must program each object to perform the intended action
when activated by the user of the GUI. In addition, you must be able to save and
launch your GUI. All of these tasks are simplified by GUIDE, MATLAB's graphical
user interface development environment.

GUI Development Environment

The process of implementing a GUI involves two basic tasks:

 Laying out the GUI components

 Programming the GUI components

GUIDE primarily is a set of layout tools. However, GUIDE also


generates an M-file that contains code to handle the initialization and launching of the

43
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

GUI. This M-file provides a framework for the implementation of the callbacks - the
functions that execute when users activate components in the GUI.

The Implementation of a GUI

While it is possible to write an M-file that contains all the commands to lay
out a GUI, it is easier to use GUIDE to lay out the components interactively and to
generate two files that save and launch the GUI:

A FIG-file - contains a complete description of the GUI figure and all of its

children (uicontrols and axes), as well as the values of all object properties.

An M-file - contains the functions that launch and control the GUI and the

callbacks, which are defined as subfunctions. This M-file is referred to as the

application M-file in this documentation.

Note that the application M-file does not contain the code that lays out
the uicontrols; this information is saved in the FIG-file.

The following diagram illustrates the parts of a GUI implementation.

4.2 Parts of GUI

44
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

4.4. Sample Code

function varargout = main(varargin)


% MAIN MATLAB code for main.fig
% MAIN, by itself, creates a new MAIN or raises the existing
% singleton*.
%
% H = MAIN returns the handle to a new MAIN or the handle to
% the existing singleton*.
%
% MAIN('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in MAIN.M with the given input arguments.
%
% MAIN('Property','Value',...) creates a new MAIN or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before main_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to main_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help main

% Last Modified by GUIDE v2.5 08-Sep-2016 18:33:45

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @main_OpeningFcn, ...
'gui_OutputFcn', @main_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT

% --- Executes just before main is made visible.

45
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

function main_OpeningFcn(hObject, eventdata, handles, varargin)


% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to main (see VARARGIN)

% Choose default command line output for main


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

% UIWAIT makes main wait for user response (see UIRESUME)


% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = main_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure


varargout{1} = handles.output;

% --- Executes on button press in pushbutton1.


function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

%%%%%Selection of input image file


[file path] = uigetfile('*.bmp;*.jpg;*.tif','Pick an Image File');

if isequal(file,0)

warndlg('File not selected');


else
inp = imread(file);
fileID = fopen('exp.txt','w');
fprintf(fileID,'%s',strcat(file));
fclose(fileID);
imwrite(imread(file),'input1.jpg');
inp = imresize(inp,[256,256]);
axes(handles.axes1);
imshow(inp);
imwrite(imresize(inp,[256 384]),'input.jpg');

46
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

if size(inp,3)>1
inp = rgb2gray(inp);
end
axes(handles.axes2);
imshow(inp);
title('Test Image Gray Scale Part');
end
%handles.inp=inp;

% --- Executes on button press in pushbutton2.


function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
img = imread('input.jpg');
J=img;
FaceDetect = vision.CascadeObjectDetector;
FaceDetect.MergeThreshold = 7 ;
BB = step(FaceDetect,img);
for i = 1:size(BB,1)
rectangle('Position',BB(i,:),'LineWidth',3,'LineStyle','- ','EdgeColor','r');
end

for i = 1:size(BB,1)
J = imcrop(img,BB(i,:));
end

imwrite(J,'Croped.jpg');
axes(handles.axes3);
imshow(J);
Freg = double(J);

%axes(handles.axes3);
%imshow(Freg,[]);
%title('Face Detection');
handles.Freg=Freg;
guidata(hObject, handles);

% --- Executes on button press in pushbutton3.


function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% --- Executes on button press in pushbutton4.


function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

47
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

%%%%%%%%%%%%%%%%%%%%%%%%%%%
fuzzycmeans(rgb2gray(imread('Croped.jpg')),2,10)

% --- Executes on button press in pushbutton5.


function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
I = rgb2gray(imread('Croped.jpg'));
corners = detectFASTFeatures(I,'MinContrast',0.1);
J = insertMarker(I,corners,'circle');
figure,imshow(J);
%%%%%%%%%%%%%%%%%%%%%%%
demo('Croped.jpg')

% --- Executes on button press in pushbutton6.


function pushbutton6_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
test

% --- Executes on button press in pushbutton7.


function pushbutton7_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
fileID = fopen('exp.txt','r');
data=fscanf(fileID,'%s');
splt=strsplit(data,'.');
C=str2num(splt{1});
if C < 300
k='female/test_set/';
Im1=rgb2gray(imread(strcat(k,data)));
t1=imread(strcat(k,data));
for i=0:13
kk=strcat(num2str(i),'.jpg');
%Im1 = rgb2gray(imresize(imread('input.jpg'),[256 384]));
Im2 = rgb2gray(imread(strcat(k,kk)));
t2=imread(strcat(k,kk));
if(t1==t2)
msgbox('FeMale');
end
%Im2=rgb2gray(imread(data));
%convert images to type double (range from from 0 to 1 instead of from 0 to
255)
Im1 = im2double(Im1);
Im2 = im2double(Im2);

48
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

%Calculate the Normalized Histogram of Image 1 and Image 2


hn1 = imhist(Im1)./numel(Im1);
hn2 = imhist(Im2)./numel(Im2);
%Calculate the histogram error
f = sum((hn1 - hn2).^2);
f=f*100;
disp(strcat(k,kk));
disp(f);
if f == 0
% clc;
disp('Result is Female');
end
end
else

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
k='male/test/';
Im1=rgb2gray(imread(strcat(k,data)));
t1=imread(strcat(k,data));
for i=301:312
kk=strcat(num2str(i),'.jpg');
% Im1 = rgb2gray(imresize(imread('input.jpg'),[256 384]));
Im2 = rgb2gray(imread(strcat(k,kk)));
t2=imread(strcat(k,kk));
if(t1==t2)
msgbox('Male');
end
% convert images to type double (range from from 0 to 1 instead of from 0 to 255)
Im1 = im2double(Im1);
Im2 = im2double(Im2);

% Calculate the Normalized Histogram of Image 1 and Image 2


hn1 = imhist(Im1)./numel(Im1);
hn2 = imhist(Im2)./numel(Im2);

% Calculate the histogram error


f = sum((hn1 - hn2).^2);
f=f*100;
disp(strcat(k,kk));
disp(f);
if f == 0
clc;
disp('Result is male');
end

end

end

49
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

function [recognized_img]=facerecog(datapath,testimg)

% In this part of function, we align a set of face images (the training set x1, x2, ... ,
xM )
%
% This means we reshape all 2D images of the training database
% into 1D column vectors. Then, it puts these 1D column vectors in a row to
% construct 2D matrix 'X'.
%
%
% datapath - path of the data images used for training
% X - A 2D matrix, containing all 1D image vectors.
% Suppose all P images in the training database
% have the same size of MxN. So the length of 1D
% column vectors is MxN and 'X' will be a (MxN)xP 2D
matrix.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%

%%%%%%%%% finding number of training images in the data path specified as


argument %%%%%%%%%%

D = dir(datapath); % D is a Lx1 structure with 4 fields as: name,date,byte,isdir of all


L files present in the directory 'datapath'
imgcount = 0;
for i=1 : size(D,1)
if not(strcmp(D(i).name,'.')|strcmp(D(i).name,'..')|strcmp(D(i).name,'Thumbs.db'))
imgcount = imgcount + 1; % Number of all images in the training database
end
end

%%%%%%%%%%%%%%%%%%%%%%%%%% creating the image matrix X


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

X = [];
for i = 1 : imgcount
str = strcat(datapath,'\',int2str(i),'.jpg');
img = imread(str);
img = rgb2gray(img);
[r c] = size(img);
temp = reshape(img',r*c,1); %% Reshaping 2D images into 1D image vectors
%% here img' is used because reshape(A,M,N) function reads the
matrix A columnwise
%% where as an image matrix is constructed with first N pixels as
first row,next N in second row so on
X = [X temp]; %% X,the image matrix with columnsgetting added for
each image

50
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Now we calculate m, A and eigenfaces.The descriptions are below :
%
% m - (MxN)x1 Mean of the training images
% A - (MxN)xP Matrix of image vectors after each vector getting
subtracted from the mean vector m
% eigenfaces - (MxN)xP' P' Eigenvectors of Covariance matrix (C) of
training database X
% where P' is the number of eigenvalues of C that best represent
the feature set
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%% calculating mean image vector %%%%%

m = mean(X,2); % Computing the average face image m = (1/P)*sum(Xj's) (j = 1 :


P)
imgcount = size(X,2);

%%%%%%%% calculating A matrix, i.e. after subtraction of all image vectors from
the mean image vector %%%%%%

A = [];
for i=1 : imgcount
temp = double(X(:,i)) - m;
A = [A temp];
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CALCULATION
OF EIGENFACES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%
%%% we know that for a MxN matrix, the maximum number of non-zero
eigenvalues that its covariance matrix can have
%%% is min[M-1,N-1]. As the number of dimensions (pixels) of each image vector
is very high compared to number of
%%% test images here, so number of non-zero eigenvalues of C will be maximum P-
1 (P being the number of test images)
%%% if we calculate eigenvalues & eigenvectors of C = A*A' , then it will be very
time consuming as well as memory.
%%% so we calculate eigenvalues & eigenvectors of L = A'*A , whose eigenvectors
will be linearly related to eigenvectors of C.
%%% these eigenvectors being calculated from non-zero eigenvalues of C, will
represent the best feature sets.

51
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

L= A' * A;
[V,D]=eig(L); %% V : eigenvector matrix D : eigenvalue matrix

%%%% again we use Kaiser's rule here to find how many Principal Components
(eigenvectors) to be taken
%%%% if corresponding eigenvalue is greater than 1, then the eigenvector will be
chosen for creating eigenface

L_eig_vec = [];
for i = 1 : size(V,2)
if( D(i,i) > 1 )
L_eig_vec = [L_eig_vec V(:,i)];
end
end

%%% finally the eigenfaces %%%


eigenfaces = A * L_eig_vec;

%In this part of recognition, we compare two faces by projecting the images into
facespace and
% measuring the Euclidean distance between them.
%
% recogimg - the recognized image name
% testimg - the path of test image
% m - mean image vector
% A - mean subtracted image vector matrix
% eigenfaces - eigenfaces that are calculated from eigenface function
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%

%%%%%%% finding the projection of each image vector on the facespace (where
the eigenfaces are the co-ordinates or dimensions) %%%%%

projectimg = [ ]; % projected image vector matrix


for i = 1 : size(eigenfaces,2)
temp = eigenfaces' * A(:,i);
projectimg = [projectimg temp];
end

%%%%% extractiing PCA features of the test image %%%%%

test_image = imread(testimg);
test_image = test_image(:,:,1);
[r c] = size(test_image);

52
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

temp = reshape(test_image',r*c,1); % creating (MxN)x1 image vector from the 2D


image
temp = double(temp)-m; % mean subtracted vector
projtestimg = eigenfaces'*temp; % projection of test image onto the facespace

%%%%% calculating & comparing the euclidian distance of all projected trained
images from the projected test image %%%%%

euclide_dist = [ ];
for i=1 : size(eigenfaces,2)
temp = (norm(projtestimg-projectimg(:,i)))^2;
euclide_dist = [euclide_dist temp];
end
[euclide_dist_min recognized_index] = min(euclide_dist);
recognized_img = strcat(int2str(recognized_index),'.jpg');
function image_out = smooth_gaussian(img,order,sig)

img2 = img;
for i=1:floor(order/2)

[h,w] = size(img2);

img2 = [img2(1,1) img2(1,:) img2(1,w);


img2(:,1) img2 img2(:,w);
img2(h,1) img2(h,:) img2(h,w)];
end

f = gauss2d(order,sig);

image_out = conv2(img2,f,'valid');

function f = gauss2d(order,sig)

f=0;
i=0;
j=0;

for x = -fix(order/2):1:fix(order/2)
j=j+1;
i=0;
for y = -fix(order/2):1:fix(order/2)
i=i+1;
f(i,j) = 1/2/pi*exp(-((x^2+y^2)/(2*sig^2)));
end
end

53
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

f = f / sum(sum(f));
function[Ifc,CI] = fuzzycmeans(I,k,Tn)

I=double(I);
[H,W]=size(I);
Icm = zeros(H,W);
IC = [];
for i=1:k
IC=cat(3,IC,I);
end

%Random initialization of cluster centers

cc = randi(250,1,k);
TFcm=0;
%-----------------------------------------------------------------

while(TFcm<Tn)
c=[];
R = [];
tmp = [];
P = [];
D=zeros(H,W,1);

for i=1:k
U=repmat(cc(i),H,W);
c=cat(3,c,U);
end

for i=1:k
r=repmat(0.000001,H,W);
R=cat(3,R,r);
end

distance=IC-c;
distance=distance.*distance+R;

dS=1./distance;

for i=1:k
D = D + dS(:,:,i);
end

for i=1:k
dist(:,:,i)=distance(:,:,i).*D;
Q(:,:,i)=1./dist(:,:,i);
end

54
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

for i=1:k
CI(i)=sum(sum(Q(:,:,i).*Q(:,:,i).*I))/sum(sum(Q(:,:,i).*Q(:,:,i)));
end

for i=1:k
tmp = cat(3,tmp,abs(cc(i)-CI(i))/cc(i));
end

for i=1:k
P = cat(3,P,Q(:,:,i));
end

for i=1:H
for j=1:W
for l=1:k
if max(P(i,j,:))==Q(i,j,l)
Icm(i,j)=l;
end
end
end
end
%------------------------------------------------------------------
if max(tmp)<0.0001
break;
else
cc = CI; %updating cluster centers
end

%----------------------------------------

Ifc=uint8(Icm);

TFcm=TFcm+1;

end%end of while loop

end
function result = knnclassification(testsamplesX,samplesX, samplesY, Knn,type)

% Classify using the Nearest neighbor algorithm


% Inputs:
% samplesX - Train samples
% samplesY - Train labels
% testsamplesX - Test samples
% Knn - Number of nearest neighbors
%
% Outputs

55
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

% result - Predicted targets


if nargin < 5
type = '2norm';
end

L = length(samplesY);
Uc = unique(samplesY);

if (L < Knn),
error('You specified more neighbors than there are points.')
end

N = size(testsamplesX, 1);
result = zeros(N,1);
switch type
case '2norm'
for i = 1:N,
dist = sum((samplesX - ones(L,1)*testsamplesX(i,:)).^2,2);
[m, indices] = sort(dist);
n = hist(samplesY(indices(1:Knn)), Uc);
[m, best] = max(n);
result(i) = Uc(best);
end
case '1norm'
for i = 1:N,
dist = sum(abs(samplesX - ones(L,1)*testsamplesX(i,:)),2);
[m, indices] = sort(dist);
n = hist(samplesY(indices(1:Knn)), Uc);
[m, best] = max(n);
result(i) = Uc(best);
end
case 'match'
for i = 1:N,
dist = sum(samplesX == ones(L,1)*testsamplesX(i,:),2);
[m, indices] = sort(dist);
n = hist(samplesY(indices(1:Knn)), Uc);
[m, best] = max(n);
result(i) = Uc(best);
end
otherwise
error('Unknown measure function');
end

56
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

CHAPTER 5

TESTING

5.1 TESTING

Testing is the process of evaluating a system or its component(s) with the intent to
find that whether it satisfies the specified requirements or not. This activity results in
the actual, expected and difference between their results. In simple words testing is
executing a system in order to identify any gaps, errors or missing requirements in
contrary to the actual desire or requirements.

According to ANSI/IEEE 1059 standard, Testing can be defined as ―A process of


analyzing a software item to detect the differences between existing and required
conditions (that is defects/errors/bugs) and to evaluate the features of the software
item‖.

5.2 TYPES OF TESTS

5.2.1 Unit testing

Unit testing involves the design of test cases that validate that the internal
program logic is functioning properly, and that program inputs produce valid outputs.
All decision branches and internal code flow should be validated. It is the testing of
individual software units of the application .it is done after the completion of an
individual unit before integration. This is a structural testing, that relies on knowledge
of its construction and is invasive. Unit tests perform basic tests at component level
and test a specific business process, application, and/or system configuration. Unit
tests ensure that each unique path of a business process performs accurately to the
documented specifications and contains clearly defined inputs and expected results.

5.2.2 Integration Testing

Integration tests are designed to test integrated software components to determine if


they actually run as one program. Testing is event driven and is more concerned with
the basic outcome of screens or fields. Integration tests demonstrate that although the
components were individually satisfaction, as shown by successfully unit testing, the

57
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

Combination of components is correct and consistent. Integration testing is


specifically aimed at exposing the problems that arise from the combination of
components.

5.2.3 Functional Test

Functional tests provide systematic demonstrations that functions tested are available
as specified by the business and technical requirements, system documentation, and
user manuals. Functional testing is centered on the following items:

Valid Input : identified classes of valid input must be accepted.

Invalid Input : identified classes of invalid input must be rejected.

Functions : identified functions must be exercised.

Output : identified classes of application outputs must be exercised.

Systems/Procedures : interfacing systems or procedures must be invoked.

Organization and preparation of functional tests is focused on requirements, key


functions, or special test cases. In addition, systematic coverage pertaining to identify
Business process flows; data fields, predefined processes, and successive processes
must be considered for testing. Before functional testing is complete, additional tests
are identified and the effective value of current tests is determined.

5.2.4 System Test

System testing ensures that the entire integrated software system meets requirements.
It tests a configuration to ensure known and predictable results. An example of system
testing is the configuration oriented system integration test. System testing is based on
process descriptions and flows, emphasizing pre-driven process links and integration
points.

White Box Testing

White box testing is the detailed investigation of internal logic and structure of the
code. White box testing on an application, the tester needs to possess knowledge of

58
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

the internal working of the code. The tester needs to have a look inside the source
code and find out which unit/chunk of the code is behaving inappropriately.

Advantages:

As the tester has knowledge of the source code, it becomes very easy to find out
which type of data can help in testing the application effectively.

 It helps in optimizing the code.


 Extra lines of code can be removed which can bring in hidden defects.

Disadvantages:

 Due to the fact that a skilled tester is needed to perform white box testing, the
costs are increased.
 Sometimes it is impossible to look into every nook and corner to find out
hidden errors

Black Box Testing

The technique of testing without having any knowledge of the interior workings of the
application is Black Box testing. The tester is oblivious to the system architecture and
does not have access to the source code. Typically, when performing a black box test,
a tester will interact with the system’s user interface by providing inputs and
examining outputs without knowing how and where the inputs are worked upon.

Advantages:

 Well suited and efficient for large code segments.


 Code Access not required, knowledge of implementation, programming
language or operating systems.

Disadvantages:

 Limited Coverage since only a selected number of test scenarios are actually
performed.
 Inefficient testing, due to the fact that the tester only has limited knowledge

59
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

about an application.

Unit Testing:

Unit testing is usually conducted as part of a combined code and unit test phase of
the software lifecycle, although it is not uncommon for coding and unit testing to be
conducted as two distinct phases.

Test Strategy and Approach

Field testing will be performed manually and functional tests will be written in
detail.

Test Objectives

 All field entries must work properly.

 Pages must be activated from the identified link.

 The entry screen, messages and responses must not be delayed.

Features to Be Tested

 Verify that the entries are of the correct format

 No duplicate entries should be allowed

Test Results: All the test cases mentioned above passed successfully. No defects
encountered.

Acceptance Testing

User Acceptance Testing is a critical phase of any project and requires significant
participation by the end user. It also ensures that the system meets the functional
requirements.

Test Results: All the test cases mentioned above passed successfully. No defects
encountered.

60
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

Testing set Training set No. of males No of females


detected detected

350 200 100 100

Fig 5.1 Test Results

61
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

CHAPTER 6

RESULTS

1. This is the first GUI that appears when we execute the project in Matlab. It consists
of 3axex components in which input image, grayscale image, and facial part of input
image are displayed simultaneously. It also consists of six push buttons Browse, Face
Detection, Clustering Feature Extraction ,Classified Image, Detect. On clicking each
button performs corresponding action.

Fig: 6.1 Basic GUI

2. After browsing and selecting image program is written such that it automatically
converts input image to scale 256*256 and converts to gray scale. It is displayed in
second axis automatically.

62
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

Fig: 6.2 Conversion of Input to Gray scale image

3. After converting to gray scale, face in the input image is found out using
facefind.dll is Face Detection button is pressed.

Fig 6.3 Extraction of Facial Part From Input Image

63
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

Fig : 6.4 Cluster formation

4. Calculate the similar features of the given image by comparing the pixel values and
group them to form a cluster.

Fig: 6.5 Face Detection

64
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

Fig: 6.6 Feature Extraction

5. Creating an array vector and compare the test image with the predefined values.
Determine K value using test set and report the performance on the test set.

Fig: 6.7 Classification

Once the features are extracted ,these features are fed to K-NN classifier, it performs
classification mechanism on comparing to database image’s properties classifies
whether male/female

65
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

Fig: 6.8 Gender recognition

66
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

CHAPTER 7

CONCLUSIONS AND FUTURE WORK

In the project work, we proposed a gender recognition system based Fuzzy


C-means and NN classifier. These methods provide much improvement in recognition
accuracy for gender recognition problem. Despite its simplicity, the proposed system
can produce as good results as complicated systems. The proposed method is
evaluated in FERET gray face image database and achieves 98.13% accuracy, which
is better than that of some state-of-the-art methods. However, the proposed method
has a high dimension of features, and therefore, is computationally more expensive
than PCA and LBP.

A future study will be to reduce the feature dimension of the proposed method
in an intelligent way.

67
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

REFERENCES

[1] Golomb B., Lawrence D., Sejnowski T.: Sexnet: a neural network
identifies sex from human faces. In: Advances in Neural Information Processing
Systems, pp. 572–577. Morgan Kaufmann, San Mateo (1991)
[2] Tamura S.H., Kawai, Mitsumoto H.: Male/female identification from 8 9 6 very
low resolution face images by neural network. Pattern Recognit. 29, 331–335 (1996)
[3] Gutta, S., Weschler, H., Phillips, P.J.: Gender and ethnic classificationof human
faces using hybrid classifiers. In: Proceedingsof IEEE International Conference on
Automatic Face and Gesture Recognition, pp. 194–199 (1998)
[4] Wu B., Ai H., Huang C.: LUT-based Adaboost for gender classification. AVBPA
2688, 104–110 (2003)
[5] Moghaddam B., Yang M.H.: Gender classification with support vector
machines. In: IEEE Trans. PAMI 24, 707–711 (2002)
[6] Baluja S., Rowley H.A.: Boosting sex identification performance. Int. J. Comput.
Vis. 71, 111–119 (2007)
[7] Do, T.T.; Le, T.H., Facial Feature Extraction Using Geometric Feature and
Independent Component Analysis.
Springer-Verlag Berlin, Heidelberg . 2009, p. 231-241. ISBN 978-3- 642-01714-8.
[8] Omaia, A; Poel, J.K; Batista, L.V. 2D-DCT Distance Based Face
Recognition Using a Reduced Number of Coefficients. Computer Graphics and
Image Processing (SIBGRAPI). 2009, p. 291 - 298. ISSN 1550-1834.
[9] A. Golom, D. T. Lawrence, and T. J. Sejnowski, ―SEXNET: A neural network
identifies gender from human faces‖, Advances in Neural Information Processing
Systems, pp. 572-577, 1991
[10] B. Moghaddam and M.-H.Yang, ―Gender classification with support vector
machines‖ Proc. IEEE International Conference on Automatic Face and Gesture
Recognition, pp. 306-311, March 2000.
[11] M. Nakano, F. Yasukata and M. Fukumi, ―Age and gender classification
from face images using neural networks‖ Proc. of Signal and Image Processing,
2004.

68
Gender Recognition from Faces using Fuzzy Clustering and Nearest Neighbor Classifier

PUBLISHED PAPER

The paper with title “GENDER RECOGNITION FROM FACES USING FUZZY
CLUSETRING AND NEAREST NEIGHBOR CLASSIFIER” was published in
International Journal of Innovative Research in Computer and Communication
Engineering in October 2016.

69

You might also like