The problem or purpose of this assignment is mainly to explore the features of OpenCV using Visual Studio. We need to utilize these two resources to manipulate our self-portraits in 3 ways:
- Create a greyscale version of our portrait.
- Flip our portrait horizontally, i.e. left to right or right to left.
- Anything we would like, but I manipulated it by blurring the image.
This assignment is useful in understanding the features we could use with OpenCV to later on create much more complicated projects, and solve future coding assignments. I am assuming that I can use any provided OpenCV functions to solve some of the problems rather than writing a full function. The anticipated difficulties will be knowing the syntax and functions I should use to manipulate the image.
Method and Implementation
Brief description of the image manipulations:
- The greyscale image was manipulated by taking in the original image, and for each pixel the RGB values are averaged, and replaced by the averaged value. I used this version instead of weighting the RGB values instead just for the simplicity. The function will be listed below.
- The flipped image was created by swapping the RGB values of each pixel with its corresponding mirror pixel therefore resulting in a flipped image. The function will be listed below.
- The blurred image was created by taking in the greyscale image, and for each pixel the average is taken of the pixel itself and its surrounding pixels. Once the value is calculated, the RGB values are replaced by the value. There are special cases when calculating the values such as the corners and the edges, since there is not 8 pixels surrounding it. I blurred the image 5 times to make it really noticable. This was done with a for loop inside the blur function. The function will be listed below.
My main function reads the inputted image of me, and for each manipulation a clone of the original image was made and passed into each function. Then all the original and manipulated images are displayed in a window and to see if they are what they are supposed to look like.
|Trial||Source Image||Result Image|
Discuss your method and results:
My results turned out as what I expected, so I think my method is fairly successful. Although I cannot say the same in turns of the efficiency of my method, so I feel like it could be written in a much more efficient manner. One thing that somewhat surprised me was how dark my blurred image turned out. This could be due to either how dark the image already was, or that the way I calculated the average is slightly different creating a generally darker image. This is something I could definitely improve on in the future by experimenting with the different methods of calculation to see what is causing the darkened image, and maybe write a function that can blur the image in its original color rather than a grey scaled image.
In conclusion, my program worked correctly to achieve the goals I was aiming on achieving. There may be some flaws in the method of execution, but overall it worked well. This experiment helped me familiarize myself with C++, Visual Studio, and OpenCV by giving me a more hands on experience. I have learned how to create my own methods rather than relying on OpenCV's built-in functions.
Credits and Bibliography
Credits to the lab solution method tintImageBlue in giving me an idea on how to write using C++ and OpenCV.