function varargout = Filtered_images(varargin)

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


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

% Last Modified by GUIDE v2.5 09-Mar-2018 16:25:40

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

% Choose default command line output for Filtered_images
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=8;
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=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');

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/fingerprint.pcx','pcx'));
    case 10
        imagen=double(imread('IMAGES/flinstones.pcx','pcx'));
    case 11
        imagen=double(imread('IMAGES/Helmholtz.pcx','pcx'));
    case 12
        imagen=double(imread('IMAGES/mullerlyer.pcx','pcx'));
    case 13
        imagen=double(imread('IMAGES/Noise_1_f.pcx','pcx'));
    case 14
        imagen=double(imread('IMAGES/Noise_gaussian.pcx','pcx'));
    case 15
        imagen=double(imread('IMAGES/Noise_uniform.pcx','pcx'));
    case 16
        imagen=double(imread('IMAGES/Obama.pcx','pcx'));
    case 17
        imagen=double(imread('IMAGES/pamela.pcx','pcx'));
    case 18
        imagen=128*ones(512,512);
        imagen([(TAMX/2-1)-5:(TAMX/2-1)+5],[(TAMX/2-1)-5:(TAMX/2-1)+5])=255;
    case 19
        imagen=double(imread('IMAGES/Tiger.pcx','pcx'));
    case 20
        imagen=double(imread('IMAGES/Uc3g.pcx','pcx'));
end
Image2D=imagen;
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)


axes(handles.Plot3);%%%%%%%%PHASE PLOT
cla;

FASEimagenNORMALIZADO=(127.5*(1+1*(FASEimagen./max(max(abs(FASEimagen))))));%

imagen=FASEimagenNORMALIZADO;
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 Phase spectrum')
xlabel('Spatial frequency (c/deg)')
ylabel('Spatial frequency (c/deg)')
axis square

colormap(gray2)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%FILTERS%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


if expt.Filterideal==1
    
    if expt.Lowpassbutton==1
        FILTER=0.*ones(512,512);
        for i=1:512
            for j=1:512
                rho=sqrt(u(i,j).^2+v(i,j).^2);
                
                if rho<=expt.Lowpassfreq
                    FILTER(i,j)=1;
                end
            end
        end
    end
    if expt.Bandpassbutton==1
        FILTER=0.*ones(512,512);
        for i=1:512
            for j=1:512
                rho=sqrt(u(i,j).^2+v(i,j).^2);
                if rho>=expt.Bandpassfreq/sqrt(2)^expt.bandwidthbandpass & rho<=expt.Bandpassfreq*sqrt(2)^expt.bandwidthbandpass
                    FILTER(i,j)=1;
                end
            end
        end
    end
    if expt.Highpassbutton==1
        FILTER=0.*ones(512,512);
        for i=1:512
            for j=1:512
                rho=sqrt(u(i,j).^2+v(i,j).^2);
                
                if rho>=expt.Highpassfreq
                    FILTER(i,j)=1;
                end
            end
        end
    end
    if expt.Notchbutton==1
        FILTER=1.*ones(512,512);
        for i=1:512
            for j=1:512
                rho=sqrt(u(i,j).^2+v(i,j).^2);
                if rho>=expt.Notchfreq/sqrt(2)^expt.bandwidthnotch & rho<=expt.Notchfreq*sqrt(2)^expt.bandwidthnotch
                    FILTER(i,j)=0;
                end
            end
        end
    end
    
    REALPROD=fftshift(FILTER.*FFTmodulo.*cos(FASEimagen));
    IMAGPROD=fftshift(FILTER.*FFTmodulo.*sin(FASEimagen));
    RESULT=(REALPROD+IMAGPROD*sqrt(-1));
    FINAL=ifft2(RESULT);
    IMAGENFILTRADA=real(FINAL);
    IMAGENFILTRADANORMALIZADA=(127.5*(1+1*(IMAGENFILTRADA./max(max(abs(IMAGENFILTRADA))))));%%%
    if (loadimagenes_index==12 | loadimagenes_index==20) & expt.Lowpassbutton==1
        IMAGENFILTRADANORMALIZADA=255*(abs(IMAGENFILTRADA)./max(max(abs(IMAGENFILTRADA))));%%%
    end
end

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

if expt.FilterButterworth==1;
    angulofilt=0*pi/180;
    u0=0;
    v0=0;
    ucord=(u-u0)*cos(angulofilt)+(v-v0)*sin(angulofilt);
    vcord=-(u-u0)*sin(angulofilt)+(v-v0)*cos(angulofilt);
    r=expt.OrderButterworth;
    if expt.Lowpassbutton==1
        rhon=expt.Lowpassfreq;
        FILTER=(1+((sqrt(ucord.^2+vcord.^2)./rhon)).^(2*r)).^-1;%%LOW-PASS filter Butterworth
    end
    if expt.Bandpassbutton==1
        rhon=expt.Bandpassfreq;
        Boct=expt.bandwidthbandpass;
        Bn=(((2^Boct)-1)/((2^Boct)+1))*rhon;
        FILTER=(1+((sqrt(ucord.^2+vcord.^2)-rhon)./Bn).^(2*r)).^-1; %BAND-PASS FILTER Butterworth
    end
    if expt.Highpassbutton==1
        if expt.Highpassfreq==0; expt.Highpassfreq=0.0001;end
        rhon=expt.Highpassfreq;
        FILTER=(1+((rhon./sqrt(ucord.^2+vcord.^2))).^(2*r)).^-1;%%Filtro Butterworth paso ALTO
    end
    if expt.Notchbutton==1
        rhon=expt.Notchfreq;
        Boct=expt.bandwidthnotch;
        Bn=(((2^Boct)-1)/((2^Boct)+1))*rhon;
        FILTER=1-(1+((sqrt(ucord.^2+vcord.^2)-rhon)./Bn).^(2*r)).^-1; %BAND-PASS FILTER Butterworth
    end
    
    REALPROD=fftshift(FILTER.*FFTmodulo.*cos(FASEimagen));
    IMAGPROD=fftshift(FILTER.*FFTmodulo.*sin(FASEimagen));
    RESULT=(REALPROD+IMAGPROD*sqrt(-1));
    FINAL=ifft2(RESULT);
    IMAGENFILTRADA=real(FINAL);
    IMAGENFILTRADANORMALIZADA=(127.5*(1+1*(IMAGENFILTRADA./max(max(abs(IMAGENFILTRADA))))));%%%
    if (loadimagenes_index==12 | loadimagenes_index==20) & expt.Lowpassbutton==1
        IMAGENFILTRADANORMALIZADA=255*(abs(IMAGENFILTRADA)./max(max(abs(IMAGENFILTRADA))));%%%
    end
end



axes(handles.Plot4);
cla;
I=IMAGENFILTRADANORMALIZADA;
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))))));
else
    FFTmoduloNORMALIZADO=255*((abs(FFTimagen))./max(max((abs(FFTimagen)))));
end
FFTmoduloNORMALIZADO(TAMX/2+1,TAMX/2+1)=0;
if expt.Lowpassbutton==1
    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 of filtered image')
xlabel('Spatial frequency (c/deg)')
ylabel('Spatial frequency (c/deg)')
axis square

colormap(gray2)




axes(handles.Plot5);
cla;

Image2D=IMAGENFILTRADANORMALIZADA;
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('Filtered Image')
xlabel('Postition (degrees)')
ylabel('Postition (degrees)')
axis square



% --- Outputs from this function are returned to the command line.
function varargout = Filtered_images_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)

Plot_figure(hObject, eventdata, handles)

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




Lowpassfreq = get(handles.Lowpassfreq,'string');
expt.Lowpassfreq = str2double(Lowpassfreq);
Highpassfreq = get(handles.Highpassfreq,'string');
expt.Highpassfreq = str2double(Highpassfreq);
Bandpassfreq = get(handles.Bandpassfreq,'string');
expt.Bandpassfreq = str2double(Bandpassfreq);
Notchfreq = get(handles.Notchfreq,'string');
expt.Notchfreq = str2double(Notchfreq);
bandwidthbandpass = get(handles.bandwidthbandpass,'string');
expt.bandwidthbandpass = str2double(bandwidthbandpass);
bandwidthnotch = get(handles.bandwidthnotch,'string');
expt.bandwidthnotch = str2double(bandwidthnotch);
OrderButterworth = get(handles.OrderButterworth,'string');
expt.OrderButterworth = str2double(OrderButterworth);

expt.logvaluesbutton= get(handles.logvaluesbutton,'value');
expt.linearvaluesbutton= get(handles.linearvaluesbutton,'value');
expt.Highpassbutton= get(handles.Highpassbutton,'value');
expt.Bandpassbutton= get(handles.Bandpassbutton,'value');
expt.Lowpassbutton= get(handles.Lowpassbutton,'value');
expt.Notchbutton= get(handles.Notchbutton,'value');
expt.Filterideal= get(handles.Filterideal,'value');
expt.FilterButterworth= get(handles.FilterButterworth,'value');



% bandwidthfreq = get(handles.bandwidthfreq,'string');
% expt.bandwidthfreq = str2double(bandwidthfreq);
% bandwidthori = get(handles.bandwidthori,'string');
% expt.bandwidthori = str2double(bandwidthori);




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

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

Plot_figure(hObject, eventdata, handles)


