Detecting Skin Regions
From Say in ten sentences what everyone else says in a whole book
An Extension of a Statistical Method for Detecting Skin Regions
By Timothy Sheerman-Chase Physics (MPhys) – Year 2000-2001
Supervisor: Dr C. J. Solomon
Abstract
Facial recognition relies on a systems ability to isolating the skin region in an image. A recent journal article, “Face Detection from Color Images Using a Fuzzy Pattern Matching Method” [1] describes a method for isolating the skin regions under constant lighting conditions. The aim of the project is to extend the method so it can accurately isolate skin regions under different lighting conditions.
The method expresses the face in Farnsworth’s YUV perceptionally uniform colour space where the components constant under changes in illumination. To detect skin regions, each pixel was compared to a histogram of images under known conditions. A probability was assigned to each giving its likelihood of being skin colour. Performance was assessed by taking the ratio between the average probability of skin likelihood in the skin region and the average probability of the background.
To make the system robust under changing lighting conditions, the input images were linearly transformed to improve the detection performance. The transform was determined by the observation of a colour calibration chart under different lighting conditions. This was successful under favourable conditions.
Introduction
Facial recognition and encoding is a growing area of research. Isolating the skin region in an image is an essential early step in facial recognition. A recent journal article, “Face Detection from Color Images Using a Fuzzy Pattern Matching Method” [1] describes a method for isolating the skin regions under constant lighting conditions. The aim of the project is to extend the method so it can accurately isolate skin regions under different lighting conditions. The method expresses the face in Farnsworth’s YUV perceptionally uniform colour space where the components constant under changes in illumination.
The reason for developing a system that works under different and variable lighting conditions is that there are a wide variety of potential applications that in which the lighting conditions vary. It is important that a facial recognition system be robust, fast and efficient. The applications of facial recognition include detection of human emotion, user-friendly computer interfaces, interactive entertainment systems, and indexing of existing images. Facial recognition can also be a useful tool in law enforcement and financial security. For example when money is withdrawn from a bank the user can be visually identified instead of using a PIN number. The advantages of facial recognition compared to other biometric systems are the availability and low cost of hardware (e.g. video camera), the speed and the non-invasiveness of operation. A system must be developed to be effective under any of the anticipated conditions.
Facial recognition is a difficult task because there are, in general, many uncontrolled variables.
- The orientation of the face changes the general shape of the observed region.
- Skin colour and coloured lighting changes the apparent colour in the image.
- Background objects may have face like colour or shape.
- Beards, glasses, jewellery, and hairstyle allow a wide variety of appearances.
- Clothing changes the amount of neck and shoulders in the image.
- The face is a “plastic medium”. Its shape can change due to expressions and mouth movement.
- The level of illumination can vary.
This makes the implementation of a fast and reliable system a considerable challenge.
This project implements and extends the method described in the paper by Wu et al. [1]. Pictures are commonly expressed in terms of RGB (Red Green Blue) colour components but it is possible to express it in other colour systems. The following section explains how the picture is converted into Farnsworth Space, how the PDF is generated and how skin detection is performed.
Theory and Method
When an image’s colour is expressed in Farnsworth colour space, the likelihood of a certain pixel being skin like can be determined by comparing it to a colour probability density function (PDF). An ensemble of faces can be used to generate this probability density map (sometimes called a Skin Colour Distribution Map SCDM). This method assigns a probability to an outcome based on past results.
Perceptually Uniform Farnsworth Colour Space
Colour is expressed in Farnsworth’s Space and is independent of intensity. This is an desirable property for a recognition system. Farnsworth devised a system (YUV – these are arbitrary axis names) where two colours of an equal distance as perceived by human vision have a equal distance in this colour space. A pictorial representation of this colour space is given in Figure 1. This was generated using a C program that converts RGB colours to YUV, re-written in Matlab code (this is discussed further in section 3.2). Any colour expressible by RGB (Red Green Blue content) is contained in the colour space.
An example of an image converted from RGB to YUV components is given in Figure 2.
Acquiring and Converting to YUV
To confirm this method for detecting skin regions an ensemble of 24 images was taken by a Canon Powershot 350 digital camera. These images consisted of the faces under artificial lighting. The images were converted to Farnsworth’s YUV colour space.
A C program to convert RGB colours to YUV can be found at http://www.sys.wakayama-u.ac.jp/~chen/ucs.html. The program describes converting to CIE (Commission Internationale de l'Eclairage) standard colour space and then using a non-linear transform (in a look up reference table) to convert this to Farnsworth’s YUV. This was rewritten for Matlab 5 for easier image manipulation. The source code is given in Appendix 5. The conversion from RGB to YUV is relatively slow compared to other colour space functions. This may be improved by compiling the Matlab code or by having the routine in C.
Figure 2 shows the RGB picture and its corresponding YUV components. The Y component contains the intensity while U and V contains colour information. The low contrast in the U and V components illustrates the small range in possible U and V values.
Probability Density Function (PDF)
Typically skin colour occupies a particular area in the UV plane. A histogram can be formed of colours in the UV plane that describes the colours typically observed in the skin. The shape of the histogram depends on the skin colour and its illumination. Under different coloured lighting the histogram appears to be a different shape. Since the histogram is used in detection this histogram is called a PDF.
The following steps describe how a histogram of the UV components of skin was generated. 1. Acquire a set of digital images and isolate the skin regions. See Figure 3. 2. Convert pictures to desired colour space (e.g. YUV) 3. Prepare an array 140 by 92 (to fit UV plane) containing zeros, into which the frequency data will be sorted 4. For each pixel add one to the frequency in the histogram corresponding to the pixel’s U and V values. 5. Normalise the table to obtain the probability of a pixel being a face pixel.
Figure 3 Example of Aquired Image (left) and Facial Region Manually Isolated (right)
After the images were processed they resulted on the left plot shown in Figure 4. The skin colours all are in a specific region of the colour space. This can be compared to the plot on the right of Figure 4 which shows the PDF for 12 faces imaged in outdoor natural lighting. It is clear that under different lighting the colours occupy a different part of the colour space.
Figure 4 PDF generated in Indoor Conditions (left) & PDF generated in Natural Light (right).
To detect skin regions, we assume their colours fall in a similar part of the skin probability map. It is assumed that an arbitrary pixel that falls in this distribution can be considered “skin like”, otherwise it is background. To detect skin regions, each pixel from the image is compared to the PDF. If the colour in question has commonly been seen in example skin regions it should be given a high probability of being skin. Otherwise if the colour is not generally seen in skin region it is assumed that it is background and assigned a low probability. A typical picture with the detected face regions is shown in Figure 5.
This skin detection method has been implemented in Matlab 5.3 to achieve good performance in identifying faces under constant conditions (lighting and camera are constant). Wu et al. [1] demonstrated that this system can also identify hair pixels using a similar method. 3.4 Need for Compensation Under Different Lighting Conditions If we try to detect skin regions using a PDF that corresponds to an ensemble of faces acquired under different lighting conditions, the discrimination is poor. This is illustrated in Figure 6. The PDF used in this detection corresponded to faces observed under artificial lighting whereas the image itself was acquired in natural light.
Figure 6 Original Picture (left) – Detection Using Wrong PDF (right). The detection fails when the wrong PDF is used.
Clearly the method is unreliable when used under varying lighting conditions. The need for a more general method is clear. In other words, if the input image can be pre-processed in some way before comparison with the PDF is made, the method may be more robust.
Possible Approaches to Transform Input Images
There are several possible ways to try to make this system robust under different lighting conditions. The simplest is arguably to have a specialised PDF for each anticipated lighting condition. The disadvantage here is that the training required to generate a new PDF in new lighting conditions is a time consuming process and unlikely to be viable.
If we perform a transform on the input image’s UV co-ordinates, the PDF might correspond more closely to the skin colours in the input image. A simple approach would be to translate the centre of mass of the probability map, corresponding to the input images, on to the centre of mass of the PDF corresponding to the PDF we desire to use. (i.e. Make a simple shift in the UV plane. See Figure 8.) This would clearly not be very effective since the PDF generally have different shapes as can been seen in Figure 4. Also the PDF of the input images is required and this is not automatically available.
Figure 7 Colour Charts Used For Linear Transform (Type A left and Type B right)
If we perform a general linear transform on the UV co-ordinates of the input image we could effectively perform a shift and rotation operation on the skin PDF. This would make the centre of mass and general shape close to the desired reference PDF. It is possible to determine the required transform by observing the apparent change in colour of a calibration chart under different lighting. This is explored in the next section.
Figure 8 Observed Colour Sampled on the Chart A, Plotted in the UV Plane – Artificial Lighting (Left) and Natural Lighting (Right).
In principle, we may also seek to perform a non-linear transform, which would correspond to a warping effect on the PDF. The details and feasibility of this are not known and may be a good area of further investigation in the future. This is outside the scope of this study.
General Linear Transforms
Within the natural limits of a translate-rotation operation, a linear transform can be found that translates the input set of chart UV co-ordinates onto the reference UV co-ordinates. The matching of points is not exact as the linear equations describing the transform are over-determined and the best possible values are found using a least squares fit of the data.
Step 1 Image Acquisition
As described earlier, sets of images of faces in artificial and natural lighting were acquired. Each image had the colour chart in view. The average UV value of each colour, in each of the data sets was determined. This was carried out in Matlab semi-automatically – the user has to indicate the approximate position of the chart. If it is necessary to recalibrate the system for each facial recognition task, in an application with a constantly changing lighting conditions, it may be possible to automate this step.
To assess the performance of the method, the skin region was manually isolated. This step is not performed in an automatic implementation of a facial recognition system. If the PDF for the input images was transformed to resemble the reference PDF the method would be effective.
Step 2 Determine Transform
A matrix can be found that approximates the conversion from the six UV co-ordinates for indoor colour charts, to the six UV co-ordinates from outdoor charts. This matrix is over determined - there are only six parameters and twelve equations and thus an exact solution is not expected.
For one UV co-ordinate pair, the transform is:
|U'| = |a b| |U| + |e| |V'| |c d| |V| |f|
With six colours we change a, b, c, d, e and f to find a least squares fit between the observed colours and the ones found using the transform. If we let X=U and Y=V in general because this method might work in other colour space systems.
|X1' X2' X3' X4' X5' X6'| = |a b| |X1 X2 X3 X4 X5 X6| + |e e e e e e| |Y1' Y2' Y3' Y4' Y5' Y6'| |c d| |Y1 Y2 Y3 Y4 Y5 Y6| |f f f f f f|
The least squares fit was found in Excel 97 using Solver and checked in Matlab. The values of a, b, c, d, e and f minimise the sum of the squared differences between the transformed co-ordinates and the observed co-ordinates. A comparison between the observed and predicted values (after the transform) is given in Table 1.
| Measured | Measured | Transformed | Transformed | Observed | Observed | Diff |
| X | Y | X' | Y' | Xact | Yact | Sqr |
| 26.2 | 42.8 | 28.4 | 39.4 | 30.0 | 40.8 | 4.15 |
| 23.3 | 61.3 | 22.9 | 57.1 | 20.5 | 55.4 | 8.5 |
| 57.9 | 55.2 | 50.4 | 50.4 | 49.3 | 48.5 | 5.0 |
| 84.6 | 50.0 | 71.8 | 44.8 | 70.5 | 44.2 | 1.9 |
| 57.7 | 63.5 | 48.8 | 58.4 | 52.1 | 61.3 | 18.7 |
| a | 0.764439 |
| b | -0.17652 |
| c | -0.02432 |
| d | 0.954503 |
| e | 15.92654 |
| f | -0.85927 |
Table 1 Best Parameters for Least Square Fit
In Table 1, the measured XY values are the observed colours in artificial lighting. The "Transformed" X'Y' values are the calculated colours and the observed are the observed colours in natural lighting. By minimising the summed squared distance we attempt to make the Transformed X’Y’ close to the observed Xact and Yact. As can be seen in the table the match is good with most points being within 2 units of the observed units.
Step 3 Proceed with detection
After the linear transform is found, it can compensate for the change in lighting conditions and a standard PDF can be used to detect skin regions
By determining the PDF of the transformed input images, we can compare them to the reference probability density map. If they are similar, the reference PDF will be effective in detecting skin regions. In the images processed this seems to be the case so we expect detection to be successful.
Figure 9 Examples of Pictures Identified Using PDF from Naturally Lit Images (006->A->009). See also Figure 14.
Performance of this method can be measured by the discrimination between skin and background regions. In detection, each pixel is assigned a probability of skin likeness. The performance can be found by calculating the ratio of average skin likeness probability in the skin region to the background region. Good discrimination would have a high skin to background ratio (S/B ratio).
Optimal Colour Content of Calibration Chart
The choice of colours sampled in the UV space determines the quality of transform found. If there is an wide sampling of colours in the UV plane, the transform will be good at compensating the entire picture. If the sampling is concentrated around skin colours, the transform would more accurately compensate skin colours at the expense of the outer regions of the UV plane. The two charts used in this investigation are show in Figure 7.
Two sets of data were acquired with a digital camera. One set taken under artificial illumination (such as fluorescent lighting) and the other was outdoors in natural light (this served as a reference set). The goal was to see which colours gave the best transform to convert pictures to appear similar to the outdoor reference images. In most tests just 5 colours were used. When the larger (type B) chart was used, usually only a few colours were considered while determining the transform; the outer colours were ignored. The performances between the different colour selections were compared.
The charts actually appear different in the photographs because printers cannot produce colours as intense as shown. The chart on the left (type A) was a first attempt at determining the feasibility of using a linear transform. The chart on the right has more colours close to typical skin colour so it can more accurately determine the effects of the change in lighting conditions on the camera response to skin colour.
Results and Analysis
Measuring Performance
We can assess the performance of detection of skin regions by working out the average probability within the skin region and the background. A high average probability of skin likeness in the skin region and a low average probability in the background would indicate a good capacity for discriminating skin against background. Performance can be measured as a ratio between the average skin probability and the average background probability. This is abbreviated as S/B (skin/background).
Several sets of images were taken with each set using a particular camera and fixed illumination. For each ensemble of images a PDF was generated and the skin regions were found. The average probability in the skin region and background region is shown in Table 2.
| Average Face | Average Background | Difference In | ||
| Data Set | Probability | Probability | Probability | S/B Ratio |
| 003 | 0.670 | 0.105 | 56.5% | 6.4 |
| 006 | 0.405 | 0.056 | 34.9% | 7.2 |
| 010 | 0.218 | 0.084 | 13.4% | 2.6 |
| 011 | 0.082 | 0.079 | 0.4% | 1.0 |
Table 2 Performance Values Observed in Reproducing The Method. There is a large range of S/B ratios indicating the performance depended on the circumstances.
Notes on data sets in Table 2.
- Data set 003. Taken with a Minolta Dimage V digital camera, these images are acquired indoors with no colour chart present. The flash seems to have triggered on some shots. They were taken before and in the early stages of the project.
- Data set 006. Taken with a Canon Powershot 350. Faces in totally artificial light. The flash was not used so as to reduce intensity saturation. A simple colour chart (type A) was in view (although not at a constant orientation).
- Data set 010. Taken with a Minolta Dimage V. Faces taken indoors in a mixture of artificial and natural light. The colour calibration chart B was present in all the images. The flash was not used but this gave the images poor contrast so may adversely affect skin discrimination. This may be a factor in explaining the poor S/B ratio.
- Data set 011. Taken with a Minolta Dimage V. Faces taken entirely outdoors with calibration chart B present. All the pictures are of the author in a brown jacket. This jacket was usually recognised as skin. This ruined the skin recognition as can been seen with an S/B ratio of 1.
Figure 10 Performance of Skin Detection Method
From these performance values we can conclude that the system is certainly not perfect but in favourable conditions it works well. If objects in the background are similar in colour to skin the recognition often fails. This would in turn make the later stages of facial recognition fail. Beige walls, beige computer equipment, paper under artificial lighting and other miscellaneous object are sometimes recognised as skin. In a real application, if we could control the image background to some extent we could minimise confusing objects to maximise performance.
Effectiveness of Linear Transform
The goal is to be able to isolate skin regions from an unknown image using the PDF from an ensemble of faces under different lighting. The input images were taken from a data set, the colour chart was used to determine the transform required and then this transform was applied to the input image. This allowed the desired probability density function to be used to calculate the probabilities. The average probabilities in the skin region and in the background are shown in Figure 3.
| Average Face | Average Background | Difference In | ||
| Data Set | Probability | Probability | Probability | S/B Ratio |
| 006->A->008 | 0.30 | 0.10 | 0.21 | 3.17 |
| 006->A->009 | 0.32 | 0.09 | 0.23 | 3.69 |
| 010->B->011 | 0.25 | 0.04 | 0.21 | 6.41 |
| 010->C->009 | 0.14 | 0.03 | 0.11 | 5.10 |
Note 006->A->008 means images form data set 006, linear transform based on colour chart A are detected by the PDF of data set 008.
Table 3 Performance of Linear Transform
Note 006->A->008 means images form data set 006, linear transform based on colour chart A are detected by the PDF of data set 008.
Figure 11 Graphs of Performance of Linear Transform
This method has given good results with an S/B ratio about between 3 and 7. This is adequate for skin recognition. See Figure 9 and Figure 14 for typical results of this approach.
Optimal Colours in Colour Chart
The choice of colours used in the calibration chart may have a major impact on the performance of a skin recognition system. If we have a broad choice of colours from different parts of the colour space we may be able to determine the overall change in appearance of the picture. Conversely if we concentrate on the difference in the colours commonly contained in the face we may more accurately understand how to transform these important colours.
Data sets 010 and 011 represent faces acquired in indoor and outdoor conditions. We used 011 as the reference data. These pictures contained a colour chart with 15 colours (chart B). The transform to compensate for the change in lighting was calculated by comparing 5 colours from the chart to the reference data. These were called charts C, D and E but were in fact chart B with certain colours ignored (see Figure 12). Once the input images were compensated using a linear transform they were compared to the reference probability density map. The average probabilities in the face and background regions are shown in Table 4.
Chart B uses all colours 1-15
Chart C comprises of 5, 15, 4, 14 and 7 (this is the same as Chart A)
Chart D comprises of 2, 6, 7, 8 and 12
Chart E comprises of 1, 3, 7, 11 and 13
| Average Probability | Average Probability | |||
| Face | Background | Difference | S/B Ratio | |
| Target 011->011 | 0.41 | 0.10 | 0.32 | 4.23 |
| No transform 010->011 | 0.08 | 0.08 | 0.00 | 1.05 |
| Chart B (All cols) 010->B->011 | 0.25 | 0.04 | 0.21 | 6.35 |
| Chart C (Wide Spread) 010->C->011 | 0.15 | 0.02 | 0.13 | 8.40 |
| Chart D (Skin cols 1) 010->D->011 | 0.33 | 0.12 | 0.21 | 2.71 |
| Chart E (Skin cols 2) 010->E->011 | 0.32 | 0.09 | 0.23 | 3.72 |
Table 4 Performance of Different Colour Selections in Chart
Figure 13 Performance of Different Colour Selections in Chart (Plotted)
The 010->010 column did not use the transform and is given as an example of the system without compensation using the data sets own probability density map. This is included to show the likely maximum performance of the method. The “No Transform 010->011” is a data set compared to the reference PDF without compensation. This illustrates this skin detection method in changing lighting is not viable without some form of compensation. The S/B ratio of about 1 means it has totally failed. The background is just as likely to be found to be “skin like” as the correct region in the image.
Figure 14 Further Examples of Faces Region Detection (010->B->011) See also Figure 9.
The other linear transforms, determined from charts B to E show the effectiveness of compensating in this way. S/B ratios vary between around 3 to 8. This is sufficient for skin recognition. The performance of chart C is very high but the average probability in the face is low. This is not necessarily good because although the regions that were detected are definitely skin, hardly any of the face was found. This would cause the system to identify some part of the face as the entire skin region, e.g. the forehead or cheek.
Charts B and E give the best overall performance, considering the S/B ratio and the average probability of the face. This implies a large number of colours sampled in the UV plane is most effective at finding the correct transform for compensation.
Conclusion
Linear transforms are effective at compensating for different lighting conditions in skin recognition. The input images studied contain a calibration chart. The procedure compared the appearance of the colour chart to the appearance of the chart in some reference data. A linear transform can be determined that converts the colour co-ordinates of the colours in the chart to appear like the reference data. This transform was then applied to the input image. The input image then has a similar colour content to the reference data. The method described by Wu et al. [1] could then be used to find the facial regions. This involved comparing the pixels in the input image to the typical colours found in the reference data set of faces. The information of the colours in typical faces was contained in a Skin Colour Distribution Model (probability density map). In the comparison with the probability density map, the pixels in the input image were assigned a probability of being “skin like”. Performance was measured by finding the average probability in the skin regions and comparing it to the average probability in the background region.
The performance of the linear transform would be sufficient to find skin regions under various lighting. Favourable conditions tended to improve skin recognition.
- These conditions included good lighting that was constant across the image. It is also thought that if the input image conditions are similar to the reference data, good discrimination would be possible.
- The system must have a large reference PDF in good and constant conditions with a wide variety of face and skin types.
- A colour chart with an even sampling of colours across the UV plane improves discrimination. It also easier to location the chart if they are of constant size and orientation in the image.
- A camera which provides good colour contrast. It is important that it can easily distinguish between browns, oranges and pinks.
The method is less effective in situations where:
- Strong coloured lighting (everything appears the same colour)
- Images where the colour contrast is poor (due to darkness or camera properties)
The skin detection method itself is not perfect as skin coloured objects like cream coloured walls, computer equipment and paper were often wrongly identified as skin. We aim to achieve the best discrimination possible with the data available.
Possible Further Work
An image recorded by a camera is effected by the content of the scene, the illumination and the camera characteristics. Colour constancy is the study of the effect of illumination and can be used to remove its effects from an image. If colour constancy theory could be applied to skin we might find a better method to predict the appearance of skin under different lighting. For further reading see: - http://www.cs.berkeley.edu/~kobus/research/projects/depth_exam/depth_exam.html A logical extension of using transforms to compensate for different lighting conditions is to use a non-linear transform. This would correspond to applying a warp to the probability distribution map.
If may be useful to find the absorption, reflection and scattering properties of skin at various wavelengths. Digital cameras can only distinguish colour, which is in fact a blend of wavelengths. Much more information is contained in the spectrum of light reflecting from the skin than a colour image. Understanding of the reflection and absorption of the skin is needed to properly understand its apparent colour under different lighting conditions.
References
[1] H. Wu, Q. Chen and M. Yachida, “Face Detection from Color Images Using a Fuzzy Pattern Matching Method,” IEE Transactions On Pattern Analysis And Machine Intelligence, vol. 21, no. 6, June 1999. http://www.computer.org/tpami/tp1999/i0557abs.htm
[2] D. A. Forsyth and M. M. Fleck, “Automatic Detection of Human Nudes,” International Journal of Computer Vision, 32(1), 63-77 (1999). http://www.wkap.nl/oasis.htm/233145
[3] G. Wyszecki and W. S. Stiles, Colour Science, New York: John Wiley & Sons, Inc, 1967
[4] H. Rossotti, Colour- Why the World Isn’t Grey, Penguin Books Ltd, 1983. QC495
[5] M. D. McCreary, Digital Cameras, Scientific American: Working Knowledge: June 1998. http://www.sciam.com/1998/0698issue/0698working_tf.html
[6] M. Maylin, Analysis of the Human Face, Student Project 1999-2000
[7] J. A. Swets, R. M. Dawes and J. Monahan, “Better Decisions Through Science”, Scientific American, Page 70-75, October 2000
Appendix 1 Colour is Subjective
When a digital imaging device is used for facial detection it expresses each pixel element’s colour in an R, G and B component. According to Rossotti [4], not all colours can be expressed in a positive combination of three colour components. For example vivid yellow (=570nm) cannot be truly represented as a mix of red (=700nm) and green (=546nm). This mixture is still has a greater blue component compared to vivid yellow. This can be expressed as adding a negative blue component to red and green. This means that colours cannot be fully expressed in the RGB system (the NTSC standard) and as this is the starting point for most imaging from digital cameras – colours cannot be regarded as completely faithful even with an ideal camera.
Two matching colours in some particular lighting might not appear the same under some different lighting.
A digital camera detects colour information by filtering the incident light and detecting each intensity using a charge-coupled device (CCD) [5]. Using the data to interpolate the unknown intensities, the camera generates the picture. A camera may instead use cheaper CMOS chips instead of CCDs. This means there is not easy to find a colour’s “absolute” value.
Appendix 2 Overview of Matlab Program and Functions
Other utility programs
add_histogram The adds two histograms and normalises the result. Can also take one histogram from another to find a difference.
chart_find This searches an image for a colour calibration chart. It returns the colour readings as observed from the image.
chart_stats This is a batch program to run chart_find on many images and displays the average. It also tries to disregard bad fits.
yuvmap This generates a colour space chart so. It is not very fast. Perhaps rewrite in c?
yuvtorgb This rarely used program can be used to manually see the result of a transform on the UV co-ordinates
lsfit This does a least square fit (Newton Coates) on an over specified matrix describing the linear transform.
lsfit_func Internal function for lsfit.
Appendix 3 Getting Started with Face Finder
Basic Usage
1. Install Matlab 5.3 or other compatible version. Also install the image processing toolbox.
2. Copy Face Finder to desired location. This should include the workspace folder and its sub directories.
3. Load Matlab. Change to Face Finder Directory using cd c:/Math/Matlab/work/FaceF etc.
4. Start batch_build
5. Select Settings
Histogram Generation
1. Select “2. Choose data set” by typing 2 and hitting enter.
2. Type 006 to select the 006 data set. Not that is corresponds to the B006-????.png files in the Workspace folder.
3. Type 4 and hit enter to select “4. Convert Masked Images….” This will convert the RGB images into YUV images called E006-????.png
4. Select “5. Generate Histogram”
5. We don’t want to write separate histograms to disk so type 0 for no.
6. We don’t want to do a transform on input images so select 0
7. Went prompted input 006 to call the new histogram “probability density map006.png”
8. Enter 6 and then 006 to view the histogram and see statistics.
Find Faces Using Statistical Method (And No Transforms)
1. Make sure the 006 data set is selected as above and the histogram for that data set has been generated
2. Select “8. Detect Faces”
3. Select 1 to output to screen
4. We want to ignore the intensity information so select 0.
5. We do not want to perform transforms just yet, so select 0.
6. We want to detect iamges using the 006 PDF so enter 006.
7. Select 0 to process all images. Selecting 1 will generate only faces that are directly used in performance calculations.
Finding Faces Using a Linear Transform
1. The PDF and colour chart information must be generated for the 009 data set so we can use it as the reference data. Select 2 then 009 then 1 to forget about the old data and consider the 009 data.
2. Generate histogram by selecting 4 (Convert Masked Images) then 5 (Generate Histogram) then 0 (no separate histograms) then 0 (no transform) and enter 009 to save it as “probability density map009.png”
3. We will also have to check the appearance of the colours in the calibration chart. To do this choose 9 (“Get Colour Chart Stats”). These images contain chart type “A” so enter A.
4. When prompted, use the mouse to click on the upper left and then the lower right corner of the colour chart in the figure displayed. After all the images have been processed this writes the file “ChartA009.dat”.
5. Select the 006 data set again. (2 then 006 then 1)
6. Choose 8 (Detect Faces)
7. Output to Screen by choosing 1.
8. To ignore intensity select 0.
9. Choose 1 to select a transform to perform on the input images.
10. Select 3 (General Linear Transform)
11. Select chart type A.
12. Choose reference data set to be 009.
13. Detect with 009 probability density map.
14. Select 0 to process all images
There are many other features in the program that may also be useful but are not described fully in this section.
Appendix 4 RGB To YUV Conversion in C
This is an extract from http://www.sys.wakayama-u.ac.jp/~chen/ucs.html The conversion in the Matlab program was based directly in this code.
Perceptually Uniform Color Space (UCS)
and Its Use for Face Detection
Here, we give a color convertion program to convert a color from NTSC
RGB to the uniform color system proposed by Farnsworth.
(See COLOR SCIENCE, written by Gunter Wyszecki and W. S. Stiles,
John Wiley & Sons, Inc, 1967.)
Although the widely used L*u*v*, L*a*b* color spaces are simple and
easy to use, both of them are just rough approximations of UCS.
A better uniform color system was proposed by Farthworth in 1957. In
this color system, the two colors with an equal distance as perceived
by human viewers, will project with an equal distance here.
C source program to convert (r,g,b) to (y,uf,vf)
/* This function convert (R,G,B) in NTSC's RGB to Farthworth's UCS
* (Y, uf, vf).
* Usage: rgb2yuv(r, g, b, &y, &uf, &vf);
*/
static const unsigned short xy2uv[253][212];
void
rgb2yuv(int r, int g, int b, int *py, int *puf, int *pvf)
{
int i, n, r, g, b, yy, xx, xyz, xyzh, hairy, u, v, y, skin;
float fu, fv;
unsigned int lrgb;
/* RGB -> CIE's XYZ */
yy = 77 * r + 150 * g + 29 * b; /* CIE's Y * 256 */
*py = yy / 256; /* CIE's Y */
if (*py == 0) {
#define UGRAY 43
#define VGRAY 44
*puf = UGRAY; /* (UGRAY, VGRAY) is "white" */
*pvf = VGRAY;
return;
}
xx = 147 * r + 42 * g + 49 * b; /* CIE's X * 256 */
xyz = 55 * r + 50 * g + 87 * b; /* CIE's (X + Y + Z) * 256 */
xyzh = xyz / 2;
xx = (xx * 100 + xyzh) / xyz; /* CIE's x * 100 = X/(X+Y+Z) * 100 */
yy = (yy * 100 + xyzh) / xyz; /* CIE's y * 100 = Y/(X+Y+Z) * 100 */
/* For all visible color,
* XN <= x <= XM
* YN <= y <= YM
*/
#define XN 56
#define XM 267
#define YN 32
#define YM 284
xx -= XN;
if (xx < 0)
xx = 0;
else if (xx > XM - XN)
xx = XM - XN;
yy -= YN;
if (yy < 0)
yy = 0;
else if (yy > YM - YN)
yy = YM - YN;
/* Use a table look up to convert (x,y) to Farthworth's
* (uf,vf)
*/
uv = xy2uv[yy][xx];
*pvf = uv / 256;
*puf = uv % 256;
}
static const unsigned short xy2uv[253][212] = {
0x5,0x6,0x107,0x108,0x209,0x20b,0x30d,0x40e,
0x40f,0x511,0x613,0x614,0x616,0x717,0x719,0x71a,
and so on. See web page for complete listing.
Appendix 5 Matlab Source
For complete listings, contact Tim directly.


