function varargout = Gabor_patch(varargin)
%%%Dr. Ignacio Serrano-Pedraza 2018
%%%iserrano@ucm.es

% GABOR_PATCH MATLAB code for Gabor_patch.fig
%      GABOR_PATCH, by itself, creates a new GABOR_PATCH or raises the existing
%      singleton*.
%
%      H = GABOR_PATCH returns the handle to a new GABOR_PATCH or the handle to
%      the existing singleton*.
%
%      GABOR_PATCH('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in GABOR_PATCH.M with the given input arguments.
%
%      GABOR_PATCH('Property','Value',...) creates a new GABOR_PATCH or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before Gabor_patch_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to Gabor_patch_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 Gabor_patch

% Last Modified by GUIDE v2.5 14-Mar-2018 14:44:58

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
    'gui_Singleton',  gui_Singleton, ...
    'gui_OpeningFcn', @Gabor_patch_OpeningFcn, ...
    'gui_OutputFcn',  @Gabor_patch_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 Gabor_patch is made visible.
function Gabor_patch_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 Gabor_patch (see VARARGIN)

% Choose default command line output for Gabor_patch
handles.output = hObject;

% 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=expt.visualangle;
degreesimagey=degreesimagex;
TAMX=512;
TAMY=512;
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=expt.Orientation;
xx=x.*cosd(Angulo)+y.*sind(Angulo);
yy=-x.*sind(Angulo)+y.*cosd(Angulo);


x0=0;
y0=0;
sx=expt.SizeX;
sy=expt.SizeY;


%sx=sqrt(log(2)).*(1+2.^BOCT)./(pi*sqrt(2).*u1.*(2.^BOCT-1));%%Serrano-Pedraza et al. (2007) JoV.
%sy=sqrt(log(2))/(sqrt(2)*pi*u1*tan(gradosABO/2));;%%Serrano-Pedraza et al. (2007) JoV.



Gaussiana2D=exp(-(xx-x0).^2./(2*sx^2) - (yy-y0).^2./(2*sy^2));

if expt.Contrast>1;set(handles.Contrast,'String',1);expt.Contrast=1;end
if expt.Contrast<0;set(handles.Contrast,'String',0);expt.Contrast=0;end

L0=127.5;%Mean luminance
m=expt.Contrast;%Contraste
u0=expt.Spatial_frequency;

phase=expt.PHASE;%fase

Image2D=L0*(1+m*(cos(2*pi*u0*xx+phase)).*Gaussiana2D);



axes(handles.Plot1);
cla;
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;
xx=x.*cosd(0)+y.*sind(0);
Profile=L0*(1+m*(cos(2*pi*u0*xx+phase)).*Gaussiana2D);
plot(xx(TAMX/2+1,:),Profile(TAMX/2+1,:),'b-',xx(TAMX/2+1,:),L0*ones(length(xx(:,TAMX/2+1)),1),'k--')
if degreesimagex>=8
    grados=round(linspace(-degreesimagex/2,degreesimagex/2,9));
else
    grados=[-degreesimagex/2:degreesimagex/2];
    
end
set(gca,'xtick',grados);
set(gca,'XTickLabel',grados);
title('Luminance profile')
xlabel('Postition (degrees)')
ylabel('Pixel value')
axis([-degreesimagex/2 degreesimagex/2 0 256])


axes(handles.Plot3);
cla;
mesh(Image2D)
view([50 43])

title('3D plot')

xlabel('Postition (degrees)')
ylabel('Postition (degrees)')

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);
set(gca,'ztick',[0:64:256]);
set(gca,'zTickLabel',[0:64:256]);
axis([0 TAMX 0 TAMY 0 256])


axes(handles.Plot4);
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;
marcacentral=0.*ones(TAMX,TAMX);
marcacentral([TAMX/2:TAMX/2+3],:)=255;
marcacentral(:,[TAMX/2:TAMX/2+3])=255;
imagen((TAMX/2)+1,:)=0;
imagen(:,(TAMX/2)+1)=0;
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)



% --- Outputs from this function are returned to the command line.
function varargout = Gabor_patch_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 Contrast_Callback(hObject, eventdata, handles)
expt = getexpt(handles);
set(handles.contrastslider,  'Value', expt.Contrast);
Plot_figure(hObject, eventdata, handles)

