| 1 |
/* This program creates an ANALYZETM database header */ |
| 2 |
/* http://www.mayo.edu/bir/analyze/AnalyzeFileInfo.html */ |
| 3 |
/* |
| 4 |
* (c) Copyright, 1986-1995 |
| 5 |
* Biomedical Imaging Resource |
| 6 |
* Mayo Foundation |
| 7 |
* |
| 8 |
* to compile: |
| 9 |
* |
| 10 |
* cc -o make_hdr make_hdr.c |
| 11 |
* |
| 12 |
*/ |
| 13 |
#include <stdio.h> |
| 14 |
#include <stdlib.h> |
| 15 |
#include "dbh.h" |
| 16 |
|
| 17 |
void usage(); |
| 18 |
|
| 19 |
main(int argc, char *argv[]){ |
| 20 |
int i; |
| 21 |
struct dsr hdr; |
| 22 |
FILE *fp; |
| 23 |
static char DataTypes[9][12] = {"UNKNOWN", "BINARY", |
| 24 |
"CHAR", "SHORT", "INT","FLOAT", "COMPLEX", |
| 25 |
"DOUBLE", "RGB"}; |
| 26 |
|
| 27 |
static int DataTypeSizes[9] = {0,1,8,16,32,32,64,64,24}; |
| 28 |
|
| 29 |
if(argc != 12){ |
| 30 |
usage(); |
| 31 |
exit(0); |
| 32 |
} |
| 33 |
|
| 34 |
memset(&hdr,0, sizeof(struct dsr)); |
| 35 |
|
| 36 |
hdr.dime.vox_offset = 0.0; |
| 37 |
hdr.dime.funused1 = 0.0; |
| 38 |
hdr.dime.funused2 = 0.0; |
| 39 |
hdr.dime.funused3 = 0.0; |
| 40 |
hdr.dime.cal_max = 0.0; |
| 41 |
hdr.dime.cal_min = 0.0; |
| 42 |
|
| 43 |
|
| 44 |
hdr.dime.datatype = -1; |
| 45 |
|
| 46 |
for(i=1;i<=8;i++) |
| 47 |
if(!strcmp(argv[9],DataTypes[i])) |
| 48 |
{ |
| 49 |
hdr.dime.datatype = (1<<(i-1)); |
| 50 |
hdr.dime.bitpix = DataTypeSizes[i]; |
| 51 |
break; |
| 52 |
} |
| 53 |
|
| 54 |
if(hdr.dime.datatype <= 0) |
| 55 |
{ |
| 56 |
printf("<%s> is an unacceptable datatype \n\n", argv[9]); |
| 57 |
usage(); |
| 58 |
exit(0); |
| 59 |
} |
| 60 |
|
| 61 |
if((fp=fopen(argv[1],"w"))==0) |
| 62 |
{ |
| 63 |
printf("unable to create: %s\n",argv[1]); |
| 64 |
exit(0); |
| 65 |
} |
| 66 |
|
| 67 |
hdr.dime.dim[0] = 4; /* all Analyze images are taken as 4 dimensional */ |
| 68 |
hdr.hk.regular = 'r'; |
| 69 |
hdr.hk.sizeof_hdr = sizeof(struct dsr); |
| 70 |
|
| 71 |
hdr.dime.dim[1] = atoi(argv[2]); /* slice width in pixels */ |
| 72 |
hdr.dime.dim[2] = atoi(argv[3]); /* slice height in pixels */ |
| 73 |
hdr.dime.dim[3] = atoi(argv[4]); /* volume depth in slices */ |
| 74 |
hdr.dime.dim[4] = atoi(argv[5]); /* number of volumes per file */ |
| 75 |
|
| 76 |
/* Set the voxel dimension fields: |
| 77 |
A value of 0.0 for these fields implies that the value is unknown. |
| 78 |
Change these values to what is appropriate for your data |
| 79 |
or pass additional command line arguments */ |
| 80 |
|
| 81 |
hdr.dime.pixdim[0] = 4; /* all Analyze images are taken as 4 dimensional */ |
| 82 |
hdr.dime.pixdim[1] = atof(argv[6]); /* voxel x dimension */ |
| 83 |
hdr.dime.pixdim[2] = atof(argv[7]); /* voxel y dimension */ |
| 84 |
hdr.dime.pixdim[3] = atof(argv[8]); /* pixel z dimension, slice thickness */ |
| 85 |
|
| 86 |
hdr.dime.glmax = atoi(argv[10]); /* maximum voxel value */ |
| 87 |
hdr.dime.glmin = atoi(argv[11]); /* minimum voxel value */ |
| 88 |
|
| 89 |
|
| 90 |
/* Assume zero offset in .img file, byte at which pixel |
| 91 |
data starts in the image file */ |
| 92 |
|
| 93 |
hdr.dime.vox_offset = 0.0; |
| 94 |
|
| 95 |
/* Planar Orientation; */ |
| 96 |
/* Movie flag FALSE: 0 = transverse, 1 = coronal, 2 = sagittal |
| 97 |
Movie flag TRUE: 3 = transverse, 4 = coronal, 5 = sagittal */ |
| 98 |
|
| 99 |
hdr.hist.orient = 0; |
| 100 |
|
| 101 |
/* up to 3 characters for the voxels units label; i.e. mm., um., cm. */ |
| 102 |
|
| 103 |
strcpy(hdr.dime.vox_units," "); |
| 104 |
|
| 105 |
/* up to 7 characters for the calibration units label; i.e. HU */ |
| 106 |
|
| 107 |
strcpy(hdr.dime.cal_units," "); |
| 108 |
|
| 109 |
/* Calibration maximum and minimum values; |
| 110 |
values of 0.0 for both fields imply that no |
| 111 |
calibration max and min values are used */ |
| 112 |
|
| 113 |
hdr.dime.cal_max = 0.0; |
| 114 |
hdr.dime.cal_min = 0.0; |
| 115 |
|
| 116 |
fwrite(&hdr,sizeof(struct dsr),1,fp); |
| 117 |
fclose(fp); |
| 118 |
} |
| 119 |
|
| 120 |
void usage(){ |
| 121 |
printf("usage: make_hdr name.hdr x y z t xs ys zs datatype max min \n\n"); |
| 122 |
printf(" name.hdr = the name of the header file\n"); |
| 123 |
printf(" x = width, y = height, z = depth, t = number of volumes\n"); |
| 124 |
printf(" xs = x step, ys = y step, zs = z step\n"); |
| 125 |
printf(" acceptable datatype values are: BINARY, CHAR, SHORT,\n"); |
| 126 |
printf(" INT, FLOAT, COMPLEX, DOUBLE, and RGB\n"); |
| 127 |
printf(" max = maximum voxel value, min = minimum voxel value\n"); |
| 128 |
} |