readDicom.m 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. %% Author: Rodrigo de Barros Vimieiro
  2. % Date: May, 2018
  3. % rodrigo.vimieiro@gmail.com
  4. % =========================================================================
  5. %{
  6. % -------------------------------------------------------------------------
  7. % readDicom(imgdir,parameter,answer)
  8. % -------------------------------------------------------------------------
  9. % DESCRIPTION:
  10. % This function read a set of Dicom images from a directory.
  11. %
  12. % INPUT:
  13. % - imgdir = Directory for Dicom files
  14. % - parameter = Parameter of all geometry
  15. %
  16. % OUTPUT:
  17. % - dataDicom = Stack of Dicom images.
  18. % - infoDicom = Stack of Dicom headers.
  19. %
  20. % ---------------------------------------------------------------------
  21. % Copyright (C) <2018> <Rodrigo de Barros Vimieiro>
  22. %
  23. % This program is free software: you can redistribute it and/or modify
  24. % it under the terms of the GNU General Public License as published by
  25. % the Free Software Foundation, either version 3 of the License, or
  26. % (at your option) any later version.
  27. %
  28. % This program is distributed in the hope that it will be useful,
  29. % but WITHOUT ANY WARRANTY; without even the implied warranty of
  30. % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  31. % GNU General Public License for more details.
  32. %
  33. % You should have received a copy of the GNU General Public License
  34. % along with this program. If not, see <http://www.gnu.org/licenses/>.
  35. %}
  36. % =========================================================================
  37. %% Read Dicom images from files
  38. function [dataDicom,infoDicom] = readDicom(imgdir,parameter,answer)
  39. if(strcmp(parameter.type,'vct'))
  40. dc = 1;
  41. typecase = 1;
  42. end
  43. if(strcmp(parameter.type,'hologic'))
  44. dc = 1;
  45. typecase = 0;
  46. end
  47. if(strcmp(parameter.type,'ge'))
  48. dc = 0;
  49. typecase = 1;
  50. end
  51. if(strcmp(answer,'Microcalcifications') || strcmp(answer,'Noised'))
  52. dc = 0;
  53. typecase = 0;
  54. end
  55. img_list = dir([imgdir,filesep,'*.dcm']); % List dicom files
  56. img_count = size(img_list,1);
  57. fprintf('%2d/%2d', 1, img_count)
  58. for i=1:img_count
  59. fprintf('\b\b\b\b\b%2d/%2d', i, img_count)
  60. imgAux = single(dicomread([imgdir, filesep, img_list(i,:).name])); % Read Dicom
  61. infoAux = dicominfo([imgdir, filesep, img_list(i,:).name]); % Read Dicom headers
  62. if(typecase == 1)
  63. nProj = infoAux.InstanceNumber+dc;
  64. else
  65. filename = strtrim(img_list(i,:).name);
  66. filenameSlpited = strsplit(filename, '_');
  67. filenameSlpited = strsplit(filenameSlpited{end}, '.');
  68. nProj = str2double(filenameSlpited{1})+dc;
  69. end
  70. dataDicom(:,:,nProj) = imgAux;
  71. infoDicom(:,nProj) = infoAux;
  72. end
  73. end