My program took an image of my face as input, manipulate it in 3 ways then output the processed faces pictures.
Needs to be solved: How to convert a colored image to grayscale? How to blur a image? How to create a binary image?
The results are useful because: Grayscale image use only one number instead of 3 numbers(R,G,B for example) to describe a pixel. Blurred image also have smaller size. Pixels in binary image is either 0 or 255, which simplifies the later processing.
Difficulties: how to choose the threshold when creating the binary image.
Method and Implementation
When creating the grayscale image, I use the formulation
grayscale of each pixel = 0.3*R+0.59*G+0.11*B
It looped twice to iterate each pixel in the image, first by row, then column.
When creating the blurred image, I followed the instruction given in part2, question 2, using the grayscale image generated earlier and assigned to each pixel the average grayscale pixel value of itself and its 8 neighbors.
When creating the binary image, I referenced the website:
https://en.wikipedia.org/wiki/Binary_image and tried a few times to find a satisfied threshold.
fuction void grayScale(Mat& image) is to create a grayscale image; void blurred(Mat& image) is to create a blurred image; void binaryImg(Mat& image) is to generate the binary image.
I performed 3 tests for given 3 questions. When generating the binary image, I tried a few times between 30 to 60 to find the best threshold B (blue for RGB) to differ my face from background wall.
|trial 1: binary img|
|trial 2: blurred img|
|trial 3: grayscale img|
The results for these 3 trials show that my methods are generally successful. I expected to find a way to detect the threshold automatically but I finally write it down in the code (after I tried many times.)
Potential future work: find the way to let my program automatically find the threshold when generating a binary image.
OpenCV has a great many APIs. However, realize them by myself is interesting and helps me to understand the mathematical theory besides them better.
Credits and Bibliography
Discussions with: Zhuohao Yang, he helped me catch up with 1st lab. And the 3rd way to output a binary image was inspired by him.