steer2HarmMtx.m 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. % MTX = steer2HarmMtx(HARMONICS, ANGLES, REL_PHASES)
  2. %
  3. % Compute a steering matrix (maps a directional basis set onto the
  4. % angular Fourier harmonics). HARMONICS is a vector specifying the
  5. % angular harmonics contained in the steerable basis/filters. ANGLES
  6. % (optional) is a vector specifying the angular position of each filter.
  7. % REL_PHASES (optional, default = 'even') specifies whether the harmonics
  8. % are cosine or sine phase aligned about those positions.
  9. % The result matrix is suitable for passing to the function STEER.
  10. % Eero Simoncelli, 7/96.
  11. function mtx = steer2HarmMtx(harmonics, angles, evenorodd)
  12. %%=================================================================
  13. %%% Optional Parameters:
  14. if (exist('evenorodd') ~= 1)
  15. evenorodd = 'even';
  16. end
  17. % Make HARMONICS a row vector
  18. harmonics = harmonics(:)';
  19. numh = 2*size(harmonics,2) - any(harmonics == 0);
  20. if (exist('angles') ~= 1)
  21. angles = pi * [0:numh-1]'/numh;
  22. else
  23. angles = angles(:);
  24. end
  25. %%=================================================================
  26. if isstr(evenorodd)
  27. if strcmp(evenorodd,'even')
  28. evenorodd = 0;
  29. elseif strcmp(evenorodd,'odd')
  30. evenorodd = 1;
  31. else
  32. error('EVEN_OR_ODD should be the string EVEN or ODD');
  33. end
  34. end
  35. %% Compute inverse matrix, which maps Fourier components onto
  36. %% steerable basis.
  37. imtx = zeros(size(angles,1),numh);
  38. col = 1;
  39. for h=harmonics
  40. args = h*angles;
  41. if (h == 0)
  42. imtx(:,col) = ones(size(angles));
  43. col = col+1;
  44. elseif evenorodd
  45. imtx(:,col) = sin(args);
  46. imtx(:,col+1) = -cos(args);
  47. col = col+2;
  48. else
  49. imtx(:,col) = cos(args);
  50. imtx(:,col+1) = sin(args);
  51. col = col+2;
  52. end
  53. end
  54. r = rank(imtx);
  55. if (( r ~= numh ) & ( r ~= size(angles,1) ))
  56. fprintf(2,'WARNING: matrix is not full rank');
  57. end
  58. mtx = pinv(imtx);