im=double(imread('cameraman.tif'));

figure(1);
subplot(2,2,1);
imagesc(im);

im10=imrotate(im,10,'crop');
im10=im10+randn(size(im10))*50;
im10=round(im10);
im10(im10<0)=0;
im10(im10>255)=255;


subplot(2,2,2);
imagesc(im10);

i=1;
rot_amount=-45:45;
clear error_amount;

error_amount=zeros(91,1);

for rot=-45:45
   fixedim=imrotate(im10,rot,'crop');
   rot_amount(i)=rot;
   diff=sum(sum(abs(im(100:200,100:200)-fixedim(100:200,100:200))));
   error_amount(i)=diff;
   subplot(2,2,4);
   imagesc(fixedim(100:200,100:200));
   subplot(2,2,3);
   plot(rot_amount,error_amount);
   drawnow;
   i=i+1;
end
