backprojection.m 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. %% Author: Rodrigo de Barros Vimieiro
  2. % Date: April, 2018
  3. % rodrigo.vimieiro@gmail.com
  4. % =========================================================================
  5. %{
  6. % -------------------------------------------------------------------------
  7. % backprojection(proj,param,projNumber)
  8. % -------------------------------------------------------------------------
  9. % DESCRIPTION:
  10. % This function makes the simple backprojection of 2D images, in order
  11. % to reconstruct a certain number of slices.
  12. %
  13. % The function calculates for each voxel, which detector pixel is
  14. % associated with that voxel in the specific projection. That is done
  15. % for all angles specified.
  16. %
  17. % The geometry is for DBT with half cone-beam. All parameters are set
  18. % in "ParameterSettings" code.
  19. %
  20. % INPUT:
  21. %
  22. % - proj = 2D projection images
  23. % - param = Parameter of all geometry
  24. % - projNumber = Vector with projections numbers to be processed
  25. %
  26. % OUTPUT:
  27. %
  28. % - data3d = Volume data.
  29. %
  30. % Reference: Patent US5872828
  31. %
  32. % ---------------------------------------------------------------------
  33. % Copyright (C) <2018> <Rodrigo de Barros Vimieiro>
  34. %
  35. % This program is free software: you can redistribute it and/or modify
  36. % it under the terms of the GNU General Public License as published by
  37. % the Free Software Foundation, either version 3 of the License, or
  38. % (at your option) any later version.
  39. %
  40. % This program is distributed in the hope that it will be useful,
  41. % but WITHOUT ANY WARRANTY; without even the implied warranty of
  42. % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  43. % GNU General Public License for more details.
  44. %
  45. % You should have received a copy of the GNU General Public License
  46. % along with this program. If not, see <http://www.gnu.org/licenses/>.
  47. %}
  48. % =========================================================================
  49. %% Backprojection Code
  50. function data3d = backprojection(proj,param,projNumber)
  51. % Get parameters from struct
  52. DSR = param.DSR;
  53. DDR = param.DDR;
  54. tubeAngle = deg2rad(param.tubeDeg);
  55. numVPixels = param.nv;
  56. numUPixels = param.nu;
  57. numSlices = param.nz;
  58. numProjs = param.nProj;
  59. zCoords = param.zs; % Z object coordinates
  60. % Test if there's specific angles
  61. if(isempty(projNumber))
  62. projNumber = 1:numProjs;
  63. else
  64. if(max(projNumber(:)) <= numProjs)
  65. numProjs = size(projNumber,2);
  66. else
  67. error('Projection number exceeds the maximum for the equipment.')
  68. end
  69. end
  70. % Stack of reconstructed slices
  71. data3d = zeros(param.ny, param.nx, param.nz,'single');
  72. % Object Coordinate system in (mm)
  73. [xCoord,yCoord] = meshgrid(param.xs,param.ys);
  74. fprintf('%2d/%2d', 1, numProjs)
  75. % For each projection
  76. for p=1:numProjs
  77. fprintf('\b\b\b\b\b%2d/%2d', p, numProjs)
  78. % Get specific projection number
  79. projN = projNumber(p);
  80. % Get specific angle for the backprojection
  81. teta = tubeAngle(projN);
  82. % Get specif projection from stack
  83. proj_tmp = proj(:,:,p);
  84. % For each slice
  85. for nz=1:numSlices
  86. % Calculates a relation of voxel and detector coordinates
  87. pvCoord = yCoord+((zCoords(nz).*((DSR.*sin(teta))+ yCoord))./...
  88. ((DSR.*cos(teta))+ DDR -zCoords(nz)));
  89. puCoord = (xCoord.*((DSR.*cos(teta))+DDR))./ ...
  90. ((DSR.*cos(teta))+DDR-zCoords(nz));
  91. % Coordinate in Pixel of detector plane axis origin
  92. u0 = numUPixels;
  93. v0 = numVPixels/2;
  94. % Represent detector plane axis (Xi,Yi) in the image plane axis (i,j) (covert mm to Pixels)
  95. puCoord = -(puCoord./param.du) + u0;
  96. pvCoord = (pvCoord./param.dv) + v0;
  97. % Interpolation of the pixel coordinates of the "Projection" at the calculated pixel coordinates for the slices
  98. slice_tmp = interp2(proj_tmp,puCoord,pvCoord,'linear', 0);
  99. % Acumulate current slice with slice from previus projection
  100. data3d(:,:,nz) = data3d(:,:,nz) + slice_tmp;
  101. end % Loop end slices
  102. end % Loop end Projections
  103. data3d(:) = data3d(:)./ numProjs;
  104. end