(Actually, this is just an important subproblem... .)
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.
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
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;
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... .
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.)