Tuesday, June 28, 2011

A3 - Image Types and Formats

"A picture speaks a thousand words..." -anonymous
  
Above is one famous line indeed.
Picture serves as an outlet of reminiscing the past and rekindling memories and experiences. There is so much inside a picture considered priceless. However, even though pictures remain ubiquitous, only little is known about its physical properties by man. In this blog post, I will let you travel the inside realm of a picture by showing the physical quantities governing it.

Images come in different types depending on their properties. Basically, there are 8 types of images. Four of these are considered to be basic and four are results of advancing imaging techniques. The four basic types of images are binary, grayscale, truecolor, and indexed; while the four advanced types are high dynamic range (HDR), multi or hyperspectral, 3D and temporal images or videos.

In order to understand what distinguishes each image type from all others, I'll show you examples of each and a brief description.

BASIC IMAGE TYPES

A. Binary images 
-> A binary image is a digital image consisting of only black or white colors. In imaging sense, the only possible pixel values are either one or zero. Binary images are commonly used in fingerprints and fax machines because of the small file size(~8KB for a 256x256 pixel image).  An example is shown below with some of its properties written on its right. The properties can be displayed in Scilab 4.1.2 SIP toolbox using imfinfo(filename, 'verbose'), while for higher Scilab version(SIVP toolbox) imfinfo(filename) will suffice. The properties shown are
 FileSize: measured in bytes 
Format: "JPEG", "TIFF", "GIF", "BMP", etc. 
Width: number of columns 
Height: number of rows 
Depth: bits per pixel 
StorageType: "truecolor" or "indexed" 
NumberOfColors: size of the colormap. Equals to zero for truecolor images 
ResolutionUnit: "inch" or "centimeters" 
XResolution: number of pixels per ResolutionUnit in X direction 
YResolution: number of pixels per ResolutionUnit in Y direction 


        FileSize: 41346
         Format: PNG
          Width: 256
         Height: 256
          Depth: 8
    StorageType: truecolor
 NumberOfColors: 0
 ResolutionUnit: centimeter
    XResolution: 72.000000
    YResolution: 72.000000

