Image compression is a neat way to save memory space in storage devices. In this activity, our goal to convert an image to a format that would take less memory space for storage. The method used in compressing the image is the same compression method used in JPEG images.
First we pick an image of our choice, and then convert it to a grayscale image.
Figure 1. A 400x400 pixels image that was used for this activity. This image was obtained from deviantart.com.
Figure 2. Grayscaled image that will undergo compression.
We then cut the image into blocks with 10x10 pixels, then we vectorize it. After vectorization, we then gather all the vectorized blocks into a single list.
Principal components analysis (PCA) was then applied to the vector list. We used the built-in function in scilab, pca. The built-in function, then returns a list of eigenvalues, eigenvectors (eigenimages) and coefficients. The eigenvalues are needed to determine up to what number of eigenimages are needed to reconstruct the image of the original image. The eigenimages and its corresponding coefficients are the ones that are used in image reconstruction.
After PCA was applied on the grayscaled image, the 10x10 pixels eigenimages are obtained by arranging and concatenating the block. The eigenimages are shown below.
Figure 3. Eigenimages obtained after applying PCA on the image.
These eigenimages are the ones that will be used, together with its corresponding coefficient per block, to reconstruct the whole image. The eigenvalues will determine how many eigenimages from Figure 3 are needed to reconstruct the image. The eigenvalues are plotted below;
Figure 4. Eigenvalues of the eigenimages.
Now let's proceed to image reconstruction using the eigenimages and their corresponding coefficients. Reconstruction using all the eigenimages will result to a lossless compression and no difference will be observe between the original image and the reconstructed image. So to observe difference, we threshold the eigenvalue sum to less than a hundred percent (99%, 90%, 80%).
Figure 5. Reconstructed image with 80% thresholding. Only the first 3 eigenimages are used for reconstruction.
Figure 5. Reconstructed image with 90% thresholding. Only the first 14 eigenimages are used for reconstruction.
Figure 5. Reconstructed image with 99% thresholding. Only the first 68 eigenimages are used for reconstruction.
We can see that as the thresholding in the eigenvalues increases, the quality of the image also increases. This is expected because as the number of eigenimages used increases, the more defined the reconstructed image will be.
Now let us compute the memory space needed for the uncompressed image and the compressed image. For the uncompressed image (grayscaled image), we have 400x400 pixels and each pixel has a single value that ranges from 0 to 1 with 256 intervals. So the total image memory used is 400 * 400 * 256= 40960000 bits. On the other hand, for the compressed image, we have 40x40 blocks and we have a maximum of 100 coefficients. So the total image memory used is 40 * 40 * 100 = 160000 bits. Wow! What a difference!
Now what if we used the computed eigenimages to reconstruct a different image. Let's say a flower shown in Figure 6.
Figure 6. Image used to see if reconstruction of this image is possible using eigenimages obtained from the image in Figure 2.
First, we need to cut this image again into 10x10 pixels blocks and then vectorize it. After vectorization, we need to get the coefficients of the eigenimages from the previous image by getting the dot product of each vectorized blocks with all of the eigenimages. After obtaining the coefficients, we can now do the reconstruction. We will do reconstruction using the first 1, 3, 14 and 68 eigenimages.
Figure 7. Reconstructed image using only the first eigenimage.
Figure 8. Reconstructed image using only the first 3 eigemimages.
Figure 9. Reconstructed image using only the first 14 eigemimages.
Figure 10. Reconstructed image using only the first 68 eigemimages.
Wow! The image was reconstructed even though the eigenvectors used are from a different image. Again, it is still evident that if the number of eigenimages used is increased the quality of the image also increase.
In this activity, it is very interesting to know that there is a convenient and optimal method that can compress large sized image memory to a significantly smaller image memory. And also, eigenimages of a specific image can be used to reconstruc other images. I deserve a grade of 10 on this activity for the frustrating indexing. =P
Reference:
- Dr. Soriano. Applied Physics 186: A14 - Image Compression. 2010.
No comments:
Post a Comment