writeDcm.m 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. %% Author: Aleks Prša
  2. % Date: May, 2022
  3. % alex.prsa@gmail.com
  4. % =========================================================================
  5. %{
  6. % -------------------------------------------------------------------------
  7. % writeDcm(dataRecon3d,filestring,parameter)
  8. % -------------------------------------------------------------------------
  9. % DESCRIPTION:
  10. % This function write a set of Dicom images with respective headers.
  11. %
  12. %
  13. % INPUT:
  14. % - dataRecon3d = Reconstructed data
  15. % - filestring = Path to save
  16. % - parameter = Parameter of all geometry
  17. %
  18. % ---------------------------------------------------------------------
  19. %}
  20. % =========================================================================
  21. %% Write Dicom images
  22. function writeDcm(dataRecon3d,filestring,parameter)
  23. if(~exist(filestring))
  24. mkdir(filestring)
  25. end
  26. for k=1:size(dataRecon3d,2)
  27. dataRecon3d{1,k} = dataRecon3d{1,k} + abs(min(dataRecon3d{1,k}(:)));
  28. dataRecon3d{1,k} = (2^16-1).*mat2gray(dataRecon3d{1,k});
  29. dataRecon3d{1,k} = uint16(dataRecon3d{1,k});
  30. end
  31. % Write dicom files in respective folder
  32. fprintf('\nWriting images ')
  33. fprintf('%3d/%3d', 1, parameter.nz)
  34. for i=1:size(dataRecon3d{1,k},3)
  35. fprintf('\b\b\b\b\b\b\b%3d/%3d', i, parameter.nz)
  36. if(i<10)
  37. fileimg = [filestring,filesep,'0',num2str(i),'.dcm'];
  38. else
  39. fileimg = [filestring,filesep,num2str(i),'.dcm'];
  40. end
  41. dicomwrite(dataRecon3d{1,k}(:,:,i), fileimg);
  42. end
  43. end