function expt = getexpt(handles)
% Reads off key data from GUI
%expt = handles.expt;
A = get(handles.Contrast,'string');
expt.Contrast = str2double(A);
Spatial = get(handles.Spatial_frequency,'string');
expt.Spatial_frequency = str2double(Spatial);
PHASE = get(handles.Phase,'string');
expt.PHASE = str2double(PHASE);
Orientation = get(handles.Orientation,'string');
expt.Orientation = str2double(Orientation);
SizeX = get(handles.SizeX,'string');
expt.SizeX = str2double(SizeX);
SizeY = get(handles.SizeY,'string');
expt.SizeY = str2double(SizeY);
visualangle = get(handles.visualangle,'string');
expt.visualangle = str2double(visualangle);
expt.freqslider = get(handles.Freqslider,'value');
expt.logvaluesbutton= get(handles.logvaluesbutton,'value');
expt.linearvaluesbutton= get(handles.linearvaluesbutton,'value');
bandwidthfreq = get(handles.bandwidthfreq,'string');
expt.bandwidthfreq = str2double(bandwidthfreq);
bandwidthori = get(handles.bandwidthori,'string');
expt.bandwidthori = str2double(bandwidthori);
expt.contrastslider = get(handles.contrastslider,'value');
expt.orientationslider = get(handles.orientationslider,'value');
expt.phaseslider = get(handles.phaseslider,'value');


function Spatial_frequency_Callback(hObject, eventdata, handles)

