c_nifti 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +37 -0
  3. data/.rspec +2 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/COPYING +621 -0
  7. data/COPYING.lesser +166 -0
  8. data/Gemfile +4 -0
  9. data/README.md +117 -0
  10. data/Rakefile +6 -0
  11. data/c_nifti.gemspec +31 -0
  12. data/ext/nifticlib/extconf.rb +30 -0
  13. data/ext/nifticlib/include/nifti_image.h +2 -0
  14. data/ext/nifticlib/include/nifti_image_converters.h +3 -0
  15. data/ext/nifticlib/include/nifti_image_dimensions.h +1 -0
  16. data/ext/nifticlib/include/nifti_image_intents.h +1 -0
  17. data/ext/nifticlib/include/nifti_image_metadata.h +1 -0
  18. data/ext/nifticlib/include/nifti_image_quaternions.h +1 -0
  19. data/ext/nifticlib/include/nifti_image_spacings.h +1 -0
  20. data/ext/nifticlib/include/nifti_image_timings.h +1 -0
  21. data/ext/nifticlib/include/nifti_image_transforms.h +1 -0
  22. data/ext/nifticlib/nifti_image.c +169 -0
  23. data/ext/nifticlib/nifti_image_converters.c +65 -0
  24. data/ext/nifticlib/nifti_image_dimensions.c +113 -0
  25. data/ext/nifticlib/nifti_image_intents.c +45 -0
  26. data/ext/nifticlib/nifti_image_metadata.c +133 -0
  27. data/ext/nifticlib/nifti_image_quaternions.c +59 -0
  28. data/ext/nifticlib/nifti_image_spacings.c +87 -0
  29. data/ext/nifticlib/nifti_image_timings.c +66 -0
  30. data/ext/nifticlib/nifti_image_transforms.c +38 -0
  31. data/ext/nifticlib/nifticlib-2.0.0/CMakeLists.txt +140 -0
  32. data/ext/nifticlib/nifticlib-2.0.0/CTestConfig.cmake +13 -0
  33. data/ext/nifticlib/nifticlib-2.0.0/LICENSE +9 -0
  34. data/ext/nifticlib/nifticlib-2.0.0/Makefile +265 -0
  35. data/ext/nifticlib/nifticlib-2.0.0/Makefile.cross_mingw32 +94 -0
  36. data/ext/nifticlib/nifticlib-2.0.0/README +79 -0
  37. data/ext/nifticlib/nifticlib-2.0.0/Testing/CMakeLists.txt +7 -0
  38. data/ext/nifticlib/nifticlib-2.0.0/Testing/Data/ATestReferenceImageForReadingAndWriting.nii.gz +0 -0
  39. data/ext/nifticlib/nifticlib-2.0.0/Testing/Makefile +21 -0
  40. data/ext/nifticlib/nifticlib-2.0.0/Testing/README_regress +50 -0
  41. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/@show.diffs +33 -0
  42. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/@test +80 -0
  43. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/CMakeLists.txt +47 -0
  44. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/cmake_testscripts/bricks_test.sh +32 -0
  45. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/cmake_testscripts/comment_test.sh +65 -0
  46. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/cmake_testscripts/dci_test.sh +46 -0
  47. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/cmake_testscripts/dsets_test.sh +61 -0
  48. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/cmake_testscripts/dts_test.sh +75 -0
  49. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/cmake_testscripts/fetch_data_test.sh +45 -0
  50. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/cmake_testscripts/mod_header_test.sh +60 -0
  51. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/cmake_testscripts/newfiles_test.sh +36 -0
  52. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c01.versions +10 -0
  53. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c02.nt.help +5 -0
  54. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c03.hist +5 -0
  55. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c04.disp.anat0.info +7 -0
  56. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c05.mod.hdr +9 -0
  57. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c06.add.ext +22 -0
  58. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c07.cbl.4bricks +8 -0
  59. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c08.dts.19.36.11 +4 -0
  60. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c09.dts4.compare +9 -0
  61. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c10.dci.ts4 +15 -0
  62. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c10a.dci.run.210 +16 -0
  63. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c11.add.comment +8 -0
  64. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c12.check.comments +7 -0
  65. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c13.check.hdrs +5 -0
  66. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c14.make.dsets +21 -0
  67. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c15.new.files +21 -0
  68. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c16.rand.swap +35 -0
  69. data/ext/nifticlib/nifticlib-2.0.0/Testing/nifti_regress_test/commands/c17.file.case +34 -0
  70. data/ext/nifticlib/nifticlib-2.0.0/Testing/niftilib/CMakeLists.txt +15 -0
  71. data/ext/nifticlib/nifticlib-2.0.0/Testing/niftilib/nifti_test.c +690 -0
  72. data/ext/nifticlib/nifticlib-2.0.0/Testing/niftilib/nifti_test2.c +32 -0
  73. data/ext/nifticlib/nifticlib-2.0.0/Updates.txt +110 -0
  74. data/ext/nifticlib/nifticlib-2.0.0/bin/.gitkeep +0 -0
  75. data/ext/nifticlib/nifticlib-2.0.0/docs/Doxy_nifti.txt +123 -0
  76. data/ext/nifticlib/nifticlib-2.0.0/docs/Doxyfile.ORIG +746 -0
  77. data/ext/nifticlib/nifticlib-2.0.0/examples/CMakeLists.txt +15 -0
  78. data/ext/nifticlib/nifticlib-2.0.0/examples/Makefile +48 -0
  79. data/ext/nifticlib/nifticlib-2.0.0/examples/clib_01_read_write.c +94 -0
  80. data/ext/nifticlib/nifticlib-2.0.0/examples/fsl_api_driver.c +142 -0
  81. data/ext/nifticlib/nifticlib-2.0.0/fsliolib/CMakeLists.txt +32 -0
  82. data/ext/nifticlib/nifticlib-2.0.0/fsliolib/Makefile +29 -0
  83. data/ext/nifticlib/nifticlib-2.0.0/fsliolib/fslio.c +2426 -0
  84. data/ext/nifticlib/nifticlib-2.0.0/fsliolib/fslio.tcl +83 -0
  85. data/ext/nifticlib/nifticlib-2.0.0/fsliolib/imcp +65 -0
  86. data/ext/nifticlib/nifticlib-2.0.0/fsliolib/imglob +59 -0
  87. data/ext/nifticlib/nifticlib-2.0.0/fsliolib/imln +37 -0
  88. data/ext/nifticlib/nifticlib-2.0.0/fsliolib/immv +64 -0
  89. data/ext/nifticlib/nifticlib-2.0.0/fsliolib/imrm +29 -0
  90. data/ext/nifticlib/nifticlib-2.0.0/fsliolib/imtest +53 -0
  91. data/ext/nifticlib/nifticlib-2.0.0/fsliolib/remove_ext +33 -0
  92. data/ext/nifticlib/nifticlib-2.0.0/include/.gitkeep +0 -0
  93. data/ext/nifticlib/nifticlib-2.0.0/nifticdf/CMakeLists.txt +28 -0
  94. data/ext/nifticlib/nifticlib-2.0.0/nifticdf/Makefile +28 -0
  95. data/ext/nifticlib/nifticlib-2.0.0/nifticdf/nifticdf.c +11107 -0
  96. data/ext/nifticlib/nifticlib-2.0.0/niftilib/CMakeLists.txt +33 -0
  97. data/ext/nifticlib/nifticlib-2.0.0/niftilib/Makefile +31 -0
  98. data/ext/nifticlib/nifticlib-2.0.0/niftilib/nifti1_io.c +7509 -0
  99. data/ext/nifticlib/nifticlib-2.0.0/packaging/DevPackage.template +18 -0
  100. data/ext/nifticlib/nifticlib-2.0.0/packaging/nifticlib.spec +62 -0
  101. data/ext/nifticlib/nifticlib-2.0.0/real_easy/nifti1_read_write.c +361 -0
  102. data/ext/nifticlib/nifticlib-2.0.0/utils/CMakeLists.txt +73 -0
  103. data/ext/nifticlib/nifticlib-2.0.0/utils/Makefile +55 -0
  104. data/ext/nifticlib/nifticlib-2.0.0/utils/nifti1_test.c +95 -0
  105. data/ext/nifticlib/nifticlib-2.0.0/utils/nifti_stats.c +95 -0
  106. data/ext/nifticlib/nifticlib-2.0.0/utils/nifti_tool.c +4193 -0
  107. data/ext/nifticlib/nifticlib-2.0.0/utils/nifti_tool.h +163 -0
  108. data/ext/nifticlib/nifticlib-2.0.0/znzlib/CMakeLists.txt +31 -0
  109. data/ext/nifticlib/nifticlib-2.0.0/znzlib/Makefile +33 -0
  110. data/ext/nifticlib/nifticlib-2.0.0/znzlib/znzlib.c +322 -0
  111. data/ext/nifticlib/nifticlib.c +107 -0
  112. data/ext/nifticlib/patches/nifticlib_fpic.patch +13 -0
  113. data/features/read_modify_write.feature +11 -0
  114. data/features/step_definitions/nifti_image_steps.rb +16 -0
  115. data/features/support/env.rb +14 -0
  116. data/features/support/fixtures/sample.nii.gz +0 -0
  117. data/lib/c_nifti.rb +9 -0
  118. data/lib/c_nifti/data.rb +70 -0
  119. data/lib/c_nifti/header.rb +16 -0
  120. data/lib/c_nifti/header_element.rb +13 -0
  121. data/lib/c_nifti/header_element/datatype.rb +49 -0
  122. data/lib/c_nifti/header_element/datatype/base.rb +9 -0
  123. data/lib/c_nifti/header_element/datatype/binary.rb +11 -0
  124. data/lib/c_nifti/header_element/datatype/double.rb +11 -0
  125. data/lib/c_nifti/header_element/datatype/float.rb +11 -0
  126. data/lib/c_nifti/header_element/datatype/long_double.rb +11 -0
  127. data/lib/c_nifti/header_element/datatype/long_long.rb +11 -0
  128. data/lib/c_nifti/header_element/datatype/signed_char.rb +11 -0
  129. data/lib/c_nifti/header_element/datatype/signed_int.rb +11 -0
  130. data/lib/c_nifti/header_element/datatype/signed_short.rb +11 -0
  131. data/lib/c_nifti/header_element/datatype/unsigned_char.rb +11 -0
  132. data/lib/c_nifti/header_element/datatype/unsigned_int.rb +11 -0
  133. data/lib/c_nifti/header_element/datatype/unsigned_long_long.rb +11 -0
  134. data/lib/c_nifti/header_element/datatype/unsigned_short.rb +11 -0
  135. data/lib/c_nifti/header_element/dimensions.rb +53 -0
  136. data/lib/c_nifti/header_element/intents.rb +25 -0
  137. data/lib/c_nifti/header_element/metadata.rb +49 -0
  138. data/lib/c_nifti/header_element/miscellaneous.rb +25 -0
  139. data/lib/c_nifti/header_element/quaternions.rb +33 -0
  140. data/lib/c_nifti/header_element/spacings.rb +45 -0
  141. data/lib/c_nifti/header_element/timings.rb +37 -0
  142. data/lib/c_nifti/header_element/transforms.rb +21 -0
  143. data/lib/c_nifti/image.rb +31 -0
  144. data/lib/c_nifti/version.rb +3 -0
  145. data/lib/nifticlib.rb +1 -0
  146. data/spec/data_spec.rb +112 -0
  147. data/spec/factories/nifti_images.rb +9 -0
  148. data/spec/header_element/datatype/base_spec.rb +9 -0
  149. data/spec/header_element/datatype/binary_spec.rb +9 -0
  150. data/spec/header_element/datatype/double_spec.rb +9 -0
  151. data/spec/header_element/datatype/float_spec.rb +9 -0
  152. data/spec/header_element/datatype/long_double_spec.rb +9 -0
  153. data/spec/header_element/datatype/long_long_spec.rb +9 -0
  154. data/spec/header_element/datatype/signed_char_spec.rb +9 -0
  155. data/spec/header_element/datatype/signed_int_spec.rb +9 -0
  156. data/spec/header_element/datatype/signed_short_spec.rb +9 -0
  157. data/spec/header_element/datatype/unsigned_char_spec.rb +9 -0
  158. data/spec/header_element/datatype/unsigned_int_spec.rb +9 -0
  159. data/spec/header_element/datatype/unsigned_long_long.rb +9 -0
  160. data/spec/header_element/datatype/unsigned_short_spec.rb +9 -0
  161. data/spec/header_element/datatype_spec.rb +109 -0
  162. data/spec/header_element/dimensions_spec.rb +105 -0
  163. data/spec/header_element/intents_spec.rb +48 -0
  164. data/spec/header_element/metadata_spec.rb +96 -0
  165. data/spec/header_element/miscellaneous_spec.rb +48 -0
  166. data/spec/header_element/quaternions_spec.rb +64 -0
  167. data/spec/header_element/spacings_spec.rb +88 -0
  168. data/spec/header_element/timings_spec.rb +72 -0
  169. data/spec/header_element/transforms_spec.rb +64 -0
  170. data/spec/image_spec.rb +39 -0
  171. data/spec/spec_helper.rb +85 -0
  172. metadata +363 -0
