Assignment 8

Due: Thursday, May 9, by 5:00pm

The official due date for this assignment is 5/9/19, but you can turn in your solutions up until the last day of final exams, Tuesday, May 21, without penalty. You should hand in both a hardcopy and electronic copy of your solutions. Your hardcopy submission should include printouts of 3 code files: mobius.m, findStars.m, and mapGUI.m. To save paper, you can cut and paste all of your code files into one script, but your electronic submission should contain the separate files. Your electronic submission is described in the section How to turn in this assignment.

Reading

The following material is especially useful to review for this assignment: notes and examples from Lectures #20 and 22, and Lab #11. There is also extensive online documentation on the 3D visualization of graphics objects.

Getting Started: Download assign8_problems

Use Cyberduck to download a copy of the assign8_problems folder from the download folder. This folder contains two image files, milkyWay.jpg and Wellesley.jpg, and a code file named places.m.

Uploading your saved work

When you are done with this assignment, you should have 7 files stored in your assign8_problems folder: mobius.m, milkyWay.jpg, findStars.m, mapGUI.fig, mapGUI.m, Wellesley.jpg, and places.m.

Use Cyberduck to connect to your personal account on the CS file server and navigate to your cs112/drop/assign08 folder. Drag your assign8_problems folder to this drop folder. More details about this process can be found on the webpage on Managing Assignment Work.

Problem 1: Creating a Mobius Strip

The Mobius strip was discovered in 1858 by the German mathematician August Mobius. Here's the easiest way to make one: take a strip of paper and instead of taping it together to make a link, twist one end and then tape the edges together. Now you have a Mobius strip. As a result of the half twist, the Mobius strip has only one side and one edge. If you draw a line down the middle of the strip until you get back to your starting point, you will draw on both sides of the paper. We'll use MATLAB to visualize a Mobius strip in 3D.

A Mobius strip can be represented with the following parameterized equations:

     x = cos(u) + (v/2)*cos(u/2)*cos(u) 
     y = sin(u) + (v/2)*cos(u/2)*sin(u) 
     z = (v/2)*sin(u/2)
where 0<=u<=2*Pi; and -1<=v<=1. These equations create a Mobius strip of width 1 whose center circle has radius 1 and is centered at (0, 0, 0). The parameter u runs around the strip while v moves from one edge to the other. Here is a sample Mobius strip in MATLAB:

Write a function called mobius that creates a mobius strip as described above. You can display your strip as you like, the one shown above is just an example. Your function should set the view, colormap, lighting, material property and shading of your mobius strip. Write brief comments providing usage information for your function, so that typing help mobius in the Command Window prints a short function description.

You can click here to see a gallery of mobius strips created by cs112 students.

Problem 2: Reaching for the Stars

Your goal for this problem is to count the stars in NASA's Astronomy Picture of the Day from October 23, 2005. The milkyWay.jpg file in the assign8_problems folder contains this NASA image, which can be loaded into the MATLAB Workspace using imread. The image is automatically loaded in as a 516x624x3 matrix of type uint8. The third dimension stores red, green and blue (RGB) color components as integers ranging from 0 to 255. This color image can be displayed with imshow.

The stars in the MilkyWay image are bright white areas. Recall that in the RGB color representation, white is composed of maximum values of all three RGB colors. You can find the stars in the image by first finding locations with large red, green and blue values (i.e. locations that are close to white), and then counting the clusters of white locations. You will write a function that uses this strategy to count the stars, and also displays intermediate results along the way.

More specifically, write a function findStars that has two inputs, an image and a threshold, and performs the steps listed below:

  1. In one figure window, use subplot to create a 2x2 configuration of four images: the original image, and three gray-level images that depict the red, green and blue components of the original image (similar to our Mona Lisa example in lecture).
  2. Find the stars: create a 2-D matrix of logical values that is the same size as the input image. In this matrix, store a 1 at locations where the red, green and blue values in the input image are all above the input threshold
  3. Count the stars: use bwlabel to find the connected components of the logical matrix that you created. Connected components are groups of 1's that are connected in the image (the second input to bwlabel can be 4 or 8, depending on whether you want to consider diagonal elements as connected). The groups of image locations that are connected are all labeled with the same number, and the label number increases with each new connected component that is found. Determine the number of stars found (the number of connected components, which will be the largest number stored in the matrix of component labels).
  4. Display the stars with your own colormap: create your own colormap to display the connected components corresponding to stars - the number of colors should equal the number of stars, so that each label is displayed with a different color. For example, you could just create multiple shades of your favorite color. The index 1 in the colormap should store the color black, and colors for labels should be sufficiently large RGB values to be visible. In a separate figure window, display the star components using your colormap - imshow can display an indexed image where each value is an index into a colormap: imshow(components, colormap).
  5. Finally, print a message in the Command Window that indicates how many stars were found.

Problem 3: Wellesley Campus Places

In this problem, you'll create a simple GUI to display the locations of popular campus places on an aerial view of campus:

The assign8_problems folder contains an aerial image of the Wellesley campus, in wellesley.jpg, and a file places.m that contains a function that creates and returns a cell array of the names of some public places on campus and a 14x2 matrix with the (x,y) coordinates for these places.

Use guide to create a GUI that includes a display area, listbox, label and close button. Your program can call the places function to create the cell array of names and matrix of coordinates, and then load the list of campus names into the listbox by setting the String property for the listbox component to the cell array of names. After the aerial image is displayed on the GUI, the scatter function can be used to draw a marker (a star in the above picture) at a particular location on the map. When the user selects a new place in the listbox, the marker should move to the newly selected campus location.

How to turn in this assignment

Step 1. Complete this online form.
The form asks you to estimate your time spent on the problems. We use this information to help us design assignments for future versions of CS112. Completing the form is a requirement of submitting the assignment.

Step 2. Upload your final programs to the CS server.
When you have completed all of the work for this assignment, your assign8_problems folder should contain 7 files: mobius.m, milkyWay.jpg, findStars.m, mapGUI.fig, mapGUI.m, Wellesley.jpg, and places.m. Use Cyberduck to connect to your personal account on the server and navigate to your cs112/drop/assign08 folder. Drag your assign8_problems folder to this drop folder. More details about this process can be found on the webpage on Managing Assignment Work.

Step 3. Hardcopy submission.
Your hardcopy submission should include printouts of 3 code files, mobius.m, findStars.m, and mapGUI.m. To save paper, you can cut and paste your code files into one file, and you only need to submit one hardcopy for you and your partner. If you cannot submit your hardcopy in class on the due date, please slide it under Ellen's office door.