/code/3D image registration/dtcwt_toolbox4_3/colifilt.m

http://sparse-mri-reconstruction.googlecode.com/ · MATLAB · 98 lines · 51 code · 21 blank · 26 comment · 7 complexity · 5b405a7f148be90e180e3c21e2427342 MD5 · raw file

  1. function Y = colifilt(X, ha, hb)
  2. % function Y = colifilt(X, ha, hb)
  3. % Filter the columns of image X using the two filters ha and hb = reverse(ha).
  4. % ha operates on the odd samples of X and hb on the even samples.
  5. % Both filters should be even length, and h should be approx linear phase with
  6. % a quarter sample advance from its mid pt (ie |h(m/2)| > |h(m/2 + 1)|).
  7. %
  8. % ext left edge right edge ext
  9. % Level 2: ! | ! | !
  10. % +q filt on x b b a a a a b b
  11. % -q filt on o a a b b b b a a
  12. % Level 1: ! | ! | !
  13. % odd filt on . b b b b a a a a a a a a b b b b
  14. % odd filt on . a a a a b b b b b b b b a a a a
  15. %
  16. % The output is interpolated by two from the input sample rate and the results
  17. % from the two filters, Ya and Yb, are interleaved to give Y.
  18. % Symmetric extension with repeated end samples is used on the composite X
  19. % columns before each filter is applied.
  20. %
  21. % Cian Shaffrey, Nick Kingsbury
  22. % Cambridge University, August 2000
  23. % Modified to be fast if X = 0, May 2002.
  24. [r,c] = size(X);
  25. if rem(r,2) > 0
  26. error('No of rows in X must be a multiple of 2!');
  27. end
  28. m = length(ha);
  29. if m ~= length(hb)
  30. error('Lengths of ha and hb must be the same!');
  31. end
  32. if rem(m,2) > 0
  33. error('Lengths of ha and hb must be even!');
  34. end
  35. m2 = fix(m/2);
  36. Y = zeros(r*2,c);
  37. if ~any(X(:)), return; end
  38. if rem(m2,2) == 0,
  39. % m/2 is even, so set up t to start on d samples.
  40. % Set up vector for symmetric extension of X with repeated end samples.
  41. xe = reflect([(1-m2):(r+m2)], 0.5, r+0.5); % Use 'reflect' so r < m2 works OK.
  42. t = [4:2:(r+m)];
  43. if sum(ha.*hb) > 0,
  44. ta = t; tb = t - 1;
  45. else
  46. ta = t - 1; tb = t;
  47. end
  48. hao = ha(1:2:m);
  49. hae = ha(2:2:m);
  50. hbo = hb(1:2:m);
  51. hbe = hb(2:2:m);
  52. s = 1:4:(r*2);
  53. Y(s,:) = conv2(X(xe(tb-2),:),hae(:),'valid');
  54. Y(s+1,:) = conv2(X(xe(ta-2),:),hbe(:),'valid');
  55. Y(s+2,:) = conv2(X(xe(tb),:),hao(:),'valid');
  56. Y(s+3,:) = conv2(X(xe(ta),:),hbo(:),'valid');
  57. else
  58. % m/2 is odd, so set up t to start on b samples.
  59. % Set up vector for symmetric extension of X with repeated end samples.
  60. xe = reflect([(1-m2):(r+m2)], 0.5, r+0.5); % Use 'reflect' so r < m2 works OK.
  61. t = [3:2:(r+m-1)];
  62. if sum(ha.*hb) > 0,
  63. ta = t; tb = t - 1;
  64. else
  65. ta = t - 1; tb = t;
  66. end
  67. hao = ha(1:2:m);
  68. hae = ha(2:2:m);
  69. hbo = hb(1:2:m);
  70. hbe = hb(2:2:m);
  71. s = 1:4:(r*2);
  72. Y(s,:) = conv2(X(xe(tb),:),hao(:),'valid');
  73. Y(s+1,:) = conv2(X(xe(ta),:),hbo(:),'valid');
  74. Y(s+2,:) = conv2(X(xe(tb),:),hae(:),'valid');
  75. Y(s+3,:) = conv2(X(xe(ta),:),hbe(:),'valid');
  76. end
  77. return