ByteConversion - MRC CBU Imaging Wiki

You are not allowed to do login on this page. Login and try again.

Clear message
location: ByteConversion

Byte conversion utilites

This page describes our byte conversion utilities for analyze format images. Analyze format images consist of a header and an image file (.hdr and .img files respectively). The content of these files will depend on the byte ordering of your system. For example, analyze format images containing the same images will be different on a Sun system than they will on an Intel linux system. Some programs can recognize which byte ordering the header and image have, and load the image accordingly - for example SPM 99 does this. However, other programs do not do this, and therefore are confused by image or header information with the wrong byte order. In these cases it is useful to create new copies of your images that are in the correct byte order for the system that you are on. That is the purpose of the utilities here.There is also a program to convert 4D to 3D Analyze format images, ana4dto3d; this can be used to byte convert images - see the link above for details.

Installing the byte conversion utilities

The utilities have already been installed at the CBU. For non-CBU users, here is an archive containing the byte swapping routines.To install the files in the archive (to repeat - not necessary for CBU users):

  1. Unpack the archive into some directory. To do this, follow the instructions on the archive extraction page.

  2. If you are running the utilities on a system other than a Sun, or a PC, you will need to recompile the c files, headshow.c and headconv.c. A command line like "gcc -o headshow headshow.c" will work.
  3. Copy the byte_conv_imgs script and the headconv and headshow programs to some directory on your executable path. If necessary, type "rehash" at the unix prompt to force Unix to refresh the list of known executables on your path.

Using the utilities

To use the headshow utility, type:

headshow headername.hdr

at the system prompt. You will get output a bit like:

Data for header headername.hdr 

Datatype: 4
Vox units:mm
PixDim X: 2.000000
PixDim Y: 2.000000
PixDim Z: 2.000000
Dim X:    91
Dim Y:    109
Dim Z:    91
Descrip:  a test file 
Origin X: 46
Origin Y: 64
Origin Z: 37
Scale:    0.000031

To use headconv, type

headconv headername.hdr

at the system prompt. This will byte swap the header, andoverwritethe header file. If you want the old header back, then run headconv on it, the process is reversible.To byte convert a set of images and headers, use the byte_conv_imgs script. The script is written c shell, and requires the "dd" utility, so it is only useable in Unix. Bear in mind that it is only set up to convert 8 and 16 bit format images. To run it type:

byte_conv_imgs inputfileprefix outputdirectory

where "inputfileprefix" is the root name for unconverted files. The program will add the postfix "*.img", to this input file prefix, to select all the image files beginning with the "inputfileprefix" you specify. "outputdirectory" is the directory to which the converted images and headers will be moved. If the directory does not exist then the script will create it. So for example:

byte_conv_imgs Data/3055/Ana/n03055dy Data/3055/Swapped

will convert all files matching the wildcard Data/3055/Ana/n03055dy*img, and put the converted files into the directory "Data/3055/Swapped".The script by default assumes that the headers of the image files are in the wrong byte order initially, i.e. that you are converting images from the wrong format for the machine running the script, to the correct format for the machine running the script. In this case, the script copies the header to the output directory, converts the header to the correct format, then reads this new header to decide what the image data type is, to do the image file conversion. However, if you are converting images, which are currently in the correct format, to the opposite byte order, for use on some other system, then the converted header will now have swapped information in it, which will give you some silly value for the datatype (eg 1024). In this case, you can use the 'i' option in calling the script,

byte_conv_imgs Data/3055/Ana/n03055dy Data/3055/Swapped i

This will convert all files matching the wildcard Data/3055/Ana/n03055dy*img, where the original Data/3055/Ana/n03055dy*hdr files have the correct byte order for this system.Matthew Brett 4/11/99