Thursday, September 23, 2010

A14 - Image Compression

Image compression is a useful way to enable the storing of large images in a small memory. The most popular file format for images, jpeg, also utilizes a compression technique in saving the images. The method that is shown here uses Principal Components Analysis and uses weighted basis images to represent blocks of the image.

The original image used is the sample image of Microsoft entitled Waterlilies.



I then got the grayscale image, cut the image into blocks and used PCA to get the eigenvectors that represent the basis images. I then examined the eigenvalues.

I then chose to use the first 20 eigenfunctions that would already provide 98.973403 % or about 99 % of the information of the image. Using these eigenfunctions, I got their coefficients by getting their dot products with blocks from the grayscale image. These coefficients are the weights of the different basis images used in reconstructing the block in the image. This is the code I used for reconstruction after getting the PCA of the blocks:

y = zeros(size(I));

k=0;

for r = 1:60
for c = 1:80
itemp = I(((10*r-9):(10*r)),((10*c-9):(10*c)));
xtemp = itemp(:);
k = c + (r-1)*8;
x(k,:) = xtemp';
for i = 1:20
atemp = sum(x(k, :)'.* facpr(:,i));
a(i) = atemp;
end
h = zeros(100,1);
for m = 1:20
ytemp = a(m)*facpr(:,m);
h = h + ytemp;
end
y(((10*r-9):(10*r)),((10*c-9):(10*c))) = matrix(h,10,10);
end
end

The reconstructed image is shown below.



Upon visual inspection, it contains all the information of the grayscale of the original image. It is observed that the 1 % loss in information is not evident and irrelevant in our application because we simply have to reconstruct the image and resolution is not of great importance. Therefore, our compression is successful for our purpose. It can also be computed that instead of saving 480,000 grayscale intensities for the 600 x 800 image, upon compression using the first 2o eigenvectors from the PCA, we only need to save 48,000 numbers instead because we only save 20 coefficients per 10 x 10 block. Theoretically, the file size is reduced to only 10 % of the original!

For this activity, I give myself a grade of 15 because I worked it out on my own and understood it well enough to teach it to a classmate.

No comments:

Post a Comment