Tuesday, June 18, 2013

Image type and file formats

In this activity, we work with different types of images and how to manipulate them using an image processing software. First, we look at the properties of some images using Scilab and the function imfinfo of the Scilab Image and Video Processing (SIVP) toolbox. Using the help() function of Scilab, the parameters and output of the function inside the parentheses are described.

File name String containing the image file name.
File size Integer indicating the size of the image file in bytes.
Width Integer indicating image width in pixels.
Height Integer indicating image height in pixels.
Bit depth Integer indicating the number of bits per pixel .
Color Type String containing the color type of the image file, which can be 'grayscale' or 'truecolor'.

Also, along with the output of imfinfo(), I've also included the information from the properties of the image (by using the right click on the image).
Figure 1. Grayscale image [1]

Filename  C:\Users\Akared\Desktop\AP 186 Act 3\bleach2.bmp  
FileSize             60062  
Width                   800
Height                  600
BitDepth                  8 
ColorType   grayscale

Figure 2. Image properties of Figure 1.


Figure 2. Image of Saturn taken by the author on April 14, 2013.

The image was obtained using a Skywatcher 150mm reflecting telescope and a Samsung PL120 point-and-shoot camera set to video recording mode at 30 frames per second. The video file, 15 seconds long, was split to individual frames and processed using Registax 6.

Filename  C:\Users\Akared\Desktop\AP 186 Act 3\saturn2.tif  
FileSize              256348  
Width                      381  
Height                     168 
BitDepth                     8  
ColorType       truecolor

Figure 4. Image properties of Figure 3.

This was the video file used to obtain the image of Saturn in Figure 3:


The camera was not properly aligned with the axis of Saturn's rings and so the video that was recorded showed a tilted view of Saturn. In the video, the outline of Saturn was blurred due to atmospheric effects. By stacking the 450 frames from the 15-second video, the details on the planet became distinct. Since the effects of the atmosphere is different in each frame, averaging all those frames will cancel out the effect of the atmosphere. Also, you will now be able to see the Cassini division on the ring of Saturn, which is the gap between the inner and outer region of the ring [3].

Figure 5. Taken using Canon EOS 500D.

Filename:  C:\Users\Akared\Desktop\AP 186 Act 3\nip_scope.JPG  
FileSize         4915644
Width                 4752  
Height                3168
BitDepth                  8 
ColorType   truecolor  

Figure 6. Image properties of Figure 5.



Figure 7. GIF animation of the cutest Pokemon [2]


Figure 8. Image properties of Figure 7.

Image File Formats
Here, I'll be discussing a brief history of some image file formats and their uses.

1977-1978: Abraham Lempel and Jacob Ziv published papers on constructing dictionaries for image compression. These were named LZ77 and LZ78 compression, which became the platform for image compression techniques. Terry Welch further improved these dictionaries and created the LZW compression. [4]

1987: Graphics Interchange Format (GIF) was created by CompuServe, a company working on distributing small networks between a group of computers. GIF’s were based on the LZW compression. Before being used as a way to animate images, the GIF served as a way to save time in sending and collecting information which have repeating contents. [5] This is seen in Figure 7, where the GIF is created from the sequence of frames from the video of the anime Pokemon. From the frames of the video, information only varies in the region where the hands of Pikachu touch the cheeks. Thus there is only a need to note these variations on specific pixels, with the pixels outside this region unchanging, eliminating the redundancy of information on the latter region.

Color indexing is used on GIF files to minimize the number of bytes for the information of each pixel. This restricts the color of GIF to 256 colors. Also, one color can be assigned as transparent such that when the GIF image is placed on top of another image, the colors of the image below can be seen on the transparent region. [4]

Mid 1980’s to early 1990’s: JPEG compression was developed. The Joint Photographic Experts Group developed this method of lossy compression, hence the name of the image file format. JPEG compression works on the frequency domain of the image, but instead of using Fourier transform, Discrete Cosine Transform (DCT) is implemented (which is roughly similar to FT). Compression is performed on the frequency components of each pixel by allowing a smaller amount of possible values for higher-frequency components of the image. [4] Since it acts on the value of high-frequency components, there is no perceived difference on the resulting compressed image. 

1994: The patent for LZW compression was given to the company Unisys. The company demanded GIF users to pay royalties to the company, thus making GIF unpopular [5]. Since there was no patent on the LZ77 compression, it was developed to create the deflate compression which would be used for creating Portable Network Graphic (PNG) files. [4]

One of the features of PNG’s is the presence of the filter byte, which is apart from the image data. With the filtering of data, compressibility is increased. Furthermore, the amount of information in the image is not reduced, making it a lossless image compression.

