Imaging Fundamentals

A digital image refers to a series of two- or three-dimensional spatially ordered digitized samples of some physical quantity. The physical quantity can be practically anything. In digital photography, for example, samples represent light intensity values acquired across the lens. In positron emission tomography (PET imaging), the spatially ordered samples represent the detected level of a radioactive chemical (reflected in the number of so-called annihilation events) that is taken up by the brain or some other organ. In remote sensing, the spatially organized data could represent heat or vegetation density, and so on. The basic key to understanding images is in realizing that the spatially ordered samples are really just a stream of numbers residing in a file or memory.

Consider a simple 4x4 grayscale image (see Figure 2.3). When the data is stored on disk, it typically isn't stored as a 4x4 matrix, but rather it is represented as a list of 16 numbers (4x4=16). The meaning of the order of the numbers must be known if the image is going to be displayed or interpreted in any meaningful way. The most obvious order might be something like every fifth number represents the first element of a new row, for example. The discussion could easily be extended to a 2x2x2 cube. Data for the image is stored in a vector of 16 elements with values increasing consecutively from 1:16. By convention, every fifth element is a shift to a new line.

Figure 2.3. Simple 4x4 image.


Let's next move on to a real example that will be expanded on in Chapter 4, “Immediate Mode Imaging Model.” One common type of brain image is a T2-weighted magnetic resonance image (see Figure 2.4). Each pixel value represents the T2 signal intensity at a particular spatial location in a slice of the brain. All the pixel values are stored sequentially in a file with some header information at the beginning. Because this is a grayscale image, there is a one-to-one correspondence between a number in the file and the value of the pixel. We know the dimension of this image to be 256x256 (because that what's we told the scanner we wanted). We also know that the values are stored in short integers so we can expect 256*256 or a total of 65,536 short (2 bytes) values to be stored in the file (after moving past the slightly annoying header information of 7,904 bytes). It is always useful to calculate the expected file size for these types of projects. The size of this file then is 138,976 bytes—7,904 + (2*65,536). The data is read in with ReadImage.java (see Listing 2.2), stored in a BufferedImage and rendered to the screen.

Figure 2.4. T2-weighted MRI of the brain.


Listing 2.2 demonstrates the reading of the image data into a one-dimensional array (vector) named voxel:

Listing 2.2 ReadImage.java
int nvox = 256*256;
try {
DataInputStream vox = new
DataInputStream(newFileInputStream("I.022"));

vox.skip(7904); // skip the annoyingheader
     try {
    for (int i=1;i <= nvox;i++) {
        v = vox.readShort();
      voxel[i] =  v;
    }
} catch (EOFException e) {
   System.out.println("End of file encountered");
}
 } catch (FileNotFoundException e) {
    System.out.println("DataIOTest: " + e);
 } catch (IOException e) {
    System.out.println("DataIOTest: " + e);
 }
}

Note

This external class is not intended to be run yet and is part of a more comprehensive example that is provided in Chapter 4.


The 256x256 image is stored in a one-dimensional array (that is, vector) with a length of 65,536. Have we lost our information about which pixels are stored where? The answer is no. Every 256th number in our stretched out vector belongs to a new row in our 256x256 2D matrix. You will see this later when the raw data is put in a special data structure known as a Raster and rendered to a BufferedImage. For now, know that the width and height of the image (in this case, 256x256) are specified by the parameters passed to the constructor of our BufferedImage. Thus, the pixels are interpreted correctly.

This emphasizes a point: All images are stored as a series of numbers. If the programmer knows the meaning of the order of numbers, it is possible to read in, display, and otherwise operate on the data representing the image.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset