Problem Set #5 for Exam Practice - Image Processing | CMSC 426, Assignments of Computer Science

Material Type: Assignment; Professor: Jacobs; Class: Image Processing; Subject: Computer Science; University: University of Maryland; Term: Unknown 1989;

Typology: Assignments

Pre 2010

Uploaded on 02/13/2009

koofers-user-2br
koofers-user-2br 🇺🇸

8 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Problem Set 5
CMSC 426
Assigned Monday, March 15, Due Thursday, April 1
The goal of this problem set 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,
1999. There is a link to this paper on the class web site. Below we also include
pseudocode for the project, which is given on their web site along with some samples of
the system’s performance. I have simplified their pseudocode 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.
1. 30 points: To begin, you should write a program called my_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 = my_SSD(S, T, M)
S will contain a sample of the texture we want to generate. T contains a small
nxn neighborhood of pixels. Not all the pixels in this neighborhood have been
filled in with valid values however. So M (the mask) is an nxn matrix that
contains a 1 for each position in which T contains a valid pixel, and a 0
whenever the corresponding pixel in T should be ignored. Computing the SSD
is like correlation in that we shift the template over every position in the sample,
and compute a separate result for each position. Thus, the output D is the same
size as S. To compute D(i,j) we shift T so that its center is right on top of S(i,j).
Then we take the difference between each valid pixel in T and the corresponding
pixel in S, square the result, and then add all these together. This computation is
described on page 147 of Trucco and Verri, and by Efros and Leung with the
following fragment of pseudocode:
pf3
pf4

Partial preview of the text

Download Problem Set #5 for Exam Practice - Image Processing | CMSC 426 and more Assignments Computer Science in PDF only on Docsity!

Problem Set 5

CMSC 426

Assigned Monday, March 15, Due Thursday, April 1

The goal of this problem set 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,

  1. There is a link to this paper on the class web site. Below we also include pseudocode for the project, which is given on their web site along with some samples of the system’s performance. I have simplified their pseudocode 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.
  2. 30 points: To begin, you should write a program called my_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 = my_SSD(S, T, M) S will contain a sample of the texture we want to generate. T contains a small nxn neighborhood of pixels. Not all the pixels in this neighborhood have been filled in with valid values however. So M (the mask ) is an nxn matrix that contains a 1 for each position in which T contains a valid pixel, and a 0 whenever the corresponding pixel in T should be ignored. Computing the SSD is like correlation in that we shift the template over every position in the sample, and compute a separate result for each position. Thus, the output D is the same size as S. To compute D(i,j) we shift T so that its center is right on top of S(i,j). Then we take the difference between each valid pixel in T and the corresponding pixel in S, square the result, and then add all these together. This computation is described on page 147 of Trucco and Verri, and by Efros and Leung with the following fragment of pseudocode:

for i,j do for ii,jj do dist = (Template(ii,jj)-SampleImage(i-ii,j-jj))^ SSD(i,j) = SSD(i,j) + distValidMask(ii,jj) end SSD(i,j) = SSD(i,j) / TotWeight End However, in Matlab, it will be more efficient to implement this without looping. Here are some hints on how to do this. First, notice that (T(ii,jj)-S(i-ii,j-jj))^2 = T(ii,jj)^2 – 2T(ii,jj)S(i-ii,j-jj) + S(i-ii,j-jj)^2. Notice also that we can compute: for i,j do for ii,jj do dist = Template(ii,jj)SampleImage(i-ii,j-jj); COR(i,j) = COR(i,j) + distValidMask(ii,jj) end end with one call to imfilter with SampleImage and (Template.ValidMask) as arguments. The other parts of SSD can also be computed without any explicit looping. We can compute: for i,j do for ii,jj do dist = SampleImage(i-ii,j-jj)^2; COR(i,j) = COR(i,j) + dist*ValidMask(ii,jj) end end by calling imfilter with SampleImage.^2 and ValidMask as arguments. Test your function using the checkerboard function that we provide. Execute the call: my_SSD(checkerboard(3,3),[0 1 1; 1 0 -1; 1 0 0], [1 1 1; 1 1 0; 1 1 1]) and turn in a printout of the results, along with your code.

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 Function GetUnfilledNeighbors() returns a list of all unfilled pixels that have filled pixels as their neighbors (the image is subtracted from its morphological dilation). The list is randomly permuted and then sorted by decreasing number of filled neighbor pixels. GetNeigborhoodWindow() returns a window of size WindowSize around a given pixel. RandomPick() picks an element randomly from the list. FindMatches() is as follows: function FindMatches(Template,SampleImage) ValidMask = 1s where Template is filled, 0s otherwise TotWeight = sum i,j ValidMask(i,j) for i,j do for ii,jj do dist = (Template(ii,jj)-SampleImage(i-ii,j-jj))^ SSD(i,j) = SSD(i,j) + distValidMask(ii,jj)GaussMask(ii,jj) end SSD(i,j) = SSD(i,j) / TotWeight end PixelList = all pixels (i,j) where SSD(i,j) <= min(SSD)*(1+ErrThreshold) return PixelList end In our implementation the constant were set as follows: ErrThreshold = 0.1. Pixel values are in the range of 0 to 1.