im=imread('~/Desktop/Teaching/Images/flower.tiff');
img=rgb2gray(imresize(im,.25));

figure(1);
subplot(1,2,1);
imagesc(img);
timg=zeros(size(img));

[sy,sx]=size(img);

for theta=0:.01:20.28
  T=[1 0 -sx/2; 0 1 -sy/2; 0 0 1];
  Tinv=T^-1;
  R=[cos(theta) sin(theta) 0; -sin(theta) cos(theta) 0; 0 0 1];
  
  timg=zeros(size(img));

  A=Tinv*R*T;
  Ainv=A^-1;
  for ny=1:sy
    for nx=1:sx
       nxy=[nx; ny; 1];
       oxy=Ainv*nxy;

       ox=round(oxy(1));
       oy=round(oxy(2));
       if (ox>0 && ox<=sx && oy>0 && oy<=sy)
         timg(ny,nx)=img(oy,ox);
       end
    end
  end
  subplot(1,2,2);
  imagesc(timg);
  drawnow;
end    

