CSI Lab 03

Tuesday, January 29th

Objectives:


Introduction

Today's lab is a shorter lab than normal since part of class was taken up by the guest lecture by Ira Greenberg.

The material in this week's lab is based heavily on the material in section 3.3 of your textbook.  At times, we will ask you to work very closely with your book.  At other points, we will ask you to use what you have just done to write some code of your own.  If you get stuck, feel free to refer to the appropriate pages in your textbook. 

As in the past, the instructions are contained on this website, but the answers or signatures that you are required to obtain should be completed on the paper Activity Report which will be provided to you in lab.


Getting started

Suppose that you have been hired by the UNI athletic department to help them with some publicity.  They have two images - one is of the UNI mascot, TC, the other is of the football field in the dome - that they want to do some file manipulation with.

Save the following files to your media directory on the math-cs drive (P: drive).  You can either choose to save the following files or you can copy them from the common_media directory to your personal media directory as we did in lab1.

In order to view these files before you work with them, launch the image explorer tool by executing the following commands in the Interactions pane.

    > mascot = makePicture(pickAFile())
    > field = makePicture(pickAFile())

From the MediaTools menu in JES select the Picture tool and then select and explore each of these images.

mascot.jpg

[Q1]  What is the size of this image?

[Q2]  What is at location 180,75?

[Q3]  What position is the upper-leftmost corner of the "5" on his jersey?

[Q4]  Imagine a box surrounding the phrase "University of Northern Iowa"  What would be the approximate positions of the upper-left and lower-right corners of this box?

[Q5]  What are the RGB values of TC's fur?  Of the purple color at the bottom of the screen?

footballfield.jpg

[Q6]  What is the size of this image?

[Q7]  What is at location 180,75?

[Q8]  What are the RGB values of the "grass"?  Of the endzone? (For both of these, the values vary widely.  Pick a "typical" value.)


Activity A : Decreasing the Red in a picture

Suppose that the athletic department wants you to adjust the colors in these images.  For example, suppose that they feel that there is a little too much red in the picture of the picture of TC (there isn't, but just play along!).

Page 56  in your textbook contains Recipe 8 which is the decreaseRed() method for a Picture.

Type the code for recipe 8 into the program area (the white area at the top) of JES.  Be very careful and pay attention to details.  Remember that things such as spelling and certain kinds spacing in Python are VERY important.

When you are done, save this file to your directory on the P: drive as "lab4.py" and then load the program.  to test that it works properly run the following commands from the interactions pane:

    > mascot = makePicture( pickAFile() )
    > show(mascot)
    > decreaseRed(mascot)
    > repaint(mascot)

Please note that you will need to be patient when you run the decreaseRed() method.  This might take a while.  Trust that it will finish on its own.  If you receive errors, fix the problems.  If you have typed everything correctly you should notice a significant change to the picture.

[Q9]  What do you observe?

[Q10] This method is valid for ANY picture that you might send it as a parameter.  Try it out on the footballfield image.  What do you observe?

    > field = makePicture( pickAFile() )
    > show(field)
    > decreaseRed(field)
    > repaint(field)

[SIG1]  When you have the decreaseRed() method working, demonstrate this to a TA.


Activity B : Increasing the Red in a picture

Of course, once you have the ability to decrease the red it might be nice to be able to increase the red.  Recipe 9 on page 61 of your book offers one mechanism for doing this.  Type the code for recipe 9 into the program area of JES.  You need not start with a new file, nor do you need to delete the decreaseRed() method from Activity A.  Instead, just give yourself one or two blank lines after decreaseRed() before you start typing the increaseRed() method.

When you are done, save this file again (still named lab04.py) and test the code.  You can either do this by starting over from scratch:

    > mascot = makePicture( pickAFile() )
    > show(mascot)
    > increaseRed(mascot)
    > repaint(mascot)

OR, if you still have mascot as a defined object in memory you can work with the one you have been using...

    > increaseRed(mascot)
    > repaint(mascot)

[Q11]  What do you observe?

Invoke this method a few more times, such as :

    
    > increaseRed(mascot)
    > increaseRed(mascot)
    > increaseRed(mascot)
    > repaint(mascot)

[Q12]  What do you observe?  You may want to open the picture with your picture tool and see what happens as you run this method multiple times. 

[Q13]  What conclusion can you make about the setRed() method that you use in your increaseRed() method?

[SIG2]  Demonstrate your increaseRed() method for the TA/Instructor.


Activity C : [BONUS]  Create additional methods

Using the code from Activity A and B as a guide, create additional methods called

[SIG3]  Demonstrate these methods for the TA/Instructor