[MINC-users] converting one format to minc

Gibby Koldenhof G.Koldenhof@azu.nl
Fri Apr 9 19:29:03 2004


Hi Guys,

I'm writing up some code to convert a number of file formats to minc (I'm using minc 1.2). For some reason I get strange
results. When trying to convert 16bit signed raw data I get strange results. I first convert the raw data using
minctoraw:

rawtominc -short -input raw.raw -scan_range -xstep 1.0 -ystep 1.0 -zstep 1.0 a.mnc 100 100 100

Which outputs "a.mnc"

I then load up raw.raw from my raw load routine and save it to minc (b.mnc):

(note that all parameters are correctly set, and this is just the important calls with everything else stripped away)

/* ---------- write volume */

volume = create_volume(3, dimensions, type, signed_flag, volset_get_min(volset), volset_get_max(volset));

set_volume_sizes(volume, sizes);

  for(z = 0 ; z < volset_get_zsize(volset) ; z++)
   {
    for(y = 0 ; y < volset_get_ysize(volset) ; y++)
     {
      for(x = 0 ; x < volset_get_xsize(volset) ; x++)
       {
         double v = volset_get_voxel(volset, x, y, z);

         set_volume_voxel_value(volume, x, y, z, 0, 0, v);
       }
     }
   }

output_volume((char *)filename, type, signed_flag, volset_get_min(volset), volset_get_max(volset), volume, history,
NULL);

/* end of write volume */

Then I load up a.mnc and b.mnc and do a compare. The loading is performed with:

/* load volume */

input_volume(filename, 3, dimensions, NC_SHORT, TRUE, SHRT_MIN, SHRT_MAX, TRUE, &volume, NULL)

short * voxels = ... ;

... etc

for all voxels

        GET_VALUE_3D(value, volume, x, y, z);

       *voxels++  = value;

/* end of load volume */

mincinfo says both the files are the same, yet mincdiff tells me that the data is different. And indeed when I
internally compare all the voxels about 1/6th of the voxels have a difference of 1 (integer, e.g. a voxel from a.mnc is
203 and from b.mnc is 204 for example)  -  strangly enough when loading both files into register they look exactly the
same (also selecting voxels at different locations and checking the value) ...?

.... how ... why ... I can't understand what is going wrong. I do not do any floating point conversion anywhere (since
it looks like a roundoff error) ... I tried pretty much everything (e.g. changing the parameters to each call)

Anybody got a clue what's going wrong?

Cheers,
Gibby

---- dump from the output of my converter:

