% Fourier Transform Rotate Operator Demo
close all; clear all;
% Define Initial box

xwidth = 40;
ywidth = 40;

% Create a white box on a black background image
M= 256; N = 256;

x0 = M/2 - xwidth/2;
y0 = N/2 - ywidth/2;


image1 = zeros(M,N);
box = ones(xwidth,ywidth);
%box at centre
image1(x0:x0+xwidth-1,y0:y0+ywidth-1) = box;

% Define scale
scalex = 0.5;
scaley = 0.5;


% Image 2 = Scaled Image 1
image2 = zeros(M,N);
[px,qx] = rat(scalex);
[py,qy] = rat(scaley);

in_image2 = resample(resample(double(image1),px,qx)',py,qy)';

xrange = int16(M/2-M*scalex/2:M/2+M*scalex/2-1);
yrange = int16(N/2-N*scaley/2:N/2+N*scaley/2-1);
image2(xrange,yrange)= in_image2; 

figure(1)
imshow(image1);
title('Image 1');

figure(2)
imshow(image2);
title('Image 2');

% Compute  Fourier Transfoms.
imft1 = fft2(double(image1));
imft2 = fft2(double(image2));

figure(3)
imagesc(abs(fftshift(imft1)))
title('Fourier Transform of Image 1 (imft1)');

figure(4)
imagesc(abs(fftshift(imft2)))
title('Fourier Transform of Image 2 (imft2)');