Assignment Title

CS 585 HW 1
Yuankai He
Date: 12 Sept 2018

Problem Definition

Give a concise description of current problem. What needs to be solved? Why is the result useful? Do you make any assumptions? What are the anticipated difficulties?

The homework asks us to create 3 images. The first image, convert a colored BGR image into a gray scale image. The second image, flip the image, horizontally or vertically. The third image, it can be manipulated any ways. We couldn't use any builtin functions. The result is very useful in defining what a gray scale image is, and how to convert images.

Method and Implementation

Give a concise description of the implemented method. For example, you might describe the motivation of your idea, the algorithmic steps of your methods, or the mathematical formulation of your method.

For the gray scale image, I went from top left, moving right across the first row and then move to the second row. I find this approach to be the most straightforward approach. Since I do not need to recognize any objects, I do not to use flood filling or sequential labeling.

Briefly outline the functions you created in your code to carry out the algorithmic steps you described earlier.

I have just one function that cycles through the pixels from top left to bottom right.


Describe your experiments, including the number of tests that you performed, and the relevant parameter values.

I ran the test several times using different images. The image I used compared to the boston image, my image ran faster and used less memory. This is because the image I used has less pixels.

Define your evaluation metrics, e.g., detection rates, accuracy, running time.

The output images came out as expected.


List your experimental results. Provide examples of input images and output images. If relevant, you may provide images showing any intermediate steps. If your work involves videos, do not submit the videos but only links to them.


Trial 1: Gray Scale
Trial 2: Flipped
Trial 3: Something Fun


Discuss your method and results:


Based on your discussion, what are your conclusions? What is your main message?

I learned alot from this homework. When converting to gray scale, I was a bit confused. I thought the 3 BGR values would be reduce to just one value, but instead, its the BGR taking the same computed value. Flipping the image was relatively easy, and I had no troubles doing that. Creating a fun image seemed to be a challenge, I dont feel like I've learned enough to create a funny image.

Credits and Bibliography

Cite any papers or other references you consulted while developing your solution. Citations to papers should include the authors, the year of publication, the title of the work, and the publication information (e.g., book name and publisher; conference proceedings and location; journal name, volume and pages; technical report and institution).


#include #include #include #include #include using namespace cv; using namespace std; int main() { Mat image; image = imread("me.jpg", IMREAD_COLOR); // Read the file if (image.empty()) // Check for invalid input { cout << "Could not open or find the image" << std::endl; return 0; } cout << "Hello World" << std::endl; // convert image to gray scale for (int i = 0; i < image.rows; i++) { for (int y = 0; y < image.cols; y++) { int b = (i, y)[0]; int g = (i, y)[1]; int r = (i, y)[2]; int first_comp = max(b, g); int gray_max = max(first_comp, r); (i, y)[0] = gray_max; (i, y)[1] = gray_max; (i, y)[2] = gray_max; } } //save image imwrite("grayscale.jpg", image); image = imread("me.jpg", IMREAD_COLOR); // flip image for (int i = 0; i < image.rows; i++) { for (int y = 0; y < image.cols/2; y++) { Vec3b temp = (i, y); (i, y) = (i, image.cols - 1 - y); (i, image.cols -1 - y) = temp; // other way to do the flipped image /*int b = (i, y)[0]; int g = (i, y)[1]; int r = (i, y)[2]; (i, y)[0] = (i, image.cols - 1 - y)[0]; (i, y)[1] = (i, image.cols - 1 - y)[1]; (i, y)[2] = (i, image.cols - 1 - y)[0]; (i, image.cols - 1 - y)[0] = b; (i, image.cols - 1 - y)[1] = g; (i, image.cols - 1 - y)[0] = r;*/ } } //save image imwrite("flipped.jpg", image); // do something fun! image = imread("me.jpg", IMREAD_COLOR); for (int i = 0; i < image.rows; i++) { for (int y = 0; y < image.cols; y++) { int b = (i, y)[0]; int g = (i, y)[1]; int r = (i, y)[2]; (i, y)[0] = (i, image.cols - 1 - y)[1]; (i, y)[1] = (i, image.cols - 1 - y)[1]; (i, y)[2] = (i, image.cols - 1 - y)[0]; (i, image.cols - 1 - y)[1] = b; (i, image.cols - 1 - y)[1] = g; (i, image.cols - 1 - y)[0] = r; } } imwrite("somethingfun.jpg", image); // Show our image inside it. namedWindow("Display window", WINDOW_AUTOSIZE); // Create a window for display. imshow("Display window", image); waitKey(0); // Wait for a keystroke in the window return 0; }

Credit any joint work or discussions with your classmates.