converting 'gibby.vpx' to 'b.mnc' and comparing the output with existing file 'a.mnc'
progress: prima (University Medical Center Utrecht (UMCU) vpx prima format)
prima took h00:m00:s00 (0.22 seconds)
swapping dataset 'gibby.vpx' on 'xz' axis
progress: swap (swap dataset on xz axis)
swap took h00:m00:s02 (2.57 seconds)
mirroring dataset 'gibby.vpx' on 'z' axis
progress: mirror (mirror dataset on z axis)
mirror took h00:m00:s02 (2.70 seconds)
saving dataset to 'b.mnc'
dumping 'b.mnc'
dump of outfile: xsize:   85
dump of outfile: ysize:   89
dump of outfile: zsize:   83
dump of outfile: min:     0
dump of outfile: max:     1212
dump of outfile: dtype:   3
dump of outfile: dsize:   2
dump of outfile: tsize:   627895
dump of outfile: sum:     162.870193
minc: file 'b.mnc'
minc: sizes: 85x89x83
minc: nc type = NC_SHORT (signed)
minc: dimensions 3
minc: dimension(0): yspace
minc: dimension(1): zspace
minc: dimension(2): xspace
minc: voxel min: -32768.000000
minc: voxel max: 32767.000000
minc: real min: 0.000000
minc: real max: 1212.000000
minc: x_world: 1.000000
minc: y_world: 1.000000
minc: z_world: 1.000000
minc: file 'a.mnc'
minc: sizes: 85x89x83
minc: nc type = NC_SHORT (signed)
minc: dimensions 3
minc: dimension(0): yspace
minc: dimension(1): zspace
minc: dimension(2): xspace
minc: voxel min: -32768.000000
minc: voxel max: 32767.000000
minc: real min: 0.000000
minc: real max: 1212.000000
minc: x_world: 1.000000
minc: y_world: 1.000000
minc: z_world: 1.000000
dumping 'b.mnc'
dump of compare file 1 (b.mnc): xsize:   85
dump of compare file 1 (b.mnc): ysize:   89
dump of compare file 1 (b.mnc): zsize:   83
dump of compare file 1 (b.mnc): min:     0
dump of compare file 1 (b.mnc): max:     1212
dump of compare file 1 (b.mnc): dtype:   3
dump of compare file 1 (b.mnc): dsize:   2
dump of compare file 1 (b.mnc): tsize:   627895
dump of compare file 1 (b.mnc): sum:     162.367286
dumping 'a.mnc'
dump of compare file 2 (a.mnc): xsize:   85
dump of compare file 2 (a.mnc): ysize:   89
dump of compare file 2 (a.mnc): zsize:   83
dump of compare file 2 (a.mnc): min:     0
dump of compare file 2 (a.mnc): max:     1212
dump of compare file 2 (a.mnc): dtype:   3
dump of compare file 2 (a.mnc): dsize:   2
dump of compare file 2 (a.mnc): tsize:   627895
dump of compare file 2 (a.mnc): sum:     162.369387
compare: field xsize of dataset 'b.mnc' (85) does compare to dataset 'a.mnc' (85)
compare: field ysize of dataset 'b.mnc' (89) does compare to dataset 'a.mnc' (89)
compare: field zsize of dataset 'b.mnc' (83) does compare to dataset 'a.mnc' (83)
compare: field tsize of dataset 'b.mnc' (627895) does compare to dataset 'a.mnc' (627895)
compare: field dsize of dataset 'b.mnc' (2) does compare to dataset 'a.mnc' (2)
compare: field dtype of dataset 'b.mnc' (3) does compare to dataset 'a.mnc' (3)
compare: field min of dataset 'b.mnc' (0) does compare to dataset 'a.mnc' (0)
compare: field max of dataset 'b.mnc' (1212) does compare to dataset 'a.mnc' (1212)
compare: number of voxels (resolution) of dataset 'b.mnc' (1255790) do compare to dataset 'a.mnc' (1255790)
compare: 112807 of 627895 voxels DO NOT compare between dataset 'b.mnc' and dataset 'a.mnc', largest difference was 1
compare result: *WARNING*: output dataset DOES NOT compare to 'a.mnc'
computed difference volume for 'a.mnc' and wrote file 'diff.hdr'
dumping 'copy of b.mnc'
difference file: xsize:   85
difference file: ysize:   89
difference file: zsize:   83
difference file: min:     0
difference file: max:     1
difference file: dtype:   3
difference file: dsize:   2
difference file: tsize:   627895
difference file: sum:     0.179659

--- dump of mincheader of a.mnc

