Dtm-Vic - Tutorials

Example C.4: EX_C04.Images

(Structural Compression of Images through SVD, CA and Discrete Fourier Transform)


Examples C.4 are mainly pedagogical examples which serve as an illustration for the compression effect of principal axes techniques (keeping a limited number of principal axes in Singular Value Decomposition and Correspondence Analysis) in the domain of image analysis (rather unexpected for most DtmVic users). Comparison is made with Discrete Fourier Transform (keeping a limited number of terms from the expansion) that takes into account the relative locations of the pixels.

It does not make use of data in internal DtmVic text format, since it deals with digitalized images. A simple rectangular array of integers suffices: there is no need for identifiers of rows or column.

In fact, three particular formats will be used: rectangular arrays of levels of gray (simple text format), plain “pgm” format ( acronym derived from "Portable Gray Map") and, for color images, plain “ppm” format (acronym derived from "Portable Pixel Map")

A specialized interface is provided via the button “DtmVic Images” of the main menu.



1. About the data (some image formats)

To have a look at the data,


1.1 Search for the directory “ DtmVic_Examples”.


1.2 Search for the sub-directory “DtmVic_Examples_C_NumData” in “ DtmVic_Examples”.


1.3 In that directory, open the directory of Example C.4: “EX_C04.Images” .


1.4 Four sub-directories correspond to four examples:

“1_Cheetah_txt”,
“2_Baalbeck_pgm”,
“3_Cardinal_ppm_color”,
“4_Extra_pgm_ppm”

All these file can be examined via a text editor (such as “notepad” included in Windows, or a free software such that “notepad++”, or “TotalEdit”, or also within DtmVic, using the text editor enabled by the button "Open an existing command file" of the main menu).


1.5 For greyscale (US: grayscale) images, two input format are available:


1.5.1 Simple text format :

The data table contains positive integer s <= 255 that are the values of the level of grey for each pixel (no identifiers). This is the case of the image “cheetah.txt” in the folder “1_Cheetah_txt” (adapted from "The Data Compression Book", Mark Nelson, M&T Publishing Inc., 1992). Such a format that does not contain explicitly the size of the image is the simplest one. Because of its rusticity, this format is neither used nor provided by the usual image processing software.


1.5.2 The "pgm" format :

(Portable Grayscale Map) (look at the example: "2_Baalbeck.pgm", using a text editor or a notepad)

The PGM format is a simple and transparent greyscale file format.

The difference in the plain format is:

There is one image in a file (general pgm format can cope with several images).
The first line contains the format identifier: P2.
The second and the third lines contain three integers: number of columns, number of rows, and the maximum value (255).
Then the table is displayed row-wise.
Each pixel in the table is represented as an ASCII decimal number (<255).
Each pixel in the table has at least one white space before and after it.
No line should exceed 72 characters.

For more information about such a format, please consult (e.g.): http://netpbm.sourceforge.net/doc/pgm.html


1.5.3 The "ppm" format for colour images:

For (small)colour images, the input format is the ppm text format (acronym for: portable pixel map). Look at the example "3_Cardinal.ppm" , via a text editor or a notepad.

The three integers (levels of: Red, Green, Blue) describing each pixels are located consecutively in the same row.



Both pgm and ppm files can be obtained through an exportation from the free software "Open office", using a jpeg file as an input.



2. Running a first example (simple greyscale format)


In the Main Menu, Click on the button ""SVD and CA of images" (in the section: "DtmVic-Images").
The first thing to do is to select an image. One of the three buttons, on the left hand side of the window, have to be selected to open the image, according to its format.

2.1 Click on the first button "Read (formatted txt file)" in the section "Open greyscale image".

2.2 In the directory "EX_CO4_Image", open the sub-directory "1_Cheetah_txt". Within "1_Cheetah_txt", open the file "Cheetah.txt".
A message-box recalls the size of the image file. If you wish to visualize the original image, in the section "Visualization", click on: "Image (greyscale)".

2.3 Then, in the lower left part of the window, in the section "Compression techniques", click the button: "Correspondence Analysis" (to begin with).

2.4 If you wish to obtain an overview of the data reconstitution, from 1 to 100 axes, Click directly on the button: "Series from first term to total", in the right hand side panel. You can then observe the progressive reconstitution of the original data table (i.e.: the image).

2.5 If you are interested in focusing on a specific number of axes, then select the required number of axes in the vertical corresponding list, and visualize each image. Note that all the created images are saved in bitmap format (extension: ".bmp") in the directory of the analysed image file.

2.6 Instead of Correspondence Analysis, you can choose "Singular Value Decomposition", and redo all the operations 2.4 and 2.5.

2.7 If you select the lower button: "Discrete Fourier Transform", a new window is displayed.

2.8 You have then to select the mode of computation of the Fourier series ("Row-wise" or "Column-wise"). Select "Row-wise", for example.

2.9 Then, as previously, you can go directly to the right-hand side panel, and press the button: "Series from the first term to total (greyscale)" . The comparison of the obtained reconstitution (according to the number of kept terms in the Fourier decomposition) with the preceding reconstitution (using CA or SVD) is quite interesting.

2.10 If you are interested in focusing on a specific number of terms, then select the required number of terms in the vertical corresponding list, and visualize each image.


Note 1: Incidently, the graphical display of levels of grey for each row can be obtained from the button "Curves of grey levels" (press it several times to scan the whole image).

Note 2: All created images are saved in bitmap format (extension: ".bmp") in the directory of the analysed image file.

Note 3: The compression through SVD or CA does not depends on the order of rows and columns of the table (unlike the Fourier compression). Nevertheless, the "structural compression" (i.e. ignoring the relative locations of the pixels) gives worthwhile results.



3. Running other examples:


3.1 Baalbeck Temple example.
Click on the second button "Read (pgm format)", always in the section "Open greyscale image".
In the directory "EX_CO4_Image", open the sub-directory "2_Baalbeck_pgm". Within "2_Baalbeck_pgm", open the file "Baalbeck.pgm". A message-box recalls the size of the image file.
If you wish to visualize the original image, in the section " Visualization", click on: "Image (greyscale)". Then redo all the operations 2.3 to 2.10.
This example is interesting since it emphasize the fact a strong pattern (here: the columns of the temple) can contaminate the reconstitution (not in the case of Fourier reconstitution row-wise, as expected...).

3.2 Cardinal (of Mauritius) example.
Click on the third button "Read (ppm format)", in the section "Open colour image".
In the directory "EX_CO4_Image", open the sub-directory "3_cardinal_ppm_colour".
Within "3_cardinal_ppm_colour", open the file "cardinal.ppm".
A message-box recalls the size of the image file. If you wish to visualize the original image, in the section "Visualization", click on: "Image (colour)".
Then redo all the operations 2.3 to 2.10.

3.3 Extra_pgm_ppm example.
The folder "4_Extra_pgm_ppm" contains two versions (colour and grey) of an image of a young boy using a broom.
Proceed as in section 3.1 for the pgm image, and as shown in section 3.2 for the ppm image.




Note: Remind that in the ppm format, the three basic colours (RGB = Red, Green, Blue) corresponding to each pixel have consecutive locations in the same row (the length of which is consequently three times the number of pixels).

The compression through SVD or CA does not depends on the order of the columns, that means that we don't use the fact that the three colours are relative to a same pixel! Nevertheless, the "structural compression" works.

In this case, the Fourier series row-wise is not adapted (unless we choose to juxtapose column-wise the three tables Red, Green, Blue, and, in so doing, abandon the ppm format). The reader can compare the results from the two Fourier compressions row-wise and column-wise.



End of example C.4 (Images)