next up previous
Next: resize_volume() Up: Brain Volume I/O Handling Previous: convert_vector()

convert_volume()  

Convert a volume to different data type.



Synopsis


int
convert_volume( header *hdr, void **data, enum data_type newtype)


Description
Converts the data in the volume to a specific number-format using a type casting operation on each voxel value.

Range checking is performed. Values are truncated to highest representable/lowest representable when outside range. NOTE : Range checking is only performed when converting from

           anytype -> byte
	   sshort, float, long, double -> ushort
	   ushort, float, long, double -> sshort

See volio.h for available data_type's

Returns ERROR (=0) if memory allocation error occurs.

Usage

The function is typically used after read_volume() to ensure that the data is stored is the correct data format in memory.

This example program converts a file to float format.

#include "volio.h"

int 
main (int argc, char *argv[]) {
  header *hdr;
  char *data; // Could be any type!

  if (read_volume(argv[1], hdr, (void**) &data)) 
    exit(1);
  if (convert_volume(hdr, (void**) &data, T_FLOAT))
    exit(1);
  if (write_volume(argv[2], hdr, (void**) &data ))
    exit(1);

  free_header(hdr);
  free(data);
}

Revision


1.0  29/10-96   Ulrik Kjems


Program listing






Ulrik Kjems
6/3/1998