CPSC 120: Lab Assignment 7

Due at 2:59 pm on Thursday, 05/01/2014

Home | Calendar | Announcements | Assignments | Example Code | Notes


This assignment is optional!

The workload for this course consists of six labs, three exams, and three projects. This is lab #7, and its completion is optional. Other than your time, you have nothing to lose. There are two reasons to do it:

  1. Image processing algorithms are incredibly cool, and you will probably find it very satisfying to complete the ones given here.

  2. If you turn this in by the due date, it will be used to improve your grade for the course in one of two ways:

    1. It can be used to replace a low lab score from earlier in the term. Under this option, your work will be graded on the same 50-point scale as Labs 2-6. I will take the best five out of those six scores.
    2. It can be used in place of your Project #1 or Project #2 grade, for up to 35/75 of the total score (each of those labs was worth 7.5% of your total grade). You cannot count it against Project #3, however.

    The first option can repair up to 5% of your overall grade, while the second one offers up to 3.5%. I will use the option that gives the best advantage to you, but: this only applies to submissions that arrive by 2:59 pm on Thursday, May 1st. No late work will be accepted for this one.

PROBLEM ONE: Selective Color Retention

In class, we explored the process of color replacement, using the boostRed and redeyeReduction methods (see the sketch "effects", available on the Example Code page).

An interesting effect, often used in advertising and film, is to render a grayscale version of an image with selective color retention. While a complete implementation of this technique is beyond the scope of our course, we can achieve some of the same results with only slight modifications to our color replacement code.

Here, for example, is a picture of a camas lily, in full color, and with the yellow stamen left in color:

I achieved this by preserving the color (158,150,67):

void setup() {
    PImage camas = loadImage("camas.png");
    size(camas.width, camas.height);
    color col = color(158,150,67);
    retainColor(pixels, col);


Implement the retainColor method. You can get ideas and inspiration for this from the BWfilters and effects sketches.

PROBLEM TWO: Line Detection

In class on April 23rd, we explored the algorithm for line detection. This is available in the effects sketch, on the Example Code page.


Currently, this code fixes the background color of the line drawing at pure white, the line color at pure black, and the threshold for detection at 2. You are to generalize all three of these assumptions. In other words, add parameters to renderLines for the backgroundColor, lineColor, and the threshold, and modify the remaining code to use these.

color lineColor = color(64,75,105);
color bgColor = color(240,230,230);

color[] sketch = new color[pixels.length];
renderLines(pixels,sketch, width,height,5,bgColor,lineColor);



Turn in

As with all assignments for this course, submit the folder containing your Processing sketches. This should be a single folder named "hw6", which will contain your methods, all in a single source code file. You do not need to submit a paper printout of anything. Again, the turnin directory is


John H. E. Lasseter