spm_dicom_essentials.m 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. function hdr1 = spm_dicom_essentials(hdr0)
  2. % Remove unused fields from DICOM header
  3. % FORMAT hdr1 = spm_dicom_essentials(hdr0)
  4. % hdr0 - original DICOM header
  5. % hdr1 - Stripped down DICOM header
  6. %
  7. % With lots of DICOM files, the size of all the headers can become too
  8. % big for all the fields to be saved. The idea here is to strip down
  9. % the headers to their essentials.
  10. %__________________________________________________________________________
  11. % Copyright (C) 2008-2018 Wellcome Trust Centre for Neuroimaging
  12. % John Ashburner
  13. % $Id: spm_dicom_essentials.m 7416 2018-09-11 13:55:13Z john $
  14. if isempty(hdr0), hdr1 = hdr0; return; end
  15. used_fields = {...
  16. 'AcquisitionDate',...
  17. 'AcquisitionNumber',...
  18. 'AcquisitionTime',...
  19. 'BitsAllocated',...
  20. 'BitsStored',...
  21. 'CSAImageHeaderInfo',...
  22. 'Columns',...
  23. 'EchoNumbers',...
  24. 'EchoTime',...
  25. 'Filename',...
  26. 'FlipAngle',...
  27. 'HighBit',...
  28. 'ImageOrientationPatient',...
  29. 'ImagePositionPatient',...
  30. 'ImageType',...
  31. 'InstanceNumber',...
  32. 'MagneticFieldStrength',...
  33. 'Manufacturer',...
  34. 'Modality',...
  35. 'MRAcquisitionType',...
  36. 'NumberOfFrames',...
  37. 'PatientID',...
  38. 'PixelRepresentation',...
  39. 'PixelSpacing',...
  40. 'Private_0029_1110',...
  41. 'Private_0029_1210',...
  42. 'ProtocolName',...
  43. 'RepetitionTime',...
  44. 'RescaleIntercept',...
  45. 'RescaleSlope',...
  46. 'Rows',...
  47. 'SOPClassUID',...
  48. 'SamplesPerPixel',...
  49. 'ScanningSequence',...
  50. 'SequenceName',...
  51. 'SeriesDescription',...
  52. 'SeriesInstanceUID',...
  53. 'SeriesNumber',...
  54. 'SizeOfPixelData'...
  55. 'SliceNormalVector',...
  56. 'SliceThickness',...
  57. 'SpacingBetweenSlices',...
  58. 'StartOfPixelData',...
  59. 'StudyDate',...
  60. 'StudyTime',...
  61. 'TransferSyntaxUID',...
  62. 'VROfPixelData',...
  63. 'ScanOptions',...
  64. 'GE_ImageType',...
  65. 'MRScaleSlope',...
  66. 'MRScaleIntercept',...
  67. ...
  68. 'PerFrameFunctionalGroupsSequence',...
  69. 'SharedFunctionalGroupsSequence',...
  70. 'DimensionIndexSequence',...
  71. };
  72. % Should probably save some memory by stripping out unused fields
  73. % from PerFrameFunctionalGroupsSequence and PerFrameFunctionalGroupsSequence.
  74. % This is not yet a priority though.
  75. fnames = fieldnames(hdr0);
  76. for i=1:numel(used_fields)
  77. if ismember(used_fields{i},fnames)
  78. hdr1.(used_fields{i}) = hdr0.(used_fields{i});
  79. end
  80. end
  81. Private_spectroscopy_fields = {...
  82. 'Columns',...
  83. 'Rows',...
  84. 'ImageOrientationPatient',...
  85. 'ImagePositionPatient',...
  86. 'SliceThickness',...
  87. 'PixelSpacing',...
  88. 'VoiPhaseFoV',...
  89. 'VoiReadoutFoV',...
  90. 'VoiThickness'};
  91. if isfield(hdr1,'Private_0029_1110')
  92. hdr1.Private_0029_1110 = ...
  93. getfields(hdr1.Private_0029_1110,...
  94. Private_spectroscopy_fields);
  95. end
  96. if isfield(hdr1,'Private_0029_1210')
  97. hdr1.Private_0029_1210 = ...
  98. getfields(hdr1.Private_0029_1210,...
  99. Private_spectroscopy_fields);
  100. end
  101. if isfield(hdr1,'CSAImageHeaderInfo')
  102. CSAImageHeaderInfo_fields = {...
  103. 'SliceNormalVector',...
  104. 'NumberOfImagesInMosaic',...
  105. 'AcquisitionMatrixText',...
  106. 'ICE_Dims'};
  107. hdr1.CSAImageHeaderInfo = ...
  108. getfields(hdr1.CSAImageHeaderInfo,...
  109. CSAImageHeaderInfo_fields);
  110. end
  111. if isfield(hdr1,'CSASeriesHeaderInfo')
  112. CSASeriesHeaderInfo_fields = {};
  113. hdr1.CSASeriesHeaderInfo = ...
  114. getfields(hdr1.CSASeriesHeaderInfo,...
  115. CSASeriesHeaderInfo_fields);
  116. end
  117. function str1 = getfields(str0,names)
  118. str1 = [];
  119. for i=1:numel(names)
  120. for j=1:numel(str0)
  121. if strcmp(str0(j).name,names{i})
  122. str1 = [str1,str0(j)];
  123. end
  124. end
  125. end