CS40: Computer Graphics, Lab 1

Bluescreens and Fractals

By Jeff Kaufman

File Formats

There were four file formats I used in this lab; JPEG, PPM, PNG, and TIFF. JPEG was the format images came in from the camera. They were a bit fuzzy because the camera was consumer level. I used the GIMP to blur these before using them. They were also big (2592x1944, as reported by the ImageMagick program identify), so I scaled them down before further processing.

Sample code was provided for two file formats, TIFF and PPM. In response to a prompt on the lab sheet I tested the location of the origen for the two formats. I put white rectangles around (0,0) in the two types and then used display to see what part of the image had been messed with. For PPM this was the upper left, as I expected from computer graphics before and as display and xv reported. For TIFF, however, this was the lower left. This would make sense for math, but I've thought of the upper left of the screen as (0,0) for long enough that this was enough to set me against TIFF. It didn't help that the image display programs still called the upper left (0,0). I did all of my coding to work with PPM.

I used PNG as well, though only as a display format. To convert my PPM output files to PNG for web-accesiblity, and also to make thumbnails for this page, I used convert which is efficient.

Bluescreens

In this portion of the lab we took pictures of students against a blue blackground, processed the image to determine what portions were blue, and replaced those portions with appropriate pixels from a replacement background to make the students appear to be standing in front of other things.

A chromaticity filter that blanks pixels if their red value and their green value are both less than some threshold when divided by their magnitude can remove some of the blue.

   and   
The initial images for this project varied widely in background color, though, despite being taken sequentially in the same lighting conditions and against the same background. This is likely due to the flash of the camera being set to auto, as in the images with light blue backgrounds the people tend to look a little washed out. Despite the increased fidelity in human rendering, the lack of a flash and hence an easy to work with blue made processing some of the images moderately difficult. Below are two images for two different students taken sequentially and the results of running that chromaticity filter.
This method, however, does not take into account that background pixels should be more blue than pixels that are part of the person. There are some fluctuations in color and it's very easy for dark pixels to cross the threshold. Adding a second filter that requires the pixels to be more blue than red and green by some scale factor helps a lot and allows the red and green chromaticity thresholds to be set higher and so be more precise.
   and       and   
Applying that filter to the images gives markedly better results:
These are definitely better, and the one on the right is satisfactory. The left one, however, still has some ugly little black dots on the background and some spots of background in the person. Unless a portion of the foreground were to have a mesh of some sort these pixels would always be errors. So we can run a third filter that makes pixels conform to those around them if those around them are overwhelmingly either nearly all background or nearly all foreground. This gives:
Because of the way I implemented the algorithm there is a 10 pixel wide edge effect, but aside from that the image is almost entirely clean. Combining the foreground with a new background is now simple because we have a way of determining whether a pixel is foreground or background and so we can replace pixels in the new background with those from the old foreground. After some cropping to remove the edge effects we get the following picture.
Because it is fun to mess with pictures further I also made my program generate an image with multiple versions of me in one frame.

Fractals

I also wrote a program that calculates Julia and Mandelbrot set fractals and colors them by the number of iterations that it takes to get above a given threshold. I use colormap and range linearly from first black to red, then red to yellow, then yellow to white, except I make the 'infinite' value black to look better.

Before deciding on this color pattern I tried some others, but I didn't really like any of them. The smoothness of a colormap with a large number of colors appeals to me greatly, as does the fade from black to red. The alternate coloring of pixels by the number of iterations modulo two is interesting, and I like the Dr. Seuss-like pseudo depth, but it's not as pretty as a smooth fade.

I also implemented jitter sampling, with some number of calculations for each pixel averaged together. For my finished images I used 64 samples for pixel, but they look alright with only eight. Sixty four gives fewer artifacts, though.

The threshold beyond which a complex number is treated as not likely to come back down to zero from is variable at compile time, and is 20 for all of the images shown. To be more efficient I don't actually compute the magnitude of the complex numbers but instead just dot them with themselves and compare them to the threshold constant that way.

If I was going to do more optimization I would likely make one based on symmetry; both Julia and Mandelbrot fractals have a two-way symmetry, though Julia are odd and Mandelbrot are even. This would double rendering speeds.

Fractal Images

I made images of three fractals, two of them julia sets and one a mandelbrot set. The julia sets I did twice with different colormaps because I couldn't decide which one I liked better. In both cases the one on the right was done with a larger number of iterations (1024) and a larger colormap. This resulted in less internal black, which doesn't look as nice, but smoother colors elsewhere.

The Julia set defined by C = < 0.7454054, 0.1130063 > in the rectangle < -1.7, -1.2 > to < 1.7, 1.2 >

The Julia set defined by C = < -0.285, -0.013 > in the rectangle < -1.5, -1.2 > to < 1.5, 1.2 >
The Mandelbrot set in the rectangle < -1.5, -1.5 > to < 1.5, 2.5 >
In general I liked the two julia set fractals I did much more than the mandelbrot one. Mostly because they had more areas that took a lot of iterations to resolve themselves and hence made for better coloring.

Image Tools Used


Jeff Kaufman : 2005
cbr at sccs dot swarthmore dot spam edu. Remove spam.

main page