PNG’s, unlike GIF’s, are not restricted to 256 colors. Special effects can also be added on the image, aside from partial transparency, using the alpha channels of the PNG. [4]

2004: The use of GIF’s became free after the patent for the LZW compression expired.

Aside from these file formats, we also have the Tag Image File Format (TIFF) and BMP (or the Microsoft Windows Bitmap). These two image file formats are usually uncompressed. Also, together with PNG's, these three file formats can present full-color images, as they all support 24-bit color, as compared to GIF, which only has 8-bit color. [4]

Canon and Nikon have their own file formats. Raw images have extensions such as .crw and .cr2 (Canon) and .nef (Nikon). The advantage of this is that the data is stored directly after the analog to digital conversion occuring at the sensor of the camera. With this, processing can be performed outside the imaging device for more flexibility on the manipulation of the image.

Playing around with ImageJ

In this section we will be using the following image:


Figure 9: Star trail of Ursa Major (and other constellations beside it). 

The image was created by capturing 190 images, each with a 10-second exposure and 10-second interval on a Nikon D5100 DSLR. The trails of the stars show their one-hour motion across the celestial sphere. The images were processed using the program Startrails and enhanced using Photoshop CS5.

I first used converted Figure 9 into binary:

Figure 10. Conversion to binary of Figure 9.

This was achieved by selecting the "Make Binary" command under the "Binary" subsection of the "Process" menu.
Figure 11. Locating the binary conversion on ImageJ.

The image can also be converted to grayscale in the following manner:
Figure 12. Changing the image into grayscale using the 8-bit conversion 

which yields this:
Figure 13. Grayscale image of Figure 9.


Figure 14. Histogram of Figure 13.

The 8-bit conversion of ImageJ converts the image linearly from 0 to 255 [3]. The contrast can be achieved by going to this command under the "Image" menu:

Figure 15. Brightness and contrast enhancement command of ImageJ

In this activity, I have set the adjustments of the brightness and contrast to automatic. To vary the contrast, I simply adjusted the first horizontal scroll bar on the Brightness and Contrast options.

Figure 16. Adjusting the brightness and contrast.

These images, each with a different contrast value (indicated above each image):
Figure 17. Varying the contrast values for the 8-bit conversion

when saved as JPEG files have decreasing file size:
 Figure 18. File size versus scaling factor for the  8-bit conversion. The data points were fitted with a linear trend.

It can be seen that as the scaling factor is increased, with the image becoming darker, the file size decreases. The $R^2$ value of 0.8935 tells us that the relationship between the two is not linear.

Figure 19. File size versus scaling factor for the  8-bit conversion. The data points were fitted with an exponential trend.

With the 0.9495 $R^2$ value, we can roughly say that the file size has an exponential dependence on the scaling factor for this image. To verify this, maybe I'll try this on other images next time.

Going back to Scilab

Aside from the function imfinfo(), I also explored the use of the function imread(), gray_imread(), imshow(), imwrite()

With imread(), a WxHxB matrix is given out, where W is the number of pixels across the width of the image, H is the number of pixels across the height of the image, and B is the number of channels in the image. For a truecolor image, B has a value of 3. Each element of the matrix has a value corresponding to the color of the pixel. In comparision, gray_imread() gives only a WxH matrix since the image is converted into grayscale before obtaining the pixel value which would then be displayed in each element. The function im2bw(a, b) converts the image a to black and white with b as the threshold value (from 0 to 1).

The function imshow() simply displays the image enclosed in the parenthesis while imwrite(a, b) saves the created image a on to the destination specified by b.


For this activity, I would grade myself a 10/10 plus an additional 2 points. I believe that I have thoroughly discussed my results and presented them well.

References
[1] http://www.wall321.com/Anime/Bleach/bleach_bankai_ichigo_1600x1200_wallpaper_8031
[2] http://24.media.tumblr.com/aea23c88cf928413a84c795c95dad56e/tumblr_mgipztYadH1rkk672o1_400.gif
[3] Saturn's Cassini Division. Retrieved from http://starchild.gsfc.nasa.gov/docs/StarChild/solar_system_level2/cassini_division.html on June 19, 2013.
[4] Chapman, N. and J. Chapman. (2009). Digital Multimedia. 3rd edition. John Wile & Sons Ltd., England.
[5]GIF: a technical history. Retrieved from http://enthusiasms.org/post/16976438906 on June 19, 2013.
[6 ] The PNG Image File Format. Retrieved from http://www.fileformat.info/format/png/corion.htm on June 19, 2013.


No comments :

Post a Comment