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:6.28
  %theta=pi/4;
  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];

  A=Tinv*R*T;
  for oy=1:sy
    for ox=1:sx
       oxy=[ox; oy; 1];
       nxy=A*oxy;
       nx=round(nxy(1));
       ny=round(nxy(2));
       if (nx>0 && nx<=sx && ny>0 && ny<=sy)
         timg(ny,nx)=img(oy,ox);
       end
    end
  end
  subplot(1,2,2);
  imagesc(timg);
  drawnow;
end    