Figure 1: Binary image of a fingerprint
(http://www.csse.uwa.edu.au/~pk/research/matlabfns/FingerPrints/Docs/index.html)

B. Grayscale Images
->A grayscale image consists of colors from the shade of gray. To be exact, the pixel values ranges only from 0 to 255. Grayscale images need less information to be provided for each pixel since the intensities of red, green and blue(RGB) are equal that only one intensity value is used. Most commonly, biological and medical images use grayscale.

       FileSize: 2767
         Format: JPEG
          Width: 220
         Height: 229
          Depth: 8
    StorageType: truecolor
 NumberOfColors: 0
 ResolutionUnit: centimeter
    XResolution: 72.000000
    YResolution: 72.000000

Figure 2: Grayscale image of a Gecko's xray
(http://www.flickr.com/photos/milclayton/5098858362/)

C. Truecolor Images
->A truecolor image is a digital image that depicts the real object as perceived by a person in real world. It is the combination of three channels which are the intensity of red, green and blue colors. Truecolor images are the most common type because of the creation and wide distribution of commercial digital cameras.

       FileSize: 286048
         Format: JPEG
          Width: 1280
         Height: 851
          Depth: 8
    StorageType: truecolor
 NumberOfColors: 0
 ResolutionUnit: inch
    XResolution: 72.000000
    YResolution: 72.000000


Figure 3. Truecolor image of our 2011 vacation in Laguna.
(Photo taken by Mr. Arvie D. Ubarro)

D. Indexed Images
->An indexed image consists of colors represented by a colormap. Aside from saving the pixel matrix values of an image, colormap values must also be stored. Indexed images are comparable to truecolor images but with reduced information.

       FileSize: 12246
         Format: JPEG
          Width: 288
         Height: 288
          Depth: 8
    StorageType: truecolor
 NumberOfColors: 0
 ResolutionUnit: inch
    XResolution: 72.000000
    YResolution: 72.000000

Figure 4. Indexed image.
(http://printplanet.com/forums/enfocus/16504-indexed-color-spaces)

ADVANCED IMAGE TYPES
A. High Dynamic Range Images
-> Can be stored in 10- to 16-bit grayscales and are often used in very bright scenes(e.g. sun images).

       FileSize: 88904
         Format: JPEG
          Width: 600
         Height: 381
          Depth: 8
    StorageType: truecolor
 NumberOfColors: 0
 ResolutionUnit: centimeter
    XResolution: 100.000000
    YResolution: 100.000000

Figure 5. HDR image of a rally racing car.
(http://www.designsdelight.com/hdr-photography/hdr-2/?replytocom=1359)

B. Multi or hyperspectral Images
-> Uses more than 3 color bands. A multispectral image uses bands in the order of 10's while a hyperspectral  uses order of 100's. This is the most common image type used in satellite images.

       FileSize: 261424
         Format: GIF
          Width: 523
         Height: 525
          Depth: 8
    StorageType: indexed
 NumberOfColors: 256
 ResolutionUnit: centimeter
    XResolution: 72.000000
    YResolution: 72.000000

Figure 6. Multi or hyperspectral image.
(http://www.fs.fed.us/r5/rsl/projects/remote-sensing/mss.shtml)

C. 3D Images
->As the name imples, this is a 3-dimensional image where its information are stored spatially. 3D images can be taken by taking multiple images of an object a short distance apart and superimposing them.

    
   FileSize: 326560
         Format: JPEG
          Width: 800
         Height: 601
          Depth: 8
    StorageType: truecolor
 NumberOfColors: 0
 ResolutionUnit: inch
    XResolution: 96.000000
    YResolution: 96.000000


Figure 7. 3D image of a tiger.
(http://www.maximumpc.com/article/features/future_tense_3d_or_not_3d)

D. Temporal Images or Videos
-> This is basically a moving picture. Its presence became very prominent in recent times due to the invention of camera with high frame rates.

 Video 1: Temporal Video of a popping water balloon.
(http://www.youtube.com/watch?v=_HNve7bekeM)

Since we now know the different types of images, we try converting one type to another type using Scilab functions. We will implement these conversions on a truecolor image shown below
Figure 8. Truecolor image.
(Photo taken by Mr. Arvie D. Ubarro)

We can convert a truecolor image to a binary image by just using the lines 
I  = imread(filename); // Opening the image in Scilab 4.1.2 using its filename
BW = im2bw(I, level); //Converts the image I into binary by following a threshold value, level.

In Scilab, the possible threshold (level) values are between 0 to 1. It works by mapping the pixel values greater than or equal to this threshold to 1 and values less than the threshold are mapped to 0. The resulting binary image when I used a 0.5 threshold is shown below.

Figure 9. Binary image using a 0.5 threshold.

We then convert the same truecolor iamge to a grayscale image. In Scilab 4.1.2, there are two ways of doing this, useful coding lines are shown below
I  = imread(filename); // Opening the image using its filename 
GR = im2gray(I); //Converts the image I into grayscale
OR
GR = gray_imread(filename); //Converts the RGB image from the path filename into grayscale

The resulting grayscale image is shown below

Figure 10. Grayscale version of figure 8.

For both cases, the following changes in properties are observed:
  • The storage type was converted from a Truecolor image to an Indexed Image.
  • The matrix size changed from 851x2580x3 pixels into 851x2580 pixels. This is to show that converting a truecolor image to grayscale or binary flattens the image signifying that the 3channels related to RGB colors become one. The size of an image can be seen using size(matrix).
Using the techniques learned, the next goal is to separating a background from a region of interest. This can be done by following this procedure and available code:
  • Open first an image using imread(filename)
Figure 11.  Hand-drawn graph from activity 1.

  •  Convert the opened image to grayscale using the two methods introduced above. Either im2gray(image) or gray_imread(filename). This will enable us to limit the pixel values to 0 until 255 and separation will be easier.
Figure 12. Grayscale version of figure 11.
  • Obtain a histogram of the grayscale image using histplot(number of bins, image). In particular, I used 256 bins to create a separate bin for each grayscale value from 0 to 255. So what is a histogram then? A histogram of a grayscale image represents the number of pixels(y-axis) having a certain grayscale value(x-axis). The histogram can be very useful in separating lines from a background because it suggests the most suitable threshold to be used.
Figure 13. Histogram of figure 12.
  • From the histogram, we can see that the possible good threshold values are between 150/255 (0.588) and 170/255 (0.667). We used these threshold values in BW = im2bw(image, threshold) and compare the results.


          Figure 14. 0.667 threshold.                     Figure 15. 0.647 threshold.


          Figure 16. 0.627 threshold.                    Figure 17. 0.588 threshold.

By comparing results of figures 14-17, we can say that the best threshold value is 0.667 because the lines are clearly seen and the information is complete. A very simple procedure indeed. However, a possible problem you might encounter while opening the scanned image is
Do not panic when you reach that point. The problem is mainly a stacksize error or that the memory available for Scilab to use exceeds the memory needed in your program. This can be easily remedied by increasing the stacksize using stacksize(n) where n is the size you want.

Have you heard of the image file formats jpg, bmp or png? I believe yes is your answer. The million dollar question is do you know the differences between them and what distinguishes one from another? Does saving to particular file format matters? These questions can be briefly answered below.

There are actually many image file formats and the most common of them are the JPG, BMP, PNG, GIF, and TIFF. The main difference between them are in their color depth and compression.

Color depth is the number of bits needed to represent the color of a single pixel. 

Compression, on the other hand, is the reduction of irrelevant and redundant image data. There are two types of image compression:
  1. Lossy : storage of color information at a less resolution than the image itself. This results to a smaller compact file.
  2. Lossless : efficient storage of color information without compromising accuracy because every pixel information is preserved.

IMAGE FILE FORMATS
A. Joing Photographic Experts Group (JPG)
-> Commonly used in photographs containing many colors. It stores 24 bit or 16 million color information. However, the drawback is that each time the image is edited and saved, image fidelity reduces because of its lossy compression.

B. Bitmap (BMP)
-> Handles graphic files in the Microsoft Operating System. BMP files are commonly large due to its uncompressed quality.

C. Portable Network Graphics (PNG)
-> The open source version of GIF and is stored using 16 million colors. It is designed to be used in online web applications because of its robustness to integrity and transmission error checking. Its format compression is lossless

D. Graphics Interchange Format (GIF)
-> Commonly used in simple diagrams and shapes because it only stores 8 bit or 256 colors. This image format is considered to be the most suitable for storing animation effects. However, it is not advisable to use this for detailed images because of its lossless compression.

E. Tagged Image File Format (TIFF)
-> Ideal for editing large prints because of its retention of large image information. It can store variable number of bits and the compression can be lossy or lossless.

Now we know the different image file formats, some considerations must  be made before saving an image to obtain efficiency.

Phew! This is one long activity indeed. The activity is tiring yet informative. It is only after finishing the activity that I fully understand the wonderful world of images. As a conclusion, I will give myself a grade of 10.0 for satisfactorily completing the entire activity and producing results needed.

References:
  1. http://en.wikipedia.org/wiki/Image_file_formats
  2. http://www.wfu.edu/~matthews/misc/graphics/formats/formats.html
  3. "Image Types and Formats", 2010 Applied Physics 186 manual by Dr. Maricor Soriano

No comments:

Post a Comment