Application to Computer Vision - GIS and Mapping - Lecture Notes, Study notes of Geology

In these Lecture notes, the following main points were discussed by the Lecturer : Application To Computer Vision, Representation, Pca To Find Patterns, Image Compression, Implementation Code, Dimensional, Vector, Digital Image Processing, Image Compression, Image Reconstruction

Typology: Study notes

2012/2013

Uploaded on 07/23/2013

ramkumar
ramkumar 🇮🇳

4.4

(11)

89 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Chapter 4
Application to Computer Vision
This chapter will outline the way that PCA is used in computer vision, firs showing
how images are usually represented, and then showing what PCA can allow us to do
with those images. The information in this section regarding facial recognition comes
from “Face Recognition: Eigenface, Elastic Matching, and Neural Nets”, Jun Zhang et
al. Proceedings of the IEEE, Vol. 85, No. 9, September 1997. The representation infor-
mation, is taken from “Digital Image Processing” Rafael C. Gonzalez and Paul Wintz,
Addison-WesleyPublishing Company, 1987. It is also an excellent reference for further
information on the K-L transform in general. The image compression information is
taken from http://www.vision.auc.dk/ sig/Teaching/Flerdim/Current/hotelling/hotelling.html,
which also provides examples of image reconstruction using a varying amount of eigen-
vectors.
4.1 Representation
When using these sort of matrix techniques in computer vision, we must consider repre-
sentation of images. A square,

by

image can be expressed as an

4
-dimensional
vector

<

<
4
<

q q
<
where the rows of pixels in the image are placed one after the other to form a one-
dimensional image. E.g. The firs