expt = getexpt(handles);
set(handles.Freqslider,  'Value', expt.Spatial_frequency);
BOCT=expt.bandwidthfreq;
u1=expt.Spatial_frequency;
expt.SizeX=sqrt(log(2)).*(1+2.^BOCT)./(pi*sqrt(2).*u1.*(2.^BOCT-1));%%Serrano-Pedraza et al. (2007) JoV.
set(handles.SizeX, 'String', num2str(expt.SizeX,'%10.3f'));
gradosABO=expt.bandwidthori*pi/180;
expt.SizeY=sqrt(log(2))/(sqrt(2)*pi*u1*tan(gradosABO/2));%%Serrano-Pedraza et al. (2007) JoV.
set(handles.SizeY, 'String', num2str(expt.SizeY,'%10.3f'));
Plot_figure(hObject, eventdata, handles)
% --- Executes during object creation, after setting all properties.
function Spatial_frequency_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Spatial_frequency (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 Phase_Callback(hObject, eventdata, handles)
% hObject    handle to Phase (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 Phase as text
%        str2double(get(hObject,'String')) returns contents of Phase as a double
expt = getexpt(handles);
set(handles.phaseslider,  'Value', expt.PHASE);
Plot_figure(hObject, eventdata, handles)


% --- Executes during object creation, after setting all properties.
function Phase_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Phase (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


% --- 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 Orientation_Callback(hObject, eventdata, handles)
% hObject    handle to Orientation (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 Orientation as text
%        str2double(get(hObject,'String')) returns contents of Orientation as a double
expt = getexpt(handles);
set(handles.orientationslider,  'Value', expt.Orientation);
Plot_figure(hObject, eventdata, handles)


% --- Executes during object creation, after setting all properties.
function Orientation_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Orientation (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 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.Contrast, 'String', 1);
set(handles.Spatial_frequency,  'String', 2);
set(handles.Phase, 'String', 0);
set(handles.Orientation, 'String', 0);
set(handles.SizeX, 'String', 0.281);
set(handles.SizeY, 'String', 0.350);
set(handles.Freqslider,'Value',0.1);
set(handles.logvaluesbutton,'Value',0);
set(handles.linearvaluesbutton,'Value',1);
set(handles.visualangle,'String',8);
set(handles.bandwidthfreq,'String',1);
set(handles.bandwidthori,'String',30);
set(handles.contrastslider,'Value',1);
set(handles.orientationslider,'Value',0);
set(handles.phaseslider,'Value',1);
Plot_figure(hObject, eventdata, handles)




% --- Executes on slider movement.
function axisX_Callback(hObject, eventdata, handles)
% hObject    handle to axisX (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%get(hObject,'Value')
% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider

Plot_figure(hObject, eventdata, handles)


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

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


% --- Executes on slider movement.
function Freqslider_Callback(hObject, eventdata, handles)

expt = getexpt(handles);
set(handles.Spatial_frequency,  'String', expt.freqslider);
BOCT=expt.bandwidthfreq;
u1=expt.freqslider;
expt.SizeX=sqrt(log(2)).*(1+2.^BOCT)./(pi*sqrt(2).*u1.*(2.^BOCT-1));%%Serrano-Pedraza et al. (2007) JoV.
set(handles.SizeX, 'String', num2str(expt.SizeX,'%10.3f'));
gradosABO=expt.bandwidthori*pi/180;
expt.SizeY=sqrt(log(2))/(sqrt(2)*pi*u1*tan(gradosABO/2));%%Serrano-Pedraza et al. (2007) JoV.
set(handles.SizeY, 'String', num2str(expt.SizeY,'%10.3f'));

Plot_figure(hObject, eventdata, handles)


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

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end




function SizeX_Callback(hObject, eventdata, handles)
% hObject    handle to SizeX (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 SizeX as text
%        str2double(get(hObject,'String')) returns contents of SizeX as a double
expt = getexpt(handles);
u1=expt.Spatial_frequency;
BOCT=real(log2((u1*pi*expt.SizeX*sqrt(2)+sqrt(log(2)))/(u1*pi*expt.SizeX*sqrt(2)-sqrt(log(2)))));
set(handles.bandwidthfreq, 'String', num2str(BOCT,'%10.3f'));
Plot_figure(hObject, eventdata, handles)

% --- Executes during object creation, after setting all properties.
function SizeX_CreateFcn(hObject, eventdata, handles)
% hObject    handle to SizeX (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 SizeY_Callback(hObject, eventdata, handles)
% hObject    handle to SizeY (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 SizeY as text
%        str2double(get(hObject,'String')) returns contents of SizeY as a double
expt = getexpt(handles);
u1=expt.Spatial_frequency;
gradosABO=2*atand(sqrt(log(2))/(sqrt(2)*pi*u1*expt.SizeY));
set(handles.bandwidthori, 'String', num2str(gradosABO,'%10.3f'));
Plot_figure(hObject, eventdata, handles)

% --- Executes during object creation, after setting all properties.
function SizeY_CreateFcn(hObject, eventdata, handles)
% hObject    handle to SizeY (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


% --- 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



function visualangle_Callback(hObject, eventdata, handles)
% hObject    handle to visualangle (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 visualangle as text
%        str2double(get(hObject,'String')) returns contents of visualangle as a double
Plot_figure(hObject, eventdata, handles)

% --- Executes during object creation, after setting all properties.
function visualangle_CreateFcn(hObject, eventdata, handles)
% hObject    handle to visualangle (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 bandwidthfreq_Callback(hObject, eventdata, handles)
% hObject    handle to bandwidthfreq (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 bandwidthfreq as text
%        str2double(get(hObject,'String')) returns contents of bandwidthfreq as a double
expt = getexpt(handles);
BOCT=expt.bandwidthfreq;
u1=expt.Spatial_frequency;
expt.SizeX=sqrt(log(2)).*(1+2.^BOCT)./(pi*sqrt(2).*u1.*(2.^BOCT-1));%%Serrano-Pedraza et al. (2007) JoV.
set(handles.SizeX, 'String', num2str(expt.SizeX,'%10.3f'));
Plot_figure(hObject, eventdata, handles)

% --- Executes during object creation, after setting all properties.
function bandwidthfreq_CreateFcn(hObject, eventdata, handles)
% hObject    handle to bandwidthfreq (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 bandwidthori_Callback(hObject, eventdata, handles)
% hObject    handle to bandwidthori (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 bandwidthori as text
%        str2double(get(hObject,'String')) returns contents of bandwidthori as a double
expt = getexpt(handles);
gradosABO=expt.bandwidthori*pi/180;
u1=expt.Spatial_frequency;
expt.SizeY=sqrt(log(2))/(sqrt(2)*pi*u1*tan(gradosABO/2));%%Serrano-Pedraza et al. (2007) JoV.
set(handles.SizeY, 'String', num2str(expt.SizeY,'%10.3f'));
Plot_figure(hObject, eventdata, handles)

% --- Executes during object creation, after setting all properties.
function bandwidthori_CreateFcn(hObject, eventdata, handles)
% hObject    handle to bandwidthori (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


% --- Executes on slider movement.
function contrastslider_Callback(hObject, eventdata, handles)
% hObject    handle to contrastslider (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,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
expt = getexpt(handles);
set(handles.Contrast,  'String', expt.contrastslider);
Plot_figure(hObject, eventdata, handles)


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

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


% --- Executes on slider movement.
function phaseslider_Callback(hObject, eventdata, handles)
% hObject    handle to phaseslider (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,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
expt = getexpt(handles);
set(handles.Phase,  'String', expt.phaseslider);
Plot_figure(hObject, eventdata, handles)

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

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


% --- Executes on slider movement.
function orientationslider_Callback(hObject, eventdata, handles)
% hObject    handle to orientationslider (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,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
expt = getexpt(handles);
set(handles.Orientation,  'String', expt.orientationslider);
Plot_figure(hObject, eventdata, handles)

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

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end
