CS 112

Assignment 8

Due: Friday, December 8, at the beginning of class

This is the last assignment of the semester! It is best to hand in this assignment during the last class, but you may turn it in up until 5:00pm on 12/8/06. Your hardcopy submission should include a cover sheet and printouts of two code files: findStars.m and mickey.m.

Reading

The following material is especially useful to review for this assignment: Lectures #21, #22, and #23 and Lab #12.

Getting Started: Download assign8_programs from cs112d

Use Fetch or WinSCP to connect to the CS server using the cs112d account and download a copy of the assign8_programs folder from the cs112d directory onto your Desktop. Rename the folder to be yours, e.g. sohie_assign8_programs. In MATLAB, set the Current Directory to your assign8_programs folder. This folder contains only one file that is an image of the center of the Milky Way: milkyWay.jpg.

Uploading your saved work

Use Fetch or WinSCP to upload your saved work, and connect to the CS file server using your personal user account name and password. After logging in to your account:

When you are done with this assignment, you should have 3 files stored in your assign8_programs folder: milkyWay.m, findStars.m and mickey.m.

Exercise 1: Reaching for the Stars

Your goal for this exercise is to count the stars in NASA's Astronomy Picture of the Day from October 23, 2005.

In the NASA image linked above, stars are bright white areas. Recall that in RGB (red/green/blue) color representation, white consists of maximum values of all three RGB colors. You will find the stars in the image by finding locations with large red, green and blue values. As you compute the number of stars, you will also display intermediate images along the way.

More specifically, you will write a function findStars that has two inputs, an image and a threshold, that performs the steps listed below. All of the display steps can be performed with the imshow function, and each image should be displayed in a new figure window. Recall that the figure command can be used to open a new figure window. The figure and imshow commands can be placed on a single line, separated by a comma, for example:

    figure, imshow(image);

You can use the imread function to load the image 'milkyWay.jpg' into the MATLAB workspace.

Write your findStars function to perform the following steps:

  1. Display the original image
  2. Display red, green and blue components as gray-level images in separate figure windows
  3. Find the stars:
  4. Show custom-colored stars:

Remember to execute the close all function between executions of your findStars function!

Exercise 2: I'm goin' to Disneyland!

In this exercise, you will write a recursive function in a MATLAB file called mickey.m that will produce the pictures below. The function mickey takes 6 parameters: levels, xcenter, ycenter, radius, color1 and color2.

mickey(1,0,0,50,'r','b'); mickey(2,0,0,50,'r','b');
mickey(3,0,0,50,'r','b'); mickey(4,0,0,50,'r','b');
mickey(5,0,0,50,'r','b');

Let's take a close look at the level 2 figure to understand how mickey is drawn:

mickey(level, xcenter, ycenter, radius, color1, color2)
mickey(2, 0, 0, 50, 'r', 'b')

In this particular drawing, xcenter and ycenter are both 0, so the circle is centered at the origin (0,0). The radius of the big circle is 50; the radii of the two smaller circles are 50/2, or 25. The first circle is the color1 (in this case, red) and the smaller circles are color2 (in this case, blue). The yellow box in the diagram illustrates how the big circle and the little circle are positioned relative to one another.

Hints:

 

This is the end of assignment 8*.
* Even better, this is the end of the last cs112 assignment this semester. :-)