Archive

Posts Tagged ‘compression’

14. Image compression

September 24, 2010 2 comments

Image compression has been the means of reducing the size of a graphics file for better storage convenience.  It is also a useful way of reducing the time requirement of sending large files over the Web.  Here we will explore a method in image compression by Principal Component Analysis (PCA).  This technique utilizes the idea that any image can be represented as a superposition of weighted base images.

Suppose we have the following image and its grayscale conversion:

Figure 1. A sample image (characteristically sharp)and its grayscale equivalent.  Courtesy of SuperStock.

We divide image into blocks of 10×10 dimensions and concatenate them.  These sub-blocks are arranged into an nxp matrix, where n is the number of blocks and p the number of elements in each block.

We apply PCA on the matrix with the pca() function in Scilab. which returns a set of eigenvalues, eigenvectors and principal components.

Figure 2. Plot of eigenvalues (A) and principal components (B) of the image.

This produces eigenimages which would be essential elements to the compressed image.

Figure 3. Eigenimages derived from the original image.

Eigenvalues tell how essential a particular set of eigenvectors is to making up the completeness of the image.  Based on these values expressed in percentages we choose the most important eigenvectors and reconstruct the image out of these.  Figure 4 shows the resulting images at 86.7%, 93.4%, 95.5%, and 97.5%.

Figure 4. Compressed reconstructions of the image at different numbers of eigenvectors. 1, 3, 5 and 10 respectively.

We can find out how much of the image has been compressed by counting how much of the eigenvector elements were used in the reconstruction and/or determining the file sizes. Our original image has the dimension 280×340 and is stored at 75.3KB (grayscale).  When compressed with only a certain number of eigenvectors (figure above), becomes reduced to 44.2KB, 51.3KB, 53.9KB, and 60.7KB respectively.

When circumstances do not really require high-definition images, it is often best to compress the images into a good size such that it’s quality is not compromised and information is well-kept.

For this activity, I would rate myself 10 for the job well done. 🙂

Credits: Jeff A. and Jonathan A.

———————————————————————————————–—————–————————————
References:
[1] Soriano, 2010. Image compression. Applied Physics 186.
[2] Mudrova, Prochazka. , 2005. Principal component analysis in image processing.
[3] TechTarget, 2010. What is image compression?

3b. Image File Formats

June 27, 2010 Leave a comment

On the average, images compose over 50% of the pages on the Web.  And with cameras, mobile phones, and computers being part of our lives we have lots of pictures captured with friends or downloaded from the internet.  Either this makes us think that we are consuming much of our hard disks and memory cards, or creates the need to expand our storage to make sure our high-resolution pictures are well-kept.  Having the knowledge of image file formats helps you settle on a decision depending on how much priority you give between image quality, attribute flexibility, and memory space.

The size of an image is directly related to the number of pixels defining the image and the depth of the colors within its pixels. Different file formats have different algorithms as means of compressing these data into more compacted sizes.

Lossless compression aims to preserve the quality of the image and stores information without compromise. Data are compacted by simply searching for similar or repeated pixels around the image. Lossy compression, on the other hand, allows the storage of colors at lower resolution and considers the human limitation to detect these changes. Some file formats allow variation in quality levels, though certain extents, allows deterioration of image quality.

The most common file formats [1] are:

  • TIF – Tagged Image File Format, uncompressed and compressed formats
  • PNG – Portable Network Graphics, standardized compression
  • JPG – Joint Photographic Experts Group, compressed format
  • GIF – Graphics Interchange Format, compressed format

TIF is best when intentionally needing large images and high resolutions for banners or prints. It compresses data efficiently, either lossy or lossless, and at the same time preserves the quality of the images. TIFF however, will not be efficient as Web graphics because of its size. It is recommended to have it converted to a more portable format to be able to post it online.

PNG is efficient when smaller file sizes are needed without loss in content. Pixels are searched for patterns to be used to compress the file size. Compression is freely reversible and the image can easily be recovered. PNG supports alpha transparency (soft edges) useful for fades and anti-aliasing in texts.

Figure 1. A PNG image of a bridge upon sunset. Courtesy of Zicasso.

JPG is the default saving format for photo images. It stores information within the rich 16 million colors at minimum loss. It is usually preferred in photography to set the amount of compression needed.

GIF formats are usually used for web graphics. It supports transparent colors and is capable for multi-graphic animations. Images are compressed into an 8-bit color palette, indexing the pixels to 256 colors. Storing images may be lossy, but no further compression is done after that.

Figure 2. A. JPG image of a downtown street during the evening.  B. An animated GIF image of a rainy night.  Courtesy of MobileApples[1, 2].

Figure 3 displays a comparison between the latter three image formats [1]. Notice that JPG has slight quality issues with text.

_

PNG 26kB

_

JPG 6kB

_

GIF 12kB

Figure 3. Image quality and file size comparisons between, PNG, JPG and GIF.

The following table summarizes the important bases of comparison for image file formats and the distinguishing characteristics of each [1].

Format

Color Depth

Compression

Loss of Detail on Saves

Web

TIF variable lossless No No
PNG variable lossless No Yes
JPG 24 lossy Yes Yes
GIF 8 lossless No Yes

Greatly varied our formats may seem, the choice of file type still depends on the objective of how it is used. As always the main goal is to represent meaningful information, depending on the context.

———————————————————————————————–—————–————————————
References:
[1] CyWarp, 2000. Digital Photography: Photo File Formats. Queensland, Australia.
[2] Hewlett-Packard, 2010. Understanding digital photo file formats. United States.
[3] Mattews, G., 2010. Digital Image File Types Explained. Wake Forest University.
[4] Soriano, M., 2010. Image types and formats. Applied Physics 186.