CS585:Image and Video Computing
Homework 1: face detection
Problem Definition:
We were asked to create a program in Java or C to detect a face in an image. The method we were asked to use was to detect the color of the subject's skin, and turn all non-skin pixels black. This would be very useful in any application involving the detecting people. For example (and this is currently implemented) a digital camera can use this feature to find people in its field of view and make sure they are in focus. Or this could be used in countingg people passing by a camera, or many other scenarios.

Method & Implementation:
I set out to solve the problem by first calculating a skincolor from the image, and then scanning through it to turn all pixels outside a certain tolerance of this color to black. To do this I used two main functions, with a nested call. The functions were called by:

img1=colorImage(20,getSkinColor(30,img),img);

the functions are as follows:

public Color getSkinColor(int thresh, BufferedImage image): scan through a 5x5 square in the dead center of the image and average the RGB values of all pixels that do not stray from the maximum values by more than a certain threshold. This is implemented by first scanning through them (with two nested loops) to determine the brightest pixel (if red, green, and blue values are greater than the previous max), then scanning through and summing each pixel and an average value, and dividng by two. Pixels whose difference with max is greather than the threshold are excluded.
public BufferedImage colorImage(int thresh1, Color skin, BufferedImage image): given the skin color and a second threshold value, set the color of all pixels who do not equal the skin color +/- the threshold values (must pass this test for each color value) to the color black.

Experimental Results:
I found that the first threshold did not make much of a difference except at very low values (about 5 and below). In that case it would return black or a very light pixel. I found that a threshold range of 20-30

This changes the threshold in the colorImage method. Don't scroll too much as the grapics are pretty buggy.
Source Image Threshold=20 Threshold=25 Threshold=30
Source Image Threshold=20 Threshold=25 Threshold=30

Discussion and Conclusion:
Link to code