Mini-Lab: For Loops
for Manipulating Pixels in a Picture

 


Introduction

In this mini-lab you will gain practice with using Python for loops to process all pixels in a picture.



Modifying pictures pixel-by-pixel

  1. Start up JES. Add comments to the top that describe the file as a whole, such as:
    # Mini-Lab: Functions that Manipulate Pixels in a Picture
    # Your Name
    # Today's Date
  2. Type in and run the reduceRed function from the Pictures and Loops notes. Remember to add a comment for this particular function, such as:
    # Reduce the amount of red in a picture by 25%
    Debugging Tip: If the function does not work correctly, check that you remembered the colon at the end of the first line of the function definition and that you spelled all of your variable names and function names correctly.  After any edits, remember to click on the Load button before calling your function.
  3. Type in and run the increaseRed function from the notes.   Remember to add a comment for each function.
    Analysis Questions: What similarities do you see between the reduceRed function and the increaseRed function? What differences are there between the two functions?
    Include your answers to these analysis questions in comments in your program after your increaseRed function.
  4. Create and run a function called showRedChannel that sets the blue and green values for each pixel in an image to be equal to the red value. For example, a pixel with the value (RED=123, GREEN=18, BLUE=222) would be changed to (RED=123, GREEN=123, BLUE=123).
    Analysis Questions: How does showRedChannel affect the appearance of your picture? What happens to regions of the original picture that were red? What happens to regions of the picture that were blue?
    Include your answers to these analysis questions in comments in your program, either before or after your showRedChannel function.
  5. Type in and run the makeSunset function from the notes.  Test this on several different pictures.  Remember to add a comment for this function.

Submit your results

  1. Submit the file containing your functions via Moodle.