PVL (Processed VoLume) file format
As used by Drishti

Collated by Paul Bourke
June 2009, update April 2014


The description that follows is extracted with only minor editing from the Drishti online help. Some additional comments.

  • All binary data is Intel endian.

  • The third raw format is often convenient for "pure" raw data with no header.

  • While the interpretation of the axes is open, the data is notionally written with the first coordinate (eg: z) varying the slowest and the third coordinate (x) varying the fastest. For example:
       for (k=0;k<NZ;k++) { // z axis
          for (j=0;j<NY;j++) { // y axis
             for (i=0;i<NX;i++) { // x axis
                fwrite(,,,);
             }
          }
       }  
    

From the Drishti Manual

RAW Format

The datatype for volume data in the RAW file can be either unsigned byte, unsigned short (2 bytes), unsigned int (4 bytes) or float (4 bytes). There are three options for the format of RAW files :

  • [single byte][NZ][NY][NX][volume data]
    A single byte specifies the voxel type.
    0 : unsigned byte - 1 byte per voxel
    2 : unsigned short - 2 bytes per voxel
    4 : unsigned integer - 4 bytes per voxel
    8 : float - 4 bytes per voxel

    NX, NY and NZ are the grid dimensions written as 4-byte integers and volume data is the complete volumetric data with x as the fastest varying loop index. The file size for such a raw formatted file is 1+12+NX*NY*NZ*sizeof(datatype)

    For example for volume of size 128x128x128 with datatype as unsigned short (2-bytes per voxel) the file size would be 13+128*128*128*2 = 4194317 bytes.

  • [NZ][NY][NX][volume data]

    NX, NY and NZ are the grid dimensions written as 4-byte integers and volume data is the complete volumetric data with X as the fastest varying loop index. The user needs to specify voxel type in the dialog for reading raw files. The file size for such a raw formatted file is 12+NX*NY*NZ*sizeof(datatype)

    For example for volume of size 128x128x128 with datatype as unsigned short (2-bytes per voxel) the file size would be 12+128*128*128*2 = 4194316 bytes.

  • [header][volume data]

    A user defined header can be as big as the user wants. The header will be skipped while loading the volume data. The user will have to specify number of header bytes to skip.

    The volume data is the complete volumetric data with X as the fastest varying loop index. The user will have to specify grid size (NX,NY,NZ) and voxel type in the dialog for reading raw files. The file size for such a raw formatted file is NX*NY*NZ*sizeof(voxel type)

    For example for volume of size 128x128x128 with datatype as unsigned short (2-bytes per voxel) the file size would be 128*128*128*2 = 4194304 bytes.

PVL Format

PVL stands for Processed Volume. This file is generated from the RAW data by Drishti Import. The format for PVL is as follows :

The first 4 bytes are all zero.

Followed by 128 byte comment.

The next 12 bytes contain grid size as three 4-byte integers - [NZ][NY][NX].

Followed by voxel data with 2-bytes per voxel irrespective of the original volume data type. The first byte of the 2-byte voxel information is the voxel intensity and the second byte is the voxel gradient magnitude. The voxel gradient is numerically computed using Sobel transform. The voxel intensity and gradient information is scaled to fit in one byte.

The file size of a 128x128x128 volume is 4+128+12+128*128*128*2 = 4194448 bytes.

Update

Since the above was written the so called "pvl.nc" format seems to have changed. To create data files that can be read directly into Dristhi (tested on version 2.4) one creates two files, the first might be called "test.pvl.nc" and the second "test.pvl.nc.001". The first file is a small human readable text file with various parameters related to the volume, for example the dimensions. An example is given below

<!DOCTYPE Drishti_Header>
<PvlDotNcFileHeader>
  <rawfile></rawfile>
  <voxeltype>unsigned char</voxeltype>
  <pvlvoxeltype>unsigned char</pvlvoxeltype>
  <gridsize>200 100 256</gridsize>
  <voxelunit>micron</voxelunit>
  <voxelsize>1 1 1</voxelsize>
  <description>makepvlvol.c</description>
  <slabsize>201</slabsize>
  <rawmap>0 255 </rawmap>
  <pvlmap>0 255 </pvlmap>
</PvlDotNcFileHeader>

voxeltype refers to voxeltype of the original dataset from which the preprocessed volume was generated.

pvlvoxeltype refers to voxeltype of the preprocessed volume (unsigned char if not specified).

The second file contains the raw voxel values. Note the gridsize parameters are listed in order z, y, x. The slabsize should be the z depth + 1 if the volumetric data is stored in a single file. The volumetric data is of the same format as the first raw format above and written in z,y,x order, namely

[single byte][NZ][NY][NX][volume data]
A single byte specifies the voxel type.
0 : unsigned byte - 1 byte per voxel
2 : unsigned short - 2 bytes per voxel

For example

   fputc(0,fraw);
   fwrite(&nz,sizeof(int),1,fraw);
   fwrite(&ny,sizeof(int),1,fraw);
   fwrite(&nx,sizeof(int),1,fraw);
   for (k=0;k<nz;k++) {
      for (j=0;j<ny;j++) {
         for (i=0;i<nx;i++) {
            c = i % 256;
            fputc(c,fraw);
         }
      }
   }