function varargout = Fourier_demo(varargin)

%%%Dr. Ignacio Serrano-Pedraza 2018
%%%iserrano@ucm.es

% Based on the original idea of:
% Two-Dimensional Fourier Image Reconstruction (Inverse FT) Demo using Matlab
% Authors: Kota S. Sasaki and Izumi Ohzawa
% Graduate School of Frontier Biosciences, Osaka University




% FOURIER_DEMO MATLAB code for Fourier_demo.fig
%      FOURIER_DEMO, by itself, creates a new FOURIER_DEMO or raises the existing
%      singleton*.
%
%      H = FOURIER_DEMO returns the handle to a new FOURIER_DEMO or the handle to
%      the existing singleton*.
%
%      FOURIER_DEMO('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in FOURIER_DEMO.M with the given input arguments.
%
%      FOURIER_DEMO('Property','Value',...) creates a new FOURIER_DEMO or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before Fourier_demo_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to Fourier_demo_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help Fourier_demo

% Last Modified by GUIDE v2.5 09-Mar-2018 18:02:48

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;

gui_State = struct('gui_Name',       mfilename, ...
    'gui_Singleton',  gui_Singleton, ...
    'gui_OpeningFcn', @Fourier_demo_OpeningFcn, ...
    'gui_OutputFcn',  @Fourier_demo_OutputFcn, ...
    'gui_LayoutFcn',  [] , ...
    'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT

% --- Executes just before Fourier_demo is made visible.
function Fourier_demo_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to Fourier_demo (see VARARGIN)

% Choose default command line output for Fourier_demo
handles.output = hObject;
set(hObject,'WindowButtonDownFcn',  @mouseDown);
set(hObject,'WindowButtonMotionFcn',@mouseMove);
set(hObject,'WindowButtonUpFcn',    @mouseUp);
% Play_sound handles structure
guidata(hObject, handles);

Plot_figure(hObject, eventdata, handles)


function Plot_figure(hObject, eventdata, handles)
expt = getexpt(handles);
for i=1:255
    r(i)=i/255;
    g(i)=i/255;
    b(i)=i/255;
end

gray2=[r',g',b'];
colormap(gray2);
map=colormap;

degreesimagex=8;
degreesimagey=degreesimagex;
TAMX=64;
TAMY=64;
gx=degreesimagex/TAMX;%Degrees of visual angle in x direction
gy=degreesimagey/TAMY;%Degrees of visual angle in y direction

[x,y]=meshgrid(-degreesimagex/2:(degreesimagex/TAMX):((degreesimagex/2)-(degreesimagex/TAMX))...
    ,((degreesimagey/2)):-(degreesimagey/TAMY):-((degreesimagey/2)-(degreesimagey/TAMY)));


Angulo=0;
xx=x.*cosd(Angulo)+y.*sind(Angulo);
yy=-x.*sind(Angulo)+y.*cosd(Angulo);

fNu=(TAMX/degreesimagex)/2; %frecuencia de Nyquist en el eje u
fNv=(TAMY/degreesimagey)/2; %frecuencia de Nyquist en el eje v
fu=fNu*2/TAMX; %sampling rate in frequency en el eje u c/deg  c/gav otra opcion es fu=1/degreesimagex
fv=fNv*2/TAMY; %sampling rate in frequency en el eje v c/deg  c/gav otra opcion es fv=1/degreesimagey
[u,v]=meshgrid(-fNu:(2*fNu/TAMX):fNu-(2*fNu/TAMX),fNv:-(2*fNv/TAMY):-(fNv-(2*fNv/TAMY)));

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

axes(handles.Plot1);
cla;
loadimagenes_index = get(handles.loadimagenes, 'Value');
%expt = getexpt(handles);

switch loadimagenes_index
    case 1
        imagen=double(imread('IMAGES/Arturo1.pcx','pcx'));
        
    case 2
        imagen=double(imread('IMAGES/Arturo1.pcx','pcx'));
    case 3
        imagen=double(imread('IMAGES/barbara.pcx','pcx'));
    case 4
        imagen=double(imread('IMAGES/boat.pcx','pcx'));
    case 5
        imagen=double(imread('IMAGES/Bush.pcx','pcx'));
    case 6
        imagen=double(imread('IMAGES/Cibeles.pcx','pcx'));
    case 7
        imagen=double(imread('IMAGES/Einstein_Marilyn.pcx','pcx'));
    case 8
        imagen=double(imread('IMAGES/Face.pcx','pcx'));
    case 9
        imagen=double(imread('IMAGES/flinstones.pcx','pcx'));
    case 10
        imagen=double(imread('IMAGES/Helmholtz.pcx','pcx'));
    case 11
        imagen=double(imread('IMAGES/mullerlyer.pcx','pcx'));
    case 12
        imagen=double(imread('IMAGES/Noise_1_f.pcx','pcx'));
    case 13
        imagen=double(imread('IMAGES/Noise_gaussian.pcx','pcx'));
    case 14
        imagen=double(imread('IMAGES/Noise_uniform.pcx','pcx'));
    case 15
        imagen=double(imread('IMAGES/Obama.pcx','pcx'));
    case 16
        imagen=double(imread('IMAGES/pamela.pcx','pcx'));
    case 17
        imagen=double(imread('IMAGES/Tiger.pcx','pcx'));
    case 18
        imagen=double(imread('IMAGES/Uc3g.pcx','pcx'));
end
imagen=imresize(imagen,0.125);
Image2D=(127.5*(1+2*((imagen./max(max(abs(imagen))))-0.5)));%%
image(Image2D)
colormap(gray2);
map=colormap;
set(gca,'Fontsize',11);
set(gca,'LineWidth',1);
set(gca,'xcolor','k');
set(gca,'ycolor','k');
set(gca, 'xtickmode','manual');
set(gca, 'ytickmode','manual');
if degreesimagex>=8
    grados=round(linspace(-degreesimagex/2,degreesimagex/2,9));
    grados2=round(linspace(-degreesimagex/2,degreesimagex/2,9));
else
    
    grados=[-degreesimagex/2:degreesimagex/2];
    grados2=[-degreesimagex/2:degreesimagex/2];
    
end
gradosconv=(((grados/(degreesimagex/2))*(TAMX/4)+(TAMX/4))*2+1);
gradosconv(:,length(gradosconv))=TAMX;
set(gca,'xtick',gradosconv);
set(gca,'XTickLabel',grados);
set(gca,'ytick',gradosconv);
set(gca,'yTickLabel',grados2);
title('Image')
xlabel('Postition (degrees)')
ylabel('Postition (degrees)')
axis square


axes(handles.Plot2);
cla;

I=Image2D;
Lave=sum(sum(I.*gx*gy))./(degreesimagex*degreesimagey);
c=(I-Lave)./Lave;%Contrast function
FFTimagen=fftshift(fft2(c));
FFTmodulo=abs(FFTimagen);
FASEimagen=angle(FFTimagen);
MODULOimagen=log10(1+abs(FFTimagen));

if expt.logvaluesbutton==1
    FFTmoduloNORMALIZADO=((255*(MODULOimagen./max(max(abs(MODULOimagen))))));
    FFTmoduloNORMALIZADO(TAMX/2+1,TAMX/2+1)=255;
else
    FFTmoduloNORMALIZADO=255*((abs(FFTimagen))./max(max((abs(FFTimagen)))));
    FFTmoduloNORMALIZADO(TAMX/2+1,TAMX/2+1)=255;
end
imagen=FFTmoduloNORMALIZADO;
frecmax=(TAMX/degreesimagex)/2;
imagen=imagen;
image(imagen)
set(gca,'Fontsize',11);
set(gca,'LineWidth',2);
set(gca,'xcolor','k');
set(gca,'ycolor','k');
set(gca, 'xtickmode','manual');
set(gca, 'ytickmode','manual');
frecuencias=[-frecmax -frecmax/2 -frecmax/4  -frecmax/8 0 frecmax/8  frecmax/4 frecmax/2 frecmax];
frecuencias2=[frecmax frecmax/2 frecmax/4  frecmax/8 0 -frecmax/8  -frecmax/4 -frecmax/2 -frecmax];
frecuenciasconv=(((frecuencias/frecmax)*(TAMX/4)+(TAMX/4))*2+1);
frecuenciasconv(:,length(frecuenciasconv))=TAMX;
set(gca,'xtick',frecuenciasconv);
set(gca,'XTickLabel',frecuencias)
set(gca,'ytick',frecuenciasconv);
set(gca,'yTickLabel',frecuencias2)
title('2D Amplitude spectrum')
xlabel('Spatial frequency (c/deg)')
ylabel('Spatial frequency (c/deg)')
axis square

colormap(gray2)

s.FTM_reconstructed=0*ones(TAMX,TAMY);
s.MODULO_reconstructed=0*ones(TAMX,TAMY);
s.MODULO_reconstructed1=0*ones(TAMX,TAMY);
%s.PHASE_reconstructed=0*ones(TAMX,TAMY);
s.FFTmoduloNORMALIZADO=FFTmoduloNORMALIZADO;
s.frequency=0;
s.orientation=0;
s.positionx=TAMX/2+1;
s.positiony=TAMY/2+1;
s.gray2=gray2;
s.FFTmodulo=FFTmodulo;
s.FASEimagen=FASEimagen;
UpdateFFT(s,handles);
set(handles.Plot3, 'UserData', s)



function mouseDown(hObject, eventdata,handles,s)
%handles = guidata(hObject);
% is the mouse down event within the axes?
%status = false;
handles = guidata(hObject);
currentPoint = get((handles.Plot3),'CurrentPoint');

handles.mouseIsDown     = true;
guidata(hObject,handles);
expt = getexpt(handles);


currentPoint = get((handles.Plot3),'CurrentPoint');
x            = round(currentPoint(2,1));
y            = round(currentPoint(2,2));
if (x>=2 && x<=63) && (y>=2 && y<=63)
    degreesimagex=8;
    degreesimagey=degreesimagex;
    TAMX=64;
    TAMY=64;
    
    fNu=(TAMX/degreesimagex)/2; %frecuencia de Nyquist en el eje u
    fNv=(TAMY/degreesimagey)/2; %frecuencia de Nyquist en el eje v
    fu=fNu*2/TAMX; %sampling rate in frequency en el eje u c/deg  c/gav otra opcion es fu=1/degreesimagex
    fv=fNv*2/TAMY; %sampling rate in frequency en el eje v c/deg  c/gav otra opcion es fv=1/degreesimagey
    [u,v]=meshgrid(-fNu:(2*fNu/TAMX):fNu-(2*fNu/TAMX),fNv:-(2*fNv/TAMY):-(fNv-(2*fNv/TAMY)));
    
    vy=-u(x,y);
    ux=-v(x,y);
    
    frequency=sqrt(ux^2+vy^2);
    orientation=atan2d(vy,ux);
    set(handles.spatialfrequency, 'String',num2str(frequency,'%10.3f'));
    set(handles.Orientation, 'String',num2str(orientation,'%10.3f'));
    set(handles.positionx, 'String',num2str(x,'%10.3f'));
    set(handles.positiony, 'String',num2str(y,'%10.3f'));
    
    s = get(handles.Plot3, 'UserData');
    s.frequency=frequency;
    s.orientation=orientation;
    s.positionx=x;
    s.positiony=y;
    UpdateFFT(s,handles);
    
end




function  mouseUp(hObject, eventdata,handles,s)
handles = guidata(hObject);
if isfield(handles,'mouseIsDown')
    if handles.mouseIsDown
        
        handles.mouseIsDown     = false;
        handles.movingPlotHndle = [];
        handles.prevPoint       = [];
        
        % save the data
        guidata(handles.Plot3,handles);
    end
end

function mouseMove(hObject, eventdata, handles)
handles = guidata(hObject);

if isfield(handles,'mouseIsDown')
    if handles.mouseIsDown
        expt = getexpt(handles);
        
        
        currentPoint = get((handles.Plot3),'CurrentPoint');
        x            = round(currentPoint(2,1));
        y            = round(currentPoint(2,2));
        if (x>=2 && x<=63) && (y>=2 && y<=63)
            degreesimagex=8;
            degreesimagey=degreesimagex;
            TAMX=64;
            TAMY=64;
            
            fNu=(TAMX/degreesimagex)/2; %frecuencia de Nyquist en el eje u
            fNv=(TAMY/degreesimagey)/2; %frecuencia de Nyquist en el eje v
            fu=fNu*2/TAMX; %sampling rate in frequency en el eje u c/deg  c/gav otra opcion es fu=1/degreesimagex
            fv=fNv*2/TAMY; %sampling rate in frequency en el eje v c/deg  c/gav otra opcion es fv=1/degreesimagey
            [u,v]=meshgrid(-fNu:(2*fNu/TAMX):fNu-(2*fNu/TAMX),fNv:-(2*fNv/TAMY):-(fNv-(2*fNv/TAMY)));
            
            vy=-u(x,y);
            ux=-v(x,y);
            
            frequency=sqrt(ux^2+vy^2);
            orientation=atan2d(vy,ux);
            set(handles.spatialfrequency, 'String',num2str(frequency,'%10.3f'));
            set(handles.Orientation, 'String',num2str(orientation,'%10.3f'));
            set(handles.positionx, 'String',num2str(x,'%10.3f'));
            set(handles.positiony, 'String',num2str(y,'%10.3f'));
            s = get(handles.Plot3, 'UserData');
            s.frequency=frequency;
            s.orientation=orientation;
            s.positionx=x;
            s.positiony=y;
            s = UpdateFFT(s,handles);
        end
        
    end
    
end


function s = UpdateFFT(s,handles)


axes(handles.Plot3);
cla;
TAMX=64;
TAMY=64;
degreesimagex=8;
degreesimagey=8;
if (s.positionx ~= TAMX/2+1 || s.positiony ~= TAMY/2+1)
    s.FTM_reconstructed([s.positiony],[s.positionx])=s.FFTmoduloNORMALIZADO(s.positiony,s.positionx);
    s.FTM_reconstructed([TAMX-s.positiony:TAMX-s.positiony],[TAMY-s.positionx:TAMY-s.positionx])=s.FFTmoduloNORMALIZADO(TAMX-s.positiony,TAMY-s.positionx);
else
    s.FTM_reconstructed([TAMX/2+1],[TAMX/2+1])=s.FFTmoduloNORMALIZADO(TAMX/2+1,TAMX/2+1);
end
set(handles.Plot3, 'UserData', s);
imagen=s.FTM_reconstructed;
frecmax=(TAMX/degreesimagex)/2;
image(imagen);
set(gca,'Fontsize',11);
set(gca,'LineWidth',2);
set(gca,'xcolor','k');
set(gca,'ycolor','k');
set(gca, 'xtickmode','manual');
set(gca, 'ytickmode','manual');
frecuencias=[-frecmax -frecmax/2 -frecmax/4  -frecmax/8 0 frecmax/8  frecmax/4 frecmax/2 frecmax];
frecuencias2=[frecmax frecmax/2 frecmax/4  frecmax/8 0 -frecmax/8  -frecmax/4 -frecmax/2 -frecmax];
frecuenciasconv=(((frecuencias/frecmax)*(TAMX/4)+(TAMX/4))*2+1);
frecuenciasconv(:,length(frecuenciasconv))=TAMX;
set(gca,'xtick',frecuenciasconv);
set(gca,'XTickLabel',frecuencias)
set(gca,'ytick',frecuenciasconv);
set(gca,'yTickLabel',frecuencias2)
title('Move the mouse (2D Amplitude Spectrum)')
xlabel('Spatial frequency (c/deg)')
ylabel('Spatial frequency (c/deg)')
axis square
colormap(s.gray2)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
axes(handles.Plot4);
cla;
s.MODULO_reconstructed1=0*ones(TAMX,TAMY);
s.MODULO_reconstructed1(s.positiony,s.positionx)=s.FFTmodulo(s.positiony,s.positionx);
REALPROD=fftshift(s.MODULO_reconstructed1.*cos(s.FASEimagen));
IMAGPROD=fftshift(s.MODULO_reconstructed1.*sin(s.FASEimagen));
RESULTADO=(REALPROD+IMAGPROD*sqrt(-1));
FINAL=ifft2(RESULTADO);
IMAGENFILTRADA=real(FINAL);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Image2D=(127.5*(1+1*(IMAGENFILTRADA./max(max(abs(IMAGENFILTRADA))))));%

image(Image2D)
colormap(s.gray2);
map=colormap;
set(gca,'Fontsize',11);
set(gca,'LineWidth',1);
set(gca,'xcolor','k');
set(gca,'ycolor','k');
set(gca, 'xtickmode','manual');
set(gca, 'ytickmode','manual');
if degreesimagex>=8
    grados=round(linspace(-degreesimagex/2,degreesimagex/2,9));
    grados2=round(linspace(-degreesimagex/2,degreesimagex/2,9));
else
    
    grados=[-degreesimagex/2:degreesimagex/2];
    grados2=[-degreesimagex/2:degreesimagex/2];
    
end
gradosconv=(((grados/(degreesimagex/2))*(TAMX/4)+(TAMX/4))*2+1);
gradosconv(:,length(gradosconv))=TAMX;
set(gca,'xtick',gradosconv);
set(gca,'XTickLabel',grados);
set(gca,'ytick',gradosconv);
set(gca,'yTickLabel',grados2);
title('Grating that is adding')
xlabel('Postition (degrees)')
ylabel('Postition (degrees)')
axis square


axes(handles.Plot5);
cla;
s.MODULO_reconstructed(s.positiony,s.positionx)=s.FFTmodulo(s.positiony,s.positionx);
set(handles.Plot3, 'UserData', s);
REALPROD=fftshift(s.MODULO_reconstructed.*cos(s.FASEimagen));
IMAGPROD=fftshift(s.MODULO_reconstructed.*sin(s.FASEimagen));
RESULTADO=(REALPROD+IMAGPROD*sqrt(-1));
FINAL=ifft2(RESULTADO);
IMAGENFILTRADA=real(FINAL);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Image2D=(127.5*(1+1*(IMAGENFILTRADA./max(max(abs(IMAGENFILTRADA))))));
image(Image2D)
colormap(s.gray2);
map=colormap;
set(gca,'Fontsize',11);
set(gca,'LineWidth',1);
set(gca,'xcolor','k');
set(gca,'ycolor','k');
set(gca, 'xtickmode','manual');
set(gca, 'ytickmode','manual');
if degreesimagex>=8
    grados=round(linspace(-degreesimagex/2,degreesimagex/2,9));
    grados2=round(linspace(-degreesimagex/2,degreesimagex/2,9));
else
    
    grados=[-degreesimagex/2:degreesimagex/2];
    grados2=[-degreesimagex/2:degreesimagex/2];
    
end
gradosconv=(((grados/(degreesimagex/2))*(TAMX/4)+(TAMX/4))*2+1);
gradosconv(:,length(gradosconv))=TAMX;
set(gca,'xtick',gradosconv);
set(gca,'XTickLabel',grados);
set(gca,'ytick',gradosconv);
set(gca,'yTickLabel',grados2);
title('Image recovered')
xlabel('Postition (degrees)')
ylabel('Postition (degrees)')
axis square




% --- Outputs from this function are returned to the command line.
function varargout = Fourier_demo_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;




% --------------------------------------------------------------------
function OpenMenuItem_Callback(hObject, eventdata, handles)
% hObject    handle to OpenMenuItem (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
file = uigetfile('*.fig');
if ~isequal(file, 0)
    open(file);
end


% --- Executes during object creation, after setting all properties.
function Contrast_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Contrast (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

function expt = getexpt(handles)
% Reads off key data from GUI
%expt = handles.expt;

spatialfrequency = get(handles.spatialfrequency,'string');
expt.spatialfrequency = str2double(spatialfrequency);
Orientation = get(handles.Orientation,'string');
expt.Orientation = str2double(Orientation);

positionx = get(handles.positionx,'string');
expt.positionx = str2double(positionx);
positiony = get(handles.positiony,'string');
expt.positiony = str2double(positiony);

expt.logvaluesbutton= get(handles.logvaluesbutton,'value');
expt.linearvaluesbutton= get(handles.linearvaluesbutton,'value');



% --- Executes on button press in Plot_figure.
function Plot_figure_Callback(hObject, eventdata, handles)
% hObject    handle to Plot_figure (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

Plot_figure(hObject, eventdata, handles)

function CloseMenuItem_Callback(hObject, eventdata, handles)
% hObject    handle to CloseMenuItem (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
selection = questdlg(['Close ' get(handles.axixX,'Name') '?'],...
    ['Close ' get(handles.axixX,'Name') '...'],...
    'Yes','No','Yes');
if strcmp(selection,'No')
    return;
end

delete(handles.axixX)
% --------------------------------------------------------------------
function PrintMenuItem_Callback(hObject, eventdata, handles)
% hObject    handle to PrintMenuItem (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
printdlg(handles.axixX)

% --------------------------------------------------------------------
function FileMenu_Callback(hObject, eventdata, handles)
% hObject    handle to FileMenu (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in Reset.
function Reset_Callback(hObject, eventdata, handles)
% hObject    handle to Reset (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

set(handles.spatialfrequency,'String',0);
set(handles.Orientation,'String',0);
set(handles.positionx,'String',0);
set(handles.positiony,'String',0);
set(handles.logvaluesbutton,'Value',1);
set(handles.linearvaluesbutton,'Value',0);

Plot_figure(hObject, eventdata, handles)




% --- Executes on button press in logvaluesbutton.
function logvaluesbutton_Callback(hObject, eventdata, handles)
% hObject    handle to logvaluesbutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of logvaluesbutton
set(handles.linearvaluesbutton,'Value',0);
set(handles.logvaluesbutton,'Value',1);
Plot_figure(hObject, eventdata, handles)

% --- Executes on button press in linearvaluesbutton.
function linearvaluesbutton_Callback(hObject, eventdata, handles)
% hObject    handle to linearvaluesbutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
set(handles.logvaluesbutton,'Value',0);
set(handles.linearvaluesbutton,'Value',1);
Plot_figure(hObject, eventdata, handles)
% Hint: get(hObject,'Value') returns toggle state of linearvaluesbutton




% --- Executes on selection change in loadimagenes.
function loadimagenes_Callback(hObject, eventdata, handles)
% hObject    handle to loadimagenes (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns loadimagenes contents as cell array
%        contents{get(hObject,'Value')} returns selected item from loadimagenes

Plot_figure(hObject, eventdata, handles)

% --- Executes during object creation, after setting all properties.
function loadimagenes_CreateFcn(hObject, eventdata, handles)
% hObject    handle to loadimagenes (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function spatialfrequency_Callback(hObject, eventdata, handles)
% hObject    handle to spatialfrequency (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of spatialfrequency as text
%        str2double(get(hObject,'String')) returns contents of spatialfrequency as a double


% --- Executes during object creation, after setting all properties.
function spatialfrequency_CreateFcn(hObject, eventdata, handles)
% hObject    handle to spatialfrequency (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function Orientation_Callback(hObject, eventdata, handles)
% hObject    handle to spatialfrequency (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of spatialfrequency as text
%        str2double(get(hObject,'String')) returns contents of spatialfrequency as a double


% --- Executes during object creation, after setting all properties.
function Orientation_CreateFcn(hObject, eventdata, handles)
% hObject    handle to spatialfrequency (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function positionx_Callback(hObject, eventdata, handles)
% hObject    handle to positionx (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of positionx as text
%        str2double(get(hObject,'String')) returns contents of positionx as a double


% --- Executes during object creation, after setting all properties.
function positionx_CreateFcn(hObject, eventdata, handles)
% hObject    handle to positionx (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function positiony_Callback(hObject, eventdata, handles)
% hObject    handle to positiony (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of positiony as text
%        str2double(get(hObject,'String')) returns contents of positiony as a double


% --- Executes during object creation, after setting all properties.
function positiony_CreateFcn(hObject, eventdata, handles)
% hObject    handle to positiony (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
