% retransrot.m                                      Steve Mann, 1993
% ax+b group image resampling for testing Peleg algorithm.
%
% This function will rotate and translate an image at subpixel resolution.
% An additional feature (for future use) is that it can scale an image.
%
% Note the group is the forward mapping y=g(ax+b) (not (x-b)/a)
%      so rot, trans, etc reversed: g(x+1) is a _decrease_ along the real axis
%
% Use: Y = retransrot(a,X,b,interp_order,antialias_method,myNaN)
%          a is dilation: angle(a) is rotation      to act on X
%          X is input image
%          b is translation (real part is downward axis, imag part, right axis)
%
% Examples: tv(retransrot(exp(i*30*o),red)) % -30o rotated counterclockwise
%           tv(retransrot(1,red,3+4*i))    % translated -3 pixels down, -4 right
%           tv(retransrot(2,red) % displays function Y=red(2X) which is smaller
%
% retransrot(2,red,-100) is red(2x-100) = red((x-50)/.5); so 50 pel shift right
%
% retransrot(a,red,b,3,-1,255); % uses bicubic interp and makes background=255
% see also retransrotxy, detransrotxy

function Y = resamplerforPeleg(a,X,b, interp_order, antialias_method, myNaN)

if nargin == 5
  disp('retransrot: setting myNaN=NaN (default background grey level)')
  myNaN=NaN;  % default NaN
end%if

if nargin == 4
  disp('retransrot: antialias method defaulting to -1, myNaN defaulting to NaN')
  antialias_method = -1;
  myNaN=NaN;
end%if

if nargin == 3
  disp1='retransrot: interp_order and antialias_method defaulting to 1,-1; ';
  disp2='myNaN to NaN';
  disp([disp1 disp2])
  interp_order = 1;
  antialias_method = -1;
  myNaN=NaN;
end%if

if nargin == 2
  disp1='retransrot: using defaults: b=0, interp_order=1, ';
  disp2='antialias_method=-1, myNaN=NaN';
  disp([disp1 disp2])
  b=0;
  interp_order = 1;
  antialias_method = -1;
  myNaN=NaN;
end%if

if nargin == 1
  disp('--------------------------------------------')
  disp('retransrot: you MUST specify an input image, X')
  disp('--------------------------------------------')
  return
end%if

if nargin == 0
  disp('---------------------------------------------------------------------')
  disp('retransrot: you MUST specify the dilation parameter,a, and the image,X')
  disp('---------------------------------------------------------------------')
  return
end%if

image_size = size(X);  % could also use sizec: caffine2p can take both
p = caffine2p(a,b,image_size); %parameters for the image interpolator ``pchirp''

%%%Y = pchirp_0order(p,X);  % p acts on X

[M,N] = size(X);  % image size for output size = input size
M_out = M;  % output size = input size
N_out = N;
Y = pchirp2ia(p,X,interp_order,antialias_method,myNaN,M_out,N_out,1);% p acts on X

