CS 107: Pictures and Sounds: Programming with Multimedia

Kalamazoo College

Spring 2008

Mini-Lab: Selectively Changing Colors

 


Introduction

The objective of this mini-lab is to learn how to use the if-else construct by selectively changing the colors of pixels in an image.


Fixing Increase Red

  1. The increaseRed function you wrote in an earlier mini-lab crashed whenever it tried to increase the red value of a pixel above 255. Write a version of the increaseRed function that uses an if statement to ensure that this never happens. Test your function to make sure that it works as expected.

Color Switching

  1. Write a new function called colorSwitch that will replace one color in an image with another. For example, you might want to replace all of the blue pixels in an image with black. Your function should take three parameters: the picture, the color that will be replaced, and the color that will replace it. It should return the modified picture. (Your function should not change the picture that is passed in as a parameter, the first step in your function will be to make a duplicate.)
    Tip: This function is very similar to the removeRedEye function on p. 103 of the book. The only differences are that this function works on the entire image, and the color that will be changed is passed in as a parameter.
  2. Comment and test your new function.
    Analysis Question: Could your new function be used for red-eye removal? If not, what changes would be necessary?

Print your results

  1. Print the functions you created in this lab and hand them in.