function varargout = Masking_images(varargin)


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


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

% Last Modified by GUIDE v2.5 11-Mar-2018 20:09:58

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

% Choose default command line output for Masking_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/Obama.pcx','pcx'));
    case 14
        imagen=double(imread('IMAGES/pamela.pcx','pcx'));
    case 15
        imagen=double(imread('IMAGES/Tiger.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('Signal')
xlabel('Postition (degrees)')
ylabel('Postition (degrees)')
axis square


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));


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%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; %NOTCHED 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,'Fontsize',10)
set(gca,'ytick',frecuenciasconv);
set(gca,'yTickLabel',frecuencias2,'Fontsize',10)
%title('2D Amplitude spectrum of filtered image')
xlabel('Spatial frequency (c/deg)','Fontsize',10)
ylabel('Spatial frequency (c/deg)','Fontsize',10)
axis square

colormap(gray2)

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

axes(handles.Plot3);
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,'Fontsize',10);
set(gca,'ytick',gradosconv);
set(gca,'yTickLabel',grados2,'Fontsize',10);
title('Filtered Images')
xlabel('Postition (degrees)','Fontsize',10)
ylabel('Postition (degrees)','Fontsize',10)
axis square


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%  NOISE FILTERED %%%%%%%%%%%%%%%%%%%


axes(handles.Plot2);
cla;
selectnoise_index = get(handles.selectnoise, 'Value');

switch selectnoise_index
    
    case 1
        imagen=double(imread('IMAGES/Noise_gaussian.pcx','pcx'));onlyimage=0;
    case 2
        imagen=double(imread('IMAGES/Noise_gaussian.pcx','pcx'));onlyimage=0;
    case 3
        imagen=double(imread('IMAGES/Noise_uniform.pcx','pcx'));onlyimage=0;
    case 4
        imagen=double(imread('IMAGES/Noise_1_f.pcx','pcx'));onlyimage=0;
    case 5
        imagen=127.5*ones(TAMX,TAMY);onlyimage=1;
        
end
Image2D=(127.5*(1+2*((imagen./max(max(abs(imagen))))-0.5)));%%



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('Noise')
xlabel('Postition (degrees)')
ylabel('Postition (degrees)')
axis square


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));


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


if expt.Filterideal_noise==1
    
    if expt.Lowpassbutton_noise==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_noise
                    FILTER(i,j)=1;
                end
            end
        end
    end
    if expt.Bandpassbutton_noise==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_noise/sqrt(2)^expt.bandwidthbandpass_noise & rho<=expt.Bandpassfreq_noise*sqrt(2)^expt.bandwidthbandpass_noise
                    FILTER(i,j)=1;
                end
            end
        end
    end
    if expt.Highpassbutton_noise==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_noise
                    FILTER(i,j)=1;
                end
            end
        end
    end
    if expt.Notchbutton_noise==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_noise/sqrt(2)^expt.bandwidthnotch_noise & rho<=expt.Notchfreq_noise*sqrt(2)^expt.bandwidthnotch_noise
                    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_noise=(127.5*(1+1*(IMAGENFILTRADA./max(max(abs(IMAGENFILTRADA))))));%%%
end

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

if expt.FilterButterworth_noise==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_noise==1
        rhon=expt.Lowpassfreq_noise;
        FILTER=(1+((sqrt(ucord.^2+vcord.^2)./rhon)).^(2*r)).^-1;%%LOW-PASS filter Butterworth
    end
    if expt.Bandpassbutton_noise==1
        rhon=expt.Bandpassfreq_noise;
        Boct=expt.bandwidthbandpass_noise;
        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_noise==1
        if expt.Highpassfreq_noise==0; expt.Highpassfreq_noise=0.0001;end
        rhon=expt.Highpassfreq_noise;
        FILTER=(1+((rhon./sqrt(ucord.^2+vcord.^2))).^(2*r)).^-1;%%Filtro Butterworth paso ALTO
    end
    if expt.Notchbutton_noise==1
        rhon=expt.Notchfreq_noise;
        Boct=expt.bandwidthnotch_noise;
        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_noise=(127.5*(1+1*(IMAGENFILTRADA./max(max(abs(IMAGENFILTRADA))))));%%%
    
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%FILTERS%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


axes(handles.Plot6);
cla;
cla;
I=IMAGENFILTRADANORMALIZADA_noise;
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,'Fontsize',10)
set(gca,'ytick',frecuenciasconv);
set(gca,'yTickLabel',frecuencias2,'Fontsize',10)
%title('2D Amplitude spectrum of filtered image')
xlabel('Spatial frequency (c/deg)','Fontsize',10)
ylabel('Spatial frequency (c/deg)','Fontsize',10)
axis square
colormap(gray2)


axes(handles.Plot5);
cla;
Image2D=IMAGENFILTRADANORMALIZADA_noise;
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,'Fontsize',10);
set(gca,'ytick',gradosconv);
set(gca,'yTickLabel',grados2,'Fontsize',10);
%title('Filtered Image')
xlabel('Postition (degrees)','Fontsize',10)
ylabel('Postition (degrees)','Fontsize',10)
axis square



