CS 2010 Homework 8   - Due October 14

Setup

The HW 8 setup is the same as for HW 4.

Assignment

Exercise 8.1, Splitting an Image Into Lines

Implement the function colors->lines, which takes a list of colors and a number n (representing the image width). It returns a list of color lists. Each result color list contains n consecutive colors from the original list. Thus, the result list of lists represents a list of image rows, where each row is a list of colors.

   (colors->lines (list (make-color 1 2 3) (make-color 11 12 13) (make-color 21 22 23)
                        (make-color 31 32 33) (make-color 41 42 43) (make-color 51 52 53))
                  2)
   "should be"
   (list (list (make-color 1 2 3) (make-color 11 12 13))
         (list (make-color 21 22 23) (make-color 31 32 33))
         (list (make-color 41 42 43) (make-color 51 52 53)))

You can assume that the length of the color list is a multiple of n.

Exercise 8.2, Adding Images

Implement image-plus, which is just like image+: it takes two images an adds the second on top of the first. You can assume that the second image is smaller than then first.

Naturally, you cannot use image+, offset-image+, or offset-masked-image+in your implementation. Pretend instead that you are a CS 2010 instructor supplying a teachpack to first-week students, and all you have for image processing is image-width, image-height, image->color-list, color-list->image, and the color functions.

Exercise 8.3, Adding Images with Offset

Implement offset-image-plus, which is just like offset-image+: it takes an image, two offset numbers, and another image. You can assume that the second image is shorter than the first image minus the vertical offset, and it is narrower than the first image minus the horizontal offset.

As before, you cannot use image+, offset-image+, or offset-masked-image+. Furthemore, you must not handin an image-plus and offset-image-plus that contain cut-and-pasted code.

Exercise 8.4, Adding Images with Offset and Mask

Implement offset-masked-image-plus, which is like offset-masked-image+. You can assume that the last image is shorter than the first image minus the vertical offset, and it is narrower than the first image minus the horizontal offset. You can also assume that middle and last images are the same size.

As before, you cannot use image+, offset-image+, or offset-masked-image+. Furthemore, you must not handin an image-plus, offset-image-plus, and offset-masked-image-plus that contain cut-and-pasted code.

Exercise 8.5, Finding Images

Implement find-image?, which is like a combination of image-inside? and find-image: it takes two images and returns either a posn (indicating where the second image appears in the first) or false (indicating that the second image does not appear in the first).

Naturally, you cannot use find-image to implement your function. You can assume that the second image appears in the first.

This exercise is more difficult than all of the other exercises combined. Here are some hints:


Last update: Wednesday, October 8th, 2003
mflatt@cs.utah.edu