examples.txt 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. - Examples to load, make and save a nii struct:
  2. To load Analyze data or NIFTI data to a structure:
  3. nii = load_nii(NIFTI_file_name, [img_idx], [old_RGB24]);
  4. img_idx is a numerical array of image indices along the temporal
  5. axis, which is only available in NIFTI data. After you specify
  6. img_idx, only those images indexed by img_idx will be loaded. If
  7. there is no img_idx or img_idx is empty, all available images
  8. will be loaded.
  9. For RGB image, most people use RGB triple sequentially for each
  10. voxel, like [R1 G1 B1 R2 G2 B2 ...]. However, some program like
  11. Analyze 6.0 developed by AnalyzeDirect uses old RGB24, in a way
  12. like [R1 R2 ... G1 G2 ... B1 B2 ...] for each slices. In this
  13. case, you can set old_RGB24 flag to 1 and load data correctly:
  14. nii = load_nii(NIFTI_file_name, [], 1);
  15. To get a total number of images along the temporal axis:
  16. num_scan = get_nii_frame(NIFTI_file_name);
  17. You can also load the header extension if it exists:
  18. nii.ext = load_nii_ext(NIFTI_file_name);
  19. You can just load the Analyze or NIFTI header:
  20. (header contains: hk, dime, and hist)
  21. hdr = load_nii_hdr(NIFTI_file_name);
  22. You can also save the structure to a new file:
  23. (header extension will be saved if there is nii.ext structure)
  24. save_nii(nii, NIFTI_file_name);
  25. To make the structure from any 3D (or 4D) data:
  26. img = rand(91,109,91); or
  27. img = rand(64,64,21,18);
  28. nii = make_nii(img [, voxel_size, origin, datatype] );
  29. Use "help load_nii", "help save_nii", "help make_nii" etc.
  30. to get more detail information.
  31. - Examples to plot a nii struct:
  32. (More detail descriptions are available on top of "view_nii.m")
  33. Simple way to plot a nii struct:
  34. view_nii(nii);
  35. The default colormap will use the Gray if all data values are
  36. non-negative; otherwise, the default colormap will use BiPolar.
  37. You can choose other colormap, including customized colormap
  38. from panel.
  39. To imbed the plot into your existing figure:
  40. h = gcf;
  41. opt.command = 'init';
  42. opt.setarea = [0.3 0.1 0.6 0.8];
  43. view_nii(h, nii, opt);
  44. To add a colorbar:
  45. opt.usecolorbar = 1;
  46. view_nii(gcf, opt);
  47. Here, opt.command is implicitly set to 'update'.
  48. To display in real aspect ratio:
  49. opt.usestretch = 0;
  50. view_nii(gcf, opt);
  51. If you want the data value to be directly used as the index
  52. of colormap, instead of scale to the whole colormap:
  53. opt.useimagesc = 0;
  54. view_nii(gcf, opt);
  55. If you modified the data value without changing the dimension,
  56. voxel_size, and origin, you can update the display by:
  57. opt.command = 'updateimg';
  58. view_nii(gcf, nii.img, opt);
  59. If the data is completely different, display can be updated by:
  60. opt.command = 'updatenii';
  61. view_nii(gcf, nii, opt);
  62. This is an example to plot EEG source imaging on top of T1 background:
  63. 1. download overlay.zip and unzip it from:
  64. http://www.rotman-baycrest.on.ca/~jimmy/NIFTI/overlay.zip
  65. 2. T1 = load_nii('T1.nii');
  66. 3. EEG = load_nii('EEG.nii');
  67. 4. option.setvalue.idx = find(EEG.img);
  68. 5. option.setvalue.val = EEG.img(option.setvalue.idx);
  69. 6. option.useinterp = 1;
  70. 7. option.setviewpoint = [62 48 46];
  71. 8. view_nii(T1, option);
  72. - Contrast and Brightness are available under Gray and Bipolar colormap:
  73. Increase contrast in Gray colormap will make high end values
  74. more distinguishable by sacrificing the low end values; The
  75. minimum contrast (default) will display the whole range.
  76. Increase or decrease contrast in BiPolar colormap will shift
  77. the distinguishable position for both positive and negative
  78. values.
  79. Increase or decrease brightness in Gray colormap will shift
  80. the distinguishable position.
  81. Increase or decrease brightness in BiPolar colormap will make
  82. both positive and negative values more distinguishable.
  83. - Required files:
  84. All files in this package.