



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Background Subtraction 15 points
For this problem, you are given a set of 100 images of background, I 1 , I 2 , … I 100. and one test image, J. These are on the class web page in BackgroundImages.zip and foreground_image.jpg. Your task is to classify each pixel in the test image as either foreground or background. Suppose pixel J(x,y) has intensity k. To classify it, you should compute:
Once you’ve computed this for each pixel, you’ll need to choose a threshold, T , so that you classify all pixels as foreground when P(J(x,y)=k)<T. Choose a value of T by hand that seems to produce pleasing results. Our results are in BackgroundSubtractionResults.jpg. Turn in your code, a picture of your result, and indicate which threshold you used. Our results are included on the class web site for comparison.
Hint: As usual, you can achieve better performance by minimizing the amount of looping you do. However, when dealing with 100 images, you must be a little careful to avoid using up too much memory; in my implementation I do loop through the images rather than trying to perform some operations on all of them at once.
Challenge Problem: Up to 20 points
See if you can improve on this performance by using a statistical model that does not assume that every pixel is independent. For example, you could try to model the distribution of pairs of pixels, or make use of the fact that if I(x,y) = k, it is somewhat likely that in the next image, I(x+1,y)=k, (to model, for example, the way the trees move around in the wind). Describe what you did and whether it worked.
Note that this is a vague problem, and I’m not sure whether really good results can be obtained. But any good ideas that you try will get some credit, whether they work or not.
Texture Synthesis
The goal of this problem is to implement the texture synthesis method of Efros and Leung. This is described in the paper: ``Texture Synthesis by Non-parametric Sampling’’, by Efros and Leung, in the International Conference on Computer Vision,
=
100
1
2
2 2
exp ( ( , )) 100 2
i
PJ x y k k Ii^ x y
algorithm a little bit, to remove some details such as Gaussian weighting, which don’t seem to be necessary to achieve good performance.
This algorithm takes a sample of some texture and generates a new image containing a similar texture. The strategy of the algorithm is to generate each new pixel in the image using a neighborhood of already generated pixels. One looks in the sample for similar neighborhoods, selects one of these similar neighborhoods at random, and copies the corresponding pixel into the new image. You are only required to implement this program for black and white images. You are given code in GrowImageShell.m that has some parts missing, which you’ll need to fill in
As always in Matlab, it is important to avoid loops to get good performance. It is quite possible for you to complete this assignment without using any additional loops beyond the ones I use in GrowImage.
To begin, you should write a function called SSD which performs the central step of the algorithm. This will compute the sum of squared difference between a little portion of the new image you are making and every portion of the sample. It should have the form:
function D = SSD(S, T, M)
There are two things that make SSD a bit tricky. The first is that we want to do it with correlation, rather than with looping. This is partly because this will be more efficient in Matlab, but also because we want to make concrete for you the relationship between correlation and SSD as a way of matching a template to an image. The second thing that’s tricky is that we need to use a mask, M, which tells us to only perform the computation on some pixels. To separate these issues, let’s first look at SSD without a mask. We can write SSD mathematically as:
n i n
n D x y j n Sx i y j Ti j ( , ) , (, )^2
To see how this is related to correlation, let’s open up the expression:
SSD(my_checkerboard(3,3),[0 1 1; 1 0 -1; 1 0 0], [1 1 1; 1 1 0; 1 1 1]) ans = 4 4 5 7 5 4 2 4 4 4 4 4 5 4 4 3 4 4 6 5 3 2 3 5 6 5 4 7 5 3 0 3 5 8 5 4 5 4 4 3 4 4 5 4 4 3 3 5 6 5 3 2 3 4 2 3 5 8 5 3 0 3 4 4 4 4 5 4 4 3 4 4 4 4 3 3 3 4 4 4 4
Turn in a printout of the results, along with your code.
You may be worried about how to compute SSD when the template goes outside the boundary. Don’t worry about this. You can do anything that produces reasonable results. For example, you can just use the default values of imfilter, which treats pixels outside S as if they were 0. This is what I did in the example above. This will work fine, since these areas then will generally not match your template very well.
a = rand(3,3) a = 0.5515 0.1027 0. 0.1866 0.7407 0. 0.2879 0.3420 0.
a(a>.5) ans =
You might want to write FindMatches so that it takes three inputs: the sample image, the template, and the mask. Test your program on the same example that you used in problem 1. Hand in printouts of the results, and of your program.
Appendix : Below is pseudocode provided by Efros and Leung. Please note that when you code this project in Matlab you won’t want to follow this pseudocode exactly. For example, some operations that they perform with loops, you will want to perform with single Matlab routines.
Let SampleImage contain the image we are sampling from and let Image be the mostly empty image that we want to fill in (if synthesizing from scratch, it should contain a 3- by-3 seed in the center randomly taken from SampleImage, for constrained synthesis it should contain all the known pixels). WindowSize, the size of the neighborhood window, is the only user-settable parameter. The main portion of the algorithm is presented below. I have removed the part of the pseudocode that deals with Gaussian filtering, for simplicity.
function GrowImage(SampleImage,Image,WindowSize) while Image not filled do progress = 0 PixelList = GetUnfilledNeighbors(Image) foreach Pixel in PixelList do Template = GetNeighborhoodWindow(Pixel) BestMatches = FindMatches(Template, SampleImage) BestMatch = RandomPick(BestMatches) Pixel.value = BestMatch.value end return Image end