Hello, if you have any need, please feel free to consult us, this is my wechat: wx91due
CS-111 Programing Assignment 1: OpenCV Setup and Image Filtering
Submission instructions:
Please submit your code and the PDF file in a single zip file to Canvas.
You must also submit the same PDF file to Gradescope.
BOTH submissions are required for full points.
Introduction:
Programming assignments for this course are designed for you to get hands on experience in writing image processing code. The preferred programming language is C/C++ and you will use OpenCV library for reading and writing images. You are expected to write complete, stand-alone functions that perform the desired operations on the input images.
You are only allowed to use some OpenCV functions and you cannot replace the function you have to develop with its built-in functions. You will be required to submit your output image along with your function’s code.
OpenCV Installation:
a. Download free Visual Studio from https://www.visualstudio.com/free developer-offers/ and download the Visual Studio Community.
b. Install Visual Studio and when Visual Studio Installer is up, choose only “Desktop Development with C++” and install.
c. Once Visual Studio is installed, create a new “Windows Console Application” project.
II. Installing OpenCV
b. Run the executable and unzip the content in a specific location on your computer (e.g. C:\)
c. Go to your Visual Studio project (that you created in the last step) and change the following properties:
III. Start manipulating images
a. Now your project is ready to use OpenCV. Normally, images are color images, however, in this course we also will work on gray images (no color) for simplicity. An image is like a big matrix of the size of the image where each pixel has value that specifies the color or brightness of that pixel. Normally color images are RGB, which means each pixel has red, green and blue values. These values can have different ranges but the normal range for ordinary images are from 0 to 255, which means one byte per channel.
b. In the following code snippet, you will see how to read a color image, convert it to a gray image and save the new image. To use OpenCV commands in code, you need to include <opencv2\opencv.hpp> which contains OpenCV headers. The basic data structure in OpenCV is Mat, which is a matrix that can hold an image. Using the functions imread and imwrite, you can read and write images, respectively. Each pixel value can be read as OpenCV data structures Vec3b (for color images) or uchar (for grayscale images). You can create an empty Mat by specifying the size and the depth of each pixel. Here we use CV_8UC1 for gray images and CV_8UC3 for color images. If you have any confusion on how to use OpenCV or if you want to learn more about its features, you can read its very well defined documentations at https://docs.opencv.org/3.4.1/
c. One simple way to convert a color image to a gray image is taking average of the each red, green and blue channels, as you can see in the above code. However, our eyes are more sensitive to some colors than the others. According to Rec.ITU-R BT.601-7 standard, the following formula should be used to correctly convert a color image to a gray image:
Modify the above code snippet to correctly convert the RGB image to gray image and apply it to all the color input images. Submit your code with the result images.
Modify the above code snippet to replace the green with blue, red with green, and blue with red channels. Apply changes to all the color input images. Submit all result images with your code.
Image Filtering
A box filter is a square filter that averages all of the image pixels covered by the filter. The output (i.e. filtered) pixel corresponds to the center pixel of the input pixels covered by the filter kernel. The filter kernel for a 3x3 box filter is:
For each pixel in the input image, this filter adds that pixel’s value and those of its eight neighboring pixels and calculates their average. The output pixel value will be the rounded average value. You should write a function with the following signature:
Mat BoxFilterGray3(Mat I);