Friday, September 13, 2013

Not Just Your Usual Image Compression

In this activity, an image is compressed in not just the ordinary way that you know. The main reason why we want to compress images is to reduce the image size. Our cameras are continuously advancing and the information that it can gather from the object are almost limitless, in other words, high-def. But some information are not necessary. On way of compressing image is through principal component analysis (PCA). [1]

To clearly demonstrate the compression, I use a very large image of a clownfish taken from National Geographic website [2] as shown below. It has a dimension of 1600 x 1200 pixels and size of 2.12 MB - truly a BIG image. However, the very big original image encountered a problem on the working stack size in the Scilab. Even I maxed out the stack size, it really wasn't able to operate on very large scale. So, I need to resize the image to 800 x 600 pixels resulting to size of 388 KB - still relatively large.


The image was first converted to grayscale. The image was then cut into 10 x 10 pixels subblocks then concatenated into single column matrix with 100 elements. The concatenated subblocks was arranged into n x p matrix x where n is the number of subblocks and p is the number of elements in each block. We then get the pca of x. In Scilab, the following line was used.
[lambda,facpr,comprinc] = pca(double(x))

The facpr matrix contains the eigenvectors or eigenimages that composed the image, with the first column to have the highest contribution or weight to the original image and so on. The eigenvalue or the constant value

From the grayscaled image below...


the reconstructed images using different numbers of eigenimages are presented. From the lamda, the corresponding weight of each eigenimages was known. The cumsum() function will determine how many eigenvectors will achieve a specific percentage in reconstruction. One eigenimage already correspond to 95.1% of the original image. On the other hand, using 5, 20, 85 and 100 eigenimages result to 97.9%, 99.0%, 99.9% and 100% of reconstruction, respectively. 


For each reconstruction, compression of the image were made. From the grayscaled image original size of 183 KB, the reconstructed images resulted to decrease in size to 89.0 KB, 80.8 KB, 94.5 KB and 174 KB using 1, 5, 20 and 85 eigenimages, respectively. The decrease were 51.4%, 55.8%, 48.4% and 4.9%.

Using all 100 eigenimages (100% reconstruction), doesn't have much difference from when 85 eigenimages were used. Also, no compression had took place. The image size resulted to 183 KB, the same size as the original image. 



Now, let's put some colors to our reconstruction


The image size resulted to 112 KB, 97.6 KB, 114 KB and 195 KB. From the original 388 KB image size, the percent decrease were 71.1%, 74.8%, 70.6% and 49.7%. The compression was observed to be greater for the colored image. 

I thank Phoebe for helping me debug my code. I am giving myself a grade of 11/10 for accomplishing the goal of the activity and doing the reconstruction in colors. 

__________
References
[1] Soriano, M. "A13 – Image Compression." AP 186 Laboratory Manual. National Institute of Physics, University of the Philippines, Diliman. 2013.
[2] Clownfish and Bubble-Tipped Anemone. Photograph by David Doubilet. Retrieved from 
http://photography.nationalgeographic.com/photography/photo-of-the-day/clownfish-bubble-tipped-anemone/

No comments:

Post a Comment