Face Morphing Be Project


Published on

Published in: Technology, Education
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Face Morphing Be Project

  2. 2. Face Morphing Project Report on FACE MORPHING Submitted by ABHINAV MEHROTRA AKSHAY SURESH KARAN MODI Under the guidance of Prof. Ms. Ibtisam Mogul Department Of Computer Engineering Fr.Conceicao Rodrigues College Of Engineering 2
  3. 3. Face Morphing CERTIFICATE This is to certify that the project entitled “FACE MORPHING” by: Mr.ABHINAV MEHROTRA Mr.AKSHAY SURESH Mr.KARAN MODI Submitted in the partial fulfillment of the degree of BE in Computer Engineering is approved. __________ Guide _______________ ________________ Internal Examiner External Examiner _________ _____________ HOD Principal 3
  4. 4. Face Morphing ABSTRACT Today, there is almost no area of technical endeavor that is not impacted some way by digital image processing. With the advent of increasing support of graphics and images by computer, image processing has found its application in field of forensics, medicine, surgery etc. One of these applications is Face Morphing. Face Synthesis deals with the metamorphosis of an image to another image. It aims at developing software that contains a database of parts of several faces with functionality of combining various parts of different faces. Face morphing deals with the metamorphosis of an image to another image. Our project aims at developing S/W that contains a database of several faces with functionality of combining various features. It alters a few characteristics of an image to produce the desired image. Despite the researches in morphology there has not been seen much development in this field. 4
  6. 6. Face Morphing INTRODUCTION 1.1 OVERVIEW An image can be defined as 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 the intensity or gray level of the image at the point. When x, y and the amplitude values of f are all finite, discrete quantities, we call the image a digital image. The field of digital image processing refers to processing digital images by means of a digital computer. Note that a digital image is composed of a finite number of elements each of which has a particular location and value. These elements are referred to as picture elements, image elements and pixels. Pixel is a term used to donate the elements of a digital image. 1.2 DIGITAL IMAGE PROCESSING Digital Image processing is a vast field which involves many sub-branches like image enhancement, information extraction, pattern recognition. This is the field which has touched all aspects of human life. Digital Image processing stretches its application right from visible light to infra-red, x-ray as well Ultra Violet Image processing. Digital image processing is divided into 3 regions in continuum. Low level, middle level and high level processing. o Low Level processes involve primitive operations such as image preprocessing to reduce noise, contrast enhancement and image sharpening. A low level process is characterized by the fact that both inputs and outputs are images. o Mid-level processing involves tasks such as segmentation (partitioning an image into regions or objects) description of those objects to reduce them to form suitable for computer processing, and classification [recognition] of individual 6
  7. 7. Face Morphing objects. A mid level process is characterized by the fact that its inputs generally are images but its outputs are attributes extracted from those images. [e.g. edges, contours and the identity of individual objects] o High-level processing involves “making-sense” of an ensemble of recognized objects, as in image analysis, and at the far end of the continuum, performing the cognitive functions normally associated with vision. Network Image displays Computers Mass Storage Hardcopy Specialized image Image processing processing hardware software Image Sensors Problem Domain Fig 1.1 (courtesy of “Digital Image Processing:, Gonzalez and Woods) 7
  8. 8. Face Morphing 1.3 PROBLEM DEFINITION Reproduction of human faces envisioned by different individuals is still limited to artists’ trying to reproduce other’s thoughts and this being time consuming. Our project combines the power of computer with the artists’ talents and helps in reproducing human faces vis-à-vis Digital Image Processing. Project aims at developing software that contains a database of several faces with functionality of combining various features. It alters a few original characteristics of the images to produce the desired image. It contains a database of faces divided in three parts: • The first part consists of hair, forehead and eyes. • The second part contains the nose. • The third part consists of lips and chin. The user is presented with a screen that displays all the parts of various faces stored in the database. The user then chooses one image for each of the three parts. Once the decision is made, the software then takes charge. The software aims at combining these three parts from three different faces to produce a new face that looks very natural. It does so by utilizing the powerful features and functionality of Image Processing coupled with the Image Object Library provided in Virtual C++. The software also provides the user with an option to resize any of the parts’ dimensions to further achieve the envisioned look. The entire database is maintained by the user and the user is provided the freedom of adding/removing new faces’ parts to the database to improve the range and accuracy of the software’s ability to replicate human faces. 1.4 EXISTING SYSTEM WE ARE TRYING TO BETTER There are many professional applications that can create video effects. They produce great animations that are used in million-dollar movies. But, there is a downside. These programs require a million-dollar operator. You need to spend years studying a 8
  9. 9. Face Morphing professional video editing package to get yourself familiar with its interface and features. Even a simplified morphing program is not suitable for morphing faces just for fun. To correctly morph one face into another, you need to mark numerous spots first. You have to point the victim's eyes, nose, lips and other notable face areas. Marking the spots manually ensures the highest quality but it may take hours. Our program is designed to turn face morphing into real child’s play. It guesses the basic spots automatically. In most cases, though, the automatically guessed spots produce animation that is perfectly acceptable for amateur videos or web graphics. The program is fully automated too. A series of pictures are loaded and the program automatically recognizes the images as faces. Then the morphing process begins and the program renders the animation. The result is automatically saved in the source folder which can later be used for printing, distribution etc. Our program makes an attempt to provide a cheaper and better alternative to FaceMorpher which is termed as the best morphing utility in the market. 1.5 SCOPE & APPLICATIONS Our project finds applications in the following fields: Detective Agencies: This software can aid in visualizing faces of criminals as per descriptions provided by the witness who has a faint image of the criminal in his mind. The design of our software conforms to international requirements as stated by researchers. This need was further justified by an article published in NEW SCIENTIST magazine :”Face morphing could catch criminals”. Cosmetic surgery: When performing a cosmetic surgery for say enhancement of nose, a surgeon needs to give the patient an idea about his post surgery look. This task is highly facilitated when 9
  10. 10. Face Morphing various features of the face can be edited as per patient’s requirement which helps the patients to accurately visualize his post surgery look. Patient puts his face into a database and then edits various features of the face with the help of the functionality provided by the software. This enables the patient to properly specify his requirements and surgeons gets a better idea about the surgery to be performed. Hair Stylists: A barber can provide his customer better service by allowing them to experiment with various hairstyles before selecting one. Customers can superimpose hair from other face images to their face image. 10
  12. 12. Face Morphing REVIEW OF LITERATURE 2.1 SYSTEM STUDY The overall architecture for the “New Face Tool” comprises various components described below. CONTRACTION & IMAGE FILES EXPANSION OF IMAGES HISTOGRAM SPECIFICATION FACE SYNTHESIS COMBINING PROCESSED TOOL IMAGES BLURRING THE EDGES HISTOGRAM SPECIFICATION DISPLAYING THE NEW IMAGE Fig. 2.1 : Block Diagram of System 2.2 MOSAICKING Our major goal during mosaicking images is to minimize the edge formation at the point of combining the two images. While combining two images we are assuming a predefined overlap limit, which would determine the thickness of the edge formed at the 12
  13. 13. Face Morphing overlap. The actual procedure of combining the two images involves creating three matrices. These are used for the following purposes. • To store the content of the first image file, this is the first of two faces to be combined. • To store the content of the second image file, this is the second of two images to be combined. • Finally, the third matrix is going to be used to store the overlapped image consisting of the mosaic formed by combining the two images. The first of these two matrices are formed by directly using the two images to be combined, by simply reading the two image files into these matrices. The sizes of these matrices can be determined by using the width and height attributes of each of the two images. Having read on the two images in the matrices we can then combine these two images by flooding the third matrix in the following manner. First we use the matrix corresponding to the upper face to flood the third matrix, then we start flooding the target matrix using the matrix corresponding to the lower face starting from appoint in the target matrix such that the overlap of two images comes to the predetermined limit of overlapping. Having mosaicked the two images the intensities of pixels contained in the edge would be large due to the combined intensities of the two faces and hence would require an averaging operation to bring down their intensities at a level which is very close to the average intensity of the combined face. 2.3 EXPANSION/CONTRACTION Here we are using the technique of weighted averages for expanding or contracting the image. In the case of expansion, the distance between the adjacent pixels in the compressed grid corresponding to the expanded image is less than unity, as compared to unit spacing between two pixels in the original image. 13
  14. 14. Face Morphing Similarly for compressing an image we have to expand an imaginary grid, which fits on the smaller version of the image, hence the distance between adjacent pixels is the expanded grid corresponding to the shrunken image is more than unity. Thus the spacing between the pixels in the grid will be : Space_x_direction = original_x_resolution/new_x_resolution Space_y_direction = original_y_resolution/new_y_resolution To implement the weighted averages algorithm, we will have to take in consideration the intensities of all the pixels surrounding the pixel under consideration, hence the new intensity of every pixel will be calculated using the interpolation of the intensities of its diagonal neighbours. 2.4 BLURRING OF EDGES The image is passed through a Low Pass Spatial Filter to reduce edge formation at the boundary of the three parts of the face. This gives a smooth look to the face and helps in producing a gradual transition of skin tone from the first part to the third part thereby giving a natural look to the face. During the process of morphing of two separate faces, we would have to minimize edge formed at the region of combination of the two images. This can be done by applying a low pass filter or can be achieved by any other smoothing operation. 2.5 MORPHING : Morphing is a special effect in motion pictures and animations that changes (or morphs) one image into another through a seamless transition. Most often it is used to depict one person turning into another through some magical or technological means or as part of a fantasy or surreal sequence. 14
  15. 15. Face Morphing 2.6AVERAGING FILTER OPERATIONS 2.6.1 Smoothing Spatial Filters Smoothing filters are used for noise reduction. Blurring is used in preprocessing steps, such as removal of small details from an image prior to (large) object extraction and bringing of small gaps in lines or curves. Noise reduction can be accomplished by blurring with a linear filter and also by non-linear filtering. 2.6.2 Smoothing Linear Filters The desirable features of the image are characterized by sharp transition gray levels, so averaging filters have the undesirable side effect that they blur edges. Another application of this type of process includes the smoothing of false contours that result from using an insufficient number of gray levels. 1 2 1 1/9 2 4 2 1 2 1 LOW PASS FILTER MASK 1 1 1 1 1 1 1/16 1 1 1 AVERAGING FILTER MASK A major use of averaging filter is in the reduction of “irrelevant” detail in the image. By “irrelevant” we mean the pixel regions that are small with respect to the size of the filter mask. 15
  16. 16. Face Morphing The above figure shows two 3x3 smoothing filters. Use of the first filter yields the standard average of the pixels under the mark. This can be best seen by substituting the coefficients of the mask in R = 1/9 ∑ Z i ( i =1 to 9) which is the average of the gray levels of the pixels in the 3x3 neighborhood defined by the mask. Note that, instead of being 1/9, the coefficients of the filter are all 1’s. The idea here is that it is computationally more efficient to have coefficients valued 1. At the end of filtering process the entire image is divided by 9. An mxn mask would have a normalizing constant equal to1/mn. A spatial averaging filter in which all coefficients are equal is sometimes called a box filter. A second mask shown in the figure is little more interesting. This mask is called weighted average, terminology used to indicate that the pixels are multiplied by different coefficients, thus giving more importance (weight) to some pixels at the expense of the others. In the second mask shown the pixels at the center of the mask is multiplied by the higher value than any other, thus giving this pixel more importance in the calculation of the average. The other pixels are inversely weighted as a function of their distance from the center of the mask. The diagonal terms are further away from the center than the orthogonal neighbors (by a factor of √2) and thus, are weighted less than these immediate neighbors of the center pixel. The basic strategy behind weighing the center point the highest and then reducing the value of the coefficients as a function of increasing the distance from the origin is simply an attempt to reduce the blurring in the smoothing process. We could have picked other weights to accomplish the same general objective. However, the sum of all coefficients in the second mask is equal to 16, an attractive feature for computer implementation because it has an integer power of 2. In practice, it is difficult in general to see the differences between the images smoothed by using either of the masks shown above, or similar arrangements, because the area these masks span at anyone location in an image is small. 2.7 DEALING WITH COLOR IMAGES Color images consists of three components RED, GREEN and BLUE i.e RGB. Combination of these three colors helps us to form a color image. The operations that 16
  17. 17. Face Morphing can be performed on Gray Scale images can also be done on color images. To work with color images we first extract the individual RED, GREEN and BLUE components from the BMP images and form a separate matrix for each color component. We form each of these component matrices by extracting the RGB bytes individually and appending into the corresponding matrix i.e. 1st, 4th, 7th ……...bytes form the red component matrix, the 2nd , 5th , 8th ………bytes form the green component matrix, and the 3rd , 6th , 9th ………bytes form the blue component matrix. All the required operations are then performed on the individual component matrices. Then they are combined together to form the final resultant modified color image. The combination process is reverse of that extraction. A convenient way is to view this as a color plane (faces or cross sections of the cube). This can be accomplished by simply fixing one of three colors and allowing the other two to vary. For a instance, a cross-sectional plane through the center of the cube and parallel to GB plane is plane (127, G, B) for G, B=0, 1, 2,….255. Figure below shows the RED, BLUE and GREEN component images for this color plane. Thus it can be seen that the color plane can be generated using these components. 17
  18. 18. Face Morphing Color Image Processing Red Color Green Monitor RGB Generating RGB image of the cross- sectional color plane (127,G,B) The three hidden Blue surface planes in the color cube. (R-0) (G-0) (B-0) Fig 2.2 : RGB Color Plane for Display 2.8 HISTOGRAM SPECIFICATION The histogram of the digital image with gray levels in the range [ 0, L- 1] is a discrete function h(r k) = n k , Where r k is the kth gray level and n k is the number of pixels in the image having gray levels r k . The method used to generate a processed image that has a specified histogram is called histogram matching or histogram specification. k s k = T(r k) = ∑ nj/n ; k=0, 1, 2,….L-1. j=0 where pr(rj) is the probability that the pixel has gray level j. 18
  19. 19. Face Morphing Thus for equalizing the histogram of an input image we first construct a probability array prob[i] storing probability of the pixel in the input image having gray level i, where 0<=i<=255. The transformation function T is then applied to ‘prob’ array. Each value of prob[i] is then mapped to the nearest integer to give new level[i]. The pixels having gray level ‘i’ in the input image are now assigned gray level new) level[i] resulting in the histogram equalized image. This process is applied separately on each component (Red, Green and Blue) of the input image to obtain histogram equalized color image. For specifying the histogram of the input image to histogram of target image; firstly, the histogram of both input and target images need to be equalized by the above mentioned procedure resulting in the data structures new_level1[i] and new_level2[i] corresponding to the input and target image respectively. The pixels having gray level ‘i’ in the input image is now mapped to gray level ‘j’ if the gray level ‘i’ of the input image and gray level ‘j’ of the target image are equalized to same gray level, that is, new_level1[i]=new_level2[j] The above mentioned process is applied separately on each component (Red, Green Blue) of the input image to obtain histogram specified color image. 19
  21. 21. Face Morphing SRS (SOFTWARE REQUIREMENT SPECIFICATIONS) The basic issues that the SRS shall address are the following: 3.1 Functionality  Our project aims at developing software that contains a database of parts of several faces with functionality of combining various parts of different faces.  The software alters a few characteristics of the original image to produce the desired image. 3.2 External interfaces  Different parts of the face are stored in a database. 1. The first part consists of the forehead. 2. The second part contains the nose section. 3. The third part contains the lower face.  The user needs to select one part each from the above and the software displays the resulting face image. 3.3 Attributes The considerations made while designing our project are as follows 1. Images should be of the same size. 2. Images should not be black and white. 3.4 Design constraints  One of the constraints is that in our project there is a user-controlled database. Hence proper handling of database is extremely important.  The other constraint is that our project can handle only two-dimensional images. 21
  23. 23. Face Morphing NALYSIS 4.1 FEASIBILITY STUDY The feasibility study looks at three main areas of feasibility for the project: 4.1.1 Economic Feasibility From the cost benefit analysis of the hardware and software requirements carried out we can conclude that the system is economically feasible. The cost in developing the project is negligible when compared to the features provided by it. The best software currently available in the market, Face Morpher, comes with a price tag of Rs.3000/-. This amount is obscene for an individual intending to use the software for his personal use. The software is also packed with too many features that are not useful when it comes to personal use. Hence, our software aims to bridge the gap between a low-cost face morphing software and availability of all the basic features that are essential to reproduce a moderate – good quality image as the output. 4.1.2 Time Feasibility From the schedule calculations in the estimation we can conclude that the system development is feasible in terms of time. The project development can be completed in a reasonable time span. Though the analysis phase of the project took a longer time than was previously allocated, the coding process was sped up with all the members of the group working extensively and collectively. 4.1.3 Technical Feasibility From the requirement study we can conclude that the system development is technically feasible. The technical analysis of the system proves that the application can be developed within the analyzed resources. Since the analysis phase was conducted in a detailed manner, resource allocation was done as per requirements and there were no developmental issues. 23
  24. 24. Face Morphing 4.2 ESTIMATION Software project estimation is a form of problem solving; i.e., developing a cost and effort estimate for a software project. Since LOC based estimation are programming languages dependent, they penalize well designed but shorter programs and their use in estimation models requires a level of detail that is difficult to achieve before the analysis and design is to be completed: so we are considering the FP based estimation that considers the functionality delivered by the application as a normalization value. 4.2.1 FP-BASED ESTIMATION FP-based estimation focuses on the information domain values such as inputs, outputs, inquiries, files and external interfaces for CLASS. For the purpose of this estimate, the complexity weighting factor is assumed to be average. The below mentioned table presents the result of this estimate: Information Domain Value Count Weight FP-count Number of Inputs 3 4 12 Number of Outputs 3 5 15 Number of Inquiries 3 4 12 Number of Files 7 10 70 Number of External Interfaces 0 7 0 Count-total109 The estimated FP is derived using the formula: FP=COUNT-TOTAL*[0.65+0.01*ΣFi] Where ΣFi=sum of all complexity adjustment values computed by estimating the following weighting factors. FACTOR VALUE 24
  25. 25. Face Morphing Backup and recovery 0 Data communication 5 Distributed processing 0 Performance critical 4 Existing operating environment 3 On-line data entry 0 Input transactions over multiple screens 0 Master files update online 0 Information domain values complex 0 Internal Processing complex 3 Code design for reuse 4 Conversion/installation in design 3 Multiple installations 0 Applications designed for change 5 ΣFi=27 Complexity adjustment factor [0.65+0.01*27] = 0.92 ~1 Finally the estimated of FP is derived: FP=count-total*[0.65+0.01*ΣFi] FP=100.28 4.2.2 EFFORT ESTIMATION Effort estimation is required to find the number of people required to complete the project over the duration of the project. The effort estimation of our project is as follows: Considering productivity=32FP/month Labour Rate for month =100$ 1> Cost/FP=1000/32=$31.25 2> Total Cost=31.25*100.28 =$3133.75 25
  26. 26. Face Morphing 3> Effort=FP/Productivity =100.28/32 =3.13~3 person-months Thus estimated effort required for FACE MORPHING is 3 persons over a period of 5 months. 4.3 RISK ANALYSIS 4.3.1 RISK TABLE RISK CATEGORY PROBABILITY IMPACT Schedule goes PS 0.6 3 haywire. Competition in the BU 0.8 2 market. User-controlled PS 0.5 2 database CATEGORY IMPACT PS – project size 1 – Catastrophic BU – business 2 – Critical 3 – marginal 4 – Negligible 4.3.2 RMMM PLAN (Risk Mitigation Monitoring and Management) Risk id – abc Date – 12/10/07 Probability – 60% Impact – marginal Description: it is possible that the development of software is behind schedule. Mitigation: Ensure project is running on schedule Monitoring: Periodic meetings to co-ordinate work schedule 26
  27. 27. Face Morphing Management: Overlook work development and increase pace of work completion Current status: Project is completed within schedule Originator: Abhinav Mehrotra Assigned: Abhinav Mehrotra Risk id – 123 Date – 2/2/08 Probability – 80% Impact – critical Description: there is a good possibility of the software facing stiff competition in the market. Mitigation: Make the s/w fare better amongst other 2D rendering s/w. Monitoring: Check for regular developments made in other rival softwares Management: Periodically surveying the market for new features present in other s/w Current status: Product stands up to features provided by most of the rival s/w Originator: Karan Modi Assigned: Karan Modi Risk id – xyz Date – 12/3/08 Probability – 50% Impact – critical Description: improper handling of database could stop the software from functioning in the proper manner. Mitigation: Provide a user manual Monitoring: Simplify the management of database Management: Provide assistance/training to customer prior to s/w operation Current status: Arrangements made for providing training to customers. 27
  28. 28. Face Morphing Originator: Akshay Suresh Assigned: Akshay Suresh 4.4 TASK SET Task sets are designed to accommodate the different types of projects and different degrees of rigor. The different software project types are:  Concept Development Projects: These are initiated to explore some new business concept or application of some new technology.  New Application Development: These projects are undertaken as a consequence of a specific customer request.  Application Enhancement Projects: These occur when existing software undergoes major modifications to function, performance or interfaces that are observable by the end user.  Application Maintenance Projects: These correct, adapt or extend existing software in ways that may not be immediately obvious to the end user.  Re-engineering Projects: These are undertaken with the intent of rebuilding an existing legacy in system in whole or in part. 4.4.1 DEGREES OF RIGOR Four different degrees of rigor can be defined:  Casual: All process framework activities are applied, but only a minimum task set is required. Umbrella tasks are minimized and documentation is less.  Structured: Umbrella activities necessary to ensure high quality will be applied.  Strict: The full process will be applied for this project with a degree of discipline that will ensure high quality. All umbrella activities will be applied and robust work products will be produced.  Quick Reaction: Because of an emergency situation only those tasks essential to maintaining good quality will be applied. 4.4.2 Adaptation Criteria 28
  29. 29. Face Morphing It is used to determine the recommended degree of rigor with which the software process should be applied on a project. They are as follows:  Size of the project  Number of potential users  Mission criticality  Application longevity  Stability of requirements  Ease of customer/developer communication  Performance constraints  Embedded and non embedded characteristics  Project staff  Re-engineering factors 4.4.3 Computation of the task set selector  Review each of the adaptation criteria and assign the appropriate grades (1-5)  Review the weighting factor assigned to each of the criteria. The value of a weighting factor ranges from 0.8 to 1.2.  Multiply the grade with the weighting factor and the entry point multiplier.  Place the result of multiplication in the project column and compute the average of all entries and place the result in the total task set selector. 4.4.4 TASK SET SELECTOR Entry Point Multiplier Adaptation Grade Weight C N AE AM RE Product Criteria D A Proj. Size 2 1.20 0 1 1 1 1 2.4 No. of users 2 1.10 0 1 1 1 1 2.2 Busines 2 1.10 0 1 1 1 1 2.2 Criticality Appn. 3 0.90 0 1 1 0 0 2.7 Longevity Stab. Of 5 1.20 0 1 1 1 1 6.0 requirements Ease of comm. 5 0.90 1 1 1 1 1 4.5 Technology 4 0.90 1 1 0 0 1 3.6 29
  30. 30. Face Morphing Maturity Perf. 4 0.80 0 1 1 0 1 3.2 Constraints Embedded/non 1 1.20 1 1 1 0 1 1.2 emb Proj. staffing 1 1.00 1 1 1 1 1 1.0 Interoperability 3 1.10 0 1 1 1 1 3.3 Re-eng factors 3 1.20 0 1 0 0 1 0 Total 32.3 CD-CONCEPT DEVELOPMENT NA-NEW APPLICATION AE-APPLICATION ENHANCEMENT AM-APPLICATION MAINTAINENCE RE-REENGINEERING Taking the average we obtain 32.3/12=2.69 Since the T.S.S value is 1.0< T.S.S <3.0 the degree of rigor is structured. (Can be strict also- final decision made by considering all the project factors. CHAPTER 5 DESIGN • DATA DESIGN • DATA FLOW DIAGRAM LEVEL 0 • DATA FLOW DIAGRAM LEVEL 1 • USE CASE DIAGRAM • PROCEDURAL DESIGN 30
  31. 31. Face Morphing DESIGN 5.1 DATA DESIGN Data Design creates a model of data store information that is represented at a high level of abstraction. We consider the following set of principles for data specification: 1> The system analysis principles applied to function and behaviour should be applied to the data. 2> All data structures and operations to be applied to data to be performed on each should be identified. 3> A data dictionary should be established and used to define both data and program design. 4> Low level data design decisions should be defined and deferred until late in design process. 5> A software design supports the specified and realization of abstract data type. DATA FLOW DIAGRAM LEVEL 0 Image Files Image of Face Part Image Processin g Unit Edited Face Image Display Unit 31
  32. 32. Face Morphing DATA FLOW DIAGRAM LEVEL 1 Images of Face Parts Raw Image Parts Size Adjustmen t Parts Having Same Size Image Standardization Parts with Similar Intensity Merging Faces Edited Image Display Unit 32
  34. 34. Face Morphing 5.2 PROCEDURAL DESIGN The different procedures required are as follows: Search for files: The prototype should have a login screen where user has to enter a valid userid and password. The system sends this data to the database; data is validated and perform a checkup against a database. Database Required: The search contents for this purpose are required to be stored in the database.  Upload Images: The user when wants to upload files in the database must first login and enter before uploading.  Selection of three images: The user selects three different parts of the face from the library of images stored in the database to obtain the morphed image from the program. The sequence of operation is as follows: T Wrap the BMP files for the three parts selected in three Expand Contract objects. o Expand two of the three parts using ‘expand’ function to make the widths of all Parts equal. o Wrap the BMP files containing the expanded parts in three Specifications objects. o Specify the histogram of each part to target histogram using the ‘specify’ function. f Wrap the BMP files containing the histogram using the specified parts ion the three overlap objects. t Combine the three histogram specified parts using ‘combine’ function. t Wrap the BMP files containing the combined face in Specification Object. t Specify the histogram of combined face to target histogram using ‘specify’ function. 34
  35. 35. Face Morphing 5.3 DESIGN OVERVIEW The executable files for image processing programs are created using VC++. 1. The following steps will create a new project: • Select File | New | Project • Select Win32 Console Application • Set the project location to the directory containing the header files and Implementation files. • Set the project name • Select OK to begin creating the project 2. Then we specify the kind of console application • Select an empty project • Click finish • Click OK to create the project workspace 3. Once the project is created, we add files to the project, as follows: • Select Project | Add to project | Files • Highlight the .cpp files in the project • Select OK to add the files to the project 4. Once the files have been added to the project, you build and execute the result as: • To build the program, select Build | Build projectname.exe • To execute the program, select Build | Execute projectname.exe 35
  37. 37. Face Morphing CODING AND IMPLEMENTATION The language used for implementation is VC++. Our code uses Microsoft Foundation Classes (MFC) that is a C++ class library designed for creating GUI programs. The MFC wraps the Win32 API providing a higher-level, more portable programming interface. Our project (named Display) is a SDI (Single Document Interface) application that uses four main classes. • Document class • View class • Main frame Window class. • Application class. The programs tasks are divided among these four classes, and AppWizard creates separate source files for each class. The Display document class is named CDisplayDoc and is derived from the MFC class CDocument. The CDisplayDoc header file is named DisplayDoc.h and the implementation file is named DisplayDoc.cpp The Document class is responsible for storing the program data. The display view class is named CDisplayView and is derived from the MFC class CView. The CDisplayView header file is named DisplayView.h and the implementation is named DisplayView.cpp. The view class is responsible for displaying the program data, processing the input from the user an, managing the view window. The file DisplayView.cpp contains the main program logic. The display main frame window class is named CMainFrame and is derived from the MFC class CFrameWnd. The CmainFrame header file is named MainFrm.h and the implementation file is named MainFrm.cpp. The main frame window class manages the main program window, which is the frame window that contains window frame. 37
  38. 38. Face Morphing The display application class is named CDisplayApp and is derived from the MFC class CWinApp. The CDisplayApp header file is named as Display.h and the implementation file is Display.cpp. The application class manages the program as a whole that is it performs general tasks like initializing the program and performing final program clean-up. The file DisplayView.cpp includes a header file project.h, which contains class definitions of five classes that are created: • ImageProcessor • ExpandContract • Overlap • Histogram • Specification The class ImageProcessor provides functions for copying the BMP header from source to destination file, copying the data of BMP file from source file to destination file, copying data of BMP file to an array, copying data from an array to destination BMP file, closing a BMP file and extracting height and width of BMP file. The constructor of the class allocates memory, opens the BMP file. The class ExpandContract inherits ImageProcessor and provides a function to expand or Contract a source BMP file by any extent specified. The class Overlap inherits ImageProcessor and provides a function “combine” that takes as input three source BMP files and combines them into a single BMP file using predefined overlap limit. It also provides function ‘averageEdges’ which blurs the edges between overlapped parts using averaging operator. The class Histogram inherits ImageProcessor and provides a function, which first constructs the histogram of source BMP file, equalizes the histogram and stores the Equalized image in the destination BMP file. 38
  39. 39. Face Morphing The class Specification inherits ImageProcessor and provides a function, which first constructs the histogram of source BMP file, specifies the histogram to target histogram And stores the histogram specified image in the destination BMP file. The function ‘Make Face’ in the file DisplayView.ccp uses the three parts selected and Makes the face using functionality provided by the five classes in project.h. CODE FOR DISPLAYVIEW.CPP // Global Variables #include <alloc.h> #include "stdafx.h" #include "Display.h" #include "project.h" #include "DisplayDoc.h" #include "DisplayView.h" CButton *moreimages=new CButton(); int k=1; // CDisplayView construction/destruction char HeadFile[30]="0"; char NoseFile[30]="0"; char LipsFile[30]="0"; int expW1,expH1,expW2,expH2,expW3,expH3,exp; int newW,newH1,newH2,newH3; 39
  40. 40. Face Morphing // MAKEFACE FUNCTION void MakeFace(int flag) { unsigned long h1,h2,h3,w1,w2,w3; ExpandContract *E1=new ExpandContract(HeadFile,"rb"); E1->getHeightWidth(&h1,&w1); ExpandContract *E2=new ExpandContract(NoseFile,"rb"); E2->getHeightWidth(&h2,&w2); ExpandContract *E3=new ExpandContract(LipsFile,"rb"); E3->getHeightWidth(&h3,&w3); if(flag) { if(w1>=w2 && w1>=w3) { expW1=0;expH1=0; expW2=w1-w2;expH2=0; expW3=w1-w3;expH3=0; } else if(w3>=w2 && w3>=w1) { expW3=0;expH3=0; expW2=w3-w2;expH2=0; expW1=w3-w1;expH1=0; } 40
  41. 41. Face Morphing else { expW2=0;expH2=0; expW1=w2-w1;expH1=0; expW3=w2-w3;expH3=0; } } else { expH1+=newH1/100.0*(h1+expH1)-(h1+expH1); expH2+=newH2/100.0*(h2+expH2)-(h2+expH2); expH3+=newH3/100.0*(h3+expH3)-(h3+expH3); exp=newW/100.0*(w1+expW1)-(w1+expW1); expW1=expW1+exp; expW2=expW2+exp; expW3=expW3+exp; } E1->SetXYNew(expW1+w1,expH1+h1); E2->SetXYNew(expW2+w2,expH2+h2); E3->SetXYNew(expW3+w3,expH3+h3); ExpandContract *E4=new ExpandContract("c:imagesout1.bmp","wb"); ExpandContract *E5=new ExpandContract("c:imagesout2.bmp","wb"); 41
  42. 42. Face Morphing ExpandContract *E6=new ExpandContract("c:imagesout3.bmp","wb"); E1->ExpContract(E4); E2->ExpContract(E5); E3->ExpContract(E6); E1->closeFile(); E2->closeFile(); E3->closeFile(); E4->closeFile(); E5->closeFile(); E6->closeFile(); Spec *S1=new Spec("c:imagesout1.bmp","rb"); Spec *S2=new Spec("c:imagesmcv1.bmp","rb"); Spec *S3=new Spec("c:imagesout4.bmp","wb"); S3->specify(S1,S2); Spec *S4=new Spec("c:imagesout2.bmp","rb"); Spec *S5=new Spec("c:imagesmcv2.bmp","rb"); Spec *S6=new Spec("c:imagesout5.bmp","wb"); S6->specify(S4,S5); Spec *S7=new Spec("c:imagesout3.bmp","rb"); Spec *S8=new Spec("c:imagesmcv3.bmp","rb"); Spec *S9=new Spec("c:imagesout6.bmp","wb"); 42
  43. 43. Face Morphing S9->specify(S7,S8); S1->closeFile(); S2->closeFile(); S3->closeFile(); S4->closeFile(); S5->closeFile(); S6->closeFile(); S7->closeFile(); S8->closeFile(); S9->closeFile(); Overlap *Src1= new Overlap("c:imagesout6.bmp","rb"); Overlap *Src2= new Overlap("c:imagesout5.bmp","rb"); Overlap *Src3= new Overlap("c:imagesout4.bmp","rb"); Overlap *Targ= new Overlap("c:imagesoverlap.bmp","wb"); Targ->combine(Src1,Src2,Src3); Targ->closeFile(); Src1->closeFile(); Src2->closeFile(); Src3->closeFile(); 43
  44. 44. Face Morphing Spec *S10=new Spec("c:imagesoverlap.bmp","rb"); Spec *S11=new Spec("c:imagesbright.bmp","rb"); Spec *S12=new Spec("c:imagesfinalface.bmp","wb"); S12->specify(S10,S11); S10->closeFile(); S11->closeFile(); S12->closeFile(); CDisplayView::CDisplayView() { frame.Load("c:imagesFrame2.bmp"); } CDisplayView::~CDisplayView() { } BOOL CDisplayView::PreCreateWindow(CREATESTRUCT& cs) { return CView::PreCreateWindow(cs); } void CDisplayView::OnNext() {CFrameWnd *wind1=new MywindFirst(); wind1->ShowWindow(SW_SHOWMAXIMIZED); } 44
  45. 45. Face Morphing void CDisplayView::OnCombine1() { if(HeadFile[0]=='0') MessageBox("Select a head!!","Error"); else if(NoseFile[0]=='0') MessageBox("Select a Nose!!","Error"); else if(LipsFile[0]=='0') MessageBox("Select a Lips!!","Error"); else { CFrameWnd *wind=new Mywind(); wind->ShowWindow(SW_SHOWMAXIMIZED); MakeFace(1); } } void MywindFirst::OnMore() { // delete moreimages; CMenu *my_menu; my_menu=GetMenu(); my_menu->RemoveMenu(0,MF_BYPOSITION); DrawMenuBar(); 45
  46. 46. Face Morphing frame2.Load("c:imagesFrame.bmp"); CDC *pDC=GetDC(); if( GetFocus() == this ) frame2.SetPalette( pDC ); frame2.Draw( pDC,0,-30); } // FRONT PAGE void CDisplayView::Onh1() { strcpy(HeadFile,"c:imagesankitnew1.bmp"); } void CDisplayView::Onh2() { strcpy(HeadFile,"c:imageskunalnew1.bmp"); } void CDisplayView::Onh3() { strcpy(HeadFile,"c:imageskrunalnew1.bmp"); } void CDisplayView::Onh4() { strcpy(HeadFile,"c:imagesnitinnew1.bmp"); } 46
  47. 47. Face Morphing void CDisplayView::Onh5() { strcpy(HeadFile,"c:imagestarzannew1.bmp"); } void CDisplayView::Onn1() { strcpy(NoseFile,"c:imagesankitnew2.bmp"); } void CDisplayView::Onn2() { strcpy(NoseFile,"c:imageskunalnew2.bmp"); } void CDisplayView::Onn3() { strcpy(NoseFile,"c:imageskrunalnew2.bmp"); } void CDisplayView::Onn4() { strcpy(NoseFile,"c:imagesnitinnew2.bmp"); } void CDisplayView::Onn5() { strcpy(NoseFile,"c:imagestarzannew2.bmp"); } 47
  48. 48. Face Morphing void CDisplayView::Onl1() { strcpy(LipsFile,"c:imagesankitnew3.bmp"); } void CDisplayView::Onl2() { strcpy(LipsFile,"c:imageskunalnew3.bmp"); } void CDisplayView::Onl3() { strcpy(LipsFile,"c:imageskrunalnew3.bmp"); } void CDisplayView::Onl4() { strcpy(LipsFile,"c:imagesnitinnew3.bmp"); } void CDisplayView::Onl5() { strcpy(LipsFile,"c:imagestarzannew3.bmp"); } // SECOND PAGE void MywindFirst::Onh7() {strcpy(HeadFile,"c:imagesharishnew1.bmp"); } 48
  49. 49. Face Morphing void MywindFirst::Onh8() { strcpy(HeadFile,"c:imagesketannew1.bmp"); } void MywindFirst::Onh9() { strcpy(HeadFile,"c:imagesmayanknew1.bmp"); } void MywindFirst::Onh10() { strcpy(HeadFile,"c:imagesphotonew1.bmp"); } void MywindFirst::Onh11() { strcpy(HeadFile,"c:imagesxtranew1.bmp"); } void MywindFirst::Onn7() { strcpy(NoseFile,"c:imagesharishnew2.bmp"); } void MywindFirst::Onn8() { strcpy(NoseFile,"c:imagesketannew2.bmp"); } 49
  50. 50. Face Morphing void MywindFirst::Onn9() { strcpy(NoseFile,"c:imagesmayanknew2.bmp"); } void MywindFirst::Onn10() { strcpy(NoseFile,"c:imagesphotonew2.bmp"); } void MywindFirst::Onn11() { strcpy(NoseFile,"c:imagesxtranew2.bmp"); } void MywindFirst::Onl7() { strcpy(LipsFile,"c:imagesharishnew3.bmp"); } void MywindFirst::Onl8() { strcpy(LipsFile,"c:imagesketannew3.bmp"); } void MywindFirst::Onl9() { strcpy(LipsFile,"c:imagesmayanknew3.bmp"); } 50
  51. 51. Face Morphing void MywindFirst::Onl10() { strcpy(LipsFile,"c:imagesphotonew3.bmp"); } void MywindFirst::Onl11() { strcpy(LipsFile,"c:imagesxtranew3.bmp"); } void MywindFirst::OnCombine() { if(HeadFile[0]=='0') MessageBox("Select a head!!","Error"); else if(NoseFile[0]=='0') MessageBox("Select a Nose!!","Error"); else if(LipsFile[0]=='0') MessageBox("Select a Lips!!","Error"); else { CFrameWnd *wind=new Mywind(); wind->ShowWindow(SW_SHOWMAXIMIZED); MakeFace(1); DestroyWindow(); } } 51
  52. 52. Face Morphing void MywindFirst::OnBack() { DestroyWindow(); } void Mywind::OnShow() { CMenu *my_menu; my_menu=GetMenu(); my_menu->RemoveMenu(0,MF_BYPOSITION); DrawMenuBar(); CDC *pDC=GetDC(); backgnd.Load("c:imagesBackground.bmp"); if( GetFocus() == this ) backgnd.SetPalette( pDC ); backgnd.Draw( pDC,0,-30); finalface.Load("c:imagesfinalface.bmp"); if( GetFocus() == this ) finalface.SetPalette( pDC ); finalface.Draw( pDC,310,-25); } 52
  54. 54. Face Morphing TESTING 7.1 TEST REPORTS This section will focus on the different types of testing techniques used to check the correctness of the middleware. A rigorous testing cannot be applied to this project because the project is eventually a small part of the entire grid system. It has to work in co- ordination with other modules that have been mentioned earlier. 7.2 TEST PLAN Testing is a set of activity that can be planned in advance & conducted systematically. For this reason, a template for software testing – asset of steps into which we can place specific test cases, design techniques & testing methods – should be defined for the software process. The templates for software testing have the following generic characteristics: • Testing begins at the component level and work outward toward the integration of the entire computer based system. • Different testing techniques are appropriate at different points of time. • Testing & debugging must be accommodated in any testing strategy. • A successful testing is one that uncovers as-yet-undiscovered error. A strategy for software testing must accommodate low level tests that are necessary to verify a small source code has been correctly implemented as well as high level test that validate major system functions against customer requirements. 54
  55. 55. Face Morphing 7.3 TESTING PROCEDURES 7.3.1 White Box Testing: • The sequential flow of each statement has been checked. • In case of branch testing, the true and the false branches are tested properly. • The computation taking place at every step is checked to see if the desired result are achieved • Debugging of the overall program code was done by stepping through the code using F8 key. • Thus, here internal logic of the program is tested efficiently. 7.3.2 Black Box Testing: • The appropriate image is entered into the forms and the validations are verified. • The dependency or the flow of data from one form to another is verified. • The proper linking of the form from the main form is also verified. • The actions associated with the buttons are verified. • Once the test transaction has been done, the data is checked in the database to view the correctness of the data computation. • Thus, inputs were provided to the application and result obtained were matched with desired output. 7.3.3 Unit testing: • The modules, event & subroutines in the program are initially identified For e.g.: Head, Nose, Chin etc. 55
  56. 56. Face Morphing • Rules related to each module are being tested &verified individually against all possible values. 7.3.4 Integration Testing: Bottom-up approach of integration testing is used in the project. • The modules in the program are initially identified. For e.g.: Head, Nose, Chin etc • Here, every module is tested & verified against the set of all possible values. • Finally, the overall program is tested for efficient functionality of the system developed. 7.3.5 Regression Testing: • Each time a new frame was added to the second module, regression testing was performed to make sure that the newly added frame worked well with the existing software. Thus, in varied ways the testing part was accomplished. 56
  57. 57. Face Morphing 7.4 TEST CASES: INPUT : Variable sized image parts were stored in the database – face part: 200x200, nose part: 400x400 and lips part: 120x300. OUTPUT : The software failed to combine the three parts due to the allocation of pre-defined matrices for buffering the images. Hence clipping of images occurred. RESOLUTION : The matrices were dynamically allocated instead of pre-allocation which enabled the use of variable sized images thus solving the problem. INPUT : Variable sized images were used to morph one face to another – some images were smaller in size, while some were larger in size. OUTPUT : For some cases, the final resultant image was of a smaller dimension than was desirable. RESOLUTION : The user was allowed to customize the size of each image part thereby aiding him to create user-defined sized image results. INPUT : 57
  58. 58. Face Morphing Three different parts were selected and then combined to form the resultant morphed image. OUTPUT : For some cases, the final resultant image exhibited a bright band of light at the edge formation. RESOLUTION : The resultant image was passed through a Low Pass Filter to reduce the Brightness and improve blurring of edges. 58
  60. 60. Face Morphing SCREENSHOTS The First Screen Giving You the Options for selecting the Head, Nose And Lips. 60
  61. 61. Face Morphing Second screen giving more options 61
  62. 62. Face Morphing The resultant morphed image after combining the parts. Dialog box asking for customizing information: 62
  63. 63. Face Morphing Final image after customizing: The screen showing an error if any of the 3 parts are not selected. 63
  64. 64. Face Morphing RESULTS AND DISCUSSION From the perspective of a critical review the major problem with out project correctly is with color equalization, because of the image of the RGB color model the color equalization also takes place on the Hue and Saturation components of an image which causes some distortion in the final image, hence a major improvement would be to achieve this color equalization using the HIS model. Another improvement would be to include the image warping techniques which could be used to adjust some of the features such as the nose and ears. FUTURE WORK Due to severe constraints on the time that we had for implementation of this project, some extra features could be implemented in our project and hence are mentioned here as future work. The future work of our project deals with the usage of the HIS color model for achieving color equalization of the image also we have to provide for handling the usage of images of females. Finally we would like to add that techniques from image warping can be used to further provide extra functionality for adjusting the various features of a face. 64
  65. 65. Face Morphing CHAPTER 9 REFERENCES 9.1 BOOKS 1. Refael C. Gonzalez and Richard E Woods, “Digital Image Processing”, Prentice Hall, 2002. 2. A.K.Jain “Fundamentals of Digital Image Processing”, Prentice Hall, 1989. 3. Praffenburget & Gutzman , “VC ++ Bible”, Hungry Minds, 1998. 4. David J. Kruglinski, “Inside Visual C++”, Microsoft Press,2000 5. Visual C++ in 21 days, Sams Publishing, 1998 6. Roger Pressman, “Software Engineering”, Nandu Publications, 5th Edition 9.2 ARTICLE Damian Carrington , “New Scientist Print Edition”, Glasgow, 2001 9.3 WEB SITES: a. www.wikipedia.com b. www.mit.edu c. www.morphases.com d. www.facemorpher.com e. www.britanica.com f. www.face-reg.org 65