% --- Executes during object creation, after setting all properties.
function Framerate_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Framerate (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.OrderButterworth, 'String', 4);
set(handles.Lowpassfreq,  'String', 2);
set(handles.Highpassfreq, 'String', 4);
set(handles.Bandpassfreq, 'String', 4);
set(handles.bandwidthbandpass, 'String', 1);
set(handles.Notchfreq, 'String', 2);
set(handles.bandwidthnotch,'String',1);
set(handles.Filterideal,'Value',1);
set(handles.logvaluesbutton,'Value',1);
set(handles.linearvaluesbutton,'Value',0);
set(handles.FilterButterworth,'Value',0);
set(handles.Lowpassbutton,'Value',1);
set(handles.Highpassbutton,'Value',0);
set(handles.Bandpassbutton,'Value',0);
set(handles.Notchbutton,'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 button press in FilterButterworth.
function FilterButterworth_Callback(hObject, eventdata, handles)
% hObject    handle to FilterButterworth (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 FilterButterworth
set(handles.Filterideal,'Value',0);
set(handles.FilterButterworth,'Value',1);
Plot_figure(hObject, eventdata, handles)

% --- Executes on button press in Filterideal.
function Filterideal_Callback(hObject, eventdata, handles)
% hObject    handle to Filterideal (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 Filterideal
set(handles.Filterideal,'Value',1);
set(handles.FilterButterworth,'Value',0);
Plot_figure(hObject, eventdata, handles)


% --- Executes on button press in Highpassbutton.
function Highpassbutton_Callback(hObject, eventdata, handles)
% hObject    handle to Highpassbutton (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 Highpassbutton
set(handles.Highpassbutton,'Value',1);
set(handles.Bandpassbutton,'Value',0);
set(handles.Lowpassbutton,'Value',0);
set(handles.Notchbutton,'Value',0);
Plot_figure(hObject, eventdata, handles)


% --- Executes on button press in Bandpassbutton.
function Bandpassbutton_Callback(hObject, eventdata, handles)
% hObject    handle to Bandpassbutton (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 Bandpassbutton
set(handles.Highpassbutton,'Value',0);
set(handles.Bandpassbutton,'Value',1);
set(handles.Lowpassbutton,'Value',0);
set(handles.Notchbutton,'Value',0);
Plot_figure(hObject, eventdata, handles)


% --- Executes on button press in Lowpassbutton.
function Lowpassbutton_Callback(hObject, eventdata, handles)
% hObject    handle to Lowpassbutton (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 Lowpassbutton
set(handles.Highpassbutton,'Value',0);
set(handles.Bandpassbutton,'Value',0);
set(handles.Lowpassbutton,'Value',1);
set(handles.Notchbutton,'Value',0);
Plot_figure(hObject, eventdata, handles)

% --- Executes on button press in Notchbutton.
function Notchbutton_Callback(hObject, eventdata, handles)
% hObject    handle to Notchbutton (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 Notchbutton
set(handles.Highpassbutton,'Value',0);
set(handles.Bandpassbutton,'Value',0);
set(handles.Lowpassbutton,'Value',0);
set(handles.Notchbutton,'Value',1);
Plot_figure(hObject, eventdata, handles)





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


% --- Executes during object creation, after setting all properties.
function Highpassfreq_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Highpassfreq (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 Bandpassfreq_Callback(hObject, eventdata, handles)
% hObject    handle to Bandpassfreq (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 Bandpassfreq as text
%        str2double(get(hObject,'String')) returns contents of Bandpassfreq as a double
Plot_figure(hObject, eventdata, handles)


% --- Executes during object creation, after setting all properties.
function Bandpassfreq_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Bandpassfreq (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 bandwidthbandpass_Callback(hObject, eventdata, handles)
% hObject    handle to bandwidthbandpass (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 bandwidthbandpass as text
%        str2double(get(hObject,'String')) returns contents of bandwidthbandpass as a double
Plot_figure(hObject, eventdata, handles)


% --- Executes during object creation, after setting all properties.
function bandwidthbandpass_CreateFcn(hObject, eventdata, handles)
% hObject    handle to bandwidthbandpass (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 bandwidthnotch_Callback(hObject, eventdata, handles)
% hObject    handle to bandwidthnotch (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 bandwidthnotch as text
%        str2double(get(hObject,'String')) returns contents of bandwidthnotch as a double
Plot_figure(hObject, eventdata, handles)


% --- Executes during object creation, after setting all properties.
function bandwidthnotch_CreateFcn(hObject, eventdata, handles)
% hObject    handle to bandwidthnotch (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 Lowpassfreq_Callback(hObject, eventdata, handles)
% hObject    handle to Lowpassfreq (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 Lowpassfreq as text
%        str2double(get(hObject,'String')) returns contents of Lowpassfreq as a double
Plot_figure(hObject, eventdata, handles)


% --- Executes during object creation, after setting all properties.
function Lowpassfreq_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Lowpassfreq (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 OrderButterworth_Callback(hObject, eventdata, handles)
% hObject    handle to OrderButterworth (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 OrderButterworth as text
%        str2double(get(hObject,'String')) returns contents of OrderButterworth as a double
Plot_figure(hObject, eventdata, handles)


% --- Executes during object creation, after setting all properties.
function OrderButterworth_CreateFcn(hObject, eventdata, handles)
% hObject    handle to OrderButterworth (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 Notchfreq_Callback(hObject, eventdata, handles)
% hObject    handle to Notchfreq (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 Notchfreq as text
%        str2double(get(hObject,'String')) returns contents of Notchfreq as a double
Plot_figure(hObject, eventdata, handles)


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