Homework 1

The first assignment involved basic image manipulation and fractal creation.

Part 1

For the first part, I played around with xv to become comfortable with its interface. In order to become comfortable with the ppmIO library, I started by shading in a white square in an image so that I could see where the origin (0,0) is in the image (upper left, as expected). (whitesquare.c)


Then, I removed the background from the image. This was accomplished by eximining the intensity (R+G+B)/3 of each pixel. If the intensity was less than 30, the pixel was set to (128,128,128)--the standard transparent color for gifs. (background.c)


Next, I removed the cup as well. After a couple guesses and checks, I found that the cup had a red content of less than 100 for all pixels, while the stop sign (and white pole) had a red content of greater than 100 for all pixels. I set all the cup pixels to (128,128,128) as well, and I rotated the image 90 degrees counterclockwise because I didn't like having the stop sign on its side. (separate.c)


Finishing up the first part of the assignment, I composed the stop sign on another image--the amphitheater. I set it up so that all the pixels in the stop sign image which aren't (128,128,128) replace the pixels in the other image. The program doesn't care which image is bigger--the output image will be the size of the largest one, and both images will be centered in the bottom middle of the image. (placestop1.c)


As an extension to this part, I decided to compose the images in a slightly more interesting way. Instead of replacing the pixels in the image, the RGB values of both images are averaged. This causes the stop sign to appear transparent. (placestop2.c)



Part 2

For the second part, I created programs to paint the Julia Sets and the Mandelbrot Set fractals. The julia program runs off the command line as such:
julia <realmin> <realmax> <imaginarymin> <imaginarymax> <pixelwidth>
The first four arguements determine the rectangle over which to calculate the fractal, and "pixelwidth" is the width of the output picture in pixels, which determines the resolution. (julia.c)
The Julia set with C = 0.8 - j0.15 from (-1.5,-1) to (1.5,1)

This is the required image of the Julia set with C = 0.7454054 + i * 0.1130063.

For the Mandelbrot set, I used virtually the same program. The command line interface is the same. The only difference is that it creates the Mandelbrot set rather than the Julia set. (mandelbrot.c)
The Mandelbrot set from (-0.5,-1.2) to (2.0,1.2)

To color the fractals, I began by setting the intensity to be equal to the number of iterations to escape. However, this yielded undesirable results. The distance between a pixel which takes 250 iterations to escape to the nearest pixel which takes 10 iterations is very short, while the distance between a pixel which takes 3 iterations to escape and a pixel which takes 2 iterations is comparatively large. Thus, the appearance of my color scheme was that there was a bright rim of color surrounding the "lake" (non-escaping area) which faded very quickly to almost black. I wanted my colors to extend outward a little farther (it's prettier that way), so I adjusted the color by an iterative process. Beginning with the color equal to the number of iterations to escape, at each run through the iteration, I adjusted the color to be closer to the maximum number of iterations by a fraction of the distance between it and the maximum number of iterations, where the size of the fraction was proportional to how intense the color was already. Thus, a color value of 0 doesn't move, while a color of 128 moves 128/(max iterations) of the distance between 128 and the maximum number of iterations. See the plot below:
The red line has gone through 0 iterations of the adjustment, while the blue line has gone through 4 iterations. (colorbleed.c)

The effect of this adjustement was to heighten the contranst between small numbers of iterations and lessen the contrast between large numbers of iterations (the slope is steep on the left--small numbers--and shallow on the right--large numbers), making the color appear to "bleed" outward away from the lake:


More fractals:
The Mandelbrot set from (0.7495,0.0334) to (0.7498,0.0336)
The Julia set with C = 0.8 - j0.15 from (0.35,-0.4) to (0.65,0.09)

As an extension to this section, I tried making a fractal be a watermark on another picture. The program reads in the two files, and overlays some information about the fractal onto the picture. Where the factal has high intensity, the picture is darkened (preserving RGB ratios) so that a shadow type "watermark" appears. Taking a mandelbrot where the non-escape area had a high intensity, I watermarked a picture of a guitar. The mandelbrot picture points downward and is much larger than the guitar picture, so only part of the mandelbrot image appears.



Questions

How big is the stopcup picture (pixel width and height)? How did you determine this?
The stopcup image is 199x232. I determined this by opening it in xv, right clicking on the image and reading the value off the information screen.

Where is the origin of the stopcup picture--pixel (0, 0)--when you manipulate it in your code? How did you determine this?
The origin is at the upper left hand corner. I determined this by filling in a white 20x20 square in the first 20 rows and columns (see first picture).

Where is the origin of the stopcup picture in xv? How did you determine this?
It's also in the upper left hand corner. When I middle click on the image, information about the current pixel is displayed--RGB values and location.

How did you extract the red stopsign and white letters from the stopcup image?
I set all pixels with a red content of less than 100 to be RGB=(128,128,128). Only the red on the stopsign and the white on the letters and pole had a red value of more than 100.

How did you creatively modify the background of the stopcup image?
I put the stop sign on a path down the amphitheater, once making it appear solid and once making it appear transparent.

What part of the Mandelbrot set did you find the most interesting?
In general, the mandelbrot set is pretty cool. I especially like the way there's an infinitely repeating identical (assumedly so) set out past the tip. I also enjoyed playing with the coloring.

What coloring schemes did you experiment with, and which did you like the best?
For the Julia set, I made a coloring scheme where red content increased with increasing iterations to escape and blue and green content decreased with increasing iterations to escape. This gave me red "tendrils" blending through violet to a blue outside. I didn't just set the color content to be the number if iterations to escape, though, because of the rapid color change that caused--the pixel distance between a pixel with 250 iterations to escape and a pixel with 10 iterations to escape is very small, so the color change dropped off far too quickly. So I iteratively modified a straight line color map, so that the color difference between 250 iterations and 10 iterations was much smaller than it had been while the color difference between 2 and 3 iterations was much larger.
For the mandelbrot, I took this distance change a little further by making the map even shallower at high numbers and even steeper at low numbers. Making the no escape zone black, and coloring the escape area such that high iterations to escape yield bright orange colors, I got the flaming lightning effect above. For the zoomed in mandelbrot picture (the spiral), I just used a flat color map where the color value was the number of iterations to escape. I just used blue and a little bit of green on this one.
My favorite color scheme was the flaming lightning on the large mandelbrot plot.