elements (
<

-g<

will be the firs row of the
image, the next

elements are the next row, and so on. The values in the vector are
the intensity values of the image, possibly a single greyscale value.
4.2 PCA to find patterns
Say we have 20 images. Each image is

pixels high by

pixels wide. For each
image we can create an image vector as described in the representation section. We
can then put all the images together in one big image-matrix like this:
21
Docsity.com
pf3
pf4
pf5

Partial preview of the text

Download Application to Computer Vision - GIS and Mapping - Lecture Notes and more Study notes Geology in PDF only on Docsity!

Chapter 4

Application to Computer Vision

This chapter will outline the way that PCA is used in computer vision, firs showing how images are usually represented, and then showing what PCA can allow us to do with those images. The information in this section regarding facial recognition comes from “Face Recognition: Eigenface, Elastic Matching, and Neural Nets”, Jun Zhang et al. Proceedings of the IEEE, Vol. 85, No. 9, September 1997. The representation infor- mation, is taken from “Digital Image Processing” Rafael C. Gonzalez and Paul Wintz, Addison-Wesley Publishing Company, 1987. It is also an excellent reference for further information on the K-L transform in general. The image compression information is taken from http://www.vision.auc.dk/ sig/Teaching/Flerdim/Current/hotelling/hotelling.html , which also provides examples of image reconstruction using a varying amount of eigen- vectors.

4.1 Representation

When using these sort of matrix techniques in computer vision, we must consider repre-

sentation of images. A square, Œ by Œ image can be expressed as an Œ

-dimensional vector

q

q

where the rows of pixels in the image are placed one after the other to form a one-

dimensional image. E.g. The firs Œ elements (<

- g< Ž will be the firs row of the

image, the next Œ elements are the next row, and so on. The values in the vector are

the intensity values of the image, possibly a single greyscale value.

4.2 PCA to find patterns

Say we have 20 images. Each image is Œ pixels high by Œ pixels wide. For each

image we can create an image vector as described in the representation section. We can then put all the images together in one big image-matrix like this:

’^(tsx/

I

(z@\

’^ (t sx}6sxB 

’^ (t sx}6sxB 

q

q

’^ (t sy}~syB %

which gives us a starting point for our PCA analysis. Once we have performed PCA, we have our original data in terms of the eigenvectors we found from the covariance matrix. Why is this useful? Say we want to do facial recognition, and so our original images were of peoples faces. Then, the problem is, given a new image, whose face from the original set is it? (Note that the new image is not one of the 20 we started with.) The way this is done is computer vision is to measure the difference between the new image and the original images, but not along the original axes, along the new axes derived from the PCA analysis. It turns out that these axes works much better for recognising faces, because the PCA analysis has given us the original images in terms of the differences and simi- larities between them. The PCA analysis has identifie the statistical patterns in the data.

Since all the vectors are Œ

dimensional, we will get Œ

eigenvectors. In practice, we are able to leave out some of the less significan eigenvectors, and the recognition still performs well.

4.3 PCA for image compression

Using PCA for image compression also know as the Hotelling, or Karhunen and Leove

(KL), transform. If we have 20 images, each with Œ

pixels, we can form Œ

vectors, each with 20 dimensions. Each vector consists of all the intensity values from the same pixel from each picture. This is different from the previous example because before we had a vector for image , and each item in that vector was a different pixel, whereas now we have a vector for each pixel , and each item in the vector is from a different image. Now we perform the PCA on this set of data. We will get 20 eigenvectors because each vector is 20-dimensional. To compress the data, we can then choose to transform the data only using, say 15 of the eigenvectors. This gives us a fina data set with only 15 dimensions, which has saved us

“o

of the space. However, when the original data is reproduced, the images have lost some of the information. This compression technique is said to be lossy because the decompressed image is not exactly the same as the original, generally worse.

cv(var,ct) = v; cv(ct,var) = v; // do the lower part of c also. end, end, c=cv;

// This a simple wrapper function to get just the eigenvectors // since the system call returns 3 matrices function [x]=justeigs (x) // This just returns the eigenvectors of the matrix

[a, eig, b] = bdiag(x);

x= eig;

// this function makes the transformation to the eigenspace for PCA // parameters: // adjusteddata = mean-adjusted data set // eigenvectors = SORTED eigenvectors (by eigenvalue) // dimensions = how many eigenvectors you wish to keep // // The first two parameters can come from the result of calling // PCAprepare on your data. // The last is up to you.

function [finaldata] = PCAtransform(adjusteddata,eigenvectors,dimensions) finaleigs = eigenvectors(:,1:dimensions); prefinaldata = finaleigs’*adjusteddata’; finaldata = prefinaldata’;

// This function does the preparation for PCA analysis // It adjusts the data to subtract the mean, finds the covariance matrix, // and finds normal eigenvectors of that covariance matrix. // It returns 4 matrices // meanadjust = the mean-adjust data set // covmat = the covariance matrix of the data // eigvalues = the eigenvalues of the covariance matrix, IN SORTED ORDER // normaleigs = the normalised eigenvectors of the covariance matrix, // IN SORTED ORDER WITH RESPECT TO // THEIR EIGENVALUES, for selection for the feature vector.

// NOTE: This function cannot handle data sets that have any eigenvalues // equal to zero. It’s got something to do with the way that scilab treats // the empty matrix and zeros. // function [meanadjusted,covmat,sorteigvalues,sortnormaleigs] = PCAprepare (data) // Calculates the mean adjusted matrix, only for 2 dimensional data means = mean(data,"r"); meanadjusted = meanadjust(data); covmat = cov(meanadjusted); eigvalues = spec(covmat); normaleigs = justeigs(covmat); sorteigvalues = sorteigvectors(eigvalues’,eigvalues’); sortnormaleigs = sorteigvectors(eigvalues’,normaleigs);

// This removes a specified column from a matrix // A = the matrix // n = the column number you wish to remove function [columnremoved] = removecolumn(A,n) inputsize = size(A); numcols = inputsize(2); temp = A(:,1:(n-1)); for var = 1:(numcols - n) temp(:,(n+var)-1) = A(:,(n+var)); end, columnremoved = temp;

// This finds the column number that has the // highest value in it’s first row. function [column] = highestvalcolumn(A) inputsize = size(A); numcols = inputsize(2); maxval = A(1,1); maxcol = 1; for var = 2:numcols if A(1,var) > maxval maxval = A(1,var); maxcol = var; end, end, column = maxcol