Assignment 4: Transforming Colors, Drawings, and Images

Due: 10:30 p.m. Tuesday 18 February 2014

Summary: In this assignment, you will explore mechanisms for transforming images in two models: drawings as values, and raster graphics (images as collections of pixels). Our focus will be on using lists, iteration, and anonymous procedures within each of the models.

Purposes: To give you more experience with each of the image models. To give you more comfort with anonymous procedures. To emphasize the re-use of procedures.

Collaboration: You must work with assigned partners on this assignment. The partner assignments are available at You may discuss this assignment with anyone, provided you credit such discussions when you submit the assignment.

Submitting: Email your answer to . The title of your email should have the form CSC-151-01 Assignment 4 and should contain your answers to all parts of the assignment. Scheme code should be in the body of the message. You should not attach any images; we should be able to re-create them from your code.

Warning: So that this assignment is a learning experience for everyone, we may spend class time publicly critiquing your work.


Problem 1: Visualizing Colors

As you saw in your initial exploration of RGB colors in GIMP and MediaScript, there are a wide range of of colors possible. You may have also discovered that it is difficult to figure out what color a particular RGB triple, such as (18,223,51) represents. It is also useful to see how a variety of colors relate to each other.

It can therefore be helpful to build tools to help you understand colors and their relationships. We will start this assignment by considering such a procedure that helps do just that.

Write a procedure, (visualize-colors list-of-colors number-of-colors), that produces a simple visualization of a list of colors by making a list of copies of some simple shape, each colored with a different color, and each shifted slightly from the last. You may choose the shape, size, and amount to shift subsequent shapes.

An Example

For example, consider the following command

> (visualize-colors 
   (list "red" "orange" "yellow" "green" "blue" "indigo" "violet")

If we use circles of diameter 20, with each subsequent circle starting 15 units to the right of the previous circle, we should get something like the following.

Similarly, we can visualize a variety of variants of brightnesses of the color pink using the following.

> (define RGB-PINK (color->irgb "pink"))
> (visualize-colors 
   (list RGB-PINK
         (rgb-darker RGB-PINK)
         (rgb-darker (rgb-darker RGB-PINK))
         (rgb-darker (rgb-darker (rgb-darker RGB-PINK)))
         (rgb-darker (rgb-darker (rgb-darker (rgb-darker RGB-PINK)))))

Using the same visualization technique (circles of radius 20, spaced by 15 units), we would get the following image.

Some Notes

You will find it easier to do this assignment if you break the problem down in to steps.

  • Create a drawing of some basic shape. (We shifted the unit circle by 0.5 and then scaled it by 20.)
  • Make a list (of the appropriate size) of multiple copies of that shape. In the first case, we made a list of seven circles; in the second, we made a list of five circles.
  • Make a list of offsets. (We made the list (0 15 30 45 ...).)
  • Use map (along with an appropriate procedure) to offset your drawings.
  • Use map (along with an appropriate procedure) to color your drawings.
  • Turn that list of drawings into an image.
  • Show that image.

Problem 2: Visualizing Color Transformations

Using your visualize-colors procedure, write a procedure (visualize-transformations rgb-color list-of-transformations number-of-transformations), that takes a color and a list of color transformations (along with the list's length) and visualizes the result of applying each transform to the color.

For example,

> (visualize-transformations 
    (color->irgb "pink")
    (list (lambda (rgb) rgb)
          (o rgb-darker rgb-darker)
          (o rgb-darker rgb-darker rgb-darker)
          (o rgb-darker rgb-darker rgb-darker rgb-darker))

might give

Hint: If you can turn the list of transformations into a list of colors, you can then call visualize-colors on that list of colors. Do not copy and paste your code from Problem 1: This will just make your solution to this problem more complicated and harder to understand. (Also, if you made any errors in visualize-colors, now you will have two places to fix that error instead of one!)

Problem 3: Gamma Correction

Because humans do not perceive brightness linearly, some image formats modify the meaning of the stored values' brightness scale (0-255) to better cover the range of sensitivities with a nonlinear transformation.

The typical transformation is commonly called a Gamma correction, for the name of the parameter used to determine the extent of rescaling. In particular, when a color component brightness value is on the real-valued scale of 0-1 (rather than our discrete 0-255 scale), the transformation is given by Vout = Vingamma. You can read more about this transformation at Wikipedia if you're curious, or simply forge ahead with the assignment if you're not.

In this problem, you will implement a series of steps to do this gamma correction on an image.

a. Write a procedure (transform-value component gamma) that takes a color component value (i.e., a signle number in the range 0-255), and applies the gamma correction described above. Note that you'll need to rescale the component to the range 0-1 (by dividing) before you exponentiate and rescale it back to 0-255 (by multiplying) afterward.

b. Write a procedure (irgb-correct irgb gamma) that applies transform-value to each component of irgb using gamma.

c. Write a procedure (image-correct image gamma) using irgb-correct with the specified gamma value.

(image-correct kitten 2.2)

(image-correct kitten 0.45)

Problem 4: Transforming Multiple Copies

In the reading on homogeneous lists, we saw that it is possible to create some interesting non-representational images by making a list of some basic drawing and then transforming each drawing in the list in a different way.

a. Write a procedure, (playwith drawing), that makes at least 100 copies of drawing, shifts them to different positions, scales them differently, and recolors them. The result of playwith should be another drawing.

Note: It is okay if some pairs of transformed drawings have the same color, or the same position, or the same size. However, no two transformed drawings should have both the same position and the same size, because that means that we will not see one of the drawings.

b. Your result should produce a compelling image for at least one input drawing (and you should tell us what that drawing is). Write an expression (or series of expressions) that culminates in generating such an image by calling playwith. For example:

  (image-show (drawing->image (playwith ___) ___ ___))

Important Evaluation Criteria

We will judge your solutions on their correctness, conciseness, and cleverness.

Jerod Weinman

Copyright 2007-2014 Janet Davis, Matthew Kluber, Samuel A. Rebelsky, and Jerod Weinman. (Selected materials copyright by John David Stone and Henry Walker and used by permission.)

This material is based upon work partially supported by the National Science Foundation under Grant No. CCLI-0633090. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation.

Creative Commons License This work is licensed under a Creative Commons Attribution-NonCommercial 3.0 Unported License .