Docsity

Image Compression using Singular Value Decomposition (SVD) in Math 410 Project, Study Guides, Projects, Research of Mathematics

Toggle sidebar
bg1
Math 410 Project
:
Image Compression using SVD
Problem Description:
There are a huge number of ways to encode and compress images. One way is to use
principal component analysis (PCA), which in turn uses Singular Value Decomposition (SVD). The general idea is
that our image is stored as a matrix, where each element of the matrix represents a pixel. We can store information
about this whole matrix, or we can compute the SVD, and store information about
P
,
S
and
QT
. If we consider
only the information in
P
and
Q
corresponding to the rst few diagonal entries of
S
, then we've greatly reduced
the storage size. As you'll see in this project, the rst few terms in the SVD corresponding to the large eigenvalues
contain most of the information contained in the image, while the latter terms contain very little information.
The idea is that if
B
is an
n×n
matrix containing our image, we compute the SVD:
B=P SQT
which we can
write as
B=P SQT= (p1, p2, . . . , pn)
s11 0· · · 0
0s22
...
0
.
.
........
.
.
0· · · 0snn
qT
1
qT
2
.
.
.
qT
n
=p1s11qT
1+p2s22qT
2+· · · +pnsnn qT
n
where
pi
are the columns of
P
,
qi
are the columns of
Q
and
sii
are the diagonals of
S
(the singular values). Recall
that in SVD, the
sii
are arranged in order according to size. So
s11 ≥s22 ≥ · · · ≥ snn
and the terms
pisiiqT
i
with
i
small will contribute more to the sum that the latter terms. This means one can consider only a few of these
terms, and still recover information about the image.
One problem, is that if the full SVD is kept, then we've gone from
n2
elements of
B
to
2n2+n
elements in the
SVD (
n2
from
P
,
n2
from
Q
and
n
from
S
), but, if only a few terms in the SVD sum are kept, then we've greatly
reduced the amount of stored information. For example, if only
p1s11qT
1
is kept then this is just
2n+ 1
elements.
If we have a
1000 ×1000
image (only
1
megapixel) then we've got from
1,000,000
elements to only
2001
, reducing
the image size by nearly
500
times!
The goal in your assigment is to apply this procedure to an image of your face, analyze the error in the image
keeping only a certain number of terms in the SVD, and approximate the storage savings in using the SVD. You
should turn in your code (should be a single .m le), a typed document that answers each of the questions asked
as part of the assigned problem, and the
one single page
that contains the
6
images requested (clearly they will
not be
600 ×600
).
Assigned Problem:
1. Take a picture of yourself, preferable only your face, which is
600 ×600
pixels. Make sure the picture is
a JPEG le. Please try to do this using whatever tools you are comfortable with, and if you have trouble
converting to a
600 ×600
pixel JPEG le, there is an online converter here:
http://www.ivertech.com/freeOnlineImageResizer/freeOnlineImageResizer.aspx
If possible, make your image grayscale, if not, then you can convert it to grayscale using Matlab.
2. Modify the code
ImageReductionExample.m
so that it does the following:
(a) Reads you JPEG image (and converts to grayscale, if necessary).
(b) Compute the full SVD of your image matrix (the
B
matrix in the example) and returns the elements
as
P, S
and
Q
where
B=P SQT.
Note: Here we use
S
instead of
Σ
simply so we don't have to type
Sigma
into Matlab.
1
pf2

Partial preview of the text

Download Image Compression using Singular Value Decomposition (SVD) in Math 410 Project and more Study Guides, Projects, Research Mathematics in PDF only on Docsity!

Math 410 Project: Image Compression using SVD

Problem Description: There are a huge number of ways to encode and compress images. One way is to use

principal component analysis (PCA), which in turn uses Singular Value Decomposition (SVD). The general idea is that our image is stored as a matrix, where each element of the matrix represents a pixel. We can store information about this whole matrix, or we can compute the SVD, and store information about P , S and QT^. If we consider only the information in P and Q corresponding to the rst few diagonal entries of S, then we've greatly reduced the storage size. As you'll see in this project, the rst few terms in the SVD corresponding to the large eigenvalues contain most of the information contained in the image, while the latter terms contain very little information.

The idea is that if B is an n × n matrix containing our image, we compute the SVD: B = P SQT^ which we can write as

B = P SQT^ = (p 1 , p 2 ,... , pn)

s 11 0 · · · 0 0 s 22

0 · · · 0 snn

q 1 T q 2 T .. . qnT

= p 1 s 11 qT 1 + p 2 s 22 q 2 T + · · · + pnsnnqnT

where pi are the columns of P , qi are the columns of Q and sii are the diagonals of S (the singular values). Recall that in SVD, the sii are arranged in order according to size. So s 11 ≥ s 22 ≥ · · · ≥ snn and the terms pisiiqiT with i small will contribute more to the sum that the latter terms. This means one can consider only a few of these terms, and still recover information about the image.

One problem, is that if the full SVD is kept, then we've gone from n^2 elements of B to 2 n^2 + n elements in the SVD (n^2 from P , n^2 from Q and n from S), but, if only a few terms in the SVD sum are kept, then we've greatly reduced the amount of stored information. For example, if only p 1 s 11 q 1 T is kept then this is just 2 n + 1 elements. If we have a 1000 × 1000 image (only 1 megapixel) then we've got from 1 , 000 , 000 elements to only 2001 , reducing the image size by nearly 500 times!

The goal in your assigment is to apply this procedure to an image of your face, analyze the error in the image keeping only a certain number of terms in the SVD, and approximate the storage savings in using the SVD. You should turn in your code (should be a single .m le), a typed document that answers each of the questions asked as part of the assigned problem, and the one single page that contains the 6 images requested (clearly they will not be 600 × 600 ).

Assigned Problem:

  1. Take a picture of yourself, preferable only your face, which is 600 × 600 pixels. Make sure the picture is a JPEG le. Please try to do this using whatever tools you are comfortable with, and if you have trouble converting to a 600 × 600 pixel JPEG le, there is an online converter here: http://www.ivertech.com/freeOnlineImageResizer/freeOnlineImageResizer.aspx If possible, make your image grayscale, if not, then you can convert it to grayscale using Matlab.
  2. Modify the code ImageReductionExample.m so that it does the following:

(a) Reads you JPEG image (and converts to grayscale, if necessary). (b) Compute the full SVD of your image matrix (the B matrix in the example) and returns the elements as P, S and Q where B = P SQT^. Note: Here we use S instead of Σ simply so we don't have to type Sigma into Matlab.

(c) Insert code which computes the reduced SVD using only the rst k terms. (d) Insert code which computes the error in using the reduced SVD versus the full SVD. This formula is in the notes, and relates the sum of the singular values.

  1. Run your code using k = 1, 2 , 5 , 10 , 25 , 50 and 100. For each k, record the error in the reduced SVD and comment on how your reduced image compares to your original image, in terms of visual appearance.
  2. Assuming your original image can be represented at 600 ×600 = 360, 000 elements, determine what percentage of storage the reduced image uses for each of the k values above. Determine a value of k so that we would no longer have any savings in storage. Please include details as to how you calculate each of the sizes.
  3. Print the original image, and the images for k = 1, 5 , 25 , 50 and 100 on one single page. I would suggest your copy and paste the images into a document editor, such as Word, or use a program such as Photoshop.