MEDx Frequently Asked Questions - Input/Output

Q: The AVW 4D header and limitations of the AVW file format

There are a few limitions with the AVW file format, two of them are stated below. The AVW file format does not have a seperate pixel format for 16 bit unsigned. An 16 bit unsigned image saved in AVW format will be saved as 16 bit signed. The AVW file format does not support full orientation information, you may find more information about these and other aspects at this web site AVW File Format.

/*
 *
 * (c) Copyright, 1986-1995
 * Biomedical Imaging Resource
 * Mayo Foundation
 *
 * database sub-definitions
 */

#define AVW_DSR_SIZE            348

struct header_key           /* header_key        */
{                                   /* off + size*/
    int sizeof_hdr;                 /* 0 + 4     */
    char data_type[10];             /* 4 + 10    */
    char db_name[18];               /* 14 + 18   */
    int extents;                    /* 32 + 4    */
    short int session_error;        /* 36 + 2    */
    char regular;                   /* 38 + 1    */
    char hkey_un0;                  /* 39 + 1    */
};                                  /* total=40  */

struct image_dimension      /* image_dimension   */
{                                   /* off + size*/
    short int dim[8];               /* 0 + 16    */
    char vox_units[4];              /* 16 + 4    */
    char cal_units[8];              /* 20 + 4    */
    short int unused1;              /* 24 + 2    */
    short int datatype;             /* 30 + 2    */
    short int bitpix;               /* 32 + 2    */
    short int dim_un0;              /* 34 + 2    */
    float pixdim[8];                /* 36 + 32   */
    /*
        pixdim[] specifies the voxel dimensions:
        pixdim[1] - voxel width
        pixdim[2] - voxel height
        pixdim[3] - interslice distance
        ...etc
    */
    float vox_offset;               /* 68 + 4    */
    float funused1;                 /* 72 + 4    */
    float funused2;                 /* 76 + 4    */
    float funused3;                 /* 80 + 4    */
    float cal_max;                  /* 84 + 4    */
    float cal_min;                  /* 88 + 4    */
    int compressed;                 /* 92 + 4    */
    int verified;                   /* 96 + 4    */
    int glmax, glmin;               /* 100 + 8   */
};

struct data_history        /* data_history       */
{                                   /* off + size*/
    char descrip[80];               /* 0 + 80    */
    char aux_file[24];              /* 80 + 24   */
    char orient;                    /* 104 + 1   */
    char originator[10];            /* 105 + 10  */
    char generated[10];             /* 115 + 10  */
    char scannum[10];               /* 125 + 10  */
    char patient_id[10];            /* 135 + 10  */
    char exp_date[10];              /* 145 + 10  */
    char exp_time[10];              /* 155 + 10  */
    char hist_un0[3];               /* 165 + 3   */
    int views;                      /* 168 + 4   */
    int vols_added;                 /* 172 + 4   */
    int start_field;                /* 176 + 4   */
    int field_skip;                 /* 180 + 4   */
    int omax,omin;                  /* 184 + 8   */
    int smax,smin;                  /* 192 + 8   */
};                                  /* total=200 */

struct dsr                  /* dsr               */
{                                   /* off + size*/
    struct header_key hk;           /* 0 + 40    */
    struct image_dimension dime;    /* 40 + 108  */
    struct data_history hist;       /* 148 + 200 */
};                                  /* total=348 */

/* Acceptable values for hdr.dime.datatype */

#define DT_UNKNOWN              0
#define DT_BINARY               1
#define DT_UNSIGNED_CHAR        2
#define DT_SIGNED_SHORT         4
#define DT_SIGNED_INT           8
#define DT_FLOAT                16
#define DT_COMPLEX              32
#define DT_DOUBLE               64

#if COMMENTS

The Header file:

The above is the Analyze C header structure and it 
contains a total of 348 bytes.

When using the above structure - be sure to first zero
out the structure using bzero or memset before filling
in the values. This is so that the header is not 
un-initialized. The numbers to the right above specify 
the offsets of the keys within each of the subheader 
(starting from that subheader).

When filling in values be sure to fill the following 
keys (at the least):

hk = header-key structure
id = image-dimension structure
dh = data-history structure


    /* header_key */
    hk->sizeof_hdr = 348;
    hk->db_name = name of the image
    hk->extents = 16384;
    hk->session_error = 0;
    hk->regular = 'r';
    hk->hkey_un0 = 0;

    /* image_dimension */
    id->dim[0] = 4;
    id->dim[1] = width;  /* width of volume  */
    id->dim[2] = height; /* height of volume */
    id->dim[3] = slices; /* slices of volume */
    id->dim[4] = 1;     /* If writing a group of 
                         * 3D volumes, then set 
                         *this as the number of 
                         *volumes in the group */
    id->dim[5] = 0;
    id->dim[6] = 0;
    id->dim[7] = 0;

    id->pixdim[0] = 4;
    id->pixdim[1] = X voxel size;
    id->pixdim[2] = Y voxel size;
    id->pixdim[3] = Z voxel size;
    id->pixdim[4] = 0;
    id->pixdim[5] = 0;
    id->pixdim[6] = 0;
    id->pixdim[7] = 0;

    /* For setting the Display Range in MEDx */
    id->glmin = Min value in the volume;
    id->glmax = Max value in the volume; 
    id->cal_min = Min value in the volume;
    id->cal_max = Max value in the volume; 

    id->funused1 = 1.0;
    id->vox_offset = 0.0;
    id->datatype = datatype; 
        /* One of DT_xxxxx values */
        /* This is usually DT_SIGNED_SHORT or 4 */

    id->bitpix = bitpix;     
        /* Depth of volume - 8, 16 bits, etc */

Some of the Optional things that can be set:
        dh->orient;          /* Orientation of image */

        Possible values are 
        0 : transverse unflipped
        1 : coronal unflipped
        2 : sagittal unflipped
        3 : transverse flipped
        4 : coronal flipped
        5 : sagittal flipped

Writing out the image files :

Each slice is written one after another. 
Since Analyze has a left handed coordinate system with its 
origin at the lower left hand corner, when writing a slice
write the last row, then the second last row, etc, all
the way to the first row.

When writing a group of volumes, write out each volume as
described above, one after another.

#endif /* COMMENTS */

Other FAQ Topics

If you have a question that you would like to see addressed in our list of Frequently Asked Questions, please contact customer support.

Back to FAQ Home