CSS 501 Programming Assignment #3

## Goal

In this program, we are going to use recursion to create a type of image fractal. The image class you created for the previous program will be used with recursion in a non-trivial fashion to create a new image similar to the one below.

## Assignment

Using your image class, you should read in an image called test.gif and output an image called output.gif. You may change your image class if you want, but you should NOT write a class method that creates the fractal or shrinks the image. You should only use the accessor and mutator functions from your class for these operations. Your output should look like this:

Once again, you can use the image library at: ImageLib.lib and ImageLib.h

Here is another test image:                test.gif

## Details

Use the following specification exactly to get full credit.

• Determine the color of each pixel in the smaller images by averaging the appropriate 2 x 2 block of four pixels in the larger image. (Note that exceptions can occur at the boundaries. See below.)
• If the input and output both have their upper-left corner at (0, 0), then the relationship between the images is usually:

output(r, c) = (input(2r, 2c) + input(2r+1, 2c) + input(2r, 2c+1) + input(2r+1, 2c+1) ) / 4

Always round down (integer division is fine).

• For the flipped image, the relationship is similar. Again, assume the images have their upper-left corner at (0, 0). Let maxR be one less than the number of rows in the input image and maxC be one less than the number of cols in the input image:

output(r, c) = (input(maxR  2r, maxC  2c) + input(maxR  2r  1, maxC  2c) +

input(maxR  2r, maxC  2c  1) + input(maxR  2r  1, maxC  2c  1) ) / 4

• If the image has an odd number of columns, then the subimages on the left should have one more column than the subimages on the right, so that the overall image size stays the same.
• Similarly, if the image has an odd number of rows, then the subimages on the top should have one more row than the subimages on the bottom.
• If the subimage is slightly larger than half the size of the input image, then the image boundaries will need to be handled slightly different. If any of the pixels in the formulas above are outside of the input image in these cases, then average only among the valid pixels. (For recursive calls, make sure that the averaging never crosses the boundary between quadrants.)

## Approaches

There are (at least) two approaches to solving this correctly, although both use the recursion discussed above. In the first, the location of each of the recursive input and output images is maintained using careful bookkeeping without creating smaller images. In the second, each smaller quadrant is actually created as a separate (smaller) image and then they are stitched together. Either approach can achieve the correct result.

Create other interesting fractal patterns using recursion.