Wednesday, October 16, 2013

Face Detection Using MATLAB

The proposed system is implemented in MATLAB because it contains many predefined functions which facilitate implementation of the system discussed in the last chapter. MATLAB, being a scientific programming language, provides strong mathematical and numerical support for the implementation of image processing algorithms.  

4.1 Implementation

The code is divided into five phases according to the system described in the last chapter. The first phase is the input phase. The code for this phase is given in Figure 4.1. It reads the input image from the user.  


Figure 4.1: Code for input
The second phase of the code does the preprocessing required to detect skin. It first calls the function “histoeq” [18] to perform histogram equalization on the “rgb” image. Then the original image is converted to a YCbCr color image. The code is given in Figure 4.2.








Figure 4.2: Code for preprocessing










Figure 4.3: Code for skin segmentation
In the third phase, the skin region is detected. The code is shown in Figure 4.3. The conditions discussed in Table 3.1 and Table 3.2 are applied in the “if” loop on the RGB image, histogram equalized image and the YCbCr image. The output of the three conditions are integrated using the logical ‘AND’ operation.  The white region of the output image of this phase represents skin. The output of the ‘AND’ operation is then forwarded to the next phase which is the face candidate detection phase.













Figure 4.4: Code to detect face location and number of faces
The face candidate search phase is used to detect the facial candidates. The code of this phase is given in Figure 4.4.  The main idea of this phase is to select the white blobs in an image as faces. Because of the presence of noise or other black holes and cracks, they may be identified as separate blobs which make it difficult to detect faces accuracy. To overcome this problem, the gaps are filled with white spaces so as to make it a solid white blob. After converting the original image to a binary image, “Image open” is applied on the binary image followed by “Image Close”. “Bwareaopen” and “imclose” are the two built-in functions that are called to perform these operations respectively.  Noisy regions and small blobs which contain less than 100 pixels are eliminated. After that, the morphological closing operation is applied to merge gaps with a 3-by-3 square structure to find the face candidates.
To select a candidate, each of the 1’s are labeled. On each label, two conditions are applied to determine if the detected region is a face. First, the condition is based on the ratio of bounding box which covers the label. The ratio of the bounding box, width over height, should be between 0.3 and 1.5. Since the neck and chest are included in the detected region, the lower limit is taken as 0.78. The second condition is to cover the gaps inside the region. This helps in differentiating the face from other body parts such as hands.
The output of the function is the set of faces contained in the image and the total number of faces. The faces in the image are bounded by a green box while the red box tries to bind the neck portion or other skin parts which are connected to the face. If there are multiple faces, there will be one box per binding per face.

4.2 Experimental Results

The implemented algorithm is tested with images in the BAODATABASE available from facedetection.com [19].  The images contain faces of people belonging to different races and countries and of different skin tones in various backgrounds and luminance conditions. Some of the images are taken indoors while some are taken outdoors.   
The experimental results can be classified into three different categories based on the number of faces the input image contains. The first category represents images with only a single face, the second category represents images with two faces, and the third category represents images containing more than two faces.  
Each of the 370 images was submitted to the system as input. The results were checked for accuracy. The database contains 172 images containing only one face, 51 images containing two faces and 147 images containing more than 2 faces.
For single faced images (images with one face per image), the output was considered correct if there were no false positives, the number of faces determined by the system was one and the bounding box reasonably covered the faces which was determined by visual inspection. Out of 172 images 121 were detected correctly. Examples of such images are given in Figure 4.5. Examples of incorrectly detected faces are given in Figure 4.6.
For double faced images (images with two faces per image), the output was considered correct if there were no false positives, the number of faces in the output was equal to two and each bounding box reasonably covered the face. Out of 51 images, 32 images showed two faces and 4 showed one face per image. Examples of the bounding box reasonably covering the faces are given in Figure 4.7. Examples of incorrectly detected faces are given in Figure 4.8.
For images containing more than two faces, the output was considered correct if more than 50 percent of the faces were detected correctly, and there were no false positives. Out of 147, 98 of the images were detected correctly. An example of a correctly detected image is given in Figure 4.9; altogether 12 out of 15 faces have been detected correctly. An example of an incorrectly detected image is given in Figure 4.10; altogether 1 out of 4 faces has been detected correctly. In the following sections a detailed discussion of the results obtained by testing the implemented system are provided.

4.2.1 Single Faced Images

Here, faces are detected from the images which contain only one face. The background is complex in some of them. Most the images are taken in indoor conditions while some are taken in outdoor conditions and during the daylight.                                                            
Figure 4.5: Examples where face detection worked satisfactorily for single faced images


In the above figures, it can be seen that the faces are detected correctly even when the background is complex and when the face is rotated away from the normal view. The face of the baby is detected correctly in Figure 4.5.  The face of the Asian woman is also detected correctly even when it is rotated away from the normal and an ample amount of skin is exposed. Also Figure 4.5 shows a face detected correctly even when wearing glasses. In contrast the system fails to detect the face in Figure 4.6 because the skin was obstructed by the pair of glasses.                                                       
Figure 4.6: Example where face detection failed for single faced images


4.2.2 Double Faced Images                                  

            
Figure 4.7: Examples where face detection worked satisfactorily for images containing two faced images
In Figure 4.7, the system detects the faces correctly. As can be seen, the system is invariant to various backgrounds and lighting conditions. However the system fails in some cases when the pixels with intensities close to skin colors are connected and not in the shape of a face. In Figure 4.8, the second girl from the left is not detected correctly even when the skin is detected properly. Here, the face detection part of the algorithm fails to find the face even when the skin is detected properly.                                                                      
Figure 4.8: Example where face detection failed to identify two images correctly


4.2.3 Images containing three or more faces

Figure 4.9: Example where face detection detected 80% of the faces correctly
In Figure 4.9, 80% of the faces are detected properly. Sometimes the system is not able to detect faces when the skin of one person gets overlapped with the other. In the next few examples, it is shown that even when the skin is detected properly, the face detection fails because of the overlapping of skin like regions.  In Figure 4.6, the hand of the first lady gets connected with the second lady, and hence the face is not detected properly.

                                            

Figure 4.10: Examples where face detection failed in group photos           
Figure 4.11:  Example of image where two out of three faces were detected correctly                                                            
Figure 4.12: Example of image where three out of four faces were detected correctly
In Figure 4.10, while detecting the face of the second girl from the left, a whole region that includes two other girls (one on her right and one on her left) is covered. It can be seen this happens because the hands of the two other girls get connected with her face.
Thus, the experimental results show that the performance of the system drops as the number of faces in an image increases. The drop in the performance is mainly because of the skin of one person overlapping with others. Sometimes the faces in an image are not captured properly which also results in the failure of the system. In Figure 4.7 it was seen that the one of the faces was not detected because it was occluded by the shadow of his cap.


Figure 4.13: Graph showing improvement in performance when both the color models are combined together


It is worth noting that skin is detected accurately in most of the test cases. Most of the errors were because the system failed to detect the face correctly. This ability to detect skin accurately is due to the approach taken in this project which is to detect skin using multiple color models. Unlike [10], which only used RGB, or [12], which only used YCbCr, this project used both models to detect skin. The benefit of this is that false positives were eliminated, and the results of the tests confirming this are shown in Figure 4.13. The red bar shows the accuracy when solely RGB was used as the color model, the green bar shows the accuracy when YCbCr was used as the color model and the blue bar shows the accuracy when both the models where combined together.










No comments:

Post a Comment