%% magorphase.m
%% 
%% Script to create some figures comparing the importance of magnitude and
%% phase in the Cal band image so familiar to the ECE 1467 W02 sufferers. 
%% 
%% Requires the file m10067_1.mat to be in the current directory or on
%% Matlab's path. 
%% 
%% v 1.0
%% DH Brooks, Feb 2002
%%
%% v 1.1
%% modified to make all colormaps gray and to update image reading function
%% DH Brooks, Feb 2004

%% load image --> variable data and compute its 2d Fourier Transform (FT)

[data,map] = imread('m10067_1.tif', 'tif');
fdata = fft2(data);

%% create a new FT fmag with same magnitude but random phase

fmag = abs(fdata).*exp(j*(rand(size(fdata))*2*pi - pi));

%% create a new FT frandmagphase with same phase but random magnitude

frandmagphase = rand(size(data)).*exp(j*angle(fdata));

%% create a new FT fphase with constant magnitude but same phase

fphase = 1*exp(j*angle(fdata));

%% in 3 figure windows, show images of inverse FT's of each of these images

figure(1)
imagesc(abs(ifft2(fmag)))
title('Keep magnitude, random phase')
axis image
colormap('gray')

figure(2)
imagesc(abs(ifft2(frandmagphase)))
title('Keep phase, random magnitude')
axis image
colormap('gray')

figure(3)
imagesc(abs(ifft2(fphase)))
title('Keep  phase, constant magnitude')
axis image
colormap('gray')