axes(handles.Plot7);
cla;
if onlyimage==0
    Image2D=(IMAGENFILTRADANORMALIZADA+IMAGENFILTRADANORMALIZADA_noise)/2;
else
    Image2D=(IMAGENFILTRADANORMALIZADA);
end
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,'Fontsize',11);
set(gca,'ytick',gradosconv);
set(gca,'yTickLabel',grados2,'Fontsize',11);
title('Signal + Noise')
xlabel('Postition (degrees)','Fontsize',11)
ylabel('Postition (degrees)','Fontsize',11)
axis square


axes(handles.Plot8);
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))))));
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,'Fontsize',11)
set(gca,'ytick',frecuenciasconv);
set(gca,'yTickLabel',frecuencias2,'Fontsize',11)
%title('2D Amplitude spectrum of filtered image')
xlabel('Spatial frequency (c/deg)','Fontsize',11)
ylabel('Spatial frequency (c/deg)','Fontsize',11)
axis square
colormap(gray2)





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

Lowpassfreq = get(handles.Lowpassfreq_image,'string');
expt.Lowpassfreq = str2double(Lowpassfreq);
Highpassfreq = get(handles.Highpassfreq_image,'string');
expt.Highpassfreq = str2double(Highpassfreq);
Bandpassfreq = get(handles.Bandpassfreq_image,'string');
expt.Bandpassfreq = str2double(Bandpassfreq);
Notchfreq = get(handles.Notchfreq_image,'string');
expt.Notchfreq = str2double(Notchfreq);
bandwidthbandpass = get(handles.bandwidthbandpass_image,'string');
expt.bandwidthbandpass = str2double(bandwidthbandpass);
bandwidthnotch = get(handles.bandwidthnotch_image,'string');
expt.bandwidthnotch = str2double(bandwidthnotch);
OrderButterworth = get(handles.OrderButterworth_image,'string');
expt.OrderButterworth = str2double(OrderButterworth);
expt.Highpassbutton= get(handles.Highpassbutton_image,'value');
expt.Bandpassbutton= get(handles.Bandpassbutton_image,'value');
expt.Lowpassbutton= get(handles.Lowpassbutton_image,'value');
expt.Notchbutton= get(handles.Notchbutton_image,'value');
expt.Filterideal= get(handles.Filterideal_image,'value');
expt.FilterButterworth= get(handles.FilterButterworth_image,'value');

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

