You are on page 1of 3

Image Processing Project (Due April 18, 2023)

Note: All code used in the project must be attached to the project file.

1. (IMPORTING AND PLAYING AROUND) Import the follow-


ing “sunflower” image into a matrix, see Figure 1. When you import
the jpeg, it will be encoded in 8-bit numbers (minimum 0 and maximum
255). Also, the image will have red, green, and blue channels, so it will
be an 853 × 640 × 3 array, lets call it A. We can extract the R channel
by taking A(1 : 853, 1 : 640, 1), the G channel by A(1 : 853, 1 : 640, 2)
and the B channel by A(1 : 853, 1 : 640, 1).
Note: if you are using Matlab, we will do image processing in either
double (colors normalized out of 1) or uint8 (out of 255).

(a) Produce a black and white version of the sunflower image.


(b) How can I change the contrast? That is, how do I make the dark
more dark and the light more light? Implement a contrast change.
Commentary: You choose how to do this. Maybe you could con-
sider a hyperbolic tangent function (?), properly scaled of course.
(c) Rotate the image clockwise by 90◦ .
(d) Why is rotating by, say, 40◦ so difficult? Imagine the row and
column number of an entry of the matrix as a location in R2 . You
will need to center the image about the origin, and then apply a
40◦ rotation matrix to each (x, y)-coordinate. This will give you
the new locations of each pixel. However, now you have to create a
new large Cartesian grid which bounds the rotated image in order
to put the new locations into a new image matrix. The new large
grid points will not align exactly with the rotated grid points.
Thus, we need to carry over the information about the rotated
image onto a new grid that does not align exactly. Explain how

1
Figure 1: Sunflower

2
to overcome this difficulty. (For this problem, you do not
have to code this up, but must explain how to do it.)

2. (COMPUTATIONAL PROBLEM) Now, we will perform image


compression using the singular value decomposition. The singular value
decomposition can be used for image compression because it can pro-
duce the best (with respect to a matrix norm) rank-r approximation
to a given matrix. That is, if your objective is to reduce the amount
of memory that an image takes up, one way to do it is to reduce the
rank of the image matrix. This is done best with the singular value
decomposition.
Let’s look at the full singular value decomposition of the image matrix
(for example, the R, G, and B channels separately). That is, we need
all three matrices in the decomposition:

A = U ΣV T (1)

Note: in Matlab, we find the full SVD of a matrix A by typing:

[U, S, V ] = svd(A); (2)

(a) What is the condition number of the matrix A? That is, what is
the ratio of the largest to smallest singular value of A?
(b) Cut off all singular values below 0.01σ1 , where σ1 is the largest
singular value. Show the image result. It should look very similar
to the original image (but slightly compressed). What percentage
of the singular values have been removed?
(c) Cut off all singular values below 0.1σ1 and show the result. Now,
we should observe some degradation of the image, although it still
resembles a sunflower. What percentage of the singular values
have been removed?
(d) Go online and try and find a criterion for how many singular values
you should remove to do image compression and explain why this
is a good criterion for the application we have in mind.

You might also like