Harvey Mudd College
Computer Science 153
Assignment 1
Due Wednesday, September 7, by midnight

Back to Assignment 1 top-level page

Back to Assignment 1, Section 1: Matlab

Back to Assignment 1, Section 2: Images


Section 3: Solving the Vision Problem

(Actually, this is just an important subproblem... .)



Finding food

The problem is to write a matlab function findspam that takes in an image and outputs the location of the spam in the image. You can assume that the image does contain, somewhere, a can of spam. (But see "Possible Extensions" for the unfortunate situations in which no spam is available!)

To be precise, your findspam should

In addition to your code, please include a paragraph or two to explain the technique(s) you developed. Also, indicate the kinds of images on which your technique(s) do well and the kinds of images on which they don't do well, and why. Provide at least two example images on which your algorithm worked, and at least two on which it did not. Highlight the point at which your algorithm "found" the spam in each image. (You can do this with any image-altering tool, but might want to try it in matlab.) Basically, be sure to evaluate your solution after developing it.


Results:


function [xx,yy] = findspam(B);

[x,y,i] = size(B);
for i = 1:1:x,
for j = 1:1:y,
if B(i,j,1) > 150
if B(i,j,2) > 150
if B(i,j,3) < 80
B(i,j,:) = [0,255,0];
end
end
end
end
end

xx = 0;
yy = 0;
count = 0;

for i = 1:1:x,
for j = 1:1:y,
if B(i,j,1) == 0
if B(i,j,2) == 255
if B(i,j,3) == 0
xx = xx + i;
yy = yy + j;
count = count + 1;
end
end
end
end
end

xx / count
yy / count


The code has two functions. It highlights all the yellow parts of the image and then averages their location. We hope to get all the points that spell out spam and hit between the P and the A by averaging their coordinates. We say something is yellow if it has a certain amount of red and green, and not too much blue!
I used matlab to put a white dot where findspam returned as the location of spam. sorry if it's hard to see with the jpeg compression!
good example good example bad example bad example
In the first two examples we came pretty close to the right spot. The spamfinder identified the yellow spam text and could place a dot near the center, which is near the spot between P and A that was the goal. In the two less successful pictures, the spot returned is closer to the middle of the big yellow table. This is because we get a lot of false identifications when the spamfinder doesn't distinguish between the text and the table.


Resources for developing/testing your algorithm

There are 21 test images containing spam available in the directory /cs/cs153/Images/a1/spamResource. You may find imframe (or xv, or photoshop, etc.) helpful in analyzing those images in order to develop a findspam function.

You are welcome to try any idea in writing your function. The only strategy not permitted is somehow to encode the location of the spam (found by a person) and then output that remembered location. For example, the following function works extremely well for the testimage.jpg:

function [row,col] = findspam(A);
%
% The vision problem, solved!
%
col = 196;
row = 288;



Evaluation

Your code will be evaluated on the 21 resource images, along with 21 trial images. This assignment is not really intended to be "solved" (though that's not to discourage you from doing so!) As a result, grading will be very lenient. In particular, you don't need to work on any extensions; after all, this assignment could be considered a superset of the rest of the course! The extensions in the following section are here just to give you a sense of what they might be like in future assignments. Also, you can always explore in a direction of your own choosing (in fact, are encouraged to do so), rather than trying a suggested extension. Remember that the principal goal of this assignment is simply to provide an introduction to using matlab for handling images... .



Possible Extensions

This project differs from the next four scripted projects in that simply writing the findspam function is challenging enough that no extensions are necessary. However, the following are possible extensions which you should feel free to incorporate, if you like. (They will certainly be considered for extra credit.)



Back to Assignment 1 index