spm_dicom_headers.m 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. function Headers = spm_dicom_headers(DicomFilenames, Essentials)
  2. % Read header information from DICOM files
  3. % FORMAT Headers = spm_dicom_headers(DicomFilenames [,Essentials])
  4. % DicomFilenames - array of filenames
  5. % Essentials - if true, then only save the essential parts of the header
  6. %
  7. % Headers - cell array of headers, one element for each file.
  8. %
  9. % Contents of headers are approximately explained in:
  10. % http://medical.nema.org/standard.html
  11. %
  12. % This code may not work for all cases of DICOM data, as DICOM is an
  13. % extremely complicated "standard".
  14. %__________________________________________________________________________
  15. % Copyright (C) 2002-2018 Wellcome Trust Centre for Neuroimaging
  16. % John Ashburner
  17. % $Id: spm_dicom_headers.m 7374 2018-07-09 17:09:46Z guillaume $
  18. DicomFilenames = cellstr(DicomFilenames);
  19. if nargin<2, Essentials = false; end
  20. if ~isa(Essentials,'function_handle')
  21. if Essentials
  22. Essentials = @spm_dicom_essentials;
  23. else
  24. Essentials = @(x) x;
  25. end
  26. end
  27. DicomDictionary = load(fullfile(spm('Dir'),'spm_dicom_dict.mat'));
  28. Headers = {};
  29. if numel(DicomFilenames)>1
  30. spm_progress_bar('Init',numel(DicomFilenames), ...
  31. 'Reading DICOM headers', 'Files complete');
  32. end
  33. for i=1:numel(DicomFilenames)
  34. Header = spm_dicom_header(DicomFilenames{i}, DicomDictionary);
  35. Header = Essentials(Header);
  36. if ~isempty(Header)
  37. Headers{end+1} = Header;
  38. end
  39. if numel(DicomFilenames)>1, spm_progress_bar('Set',i); end
  40. end
  41. if numel(DicomFilenames)>1, spm_progress_bar('Clear'); end