Lowpassfreq_noise = get(handles.Lowpassfreq_noise,'string');
expt.Lowpassfreq_noise = str2double(Lowpassfreq_noise);
Highpassfreq_noise = get(handles.Highpassfreq_noise,'string');
expt.Highpassfreq_noise = str2double(Highpassfreq_noise);
Bandpassfreq_noise = get(handles.Bandpassfreq_noise,'string');
expt.Bandpassfreq_noise = str2double(Bandpassfreq_noise);
Notchfreq_noise = get(handles.Notchfreq_noise,'string');
expt.Notchfreq_noise = str2double(Notchfreq_noise);
bandwidthbandpass_noise = get(handles.bandwidthbandpass_noise,'string');
expt.bandwidthbandpass_noise = str2double(bandwidthbandpass_noise);
bandwidthnotch_noise = get(handles.bandwidthnotch_noise,'string');
expt.bandwidthnotch_noise = str2double(bandwidthnotch_noise);
OrderButterworth_noise = get(handles.OrderButterworth_noise,'string');
expt.OrderButterworth_noise = str2double(OrderButterworth_noise);
expt.Highpassbutton_noise= get(handles.Highpassbutton_noise,'value');
expt.Bandpassbutton_noise= get(handles.Bandpassbutton_noise,'value');
expt.Lowpassbutton_noise= get(handles.Lowpassbutton_noise,'value');
expt.Notchbutton_noise= get(handles.Notchbutton_noise,'value');
expt.Filterideal_noise= get(handles.Filterideal_noise,'value');
expt.FilterButterworth_noise= get(handles.FilterButterworth_noise,'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 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_image, 'String', 4);
set(handles.Lowpassfreq_image,  'String', 2);
set(handles.Highpassfreq_image, 'String', 4);
set(handles.Bandpassfreq_image, 'String', 4);
set(handles.bandwidthbandpass_image, 'String', 1);
set(handles.Notchfreq_image, 'String', 2);
set(handles.bandwidthnotch_image,'String',1);
set(handles.Filterideal_image,'Value',1);
set(handles.logvaluesbutton,'Value',1);
set(handles.linearvaluesbutton,'Value',0);
set(handles.FilterButterworth_image,'Value',0);
set(handles.Lowpassbutton_image,'Value',1);
set(handles.Highpassbutton_image,'Value',0);
set(handles.Bandpassbutton_image,'Value',0);
set(handles.Notchbutton_image,'Value',0);

set(handles.OrderButterworth_noise, 'String', 4);
set(handles.Lowpassfreq_noise,  'String', 2);
set(handles.Highpassfreq_noise, 'String', 4);
set(handles.Bandpassfreq_noise, 'String', 4);
set(handles.bandwidthbandpass_noise, 'String', 1);
set(handles.Notchfreq_noise, 'String', 2);
set(handles.bandwidthnotch_noise,'String',1);
set(handles.Filterideal_noise,'Value',1);
set(handles.FilterButterworth_noise,'Value',0);
set(handles.Lowpassbutton_noise,'Value',0);
set(handles.Highpassbutton_noise,'Value',0);
set(handles.Bandpassbutton_noise,'Value',1);
set(handles.Notchbutton_noise,'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_image.
function FilterButterworth_image_Callback(hObject, eventdata, handles)
% hObject    handle to FilterButterworth_image (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_image
set(handles.Filterideal_image,'Value',0);
set(handles.FilterButterworth_image,'Value',1);
Plot_figure(hObject, eventdata, handles)

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


% --- Executes on button press in Highpassbutton_image.
function Highpassbutton_image_Callback(hObject, eventdata, handles)
% hObject    handle to Highpassbutton_image (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_image
set(handles.Highpassbutton_image,'Value',1);
set(handles.Bandpassbutton_image,'Value',0);
set(handles.Lowpassbutton_image,'Value',0);
set(handles.Notchbutton_image,'Value',0);
Plot_figure(hObject, eventdata, handles)


% --- Executes on button press in Bandpassbutton_image.
function Bandpassbutton_image_Callback(hObject, eventdata, handles)
% hObject    handle to Bandpassbutton_image (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_image
set(handles.Highpassbutton_image,'Value',0);
set(handles.Bandpassbutton_image,'Value',1);
set(handles.Lowpassbutton_image,'Value',0);
set(handles.Notchbutton_image,'Value',0);
Plot_figure(hObject, eventdata, handles)


% --- Executes on button press in Lowpassbutton_image.
function Lowpassbutton_image_Callback(hObject, eventdata, handles)
% hObject    handle to Lowpassbutton_image (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_image
set(handles.Highpassbutton_image,'Value',0);
set(handles.Bandpassbutton_image,'Value',0);
set(handles.Lowpassbutton_image,'Value',1);
set(handles.Notchbutton_image,'Value',0);
Plot_figure(hObject, eventdata, handles)

% --- Executes on button press in Notchbutton_image.
function Notchbutton_image_Callback(hObject, eventdata, handles)
% hObject    handle to Notchbutton_image (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_image
set(handles.Highpassbutton_image,'Value',0);
set(handles.Bandpassbutton_image,'Value',0);
set(handles.Lowpassbutton_image,'Value',0);
set(handles.Notchbutton_image,'Value',1);
Plot_figure(hObject, eventdata, handles)





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


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


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


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


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


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


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


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


% --- Executes on selection change in selectnoise.
function selectnoise_Callback(hObject, eventdata, handles)
% hObject    handle to selectnoise (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 selectnoise contents as cell array
%        contents{get(hObject,'Value')} returns selected item from selectnoise
Plot_figure(hObject, eventdata, handles)

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

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

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

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

% --- Executes during object creation, after setting all properties.
function Lowpassfreq_noise_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Lowpassfreq_noise (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 Lowpassbutton_noise.
function Lowpassbutton_noise_Callback(hObject, eventdata, handles)
% hObject    handle to Lowpassbutton_noise (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_noise
set(handles.Highpassbutton_noise,'Value',0);
set(handles.Bandpassbutton_noise,'Value',0);
set(handles.Lowpassbutton_noise,'Value',1);
set(handles.Notchbutton_noise,'Value',0);
Plot_figure(hObject, eventdata, handles)

% --- Executes on button press in Notchbutton_noise.
function Notchbutton_noise_Callback(hObject, eventdata, handles)
% hObject    handle to Notchbutton_noise (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_noise
set(handles.Highpassbutton_noise,'Value',0);
set(handles.Bandpassbutton_noise,'Value',0);
set(handles.Lowpassbutton_noise,'Value',0);
set(handles.Notchbutton_noise,'Value',1);
Plot_figure(hObject, eventdata, handles)


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

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

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

% --- Executes during object creation, after setting all properties.
function Highpassfreq_noise_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Highpassfreq_noise (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 Bandpassbutton_noise.
function Bandpassbutton_noise_Callback(hObject, eventdata, handles)
% hObject    handle to Bandpassbutton_noise (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_noise
set(handles.Highpassbutton_noise,'Value',0);
set(handles.Bandpassbutton_noise,'Value',1);
set(handles.Lowpassbutton_noise,'Value',0);
set(handles.Notchbutton_noise,'Value',0);
Plot_figure(hObject, eventdata, handles)

% --- Executes on button press in Highpassbutton_noise.
function Highpassbutton_noise_Callback(hObject, eventdata, handles)
% hObject    handle to Highpassbutton_noise (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_noise
set(handles.Highpassbutton_noise,'Value',1);
set(handles.Bandpassbutton_noise,'Value',0);
set(handles.Lowpassbutton_noise,'Value',0);
set(handles.Notchbutton_noise,'Value',0);
Plot_figure(hObject, eventdata, handles)

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

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


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