Programming assignment - OpenCV Image Operations

CS 585 HW 1
Ellen Lo
September 12, 2018


Problem Definition

This programming assignment is an introduction to OpenCV and its operations to images. Instead of using built-in functions of OpenCV, this assignment directly reads RGB value of pixels from input image and convert it to grayscale value. Expected challenges are type conversions and inaccurate pixel assignment.


Method and Implementation

The program reads face input image in color. By averaging R, G, and B components of each pixel, the generated grayscale values is written into grayscale Mat. The result is saved as "grayscale.png".

Second, using the grayscale result, I iterate through the pixels row by row and flip the image by assigning pixels from right the left. The result is saved as "flipped.png".

Third, I create a blur function which takes a Mat input and its size and output a blurred image. The blurring operation assigns each pixel to the average grayscale pixel value of itself and its neighbors. An if statement is used to handle the varying number of neighbors, for instance, corner of image only has 3 neighbors, border has 5 neighbors, and the rest has 8. By running the blur function 11 times, a significantly blurred output is saved as "blurred.png".

Finally, the 3 outputs are saved and displayed in 3 separate windows along with the input image.


Experiments

Both grayscale and flipped image outputs meet expectation, so no extra tests are conducted. However, in order to create a significantly blurred image from the flipped image, I ran the blurring function with different number of iterations. Results are shown in the next section.

The program was tested on OSX machines with OpenCV installed only. Run /Applications/CMake.app/Contents/bin/cmake . in directory containing main program file and make to compile. Then run ./A1, as configured in CMakeLists.txt file, to run program.


Results

The first table show the input image and 3 output results. The second table show outputs of flipped image blurred once, 4 times, and 11 times. Images are stored inside "html/img" folder.

Results

Input image Grayscale image Flipped image Blurred image

Blurred variable number of times

Original image Blurred once Blurred 4 times Blurred 11 times


Discussion

Discuss your method and results:


Conclusions

This programming assignment was very useful for me to brush up my OpenCV programming practices. I was successful in setting up OpenCV on my own machine and completing all tasks given in programming assignment. I look forward to writing more advanced computer vision algorithms, such as object detection, edge detection, and cascade classifiers.


Credits and Bibliography

Wired Watershed, HOWTO: Install, Build and Use openCV (MacOSX 10.10). https://blogs.wcode.org/2014/10/howto-install-build-and-use-opencv-macosx-10-10/

This is an independent work by Ellen Lo.