netcdf a {
dimensions:
 yspace = 85 ;
 zspace = 89 ;
 xspace = 83 ;
variables:
 int rootvariable ;
  rootvariable:varid = "MINC standard variable" ;
  rootvariable:vartype = "group________" ;
  rootvariable:version = "MINC Version    1.0" ;
  rootvariable:parent = "" ;
  rootvariable:children = "image\n",
    "study" ;
 int study ;
  study:parent = "rootvariable" ;
  study:varid = "MINC standard variable" ;
  study:vartype = "group________" ;
  study:version = "MINC Version    1.0" ;
  study:modality = "MRI__" ;
 double yspace ;
  yspace:varid = "MINC standard variable" ;
  yspace:vartype = "dimension____" ;
  yspace:version = "MINC Version    1.0" ;
  yspace:comments = "Y increases from patient posterior to anterior" ;
  yspace:spacing = "regular__" ;
  yspace:alignment = "centre" ;
  yspace:step = 1. ;
  yspace:start = 0. ;
 double zspace ;
  zspace:varid = "MINC standard variable" ;
  zspace:vartype = "dimension____" ;
  zspace:version = "MINC Version    1.0" ;
  zspace:comments = "Z increases from patient inferior to superior" ;
  zspace:spacing = "regular__" ;
  zspace:alignment = "centre" ;
  zspace:step = 1. ;
  zspace:start = 0. ;
 double xspace ;
  xspace:varid = "MINC standard variable" ;
  xspace:vartype = "dimension____" ;
  xspace:version = "MINC Version    1.0" ;
  xspace:comments = "X increases from patient left to right" ;
  xspace:spacing = "regular__" ;
  xspace:alignment = "centre" ;
  xspace:step = 1. ;
  xspace:start = 0. ;
 short image(yspace, zspace, xspace) ;
  image:parent = "rootvariable" ;
  image:varid = "MINC standard variable" ;
  image:vartype = "group________" ;
  image:version = "MINC Version    1.0" ;
  image:complete = "true_" ;
  image:signtype = "signed__" ;
  image:image-max = "--->image-max" ;
  image:image-min = "--->image-min" ;
  image:valid_range = -32768., 32767. ;
 double image-min(yspace) ;
  image-min:varid = "MINC standard variable" ;
  image-min:vartype = "var_attribute" ;
  image-min:version = "MINC Version    1.0" ;
  image-min:_FillValue = 0. ;
  image-min:parent = "image" ;
 double image-max(yspace) ;
  image-max:varid = "MINC standard variable" ;
  image-max:vartype = "var_attribute" ;
  image-max:version = "MINC Version    1.0" ;
  image-max:_FillValue = 1. ;
  image-max:parent = "image" ;

// global attributes:
  :history = "Tue Apr  6 11:52:52 2004>>> rawtominc -short -coronal -clobber -input ./voor_gibby.raw -scan_range -mri
./voor_gibby.mnc.tmp 85 89 83\n",
    "Tue Apr  6 11:52:54 2004>>> mincreshape -clobber -coronal ./voor_gibby.mnc.tmp ./voor_gibby.mnc\n",
    "" ;
data:

 rootvariable = _ ;

 study = _ ;

 yspace = 0 ;

 zspace = 0 ;

 xspace = 0 ;

 image-min = _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
    _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
    _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
    _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ ;

 image-max = 24, 38, 66, 240, 467, 763, 909, 1075, 1145, 1139, 1212, 1172,
    1127, 1136, 1145, 1159, 1117, 1089, 1085, 1075, 1045, 1029, 993, 1026,
    1033, 1061, 1097, 1152, 1145, 1155, 1153, 1095, 1058, 1041, 1019, 1008,
    1040, 999, 993, 956, 980, 984, 1016, 982, 959, 915, 924, 923, 959, 972,
    928, 910, 914, 880, 907, 868, 875, 915, 918, 926, 899, 933, 868, 907,
    903, 941, 949, 894, 929, 927, 951, 935, 975, 990, 1006, 941, 948, 963,
    1001, 1028, 1103, 1026, 1033, 1078, 1064 ;
}

--- dump of mincheader of b.mnc

