ProjectionNoising.m 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. %% Author: Aleks Prša
  2. % Date: July, 2022
  3. % alex.prsa@gmail.com
  4. % =========================================================================
  5. %{
  6. %
  7. % DESCRIPTION:
  8. %
  9. % Program for noising projection images.
  10. %
  11. % Faculty of Mathematic and Physics
  12. % University in Ljubljana
  13. % Ljubljana, Slovenia
  14. %
  15. %}
  16. % =========================================================================
  17. %% Choose initial number of photons
  18. close all;clear;clc
  19. It = 3; % Anode current - number of photon
  20. %% Load data
  21. path_User = userpath;
  22. path_ProjData = uigetdir(path_User);
  23. addpath(genpath('Functions'));
  24. addpath(genpath('Parameters'));
  25. ParameterSettings_MicroInsertion
  26. % Load projection data
  27. if(path_ProjData == 0)
  28. fprintf('Cancelled by user \n');
  29. return;
  30. else
  31. userpath(path_ProjData);
  32. fprintf('Reading DICOMs ')
  33. answer = 'Noised';
  34. [dataProj,infoDicom] = readDicom(path_ProjData,parameter,answer);
  35. parameter.bitDepth = infoDicom(:,1).BitDepth;
  36. end
  37. %% Projection noising
  38. fprintf('\nProjection noising ')
  39. for i=1:size(dataProj,3)
  40. fprintf('\b\b\b\b\b%2d/%2d', i, size(dataProj,3))
  41. attenuation(:,:,i) = (dataProj(:,:,i) - parameter.mu) / (parameter.eo*parameter.Io);
  42. attenuation(attenuation < 0) = 0;
  43. attenuation(attenuation > 1) = 1;
  44. lambda = attenuation(:,:,i) .* (parameter.alpha * It);
  45. newProjection(:,:,i) = parameter.eo * poissrnd(lambda,parameter.nv,parameter.nu) + parameter.mu;
  46. end
  47. %% Save data
  48. filestring = ['Output',filesep,'Noised',filesep,'Projections'];
  49. if(~exist(filestring))
  50. mkdir(filestring)
  51. end
  52. fprintf('\nWriting DICOM projections ')
  53. writeDicomProj(newProjection,infoDicom,filestring,parameter);
  54. fprintf('\nSaving projections... \n')
  55. save(['Output',filesep,'Noised',filesep,'NoisedProjections.mat'],'dataProj','-v7.3');
  56. infoDicom = [];
  57. fprintf('\nFINISHED - Data stored in "Noised" folder\n')
  58. beep