Mini-Lab: Selectively Changing Colors

 


Introduction

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


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 in the notes. The only differences are that this function works on the entire image, and the color that will be changed is also passed in as a parameter.
  2. Comment and test your new function.
    Tip 2: What if there was more color change — or less color change — than you were expecting? Try using different values for your comparison: 100, 165, 200, 250, etc. Try changing out different colors — if you switched out blue to start with, try switching out red or green instead. You could even try reversing the comparison — what happens if you use > instead of < (or vice versa)? Experiment with different pictures, colors, and threshold values to see what effects you can create.
    Analysis Question: Could your new function be used for red-eye removal? If not, what changes would be necessary?

Submit your results

  1. Submit the file you created in this mini-lab via Kit. Be sure to include your answer to the analysis question as a comment after your function.

  2. Submit an original image along with the new version of it obtained through your colorSwitch function.