netcdf b {
dimensions:
 yspace = 85 ;
 zspace = 89 ;
 xspace = 83 ;
variables:
 int rootvariable ;
  rootvariable:varid = "MINC standard variable" ;
  rootvariable:vartype = "group________" ;
  rootvariable:version = "MINC Version    1.0" ;
  rootvariable:parent = "" ;
  rootvariable:children = "image" ;
 double yspace ;
  yspace:varid = "MINC standard variable" ;
  yspace:vartype = "dimension____" ;
  yspace:version = "MINC Version    1.0" ;
  yspace:comments = "Y increases from patient posterior to anterior" ;
  yspace:spacing = "regular__" ;
  yspace:alignment = "centre" ;
  yspace:step = 1. ;
  yspace:start = 0. ;
  yspace:units = "mm" ;
 double zspace ;
  zspace:varid = "MINC standard variable" ;
  zspace:vartype = "dimension____" ;
  zspace:version = "MINC Version    1.0" ;
  zspace:comments = "Z increases from patient inferior to superior" ;
  zspace:spacing = "regular__" ;
  zspace:alignment = "centre" ;
  zspace:step = 1. ;
  zspace:start = 0. ;
  zspace:units = "mm" ;
 double xspace ;
  xspace:varid = "MINC standard variable" ;
  xspace:vartype = "dimension____" ;
  xspace:version = "MINC Version    1.0" ;
  xspace:comments = "X increases from patient left to right" ;
  xspace:spacing = "regular__" ;
  xspace:alignment = "centre" ;
  xspace:step = 1. ;
  xspace:start = 0. ;
  xspace:units = "mm" ;
 double image-min ;
  image-min:varid = "MINC standard variable" ;
  image-min:vartype = "var_attribute" ;
  image-min:version = "MINC Version    1.0" ;
  image-min:_FillValue = 0. ;
  image-min:parent = "image" ;
 double image-max ;
  image-max:varid = "MINC standard variable" ;
  image-max:vartype = "var_attribute" ;
  image-max:version = "MINC Version    1.0" ;
  image-max:_FillValue = 1. ;
  image-max:parent = "image" ;
 short image(yspace, zspace, xspace) ;
  image:parent = "rootvariable" ;
  image:varid = "MINC standard variable" ;
  image:vartype = "group________" ;
  image:version = "MINC Version    1.0" ;
  image:image-max = "--->image-max" ;
  image:image-min = "--->image-min" ;
  image:complete = "true_" ;
  image:signtype = "signed__" ;
  image:valid_range = 0., 1212. ;

// global attributes:
  :history = "volume created on Sat 10 Apr 2004 01:16:10 by user \'gibby\' (uid=-1) on host \'QUARK\' (win32) by
application VoxCon version 1.0.8-Granite[21/03/04]\n",
    "set name to \'copy of unknown\' on Sat 10 Apr 2004 01:16:10 by user \'gibby\' (uid=-1) on host \'QUARK\' (win32) by
application VoxCon version 1.0.8-Granite[21/03/04]\n",
    "set data on Sat 10 Apr 2004 01:16:10 by user \'gibby\' (uid=-1) on host \'QUARK\' (win32) by application VoxCon
version 1.0.8-Granite[21/03/04]\n",
    "copied history[0] from parent(unknown) by procedure \'duplicate\': \'volume created on Sat 10 Apr 2004 01:16:08 by
user \'gibby\' (uid=-1) on host \'QUARK\' (win32) by application VoxCon version 1.0.8-Granite[21/03/04]\'\n",
    "copied history[1] from parent(unknown) by procedure \'duplicate\': \'swap on \'xz\' axis on Sat 10 Apr 2004
01:16:08 by user \'gibby\' (uid=-1) on host \'QUARK\' (win32) by application VoxCon version
1.0.8-Granite[21/03/04]\'\n",
    "duplicated from \'unknown\' on Sat 10 Apr 2004 01:16:10 by user \'gibby\' (uid=-1) on host \'QUARK\' (win32) by
application VoxCon version 1.0.8-Granite[21/03/04]\n",
    "mirror on \'z\' axis on Sat 10 Apr 2004 01:16:10 by user \'gibby\' (uid=-1) on host \'QUARK\' (win32) by
application VoxCon version 1.0.8-Granite[21/03/04]\n",
    "generated by VoxCon, version 1.0.8-Granite[21/03/04], command line was: k:\\raychase\\voxcon.exe -i
voor_gibby.vpx -o b.mnc -s xz -m z -d -p -f -c a.mnc -C diff.hdr \n",
    "set name to \'b.mnc\' on Sat 10 Apr 2004 01:16:13 by user \'gibby\' (uid=-1) on host \'QUARK\' (win32) by
application VoxCon version 1.0.8-Granite[21/03/04]" ;
data:

 rootvariable = _ ;

 yspace = 0 ;

 zspace = 0 ;

 xspace = 0 ;

 image-min = _ ;

 image-max = 1212 ;
}


-----