steer.m 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. % RES = STEER(BASIS, ANGLE, HARMONICS, STEERMTX)
  2. %
  3. % Steer BASIS to the specfied ANGLE.
  4. %
  5. % BASIS should be a matrix whose columns are vectorized rotated copies of a
  6. % steerable function, or the responses of a set of steerable filters.
  7. %
  8. % ANGLE can be a scalar, or a column vector the size of the basis.
  9. %
  10. % HARMONICS (optional, default is N even or odd low frequencies, as for
  11. % derivative filters) should be a list of harmonic numbers indicating
  12. % the angular harmonic content of the basis.
  13. %
  14. % STEERMTX (optional, default assumes cosine phase harmonic components,
  15. % and filter positions at 2pi*n/N) should be a matrix which maps
  16. % the filters onto Fourier series components (ordered [cos0 cos1 sin1
  17. % cos2 sin2 ... sinN]). See steer2HarmMtx.m
  18. % Eero Simoncelli, 7/96.
  19. function res = steer(basis,angle,harmonics,steermtx)
  20. num = size(basis,2);
  21. if ( any(size(angle) ~= [size(basis,1) 1]) & any(size(angle) ~= [1 1]) )
  22. error('ANGLE must be a scalar, or a column vector the size of the basis elements');
  23. end
  24. %% If HARMONICS are not passed, assume derivatives.
  25. if (exist('harmonics') ~= 1)
  26. if (mod(num,2) == 0)
  27. harmonics = [0:(num/2)-1]'*2 + 1;
  28. else
  29. harmonics = [0:(num-1)/2]'*2;
  30. end
  31. else
  32. harmonics = harmonics(:);
  33. if ((2*size(harmonics,1)-any(harmonics == 0)) ~= num)
  34. error('harmonics list is incompatible with basis size');
  35. end
  36. end
  37. %% If STEERMTX not passed, assume evenly distributed cosine-phase filters:
  38. if (exist('steermtx') ~= 1)
  39. steermtx = steer2HarmMtx(harmonics, pi*[0:num-1]/num, 'even');
  40. end
  41. steervect = zeros(size(angle,1),num);
  42. arg = angle * harmonics(find(harmonics~=0))';
  43. if (all(harmonics))
  44. steervect(:, 1:2:num) = cos(arg);
  45. steervect(:, 2:2:num) = sin(arg);
  46. else
  47. steervect(:, 1) = ones(size(arg,1),1);
  48. steervect(:, 2:2:num) = cos(arg);
  49. steervect(:, 3:2:num) = sin(arg);
  50. end
  51. steervect = steervect * steermtx;
  52. if (size(steervect,1) > 1)
  53. tmp = basis' .* steervect';
  54. res = sum(tmp)';
  55. else
  56. res = basis * steervect';
  57. end