![]() |
CS 112
Assignment 8 |
|
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
.
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
.
drop/assign8
folder
assign8_programs
folder into your
drop/assign8
folder
assign8_programs
folder from the Desktop by dragging
it to the trash can, and then empty the trash (Finder--> Empty Trash).
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
.
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.
findStars
function to perform the following
steps:
size
function
returns the size of all three dimensions, and a matrix can be created
to store logical values with the logical
function, e.g.
matrix = logical(zeros(10,10))
)
(x,y)
is greater than the input threshold, then store a 1 in
position (x,y)
in the red component
logical matrix.
imshow
can
display a logical matrix) [Note: although it is possible to count the stars without
generating the three separate color component matrices, it is, shall we say,
illuminating to view the red, green and blue components of the original image independently].
bwlabel
to find
connected components of a binary image (analogous to a logical matrix) - groups of
1's that are connected in the image (second input to bwlabel
is 4 or 8,
depending on whether you want to consider diagonal elements as connected). The groups of
pixels that are connected are all labeled with the same number, and the label number
increases with each new connected component that is found.
imshow
can display an
indexed image where each value is an index into a colormap):
imshow(components, colormap)
Remember to execute the close all
function between executions of your
findStars
function!
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:
fill()
function:
function h = drawBubble(rad,xc,yc,c)
% draw a circle in a given radius, xcenter, ycenter and color
angles = linspace(0,2*pi,40);
bubx = xc+(rad*cos(angles));
buby = yc+(rad*sin(angles));
fill(bubx,buby,c);
axis square off
To create a filled circle, try:
>> drawBubble(20,50,50,'b');
which creates this picture:
>> figure, hold on
>> mickey(2,0,0,50,'r','b');
>> hold off
This is the end of assignment 8*.
* Even better, this is the end of the last cs112 assignment this semester. :-)