]> Creatis software - clitk.git/blob - scripts/create_mhd_3D.sh
GateAsciiImageIO is now cross-platform using itksys::RegularExpression
[clitk.git] / scripts / create_mhd_3D.sh
1 #!/bin/sh
2
3
4 #################################################################################
5 # create_mhd_3D         argument : {image data} raw_image nom_fichier_de_sortie #
6 #################################################################################
7 if [ $# -lt 1 ] 
8 then
9     echo "Usage: create_mhd_3D.sh dimx dimy dimz spcx spcy spcz offx offy offz pixel_type raw_image_file output_file"
10     echo "dim*: dimensions of the image"
11     echo "spc*: pixel spacing along each dimension"
12     echo "off*: offset along each dimension"
13     echo "pixel_type: CHAR, UCHAR, SHORT, USHORT, FLOAT"
14     echo "raw_image_file: image to be referenced by the mhd file created"
15     echo "output_file: mhd to be created"
16     exit 1
17 fi
18
19 # can point to existing raw files
20 n=`ls ${11} | wc -l`
21 if [ $n -eq 0 ] 
22 then
23     echo "${11} does not exist. Cannot create mhd file."
24     exit 
25 fi
26
27 # check if the raw file has the "raw" extension
28 n=`ls ${11} | grep .raw | wc -l`
29 if [ $n -eq 0 ] 
30 then
31     # change extension to raw
32     raw_base=`echo ${11} | cut -d . -f 1`; 
33     raw_file=$raw_base".raw"; 
34     mv ${11} $raw_file
35 else
36     raw_file=${11}
37 fi
38
39 # create file (with some default values...)
40 echo "NDims = 3" > ${12}
41 echo "TransformMatrix = 1 0 0 0 1 0 0 0 1" >> ${12}
42 echo "Offset = " $7 $8 $9 >> ${12}
43 echo "CenterOfRotation = 0 0 0" >> ${12}
44 echo "AnatomicalOrientation = RAI" >> ${12}
45 echo "ElementSpacing = " $4 $5 $6 >> ${12}
46 echo "DimSize = " $1 $2 $3 >> ${12}
47 echo "ElementType = MET_"${10} >> ${12}
48 echo "ElementDataFile = " $raw_file >> ${12}
49
50