% M-Script to test the windowing concept
%
% Authors: Borgo, Soranzo, Grassi
% Date: 2009

load mandrill
WCentx=size(X,1)/2; % calculate the center of image, x axis
WCenty=size(X,2)/2; % calculate the center of image, y axis
WSize=100; % WSize is HALF the length of the square window

% Create the Window
SqWindow=zeros(size(X));
SqWindow([-WSize:WSize]+WCentx,[-WSize:WSize]+WCentx)=1;

[Xax,Yax]=meshgrid([1:size(X,2)],[1:size(X,1)]);
StanDev = 100; % Standard deviation
GaWindow=(1/sqrt(2*pi*StanDev)).*exp(-0.5*(((Xax-WCentx)/StanDev).^2+...
((Yax-WCenty)/StanDev).^2));
GaWindow=GaWindow./max(max(GaWindow)); % Normalization

SqWindowedImage=X.*(SqWindow); % Windowing of the original image;
GaWindowedImage=X.*(GaWindow); % Windowing of the original image;

figure; % Display the window
colormap(gray(255));
subplot(1,2,1);
imagesc(SqWindow); % imagesc is the same as image
% but scale the data to the full
% range of the current colormap
axis off;title('Square Window');
subplot(1,2,2); imagesc(GaWindow*254+1);
axis off;title('Gaussian Window');

figure; % Display the windowed image
colormap(gray(255));
subplot(1,2,1);imagesc(SqWindowedImage);
axis off; title('Squared Windowed Image');
subplot(1,2,2);imagesc(GaWindowedImage);
axis off;title('Gaussian Windowed Image');