Image Processing: Squared Euclidean Distances, Inverse Matrix, K-Means, Lucas-Kanade Flow, Assignments of Computer Science

Instructions for homework 8 in cse190 - image processing class taught by prof. Serge belongie at university of california, san diego. The homework includes two parts. In the first part, students are required to derive a matrix of squared euclidean distances between feature vectors and prototype vectors and to calculate the inverse of a 2x2 matrix. In the second part, students are asked to implement the k-means clustering algorithm and lucas-kanade optical flow algorithm using matlab.

Typology: Assignments

Pre 2010

Uploaded on 03/28/2010

koofers-user-da4
koofers-user-da4 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSE190 Image Processing Homework #8
Instructor: Prof. Serge Belongie. T.A.: Josh Wills.
http://www-cse.ucsd.edu/~sjb/classes/wi02/cse190
Due (in class) 1:25pm Wed. Mar. 13, 2002.
Written exercises
1. Suppose you are given a set of Nfeature vectors {x1,x2,. . . , xN}and kprototype vectors
{m1,m2, . . . , mk}. Assume all of the vectors are of size n×1. Show that the N×kmatrix
of squared Euclidean distances between the feature vectors and the prototype vectors can be
obtained by computing the following matrix:
T=E1T
k+1NFT2XTY
where Eis an N×1 vector with entries Ei=kxik2,Fis a k×1 vector with entries Fi=kmik2,
1is a column vector of ones whose length is given by its subscript, Xis an n×Nmatrix of
feature vectors, and Yis an n×kmatrix of prototype vectors.
2. Consider the 2 ×2 matrix
A=a b
c d .
Show that the inverse is given by
A1=1
det(A)db
c a .
Matlab exercises
1. Clustering in color space using k-means.
(a) Implement the k-means clustering algorithm as described in class. For the stopping
criterion, allow the user to supply a threshold on the change in J(the sum of squared error
over all clusters) on each iteration, as well as a maximum allowed number of iterations
(e.g. 25). Have your program output the value of Jon each iteration. Initialize the cluster
centers by choosing kfeature vectors at random from the data.
(b) Load in Figure 6.30(a) (the bowl of strawberries) and use imresize with the ’bilinear’
option and M=0.25 to reduce its resolution by a factor of 4 in xand y. Display the resized
image. Construct a matrix of 3-dimensional feature vectors for this image using the RGB
values of each pixel.
(c) Use k-means to perform clustering on this image using k= 3 and k= 4. In each case,
run three trials to see the effects of the random initialization. Display each of the six
resulting segmentations as a pseudocolor cluster membership image, like the example
shown in class. (Note: if you don’t have access to a color printer, it’s ok to use shades of
gray.)
Things to turn in:
Code listing for parts 1a and 1b.
Program output and parameter settings for part 1c.
2. Lucas-Kanade optical flow.
1
pf2

Partial preview of the text

Download Image Processing: Squared Euclidean Distances, Inverse Matrix, K-Means, Lucas-Kanade Flow and more Assignments Computer Science in PDF only on Docsity!

CSE190 – Image Processing – Homework # Instructor: Prof. Serge Belongie. T.A.: Josh Wills. http://www-cse.ucsd.edu/~sjb/classes/wi02/cse Due (in class) 1:25pm Wed. Mar. 13, 2002.

Written exercises

  1. Suppose you are given a set of N feature vectors {x 1 , x 2 ,... , xN } and k prototype vectors {m 1 , m 2 ,... , mk}. Assume all of the vectors are of size n × 1. Show that the N × k matrix of squared Euclidean distances between the feature vectors and the prototype vectors can be obtained by computing the following matrix:

T = E1Tk + (^1) N FT^ − 2 XT^ Y

where E is an N ×1 vector with entries Ei = ‖xi‖^2 , F is a k ×1 vector with entries Fi = ‖mi‖^2 , 1 is a column vector of ones whose length is given by its subscript, X is an n × N matrix of feature vectors, and Y is an n × k matrix of prototype vectors.

  1. Consider the 2 × 2 matrix A =

[

a b c d

]

Show that the inverse is given by

A−^1 =

det(A)

[

d −b −c a

]

Matlab exercises

  1. Clustering in color space using k-means.

(a) Implement the k-means clustering algorithm as described in class. For the stopping criterion, allow the user to supply a threshold on the change in J (the sum of squared error over all clusters) on each iteration, as well as a maximum allowed number of iterations (e.g. 25). Have your program output the value of J on each iteration. Initialize the cluster centers by choosing k feature vectors at random from the data. (b) Load in Figure 6.30(a) (the bowl of strawberries) and use imresize with the ’bilinear’ option and M=0.25 to reduce its resolution by a factor of 4 in x and y. Display the resized image. Construct a matrix of 3-dimensional feature vectors for this image using the RGB values of each pixel. (c) Use k-means to perform clustering on this image using k = 3 and k = 4. In each case, run three trials to see the effects of the random initialization. Display each of the six resulting segmentations as a pseudocolor cluster membership image, like the example shown in class. (Note: if you don’t have access to a color printer, it’s ok to use shades of gray.)

Things to turn in:

  • Code listing for parts 1a and 1b.
  • Program output and parameter settings for part 1c.
  1. Lucas-Kanade optical flow.

(a) Implement the Lucas-Kanade algorithm for measuring optical flow, as described in class. Allow the user to specify the size of the window used in enforcing the smoothness con- straint. Use the quiver function to display the optical flow vectors. In addition, have your program return the two eigenvalues of the windowed image second moment matrix at each pixel. (b) Construct two frames of a simple motion sequence as follows. Make a 16×16 white square centered on a black background of size 32 × 32. Blur it with a Gaussian filter with σ = 1. This image represents I(x, y, t). Produce the second image, representing I(x, y, t + 1), by displacing the first image down one pixel and to the right one pixel. Display each frame, as well as It and the two components of ∇I. (c) Compute and display the optical flow for the above sequence using a window size of 5 × 5. Since you know the “ground truth” displacement (i.e. u = 1, v = 1), comment on the accuracy of your measured optical flow at various points throughout the image. Demonstrate how, by applying a threshold on the eigenvalues, you can suppress the flow vectors at pixels that suffer from the aperture problem. (d) Construct a new sequence consisting of the original first frame and a second frame pro- duced by rotating the first one by 5◦^ (use imrotate with the ’bil’ and ’crop’ options). Now repeat step 2c using this sequence.

Things to turn in:

  • Code listing for steps 2a, 2b, 2c, and 2d.
  • Program output for steps 2b, 2c, and 2d.
  • Written comments for steps 2c and 2d.