%  Show manipulation of 2D transforms
%  and the influence of phase and amplitude
%
%  Version 1, JAJ, 20/5-2003, NE 2003
%  Version 1.1, JAJ, 3/11-2003
%     Using local files for data

%  Load the different data and calculate

%load C:\MATLABR11\toolbox\matlab\demos\spine
load spine
spine=X;
disp('Calculating spectra of images...')
dft2_spine=fft2(X,512,512);
abs_spine=20*log10(fftshift(abs(dft2_spine)));
abs_spine=abs_spine-max(max(abs_spine));

%load C:\MATLABR11\toolbox\matlab\demos\mandrill
load mandrill
mandril=X;
dft2_mandril=fft2(X,512,512);
abs_mandril=20*log10(fftshift(abs(dft2_mandril)));
abs_mandril=abs_mandril-max(max(abs_mandril));

ult=(sin(2*pi*6/512*(1:512)).*hanning(512)')' * hanning(512)';
dft2_ult=fft2(ult,512,512);
abs_ult=20*log10(fftshift(abs(dft2_ult)));
abs_ult=abs_ult-max(max(abs_ult));

%  Make the inverse transform

new_img_ult=real(ifft2(abs(dft2_ult).*exp(sqrt(-1)*angle(dft2_mandril))));
new_img=real(ifft2(abs(dft2_spine).*exp(sqrt(-1)*angle(dft2_mandril))));

%  Show the different possibilites and make buttons for it

clf
hp1=axes('position',[0.20 0.55 0.35 0.4]);  
hp2=axes('position',[0.60 0.55 0.35 0.4]);  
hp3=axes('position',[0.20 0.07 0.35 0.4]);  
hp4=axes('position',[0.60 0.07 0.35 0.4]);  

t1=uicontrol('Style','Pushbutton','Units','normalized','Position',[0.01 0.8 0.1 0.08],...
              'Callback','axes(hp1); imagesc(spine); title(''Amplitude from image''); colormap(gray); axes(hp2); imagesc(mandril); title(''Phase from image''); colormap(gray);',...
              'String','Nrml img');

t2=uicontrol('Style','Pushbutton','Units','normalized','Position',[0.01 0.7 0.1 0.08],...
              'Callback','axes(hp1); imagesc(ult); title(''Amplitude from image''); colormap(gray); axes(hp2); imagesc(mandril); title(''Phase from image''); colormap(gray);',...
              'String','Ult img');

t3=uicontrol('Style','Pushbutton','Units','normalized','Position',[0.01 0.6 0.1 0.08],...
              'Callback','show_spectrum(hp3,abs_spine); show_spectrum(hp4,abs_mandril);',...
              'String','Nrml spec');

t4=uicontrol('Style','Pushbutton','Units','normalized','Position',[0.01 0.5 0.1 0.08],...
              'Callback','show_spectrum(hp3,abs_ult); show_spectrum(hp4,abs_mandril);',...
              'String','Ult spec');

t5=uicontrol('Style','Pushbutton','Units','normalized','Position',[0.01 0.4 0.1 0.08],...
              'Callback','axes(hp3); imagesc(new_img); colormap(gray);',...
              'String','Nrml comb');

t6=uicontrol('Style','Pushbutton','Units','normalized','Position',[0.01 0.3 0.1 0.08],...
              'Callback','axes(hp3); imagesc(new_img_ult); colormap(gray);',...
              'String','Ult comb');

