Constantino Fernández Pérez
The goal of this part of the assignment is to familiarize with programming with images. This program will take an image of my face as an input, and will manipulate it in three ways, outputting the processed face.
To start processing the image we will first save the image as a matrix called "image". Each element of the matrix represents a pixel of the image. This pixels are represented by 3 values of 8 bits each one (0 to 255) containing the amout of blue, green and red (BGR).
Because it is an 8-bit 3-channels color image, we must use the type of matrix CV_8UC3 (default) to store this pixel values.
Create a grayscale image of your face by converting your color image using one of the conversions we discussed in class last week.
In order to convert the color image to a grayscale image I used the average method which consists on adding the three BGR values and dividing them by three (average) to get the remaining single value of each pixel.
Because we want to convert the color image to an 8-bit 1-channel grayscale image we must create a CV_8UC1 matrix called "bwimage".
Now to fill this matrix I did two loops (one for the rows and one for the columns) to go over each element of the matrix "image", saved its pixel in a Vec3b vector called "pixelColor", computed the average of these three values, and saved it in the same position of the matrix "bwimage".
Once the entire matrix had been gone through, I displayed the new black and white image in a new window.
Flip your face image horizontally.
Because the flipped image would still be a colour image I created a CV_8UC3 matrix (default) called "flippedImage".
Now to fill this matrix first I saved the numer of columns in a value called "c".I did two loops (one for the rows using i and one for the columnsusing j) to go over each element of the matrix "image", and saved its pixel in the position (i, c-1-j) of the "flippedImage".
Once the entire matrix had been gone through, I displayed the flipped image in a new window.
Come up with a third way of manipulating your face that produces an interesting output.
I decided that it would be fun to change the tones of my face to make me look tanner.
Because the tanned image would still be a color image I created a CV_8UC3 matrix called "flippedImage".
To fill up this matrix I did two loops (one for the rows and one for the columns) that went over each element of the matrix "image" and saved its pixel in a Vec3b vector called "pixelColor".
For each pixel in the photo the first thing I had to do was make sure the pixel was part of my face (or at least of its tone) so what I did was create four if-conditions to compare each BGR value to values of my real skin tone.
With the first two I separated what couldn't be part of my face (either because it was too bright or had a tone that doesn't belong to any real skin tone) and filled the "tannedPicture" with the same values as the original pixel.
With the other two I separated the part of the face that had reflections from the part that was fine and reduced the BGR values. By doing this I could also make a little bit darker the reflection parts so that the tan effect was more noticeable.
Once the entire matrix had been gone through, I displayed the tanned image in a new window.
These methods to manipulate the photos are very basic because what we were trying to do was familiarize with programming with images, but opencv has its own functions to directly convert colours or apply filters. It was a good homework to get used to manipulating images and understanding how each pixel and the changes that you can apply to them really work.