@@ -0,0 +1,8 @@
1
+
2
+ # - copy some of the sub-bricks of the default stat file,
3
+ # storing the history (command), and writing to a new 'f4.nii'
4
+ # - compare these nifti_image structs
5
+
6
+
7
+ nifti_tool -keep_hist -cbl -infiles stat0.nii'[178..$,0,1]' -prefix f4
8
+ nifti_tool -diff_nim -infiles stat0.nii f4.nii
@@ -0,0 +1,4 @@
1
+
2
+ # display a time series from our stat brick
3
+
4
+ nifti_tool -quiet -disp_ts 19 36 11 -infiles stat0.nii | tee o.08.ts.19.36.11
@@ -0,0 +1,9 @@
1
+
2
+ # get some time series values in multiple ways, and compare
3
+
4
+ nifti_tool -quiet -disp_ts 19 36 11 -infiles stat0.nii \
5
+ | awk '{print $(NF-1), $NF, $1, $2}' | tee o.09.ts4.1.awk
6
+ nifti_tool -quiet -disp_ts 19 36 11 -infiles f4.nii | tee o.09.ts4.2.awk
7
+
8
+ diff o.09.ts4.1.awk o.09.ts4.2.awk
9
+ if( $status ) echo '** failure, ts4 files differ'
@@ -0,0 +1,15 @@
1
+
2
+ # get the time series for a slice, get the same sub-bricks,
3
+ # compare nifti_images, and display the time series again
4
+ #
5
+ # this should match the previous
6
+
7
+ nifti_tool -keep_hist -cci 19 36 -1 -1 0 0 0 -prefix f.19.36 -infiles stat0.nii
8
+ nifti_tool -keep_hist -cbl -prefix f.19.36.t4.nii \
9
+ -infiles f.19.36.nii'[178..$,0,1]'
10
+ nifti_tool -diff_nim -infiles f.19.36.nii f.19.36.t4.nii | tee o.10.diff_nim
11
+ nifti_tool -quiet -disp_ci 0 0 11 -1 0 0 0 -infiles f.19.36.t4.nii \
12
+ | tee o.10.dci.4
13
+
14
+ diff o.09.ts4.1.awk o.10.dci.4
15
+ if( $status ) echo '** failure, o.09 and o.10 ts files differ'
@@ -0,0 +1,16 @@
1
+
2
+ # get the time series for a slice, get the same sub-bricks,
3
+ # compare nifti_images, and display the time series again
4
+ #
5
+ # this should match the previous
6
+
7
+ nifti_tool -keep_hist -cci 3 3 3 -1 -1 -1 -1 -prefix r.333 -infiles run.210.nii
8
+ nifti_tool -keep_hist -cci 3 3 3 -1 1 1 1 -prefix r.333.111 -infiles run.210.nii
9
+ nifti_tool -disp_ci -1 -1 -1 -1 -1 -1 -1 -infiles r.333.111.nii -quiet \
10
+ | tee o.10a.dci.1
11
+ nifti_tool -disp_ci 0 0 0 -1 1 1 1 -infiles r.333.nii -quiet \
12
+ | tee o.10a.dci.2
13
+
14
+ diff o.10a.dci.?
15
+ if( $status ) echo '** failure, o.10a.dci timeseries files differ'
16
+
@@ -0,0 +1,8 @@
1
+
2
+ # add some comment and afni extensions, then display them
3
+
4
+ nifti_tool -keep_hist -prefix f4.comment -infiles f.19.36.t4.nii \
5
+ -add_comment '4 slice time series' \
6
+ -add_afni_ext 'and an AFNI extension' \
7
+ -add_comment 'how about a question AND a comment?'
8
+ nifti_tool -disp_ext -infiles f4.comment.nii
@@ -0,0 +1,7 @@
1
+
2
+ # duplicate a dataset, and strip the extras, then compare
3
+
4
+ nifti_tool -cbl -infiles f4.comment.nii -prefix f4.to.clear.nii
5
+ nifti_tool -overwrite -strip -infiles f4.to.clear.nii
6
+ nifti_tool -disp_ext -infiles f4.to.clear.nii
7
+ nifti_tool -diff_nim -infiles f4.comment.nii f4.to.clear.nii
@@ -0,0 +1,5 @@
1
+
2
+ # check the nifti_1_header and nifti_image structes of the .nii files
3
+
4
+ nifti_tool -check_hdr -infiles *.nii
5
+ nifti_tool -check_nim -infiles *.nii
@@ -0,0 +1,21 @@
1
+
2
+ # - create datasets out of nothing
3
+ #
4
+ # - modify some fields and compare against other datasets
5
+
6
+ # just test a basic make im, mostly to capture the debug output
7
+ nifti_tool -make_im -debug 3 -new_dim 4 64 64 21 180 0 0 0 -prefix new_epi.nii
8
+
9
+ # compare hdr and nim in a fresh image to the existing one
10
+ nifti_tool -diff_hdr -new_dim 4 64 64 21 180 0 0 0 \
11
+ -infiles MAKE_IM stat0.nii
12
+ nifti_tool -diff_nim -new_dim 4 64 64 21 180 0 0 0 \
13
+ -infiles MAKE_IM stat0.nii
14
+
15
+ # clean up the nim by adjusting pixdim (from empty MAKE_IM)
16
+ nifti_tool -mod_hdr -new_dim 4 64 64 21 180 0 0 0 \
17
+ -mod_field pixdim '0.0 4.0 4.0 6.0 3.0 1.0 1.0 1.0' \
18
+ -prefix epi_180_pixdim.nii -infiles MAKE_IM
19
+
20
+ # and compare again
21
+ nifti_tool -diff_nim -infiles stat0.nii epi_180_pixdim.nii
@@ -0,0 +1,21 @@
1
+
2
+ # test writing various output file types
3
+ nifti_tool -make_im -prefix new1.hdr
4
+ nifti_tool -make_im -prefix new2.hdr.gz
5
+ nifti_tool -make_im -prefix new3.img.gz
6
+ nifti_tool -make_im -prefix new4.nii.gz
7
+ nifti_tool -make_im -prefix new5.nia
8
+
9
+ # test reading them
10
+ nifti_tool -copy_im -prefix ncopy1.nii -infiles new1.hdr
11
+ nifti_tool -copy_im -prefix ncopy2.nii -infiles new2.hdr.gz
12
+ nifti_tool -copy_im -prefix ncopy3.nii -infiles new3.img.gz
13
+ nifti_tool -copy_im -prefix ncopy4.nii -infiles new4.nii.gz
14
+ nifti_tool -copy_im -prefix ncopy5.nii -infiles new5.nia
15
+
16
+ # verify that they are all the same
17
+ set count = 0
18
+ foreach index ( 2 3 4 5 )
19
+ diff ncopy1.nii ncopy$index.nii
20
+ if ( $status ) echo "-- failure on test index $index --"
21
+ end
@@ -0,0 +1,35 @@
1
+ #!/bin/tcsh
2
+
3
+ echo '------------- DISP nifti_1_header -------------'
4
+ nifti_tool -disp_hdr -debug 2 -infiles rand.hdr > out.rand.hdr
5
+ echo '------------- DISP nifti_analyze75 ------------'
6
+ nifti_tool -disp_ana -debug 2 -infiles rand.hdr > out.rand.ana
7
+
8
+ cp rand.hdr swap.ana.hdr
9
+ cp rand.hdr swap.nim.hdr
10
+ cp rand.hdr swap.old.hdr
11
+ cp rand_nifti.hdr swap.old_nifti.hdr
12
+ cp rand_nifti.hdr swap.new_nifti.hdr
13
+
14
+ echo '------------- SWAP nifti_1_header -------------'
15
+ nifti_tool -swap_as_nifti -infiles swap.nim.hdr -overwrite -debug 2
16
+ echo '------------- SWAP nifti_analyze75 ------------'
17
+ nifti_tool -swap_as_analyze -infiles swap.ana.hdr -overwrite -debug 2
18
+ echo '------------- SWAP old analyze ----------------'
19
+ nifti_tool -swap_as_old -infiles swap.old.hdr -overwrite -debug 2
20
+ echo '------------- SWAP old vs new nifti ------------------'
21
+ nifti_tool -swap_as_old -infiles swap.old_nifti.hdr -overwrite -debug 2
22
+ nifti_tool -swap_as_nifti -infiles swap.new_nifti.hdr -overwrite -debug 2
23
+
24
+ echo '------------- DISP nifti_1_header swapped -------------'
25
+ nifti_tool -disp_hdr -debug 2 -infiles swap.nim.hdr > out.rand.swap.hdr
26
+ echo '------------- DISP nifti_analyze75 swapped ------------'
27
+ nifti_tool -disp_ana -debug 2 -infiles swap.ana.hdr > out.rand.swap.ana
28
+
29
+ echo '------------- DIFF old/new analyze -----------'
30
+ nifti_tool -diff_hdr -debug 2 -infiles swap.old.hdr swap.ana.hdr \
31
+ > out.rand.swap.compare.analyze
32
+ echo '------------- DIFF old/new nifti -------------'
33
+ nifti_tool -diff_hdr -debug 2 -infiles swap.new_nifti.hdr swap.old_nifti.hdr \
34
+ > out.rand.swap.compare.nifti
35
+
@@ -0,0 +1,34 @@
1
+
2
+ # - test read/write of datasets with various name cases
3
+ # - .nii .hdr .img .NII .HDR .IMG
4
+ # - compressed
5
+ # - error conditions
6
+
7
+ # start with a basic dataset
8
+ nifti_tool -make_im -new_dim 3 3 4 5 1 0 0 0 -prefix small.nii
9
+
10
+ set prefix = t17
11
+
12
+ # read/write of 3 cap cases
13
+ nifti_tool -cbl -keep_hist -infiles small.nii -prefix $prefix.1.NII
14
+ nifti_tool -cbl -keep_hist -infiles $prefix.1.NII -prefix $prefix.2.HDR
15
+ nifti_tool -cbl -keep_hist -infiles $prefix.2.HDR -prefix $prefix.3.IMG
16
+
17
+ nifti_tool -diff_hdr -infiles $prefix.2.HDR small.nii
18
+ nifti_tool -diff_nim -infiles $prefix.2.HDR $prefix.3.IMG
19
+
20
+ # compression cases
21
+ nifti_tool -cbl -keep_hist -infiles $prefix.1.NII -prefix $prefix.4.NII.GZ
22
+ nifti_tool -cbl -keep_hist -infiles $prefix.4.NII.GZ -prefix $prefix.5.HDR.GZ
23
+ nifti_tool -cbl -keep_hist -infiles $prefix.5.HDR.GZ -prefix $prefix.6.IMG.GZ
24
+
25
+ nifti_tool -diff_hdr -infiles $prefix.6.HDR.GZ small.nii
26
+
27
+ # display last header
28
+ nifti_tool -disp_hdr -infiles $prefix.6.IMG.GZ
29
+
30
+ # error cases
31
+ echo should be errors:
32
+ nifti_tool -disp_hdr -infiles small.NII
33
+ nifti_tool -disp_hdr -infiles $prefix.4.NII.gz
34
+
@@ -0,0 +1,15 @@
1
+ #File Generated by Hans J. Johnson
2
+ #Please contact hans-johnson@uiowa.edu for making enhancments/corrections
3
+ PROJECT(NIFTILIB_TESTS)
4
+
5
+ INCLUDE_DIRECTORIES(${NIFTILIB_SOURCE_DIR} ${ZNZLIB_SOURCE_DIR} ${NIFTILIB_SOURCE_DIR}/../utils)
6
+
7
+ ADD_EXECUTABLE(first_test nifti_test.c)
8
+ TARGET_LINK_LIBRARIES(first_test niftiio )
9
+
10
+ ADD_EXECUTABLE(second_test nifti_test2.c)
11
+ TARGET_LINK_LIBRARIES(second_test niftiio )
12
+
13
+
14
+ ADD_TEST(first_test first_test )
15
+
@@ -0,0 +1,690 @@
1
+ /*
2
+ * test program for NIFTI lib.
3
+ */
4
+ #include <nifti1_io.h>
5
+ enum NIFTITEST_BOOL {
6
+ NIFTITEST_TRUE=1,
7
+ NIFTITEST_FALSE=0
8
+ };
9
+
10
+ void _PrintTest(const int line,const char * message,const int FailureOccured, const enum NIFTITEST_BOOL isFatal,int *ErrorAccum)
11
+ {
12
+ if(FailureOccured==NIFTITEST_TRUE) /* This line can be commented out for a more verbose output */
13
+ {
14
+ char const * const PREFIX= (FailureOccured)?"==========ERROR":"..........SUCCESS";
15
+ char const * const ISFATALPREFIX= (isFatal && FailureOccured)?" FATAL":"";
16
+ printf("%s%s (LINE %d): %s\n",PREFIX,ISFATALPREFIX,line,message);
17
+ fflush(stdout);
18
+ *ErrorAccum+=FailureOccured;
19
+ if(isFatal==NIFTITEST_TRUE && FailureOccured==NIFTITEST_TRUE)
20
+ {
21
+ printf("\n\nTOTAL ERRORS=%d\n",*ErrorAccum);
22
+ exit( *ErrorAccum);
23
+ }
24
+ }
25
+ return;
26
+ }
27
+ #define PrintTest(message,failure,isfailure,errorcount) \
28
+ _PrintTest(__LINE__,message,failure,isfailure,errorcount)
29
+
30
+ nifti_image * generate_reference_image( const char * write_image_filename , int * const Errors)
31
+ {
32
+ nifti_1_header reference_header;
33
+ memset(&reference_header,0,sizeof(reference_header));
34
+ reference_header.sizeof_hdr=sizeof(reference_header);
35
+ reference_header.regular='r';
36
+ reference_header.extents=16384;
37
+
38
+ reference_header.dim[0]=5;
39
+ reference_header.dim[1]=23;
40
+ reference_header.dim[2]=17;
41
+ reference_header.dim[3]=11;
42
+ reference_header.dim[4]=7;
43
+ reference_header.dim[5]=3;
44
+ reference_header.dim[6]=1; //This MUST be 1 anything else is invalid due to code that usees huristics to fix other possible problems;
45
+ reference_header.dim[7]=1; //This MUST be 1 anything else is invalid due to code that usees huristics to fix other possible problems;
46
+ reference_header.intent_p1=10101010.101F;
47
+ reference_header.intent_p2=987654321.0F;
48
+ reference_header.intent_p3=-1234.0F;
49
+ reference_header.intent_code=NIFTI_INTENT_ESTIMATE;
50
+ reference_header.datatype=DT_INT32;
51
+ reference_header.pixdim[0]=-1.0F; /* this is really qfac */
52
+ reference_header.pixdim[1]=0.25F;
53
+ reference_header.pixdim[2]=0.5F;
54
+ reference_header.pixdim[3]=1.0F;
55
+ reference_header.pixdim[4]=2.0F;
56
+ reference_header.pixdim[5]=4.0F;
57
+ reference_header.pixdim[6]=-2.0e10F;
58
+ reference_header.pixdim[7]=-2.0e10F;
59
+ reference_header.vox_offset=0;
60
+ reference_header.scl_slope=0.25;
61
+ reference_header.scl_inter=128;
62
+ reference_header.qform_code=NIFTI_XFORM_SCANNER_ANAT;
63
+ reference_header.quatern_b=-0.5F;
64
+ reference_header.quatern_c= 0.5F;
65
+ reference_header.quatern_d=-0.5F;
66
+ reference_header.qoffset_x=reference_header.dim[1]/2.0F;
67
+ reference_header.qoffset_y=reference_header.dim[2]/2.0F;
68
+ reference_header.qoffset_z=reference_header.dim[3]/2.0F;
69
+ reference_header.sform_code=NIFTI_XFORM_SCANNER_ANAT;
70
+ reference_header.srow_x[0]=0.5;
71
+ reference_header.srow_x[1]=0.0;
72
+ reference_header.srow_x[2]=0.0;
73
+ reference_header.srow_x[3]=0.0;
74
+ reference_header.srow_y[0]=0.0;
75
+ reference_header.srow_y[1]=1.0;
76
+ reference_header.srow_y[2]=0.0;
77
+ reference_header.srow_y[3]=0.0;
78
+ reference_header.srow_z[0]=0.0;
79
+ reference_header.srow_z[1]=0.0;
80
+ reference_header.srow_z[2]=2.0;
81
+ reference_header.srow_z[3]=0.0;
82
+ reference_header.magic[0]='n';
83
+ reference_header.magic[1]='+';
84
+ reference_header.magic[2]='1';
85
+ reference_header.magic[3]='\0';
86
+ /* String is purposfully too long */
87
+ strncpy(reference_header.intent_name,"PHANTOM_DATA to be used for regression testing the nifti reader/writer",16);
88
+ strncpy(reference_header.descrip,"This is a very long dialog here to use up more than 80 characters of space to test to see if the code is robust enough to deal appropriatly with very long and obnoxious lines.",80);
89
+
90
+ {
91
+ int nbyper;
92
+ int swapsize;
93
+ nifti_datatype_sizes(reference_header.datatype ,&nbyper,&swapsize);
94
+ reference_header.bitpix=nbyper*8;
95
+ }
96
+
97
+ nifti_image * reference_image=nifti_convert_nhdr2nim(reference_header,write_image_filename);
98
+ {
99
+ const unsigned int NumVoxels=reference_image->nx*reference_image->ny*reference_image->nz*reference_image->nt*reference_image->nu;
100
+ reference_image->data=(signed int *)calloc(NumVoxels,sizeof(signed int)) ; /*!< pointer to data: nbyper*nvox bytes */
101
+ PrintTest("Checking memory allocation",reference_image->data ==0 ,NIFTITEST_TRUE,Errors);
102
+ {
103
+ signed int i=0;
104
+ for(; i < (signed int)NumVoxels ; i++)
105
+ {
106
+ ((signed int *)(reference_image->data))[i]=i;
107
+ }
108
+ }
109
+ }
110
+ PrintTest("Setting filenames",nifti_set_filenames( reference_image,write_image_filename, 0, 0 ) != 0, NIFTITEST_TRUE,Errors);
111
+ PrintTest("Setting type from names",nifti_set_type_from_names( reference_image ) != 0, NIFTITEST_TRUE,Errors);
112
+ /* PrintTest("Checking type and names",nifti_type_and_names_match( reference_image , 1 ) != 1, NIFTITEST_TRUE,Errors); */
113
+ PrintTest("Check reference_image data is non null",(reference_image->data==0),NIFTITEST_TRUE,Errors);
114
+ return reference_image;
115
+ }
116
+
117
+
118
+ void compare_reference_image_values(nifti_image const * const reference_image, nifti_image const * const reloaded_image, int * const Errors)
119
+ {
120
+ PrintTest("Checking nifti_type",(reference_image->nifti_type!=reloaded_image->nifti_type),NIFTITEST_FALSE,Errors);
121
+ PrintTest("Checking fname",(strcmp(reference_image->fname,reloaded_image->fname)),NIFTITEST_FALSE,Errors);
122
+ PrintTest("Checking iname",(strcmp(reference_image->iname,reloaded_image->iname)),NIFTITEST_FALSE,Errors);
123
+ PrintTest("Checking ndim",(reference_image->ndim!=reloaded_image->ndim),NIFTITEST_FALSE,Errors);
124
+ PrintTest("Checking nx",(reference_image->nx!=reloaded_image->nx),NIFTITEST_FALSE,Errors);
125
+ PrintTest("Checking ny",(reference_image->ny!=reloaded_image->ny),NIFTITEST_FALSE,Errors);
126
+ PrintTest("Checking nz",(reference_image->nz!=reloaded_image->nz),NIFTITEST_FALSE,Errors);
127
+ PrintTest("Checking nt",(reference_image->nt!=reloaded_image->nt),NIFTITEST_FALSE,Errors);
128
+ PrintTest("Checking nu",(reference_image->nu!=reloaded_image->nu),NIFTITEST_FALSE,Errors);
129
+ PrintTest("Checking dx",(reference_image->dx!=reloaded_image->dx),NIFTITEST_FALSE,Errors);
130
+ PrintTest("Checking dy",(reference_image->dy!=reloaded_image->dy),NIFTITEST_FALSE,Errors);
131
+ PrintTest("Checking dz",(reference_image->dz!=reloaded_image->dz),NIFTITEST_FALSE,Errors);
132
+ PrintTest("Checking dt",(reference_image->dt!=reloaded_image->dt),NIFTITEST_FALSE,Errors);
133
+ PrintTest("Checking du",(reference_image->du!=reloaded_image->du),NIFTITEST_FALSE,Errors);
134
+ PrintTest("Checking datatype",(reference_image->datatype!=reloaded_image->datatype),NIFTITEST_FALSE,Errors);
135
+ {
136
+ const unsigned int NumVoxels=reference_image->nx*reference_image->ny*reference_image->nz*reference_image->nt*reference_image->nu;
137
+ PrintTest("Check loaded data is non null",(reloaded_image->data==0),NIFTITEST_TRUE,Errors);
138
+ PrintTest("Check reference_image data is non null",(reference_image->data==0),NIFTITEST_TRUE,Errors);
139
+ {
140
+ unsigned int CurrVoxel=0;
141
+ for(; CurrVoxel < NumVoxels ; CurrVoxel++)
142
+ {
143
+ /*printf("%d ",CurrVoxel); fflush(stdout);*/
144
+ if( ((int *)(reference_image->data))[CurrVoxel] != ((int *)(reloaded_image->data))[CurrVoxel])
145
+ {
146
+ PrintTest("Incorrect Pixel Value Found",0,NIFTITEST_FALSE,Errors);
147
+ }
148
+ }
149
+ }
150
+ }
151
+ PrintTest("Checking xyz_units",(reference_image->xyz_units!=reloaded_image->xyz_units),NIFTITEST_FALSE,Errors);
152
+ PrintTest("Checking time_units",(reference_image->time_units!=reloaded_image->time_units),NIFTITEST_FALSE,Errors);
153
+ PrintTest("Checking intent_code",(reference_image->intent_code!=reloaded_image->intent_code),NIFTITEST_FALSE,Errors);
154
+ PrintTest("Checking intent_name",(strncmp(reference_image->intent_name,reloaded_image->intent_name,16) )!=0,NIFTITEST_FALSE,Errors);
155
+ PrintTest("Checking description",(strncmp(reference_image->descrip,reloaded_image->descrip,80))!=0,NIFTITEST_FALSE,Errors);
156
+ return ;
157
+ }
158
+
159
+ int main (int argc, char *argv[])
160
+ {
161
+ char TEMP_STR[256];
162
+ nifti_set_debug_level(3);
163
+ int Errors=0;
164
+ {
165
+ PrintTest("NOT REALLY AN ERROR, JUST TESTING THE ERROR TEST REPORTING MECHANISM",1,NIFTITEST_FALSE,&Errors);
166
+ PrintTest("NOT REALLY AN ERROR, JUST TESTING THE ERROR COUNTING MECHANISM",Errors==1,NIFTITEST_FALSE,&Errors);
167
+ Errors=0;
168
+ }
169
+ {
170
+ const char write_image_filename[6][64]={
171
+ "ATestReferenceImageForReadingAndWriting.nii",
172
+ "ATestReferenceImageForReadingAndWriting.hdr",
173
+ "ATestReferenceImageForReadingAndWriting.img",
174
+ "ATestReferenceImageForReadingAndWriting.nii.gz",
175
+ "ATestReferenceImageForReadingAndWriting.hdr.gz",
176
+ "ATestReferenceImageForReadingAndWriting.img.gz"
177
+ };
178
+ printf("======= Testing All Nifti Valid Names ======\n");
179
+ fflush(stdout);
180
+ unsigned int filenameindex;
181
+ for(filenameindex=0;filenameindex<6; filenameindex++)
182
+ {
183
+ char buf[512];
184
+ int CompressedTwoFile = strstr(write_image_filename[filenameindex],".img.gz") != 0 ||
185
+ strstr(write_image_filename[filenameindex],".hdr.gz") != 0;
186
+
187
+ printf("======= Testing with filename: %s ======\n",write_image_filename[filenameindex]);
188
+ fflush(stdout);
189
+ nifti_image * reference_image = generate_reference_image(write_image_filename[filenameindex],&Errors);
190
+ /*
191
+ * Add an extension to test extension reading
192
+ */
193
+ {
194
+ static char ext[] = "THIS IS A TEST";
195
+ sprintf(buf,"nifti_add_extension %s",write_image_filename[filenameindex]);
196
+ PrintTest(buf,
197
+ nifti_add_extension(reference_image,
198
+ ext,sizeof(ext),
199
+ NIFTI_ECODE_COMMENT) == -1,
200
+ NIFTITEST_FALSE,&Errors);
201
+ sprintf(buf,"valid_nifti_extension %s",write_image_filename[filenameindex]);
202
+ PrintTest("valid_nifti_extensions",
203
+ valid_nifti_extensions(reference_image) == 0,
204
+ NIFTITEST_FALSE,&Errors);
205
+ }
206
+ PrintTest("Create reference image",reference_image==0,NIFTITEST_TRUE,&Errors);
207
+ nifti_image_write ( reference_image ) ;
208
+ /*
209
+ * test nifti_copy_extension
210
+ */
211
+ {
212
+ nifti_image *nim = nifti_simple_init_nim();
213
+ PrintTest("nifti_copy_extension",
214
+ nifti_copy_extensions(nim,reference_image),
215
+ NIFTITEST_FALSE,&Errors);
216
+
217
+ nifti_image_free(nim);
218
+ nim = nifti_copy_nim_info(reference_image);
219
+ PrintTest("nifti_copy_nim_info",
220
+ nim == 0,
221
+ NIFTITEST_FALSE,&Errors);
222
+ PrintTest("nifti_nim_is_valid",
223
+ nifti_nim_is_valid(nim,0) == 0,
224
+ NIFTITEST_FALSE,&Errors);
225
+
226
+
227
+ nifti_image_free(nim);
228
+
229
+ }
230
+ {
231
+ nifti_image * reloaded_image = nifti_image_read(reference_image->fname,1);
232
+ PrintTest("Reload of image ",reloaded_image==0,NIFTITEST_TRUE,&Errors);
233
+
234
+ {
235
+ /*
236
+ * if the file is named '.img', '.hdr', '.img.gz', or '.hdr.gz', then
237
+ * the header extensions won't be saved with the file.
238
+ * The test will fail if it finds an extension in a 2-file NIfTI, or
239
+ * fails to find one in a '.nii' or '.nii.gz' file.
240
+ */
241
+ int result = valid_nifti_extensions(reloaded_image);
242
+ sprintf(buf,"reload valid_nifti_extensions %s",write_image_filename[filenameindex]);
243
+ PrintTest(buf,
244
+ CompressedTwoFile ? result != 0 : result == 0,
245
+ NIFTITEST_FALSE,&Errors);
246
+ }
247
+ nifti_image_infodump(reloaded_image);
248
+ compare_reference_image_values(reference_image,reloaded_image,&Errors);
249
+ nifti_image_free(reloaded_image);
250
+ }
251
+
252
+ {
253
+ nifti_brick_list NB_orig, NB_select;
254
+
255
+ nifti_image * nim_orig, * nim_select;
256
+
257
+ int blist[5] = { 7, 0, 5, 5, 9 };
258
+
259
+ /*
260
+ * test some error paths in the nifti_image_read_bricks
261
+ */
262
+ nim_orig = nifti_image_read_bricks(reference_image->fname,0,blist, &NB_orig);
263
+ PrintTest("invalid arg bricked image read 1",nim_orig != 0,NIFTITEST_FALSE,&Errors);
264
+
265
+ nim_orig = nifti_image_read_bricks(reference_image->fname, 0, NULL, &NB_orig);
266
+ PrintTest("Reload of bricked image",nim_orig == 0,NIFTITEST_FALSE,&Errors);
267
+ nifti_free_NBL(&NB_orig);
268
+ nifti_image_free(nim_orig);
269
+
270
+ nim_select = nifti_image_read_bricks(reference_image->fname, 5, blist, &NB_select);
271
+ PrintTest("Reload of bricked image with blist",nim_orig == 0,NIFTITEST_FALSE,&Errors);
272
+ nifti_free_NBL(&NB_select);
273
+ nifti_image_free(nim_select);
274
+
275
+ }
276
+ /*
277
+ * test nifti_update_dims_from_array
278
+ */
279
+ PrintTest("nifti_update_dims_from_array -- valid dims",
280
+ nifti_update_dims_from_array(reference_image) != 0,
281
+ NIFTITEST_FALSE,&Errors);
282
+ reference_image->dim[0] = 8;
283
+ PrintTest("nifti_update_dims_from_array -- invalid dims",
284
+ nifti_update_dims_from_array(reference_image) == 0,
285
+ NIFTITEST_FALSE,&Errors);
286
+ {
287
+ nifti_1_header x = nifti_convert_nim2nhdr(reference_image);
288
+ char buf[512];
289
+ sprintf(buf,"nifti_hdr_looks_good %s",reference_image->fname);
290
+ PrintTest(buf,
291
+ !nifti_hdr_looks_good(&x),
292
+ NIFTITEST_FALSE,&Errors);
293
+ }
294
+
295
+ nifti_image_free(reference_image);
296
+ }
297
+ /*
298
+ * check nifti_findimgname
299
+ */
300
+ {
301
+ char *imgname = nifti_findimgname("ATestReferenceImageForReadingAndWriting.hdr",2);
302
+ PrintTest("nifti_findimgname",
303
+ imgname == 0 ||
304
+ strcmp(imgname,"ATestReferenceImageForReadingAndWriting.img") != 0,
305
+ NIFTITEST_FALSE,&Errors);
306
+ free(imgname);
307
+ }
308
+ {
309
+ int IsNiftiFile;
310
+ IsNiftiFile = is_nifti_file(write_image_filename[0]);
311
+ PrintTest("is_nifti_file0",
312
+ IsNiftiFile != 1,NIFTITEST_FALSE,&Errors);
313
+ IsNiftiFile = is_nifti_file(write_image_filename[1]);
314
+ PrintTest("is_nifti_file1",
315
+ IsNiftiFile != 2,NIFTITEST_FALSE,&Errors);
316
+ IsNiftiFile = is_nifti_file(write_image_filename[3]);
317
+ PrintTest("is_nifti_file2",
318
+ IsNiftiFile != 1,NIFTITEST_FALSE,&Errors);
319
+ IsNiftiFile = is_nifti_file(write_image_filename[4]);
320
+ PrintTest("is_nifti_file2",
321
+ IsNiftiFile != 2,NIFTITEST_FALSE,&Errors);
322
+ }
323
+
324
+ }
325
+ {
326
+ /*
327
+ * test writing and reading an ascii file
328
+ */
329
+ nifti_image * reference_image =
330
+ generate_reference_image("TestAsciiImage.nia",&Errors);
331
+ reference_image->nifti_type = 3;
332
+ nifti_image_write(reference_image);
333
+ nifti_image * reloaded_image = nifti_image_read("TestAsciiImage.nia",1);
334
+ PrintTest("Read/Write Ascii image",
335
+ reloaded_image == 0,NIFTITEST_FALSE,&Errors);
336
+ nifti_image_free(reference_image);
337
+ nifti_image_free(reloaded_image);
338
+ }
339
+
340
+ {
341
+ enum { NUM_FILE_NAMES=8 };
342
+ const char * FILE_NAMES[NUM_FILE_NAMES]={
343
+ "myimage",
344
+ "myimage.tif",
345
+ "myimage.tif.gz",
346
+ "myimage.nii",
347
+ "myimage.img.gz",
348
+ ".nii",
349
+ ".myhiddenimage",
350
+ ".myhiddenimage.nii"
351
+ };
352
+ const char * KNOWN_FILE_BASENAMES[NUM_FILE_NAMES]={
353
+ "myimage",
354
+ "myimage.tif",
355
+ "myimage.tif.gz",
356
+ "myimage",
357
+ "myimage",
358
+ "",
359
+ ".myhiddenimage",
360
+ ".myhiddenimage"
361
+ };
362
+ const int KNOWN_nifti_validfilename[NUM_FILE_NAMES]={
363
+ 1,
364
+ 1,
365
+ 1,
366
+ 1,
367
+ 1,
368
+ 0,
369
+ 1,
370
+ 1
371
+ };
372
+ const int KNOWN_nifti_is_complete_filename[NUM_FILE_NAMES]={
373
+ 0,
374
+ 0,
375
+ 0,
376
+ 1,
377
+ 1,
378
+ 0,
379
+ 0,
380
+ 1
381
+ };
382
+ unsigned int fni;
383
+ for(fni=0;fni<NUM_FILE_NAMES;fni++)
384
+ {
385
+ printf("\nTesting \"%s\" filename\n",FILE_NAMES[fni]);
386
+ {
387
+ int KnownValid=nifti_validfilename(FILE_NAMES[fni]);
388
+ snprintf(TEMP_STR,256,"nifti_validfilename(\"%s\")=%d",FILE_NAMES[fni],KnownValid);
389
+ PrintTest(TEMP_STR,KnownValid != KNOWN_nifti_validfilename[fni],NIFTITEST_FALSE,&Errors);
390
+ }
391
+ {
392
+ int KnownValid=nifti_is_complete_filename(FILE_NAMES[fni]);
393
+ snprintf(TEMP_STR,256,"nifti_is_complete_filename(\"%s\")=%d",FILE_NAMES[fni],KnownValid);
394
+ PrintTest(TEMP_STR,KnownValid != KNOWN_nifti_is_complete_filename[fni],NIFTITEST_FALSE,&Errors);
395
+ }
396
+
397
+ {
398
+ char * basename=nifti_makebasename(FILE_NAMES[fni]);
399
+ snprintf(TEMP_STR,256,"nifti_makebasename(\"%s\")=\"%s\"",FILE_NAMES[fni],basename);
400
+ PrintTest(TEMP_STR,strcmp(basename,KNOWN_FILE_BASENAMES[fni]) != 0,NIFTITEST_FALSE,&Errors);
401
+ free(basename);
402
+
403
+ }
404
+ }
405
+ /*
406
+ * the following 2 calls aren't tested, because all they do is display
407
+ * compile-time information -- no way to fail unless writing to stdout fails.
408
+ */
409
+ nifti_disp_lib_hist();
410
+ nifti_disp_lib_version();
411
+ /*
412
+ * the following exercises error path code in nifti_image_read_bricks
413
+ */
414
+ PrintTest(
415
+ "nifti_image_read_bricks 1",
416
+ nifti_image_read_bricks((char *)0,-1,(const int *)0,(nifti_brick_list *)0) != 0,
417
+ NIFTITEST_FALSE,
418
+ &Errors);
419
+ PrintTest(
420
+ "nifti_image_read_bricks 1",
421
+ nifti_image_read_bricks("NOFILE.NOFILE",-1,(const int *)0,(nifti_brick_list *)0) != 0,
422
+ NIFTITEST_FALSE,
423
+ &Errors);
424
+ }
425
+ /*
426
+ * call nifti_datatype_string with all possible values
427
+ */
428
+ #define nifti_datatype_test(constant,string) \
429
+ { \
430
+ char buf[64]; \
431
+ sprintf(buf,"nifti_datatype_string %s",string); \
432
+ PrintTest( \
433
+ buf, \
434
+ strcmp(nifti_datatype_string(constant),string) != 0, \
435
+ NIFTITEST_FALSE, \
436
+ &Errors); \
437
+ }
438
+ nifti_datatype_test(DT_UNKNOWN,"UNKNOWN");
439
+ nifti_datatype_test(DT_BINARY, "BINARY");
440
+ nifti_datatype_test(DT_INT8, "INT8");
441
+ nifti_datatype_test(DT_UINT8, "UINT8");
442
+ nifti_datatype_test(DT_INT16, "INT16");
443
+ nifti_datatype_test(DT_UINT16, "UINT16");
444
+ nifti_datatype_test(DT_INT32, "INT32");
445
+ nifti_datatype_test(DT_UINT32, "UINT32");
446
+ nifti_datatype_test(DT_INT64, "INT64");
447
+ nifti_datatype_test(DT_UINT64, "UINT64");
448
+ nifti_datatype_test(DT_FLOAT32, "FLOAT32");
449
+ nifti_datatype_test(DT_FLOAT64, "FLOAT64");
450
+ nifti_datatype_test(DT_FLOAT128, "FLOAT128");
451
+ nifti_datatype_test(DT_COMPLEX64, "COMPLEX64");
452
+ nifti_datatype_test(DT_COMPLEX128, "COMPLEX128");
453
+ nifti_datatype_test(DT_COMPLEX256, "COMPLEX256");
454
+ nifti_datatype_test(DT_RGB24, "RGB24");
455
+ #define nifti_is_inttype_test(constant,rval) \
456
+ { \
457
+ char buf[64]; \
458
+ sprintf(buf,"nifti_datatype_string %d",constant); \
459
+ PrintTest( \
460
+ buf, \
461
+ nifti_is_inttype(constant) != rval, \
462
+ NIFTITEST_FALSE, \
463
+ &Errors); \
464
+ }
465
+ nifti_is_inttype_test(DT_UNKNOWN,0);
466
+ nifti_is_inttype_test(DT_BINARY,0);
467
+ nifti_is_inttype_test(DT_INT8,1);
468
+ nifti_is_inttype_test(DT_UINT8,1);
469
+ nifti_is_inttype_test(DT_INT16,1);
470
+ nifti_is_inttype_test(DT_UINT16,1);
471
+ nifti_is_inttype_test(DT_INT32,1);
472
+ nifti_is_inttype_test(DT_UINT32,1);
473
+ nifti_is_inttype_test(DT_INT64,1);
474
+ nifti_is_inttype_test(DT_UINT64,1);
475
+ nifti_is_inttype_test(DT_FLOAT32,0);
476
+ nifti_is_inttype_test(DT_FLOAT64,0);
477
+ nifti_is_inttype_test(DT_FLOAT128,0);
478
+ nifti_is_inttype_test(DT_COMPLEX64,0);
479
+ nifti_is_inttype_test(DT_COMPLEX128,0);
480
+ nifti_is_inttype_test(DT_COMPLEX256,0);
481
+ nifti_is_inttype_test(DT_RGB24,1);
482
+ #define nifti_units_string_test(constant,string) \
483
+ { \
484
+ char buf[64]; \
485
+ sprintf(buf,"nifti_units_string_test %s",string); \
486
+ PrintTest( \
487
+ buf, \
488
+ strcmp(nifti_units_string(constant),string) != 0, \
489
+ NIFTITEST_FALSE, \
490
+ &Errors); \
491
+ }
492
+ nifti_units_string_test(NIFTI_UNITS_METER,"m");
493
+ nifti_units_string_test(NIFTI_UNITS_MM,"mm");
494
+ nifti_units_string_test(NIFTI_UNITS_MICRON,"um");
495
+ nifti_units_string_test(NIFTI_UNITS_SEC,"s");
496
+ nifti_units_string_test(NIFTI_UNITS_MSEC,"ms");
497
+ nifti_units_string_test(NIFTI_UNITS_USEC,"us");
498
+ nifti_units_string_test(NIFTI_UNITS_HZ,"Hz");
499
+ nifti_units_string_test(NIFTI_UNITS_PPM,"ppm");
500
+ nifti_units_string_test(NIFTI_UNITS_RADS,"rad/s");
501
+ #define nifti_intent_string_test(constant,string) \
502
+ { \
503
+ char buf[64]; \
504
+ sprintf(buf,"nifti_intent_string %s",string); \
505
+ PrintTest( \
506
+ buf, \
507
+ strcmp(nifti_intent_string(constant),string) != 0, \
508
+ NIFTITEST_FALSE, \
509
+ &Errors); \
510
+ }
511
+ nifti_intent_string_test(NIFTI_INTENT_CORREL,"Correlation statistic");
512
+ nifti_intent_string_test(NIFTI_INTENT_TTEST,"T-statistic");
513
+ nifti_intent_string_test(NIFTI_INTENT_FTEST,"F-statistic");
514
+ nifti_intent_string_test(NIFTI_INTENT_ZSCORE,"Z-score");
515
+ nifti_intent_string_test(NIFTI_INTENT_CHISQ,"Chi-squared distribution");
516
+ nifti_intent_string_test(NIFTI_INTENT_BETA,"Beta distribution");
517
+ nifti_intent_string_test(NIFTI_INTENT_BINOM,"Binomial distribution");
518
+ nifti_intent_string_test(NIFTI_INTENT_GAMMA,"Gamma distribution");
519
+ nifti_intent_string_test(NIFTI_INTENT_POISSON,"Poisson distribution");
520
+ nifti_intent_string_test(NIFTI_INTENT_NORMAL,"Normal distribution");
521
+ nifti_intent_string_test(NIFTI_INTENT_FTEST_NONC,"F-statistic noncentral");
522
+ nifti_intent_string_test(NIFTI_INTENT_CHISQ_NONC,"Chi-squared noncentral");
523
+ nifti_intent_string_test(NIFTI_INTENT_LOGISTIC,"Logistic distribution");
524
+ nifti_intent_string_test(NIFTI_INTENT_LAPLACE,"Laplace distribution");
525
+ nifti_intent_string_test(NIFTI_INTENT_UNIFORM,"Uniform distribition");
526
+ nifti_intent_string_test(NIFTI_INTENT_TTEST_NONC,"T-statistic noncentral");
527
+ nifti_intent_string_test(NIFTI_INTENT_WEIBULL,"Weibull distribution");
528
+ nifti_intent_string_test(NIFTI_INTENT_CHI,"Chi distribution");
529
+ nifti_intent_string_test(NIFTI_INTENT_INVGAUSS,"Inverse Gaussian distribution");
530
+ nifti_intent_string_test(NIFTI_INTENT_EXTVAL,"Extreme Value distribution");
531
+ nifti_intent_string_test(NIFTI_INTENT_PVAL,"P-value");
532
+ nifti_intent_string_test(NIFTI_INTENT_LOGPVAL,"Log P-value");
533
+ nifti_intent_string_test(NIFTI_INTENT_LOG10PVAL,"Log10 P-value");
534
+ nifti_intent_string_test(NIFTI_INTENT_ESTIMATE,"Estimate");
535
+ nifti_intent_string_test(NIFTI_INTENT_LABEL,"Label index");
536
+ nifti_intent_string_test(NIFTI_INTENT_NEURONAME,"NeuroNames index");
537
+ nifti_intent_string_test(NIFTI_INTENT_GENMATRIX,"General matrix");
538
+ nifti_intent_string_test(NIFTI_INTENT_SYMMATRIX,"Symmetric matrix");
539
+ nifti_intent_string_test(NIFTI_INTENT_DISPVECT,"Displacement vector");
540
+ nifti_intent_string_test(NIFTI_INTENT_VECTOR,"Vector");
541
+ nifti_intent_string_test(NIFTI_INTENT_POINTSET,"Pointset");
542
+ nifti_intent_string_test(NIFTI_INTENT_TRIANGLE,"Triangle");
543
+ nifti_intent_string_test(NIFTI_INTENT_QUATERNION,"Quaternion");
544
+ nifti_intent_string_test(NIFTI_INTENT_DIMLESS,"Dimensionless number");
545
+ nifti_intent_string_test(-200,"Unknown");
546
+
547
+ #define nifti_slice_string_test(constant,string) \
548
+ { \
549
+ char buf[64]; \
550
+ sprintf(buf,"nifti_slice_string_test %s",string); \
551
+ PrintTest( \
552
+ buf, \
553
+ strcmp(nifti_slice_string(constant),string) != 0, \
554
+ NIFTITEST_FALSE, \
555
+ &Errors); \
556
+ }
557
+ nifti_slice_string_test(NIFTI_SLICE_SEQ_INC,"sequential_increasing");
558
+ nifti_slice_string_test(NIFTI_SLICE_SEQ_DEC,"sequential_decreasing");
559
+ nifti_slice_string_test(NIFTI_SLICE_ALT_INC,"alternating_increasing");
560
+ nifti_slice_string_test(NIFTI_SLICE_ALT_DEC,"alternating_decreasing");
561
+ nifti_slice_string_test(NIFTI_SLICE_ALT_INC2,"alternating_increasing_2");
562
+ nifti_slice_string_test(NIFTI_SLICE_ALT_DEC2,"alternating_decreasing_2");
563
+ #define nifti_orientation_string_test(constant,string) \
564
+ { \
565
+ char buf[64]; \
566
+ sprintf(buf,"nifti_orientation_string_test %s",string); \
567
+ PrintTest( \
568
+ buf, \
569
+ strcmp(nifti_orientation_string(constant),string) != 0, \
570
+ NIFTITEST_FALSE, \
571
+ &Errors); \
572
+ }
573
+ nifti_orientation_string_test(NIFTI_L2R,"Left-to-Right");
574
+ nifti_orientation_string_test(NIFTI_R2L,"Right-to-Left");
575
+ nifti_orientation_string_test(NIFTI_P2A,"Posterior-to-Anterior");
576
+ nifti_orientation_string_test(NIFTI_A2P,"Anterior-to-Posterior");
577
+ nifti_orientation_string_test(NIFTI_I2S,"Inferior-to-Superior");
578
+ nifti_orientation_string_test(NIFTI_S2I,"Superior-to-Inferior");
579
+
580
+ #define nifti_datatype_sizes_test(constant,Nbyper,Swapsize) \
581
+ { \
582
+ int nbyper; \
583
+ int swapsize; \
584
+ char buf[64]; \
585
+ sprintf(buf,"nifti_datatype_sizes_test %d",constant); \
586
+ nifti_datatype_sizes(constant,&nbyper,&swapsize); \
587
+ PrintTest( \
588
+ buf, \
589
+ nbyper != Nbyper || swapsize != Swapsize, \
590
+ NIFTITEST_FALSE, \
591
+ &Errors); \
592
+ }
593
+
594
+ nifti_datatype_sizes_test(DT_UINT8,1,0);
595
+ nifti_datatype_sizes_test(DT_UINT16,2,2);
596
+ nifti_datatype_sizes_test(DT_RGB24,3,0);
597
+ nifti_datatype_sizes_test(DT_FLOAT32,4,4);
598
+ nifti_datatype_sizes_test(DT_COMPLEX64,8,4);
599
+ nifti_datatype_sizes_test(DT_UINT64,8,8);
600
+ nifti_datatype_sizes_test(DT_FLOAT128,16,16);
601
+ nifti_datatype_sizes_test(DT_COMPLEX128,16,8);
602
+ nifti_datatype_sizes_test(DT_COMPLEX256,32,16);
603
+
604
+ {
605
+ mat44 R;
606
+ unsigned i,j;
607
+ for(i = 0; i < 4; i++)
608
+ for(j = 0; j < 4; j++)
609
+ R.m[i][j] = (i == j ? 1 : 0);
610
+ float qb;
611
+ float qc;
612
+ float qd;
613
+ float qx;
614
+ float qy;
615
+ float qz;
616
+ float dx;
617
+ float dy;
618
+ float dz;
619
+ float qfac;
620
+ nifti_mat44_to_quatern(R,&qb,&qc,&qd,&qx,&qy,&qz,&dx,&dy,&dz,&qfac);
621
+ PrintTest("nifti_mat44_to_quatern",
622
+ qb != 0.000000 || qc != 0.000000 || qd != 0.000000 ||
623
+ qx != 0.000000 || qy != 0.000000 || qd != 0.000000 ||
624
+ dx != 1.000000 || dy != 1.000000 || dz != 1.000000 ||
625
+ qfac != 1.000000,
626
+ NIFTITEST_FALSE,&Errors);
627
+ }
628
+ {
629
+ mat44 x = nifti_make_orthog_mat44(0.14,0.0,0.0,
630
+ 0.0,0.9,0.0,
631
+ 0.0,0.0,1.1);
632
+
633
+ PrintTest("nifti_make_orthog_mat44",
634
+ x.m[0][0] != 1.0 || x.m[1][1] != 1.0 ||
635
+ x.m[2][2] != 1.0 || x.m[3][3] != 1.0,
636
+ NIFTITEST_FALSE,&Errors);
637
+ }
638
+ {
639
+ static char x[16] = { 'a','b','c','d','e','f','g','h',
640
+ 'H','G','F','E','D','C','B','A' };
641
+ nifti_swap_Nbytes(1,16,(void *)x);
642
+ PrintTest("nifti_swap_16bytes",
643
+ x[0] != 'A' || x[1] != 'B' || x[2] != 'C' || x[3] != 'D' ||
644
+ x[4] != 'E' || x[5] != 'F' || x[6] != 'G' || x[7] != 'H' ||
645
+ x[8] != 'h' || x[9] != 'g' || x[10] != 'f' || x[11] != 'e' ||
646
+ x[12] != 'd' || x[13] != 'c' || x[14] != 'b' || x[15] != 'a',
647
+ NIFTITEST_FALSE,&Errors);
648
+
649
+ }
650
+ {
651
+ static char x[8] = { 'a','b','c','d','D','C','B','A' };
652
+ nifti_swap_Nbytes(1,8,(void *)x);
653
+ PrintTest("nifti_swap_8bytes",
654
+ x[0] != 'A' || x[1] != 'B' || x[2] != 'C' || x[3] != 'D' ||
655
+ x[4] != 'd' || x[5] != 'c' || x[6] != 'b' || x[7] != 'a',
656
+ NIFTITEST_FALSE,&Errors);
657
+
658
+ }
659
+ {
660
+ /*
661
+ * test nifti_simple_init_nim
662
+ */
663
+ nifti_image *nim = nifti_simple_init_nim();
664
+ PrintTest("nifti_simple_init_nim",
665
+ nim == 0,NIFTITEST_FALSE,&Errors);
666
+ nifti_image_free(nim); nim = 0;
667
+ /*
668
+ * test nifti_image_open
669
+ */
670
+ znzFile f = nifti_image_open("ATestReferenceImageForReadingAndWriting.hdr","r",&nim);
671
+ PrintTest("nifti_image_open",
672
+ nim == 0 || f == 0,
673
+ NIFTITEST_FALSE,&Errors);
674
+ PrintTest("nifti_image_load",
675
+ nifti_image_load(nim) == -1,
676
+ NIFTITEST_FALSE,&Errors);
677
+ nifti_image_unload(nim);
678
+ PrintTest("nifti_image_unload",
679
+ nim->data != 0,
680
+ NIFTITEST_FALSE,&Errors);
681
+
682
+ znzclose(f);
683
+ nifti_image_free(nim);
684
+ }
685
+ /*
686
+ * call various functions from nifti_stats
687
+ */
688
+ printf("\n\nTOTAL ERRORS=%d\n",Errors);
689
+ return Errors;
690
+ }