Wednesday, September 14, 2011

Exploring an image file: dump

Understanding the architecture of an image file requires the use of a small utility program (in Unix world, 'od' is one of them) allowing to read byte per byte the contents of such a file. For this purpose, I developed a tiny image dump [Link] ...

WORK IN PROGRESS

1- Installation


In ImageJ, go to Plugins > New > Macro for creating a new macro window. Then, copy the image dump I wrote as an IJ script [Link], and paste the source code (in raw format) in the macro window.
Now, you are ready to start...

2- 'ROI' mode

In this mode, you are looking at the values 'behind' the pixels colors (or gray levels). This mode requires a rectangular selection area and displays all the values contained in it. You can choose to display these values in a numeric, hexadecimal, or alphanumeric format. The other options in the dialog box are not used in this mode.

For example, create a 32x32 8-bit image with a black background and with the pen tool (Tool # 16), draw a white point. Then, choose the Rectangle Tool (Tool #1) and select a small area containing the white point. Run the image dump script and click on the 'OK' button. The table of Fig. 1 is calculated...

Fig.1: From the test image (left), the selected area is displayed in numeric, hexadecimal, and alphanumeric formats, respectively.
In this table, the white point corresponds to a pixel value  of 255 and the neighboring black pixels to the value 0. 

In this 'ROI' mode, the pixel values can be displayed according to three display modes.
- numeric: This is the default display mode which prints the pixel values as numbers (integers) and in case of a RGB color image as a triplet R,G,B.
- hexadecimal:The hexadecimal notation allows a more compact display.
- alphanumeric: The program tries to convert the pixel values as a character (belonging to the ASCII table) and in the other cases prints a backslash (\) before the value. This is only available for 8-bit images ... and is really interesting in 'dump' mode (see next section).

3- 'Dump' mode

WORK IN PROGRESS

This mode allows the exploration of the data (header information and pixels) stored in an image file.

3-1- Preparing the image


Download this test image [Link] and look at its size in bytes (in your favorite OS, right click (or equivalent) on the file icon and choose Properties, then read the exact size in bytes (Fig.1).
Fig. 1: Read the image size in the Properties menu. Here, the size is 201646 bytes.
From this value, we are able to get information about the architecture of the file. Indeed, this image is a RGB image of 297x226 pixels. Its size (in bytes) can be deduced and is equal to : 297 x 226 x 3 = (here, we assume that RGB is encoded as 1 byte per channel).
The difference between the two sizes is 201646 -  201366 = 280 bytes. These extra-data correspond to non-pixel values and are usually located at the beginning of the file

How does it work?
Import this image file as a raw image in File > Import > 


Data mining
You need a test image


No comments:

Post a Comment