filterProj.m 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. %% Author: Rodrigo de Barros Vimieiro
  2. % Date: April, 2018
  3. % rodrigo.vimieiro@gmail.com
  4. % =========================================================================
  5. %{
  6. % -------------------------------------------------------------------------
  7. % filterProj(proj,param,cutoff,filterOrder)
  8. % -------------------------------------------------------------------------
  9. % DESCRIPTION:
  10. % This function filters the projection based on Feldkamp algorithms. It
  11. % also applies a window filter to discourage noise and avoid ringing
  12. % effect.
  13. %
  14. % The geometry is for DBT with half cone-beam. All parameters are set
  15. % in "ParameterSettings" code.
  16. %
  17. % INPUT:
  18. %
  19. % - proj = 2D projection images
  20. % - param = Parameter of all geometry
  21. % - cutoff = Cut off frequency up to Nyquist
  22. % - filterOrder = Butterworth filter order
  23. %
  24. % OUTPUT:
  25. %
  26. % - filteredProj = Filtered projections.
  27. %
  28. % Reference: Jiang Hsieh's book (second edition)
  29. % Reference: Fessler, J. A.: Fundamentals of CT Reconstruction in 2D
  30. % and 3D. In: Brahme, A. (eds.) Comprehensive Biomedical Physics,
  31. % 1st ed., vol. 2, pp 263-295. Elsevier, Netherlands (2014).
  32. % doi:10.1016/B978-0-444-53632-7.00212-4.
  33. % Reference: Fessler Book -> (http://web.eecs.umich.edu/~fessler/book/c-tomo.pdf)
  34. %
  35. % ---------------------------------------------------------------------
  36. % Copyright (C) <2018> <Rodrigo de Barros Vimieiro>
  37. %
  38. % This program is free software: you can redistribute it and/or modify
  39. % it under the terms of the GNU General Public License as published by
  40. % the Free Software Foundation, either version 3 of the License, or
  41. % (at your option) any later version.
  42. %
  43. % This program is distributed in the hope that it will be useful,
  44. % but WITHOUT ANY WARRANTY; without even the implied warranty of
  45. % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  46. % GNU General Public License for more details.
  47. %
  48. % You should have received a copy of the GNU General Public License
  49. % along with this program. If not, see <http://www.gnu.org/licenses/>.
  50. %}
  51. % =========================================================================
  52. %% Filtering Code
  53. function filteredProj = filterProj(proj,param,cutoff,filterOrder)
  54. filteredProj = zeros(size(proj),'single');
  55. % Detector Coordinate sytem in (mm)
  56. [uCoord,vCoord] = meshgrid(param.us,param.vs);
  57. % Compute weighted projections (Fessler Book Eq. (3.10.6))
  58. weightFunction = param.DSO ./ sqrt((param.DSD.^2)+(vCoord.^2)+(uCoord.^2));
  59. % Apply weighting function on each proj
  60. for i=1:param.nProj
  61. filteredProj(:,:,i) = proj(:,:,i).* weightFunction;
  62. end
  63. % Increase filter length to two times nv to decrease freq step
  64. h_Length = 2^nextpow2(2*param.nv);
  65. % Builds ramp filter in space domain
  66. ramp_kernel = ramp_builder(h_Length);
  67. % Window filter in freq domain
  68. H_filter = filter_window(ramp_kernel, h_Length, cutoff, filterOrder);
  69. % Replicate to all columns to build a 2D filter kernel
  70. H_filter = repmat(H_filter',1,param.nu);
  71. % Proj in freq domain
  72. H_proj = zeros(h_Length,param.nu,'single');
  73. fprintf('%2d/%2d', 1, param.nProj)
  74. % Filter each projection
  75. for i=1:param.nProj
  76. fprintf('\b\b\b\b\b%2d/%2d', i, param.nProj)
  77. H_proj(1:param.nv,:) = filteredProj(:,:,i);
  78. % Fourier transfor in projections
  79. H_proj = fftshift(fft(H_proj));
  80. % Multiplication in frequency = convolution in space
  81. H_proj = H_proj .* H_filter;
  82. % Inverse Fourier transfor
  83. H_proj = (real(ifft(ifftshift(H_proj))));
  84. filteredProj(:,:,i) = H_proj(1:param.nv,:);
  85. end
  86. end
  87. %% Function Ramp Filter
  88. %{
  89. The function builds Ramp Filter in space domain
  90. Reference: Jiang Hsieh's book (second edition,page 73) Eq. 3.29
  91. Reference: Fessler Book Eq.(3.4.14)
  92. %}
  93. function h = ramp_builder(h_Length)
  94. n = (-(h_Length/2):(h_Length/2-1));
  95. h = zeros(size(n),'single');
  96. h(h_Length/2+1) = 1/4; % Eq. 3.29
  97. odd = mod(n,2) == 1; % Eq. 3.29
  98. h(odd) = -1 ./ (pi * n(odd)).^2; % Eq. 3.29
  99. end
  100. %% Function Window Ramp Filter
  101. %{
  102. The function builds Ramp Filter apodizided in frequency domain
  103. Reference: Fessler Book and MIRT
  104. %}
  105. function H_filter = filter_window(ramp_kernel, h_Length, cutoff, filterOrder)
  106. H_ramp = abs(fftshift(fft(ramp_kernel))); % Bring filter to freq domain
  107. w = round(h_Length*cutoff); % Cut off freq
  108. n = (-(h_Length/2):(h_Length/2-1));
  109. % Hanning filter + applying cut off frequency
  110. H_window = 0.5 * (1 + cos(2*pi*n/w)); % Normal Hanning
  111. H_window = H_window .* (abs(n) < w/2); % Apply cut off freq
  112. %H_window = 1 ./ (1 + (n/w).^ (2*filterOrder)); %Butterworth
  113. H_filter = H_ramp .* H_window; % Apply window filter
  114. end