Due Date
-
All three parts must be submitted by 10pm on Friday, Nov 4.
Submit the programming work online to
http://culearn.colorado.edu. Late work is accepted until noon on
Monday, Nov 7 with a ten-point late penalty.
Working Alone
-
You may talk with other students and instructors about the
assignments, and you may help each other in any way to
create your initial photos
for use in this assignment.
But you may not look at or copy code written by others.
The penalty for violating this code is an F for the entire semester.
Submission Note
-
You must submit both your .cxx file and your .jpg file! Otherwise,
the TA cannot grade your work!
Programming Style
-
For full credit, your work must show good judgement in deciding
which parts of your program to make into separate functions with
parameters. A large main program or individual large functions will
not receive full credit.
Also, all your work must follow these the essential style
items from
www.cs.colorado.edu/~main/style.html.
Preliminary Work
-
Before you begin this assignment, you'll need two photos:
- A photo of yourself with a white sheet as the background. I laid
down on the sheet, and had Janet take the picture. Wear something
nice, but do not wear anything that is white or grey!
You must crop the
picture so that nothing shows except you and the sheet, and reduce the
size of the picture to no more than 600 by 600 pixels. I'm using this picture, that I called michael.jpg:
- The second picture is any image that you'd like to use as a
background. I'm using this image, background.jpg, from
nasa.gov:
- Note that the two pictures must have exactly the same
dimensions. If you have trouble editing your images to meet these
requirements, then please come see us during office hours.
The Assignment: Part 1 of 3
-
Write a program that reads the image of you and displays it in a
graphics window that is exactly the same size as the image. Whenever
you click on a location in the image, the program should print (using
cout) the red, green and blue values for the pixel where you
clicked. As you know, these numbers may range from 0 to 255. A
reminder of the code to get these values for a pixel at coordinates
px,py (all variables are int):
color = getpixel(px,py);
red = RED_VALUE(color);
green = GREEN_VALUE(color);
blue = BLUE_VALUE(color);
The program has a loop, so that you can make multiple clicks and get
the values for lots of different pixels.
The function to read a jpg file from the hard drive is called
readimagefile, and you can look up it's documentation on the winbgim
link on our home page.
Put your work in a file called photo1.cxx.
The Assignment: Part 2 of 3
-
For photo2.cxx, write a program that again displays your picture in a
graphics window. After displaying the picture, it then changes all of
the sheet's pixels to GREEN, and then have a long delay (1000 seconds
or more).
I'd suggest that you write a bool
function that you call to determine whether a pixel is part of the
sheet. For the most part, these pixels will be white or grey, and you
can detect such a pixel by looking at its red, green and blue
components. None of those components should be too small (because then
the pixel starts to be black), and all three components should be
pretty close to each other. In my first attempt at this, I required
the pixels values to each be greater than 80 and for the difference
between any two of the rgb values to
be no more than 20. Here's what I got when I changed all these
pixels to GREEN:
This isn't quite right. There are some pixels on my jeans that got
changed to green, and some of the sheet pixels did not become green. I
used my first program to determine what color those particular pixels
were, and then I adjusted my algorithm several times until I was
getting a pretty good result, like this:
You might need some interesting adjustments to your algorithm. For
example, my jeans had a lot of bluish-grey that was being picked
up. To eliminate these pixels, I required the pixels to not have much
more blue than red. Even so, my pixel selection is still not perfect,
but it is good enough for a one-week assignment.
The Assignment: Part 3 of 3
-
For photo3.cxx, you will open two different graphics window. One will
have your picture and the other will have the background that you
selected from nasa or somewhere else. (Make sure that you give a
citation in your program for the source of your background). Here's
how I opened my two windows, so that they were both on the screen:
initwindow(WIDTH, HEIGHT, "Outer Space!", 0, 0, false);
readimagefile("background.jpg", 0, 0, WIDTH, HEIGHT);
initwindow(WIDTH, HEIGHT, "Michael!", 50, 50, false);
readimagefile("michael.jpg", 0, 0, WIDTH, HEIGHT);
This opens both windows at the same time. The background window is
placed on the screen at (0,0), and the picture of me is slightly
offset at (50,50).
After you have both windows open, please go through the picture of
yourself one pixel at a time. Any time you find a pixel that is part
of the sheet, replace it with the pixel from the same location of the
background photo (instead of coloring it GREEN!).
Here's what I got:
Programming Hints
-
- When you have two graphics windows open, you must continually tell
the bgi library which window you want to work in. The windows are
numbered 0 (for the first window opened) and 1 (for the second
window). For example, if you want to put a pixel on window number 1,
you would write this code:
setcurrentwindow(1);
putpixel(px, py, c);
By the way, if you want to save the window to a bmp file on your hard
drive,
you can do so by clicking
on the top left corner and choose the Save Image As option!
My thanks to Professor Clayton Lewis for this assignment idea!