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

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

% Last Modified by GUIDE v2.5 21-Feb-2009 14:29:28

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

% Choose default command line output for Principal
%Valores Iniciales al cargar
handles.output = hObject;
clc
axes(handles.graf1)
cla reset  
axis off
axes(handles.graf2)
axis off
cla reset
axis off
set(handles.Filtrar,'Enable','Off')
set(handles.tfiltro,'Enable','Off')
set(handles.edit1,'Visible','Off')
set(handles.text1,'Visible','Off')
set(handles.textalpha,'Visible','Off')
set(handles.text5,'Visible','Off')
set(handles.text6,'Visible','Off')
set(handles.text7,'Visible','Off')
set(handles.text5,'String',' ')
set(handles.text6,'String',' ')
set(handles.text7,'String',' ')
set(handles.slider2,'Visible','Off')
set(handles.parametros,'Visible','Off')
handles.im2=0;
handles.haydata=0;
handles.d=0;
% Update handles structure
guidata(hObject, handles);

% UIWAIT makes Principal wait for user response (see UIRESUME)
% uiwait(handles.figure1);


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


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

% Funciones del boton 'Cargar' para procesar una imagen
[FileName Path]=uigetfile({'*.jpg'},'Abrir Imagen');
if isequal(FileName,0)
    return
else
a=imread(strcat(Path,FileName));
tam = size(a);
end

%Verifico si la imagen es a color o en blanco y negro
if length(tam)==3
    rpta=questdlg('La imagen que desea cargar se encuentra a color. Desea procesarla en la escala de grises?');
    
    switch rpta
    
    case 'Yes'
        a=rgb2gray(a);
        handles.imload=1    %bandera para determinar si existe imagen cargada
    
    case 'No'
        handles.imload=0    
    
    case 'Cancel'
        handles.imload=0
    end
    
else
    handles.imload=1;
end

if handles.imload==1
    
    axes(handles.graf1);
    axis off;
    imshow(a);
    handles.im=a;
    set(handles.Filtrar,'Enable','On')
    
    axes(handles.graf2)
    axis off
    cla reset
    axis off
    
    set(handles.tfiltro,'Enable','On')
    set(handles.text5,'String',' ')
    set(handles.text6,'String',' ')
    set(handles.text7,'String',' ')
    set(handles.slider2,'Visible','Off')
end

    


guidata(hObject,handles);


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

%Accion del boton Filtrar dependiende del valor seleccionado en el
%el menu deplegable

h=get(handles.tfiltro,'Value'); %Lectura del valor del menu desplegable

switch h

    case 1
       errordlg('Por favor seleccione un tipo de filtro'); 
    
    case 2      % Unsharp
        p=handles.im;
        f=mat2gray(p);
        H=fspecial('unsharp'); 
        y=imfilter(f,H,'replicate');
        final=f+y; 
        final=mat2gray(final,[0,255]);
        axes(handles.graf2);
        axis off;
        imshow(final,[]);
        handles.im2=final;
        handles.op67=0;% bandera para determinar si la imagen esta uint8 o double
        guidata(hObject, handles);

    case 3      %Emboss
        p=handles.im;
        f=mat2gray(p);
        H=[-2 -1 0; -1 1 1; 0 1 2]; 
        y=imfilter(f,H,'replicate');
        final=f+y; 
        final=mat2gray(final,[0,255]);
        axes(handles.graf2);
        axis off;
        imshow(final,[]);
        handles.im2=final;
        handles.op67=0;
        guidata(hObject,handles);
        
    case 4      %Realce 1
        p=handles.im;
        f=mat2gray(p);
        H=[-1 -1 -1; -1 9 -1; -1 -1 -1]; 
        y=imfilter(f,H,'replicate');
        final=f+y; 
        final=mat2gray(final,[0,255]);
        axes(handles.graf2);
        axis off;
        imshow(final,[]);
        handles.im2=final;
        handles.op67=0;
        guidata(hObject,handles);
        
    case 5      %Realce 2
        p=handles.im;
        f=mat2gray(p);
        H=(1/7)*[-1 -2 -1; -2 19 -2; -1 -2 -1]; 
        y=imfilter(f,H,'replicate');
        final=f+y; 
        final=mat2gray(final,[0,255]);
        axes(handles.graf2);
        axis off;
        imshow(final,[]);
        handles.im2=final;
        handles.op67=0;
        guidata(hObject,handles);

    case 6      %Roberts
        p=handles.im;
        f=mat2gray(p);
        
        Hx=[0 0 -1; 0 1 0; 0 0 0]; 
        yx=imfilter(f,Hx,'replicate');
        Hy=[-1 0 0; 0 1 0; 0 0 0]; 
        yy=imfilter(f,Hy,'replicate');
        y=abs(yx)+abs(yy)
        final=f+y; 
        final=mat2gray(final,[0,255]);
        axes(handles.graf2);
        axis off;
        imshow(final,[]);
        handles.im2=final
        handles.op67=0;
        guidata(hObject,handles);
    
    case 7      %Prewitt
        p=handles.im;
        f=mat2gray(p);
       
        Hx=fspecial('prewitt'); 
        Hy=Hx';
        yx=imfilter(f,Hx,'replicate');
        yy=imfilter(f,Hy,'replicate');
        y=abs(yx)+abs(yy);
        final=f+y; 
        final=mat2gray(final,[0,255]);
        axes(handles.graf2);
        axis off;
        imshow(final,[]);
        handles.im2=final
        handles.op67=0;
        guidata(hObject,handles);
        
    case 8      %Sobel
        p=handles.im;
        f=mat2gray(p);
        
        Hx=fspecial('sobel'); 
        Hy=Hx'
        yx=imfilter(f,Hx,'replicate');
        yy=imfilter(f,Hy,'replicate');
        y=abs(yx)+ abs(yy);
        final=f+y;
        final=mat2gray(final,[0 255]);
        axes(handles.graf2);
        axis off;
        imshow(final,[]);
        handles.im2=final
        handles.op67=0;
        guidata(hObject,handles);
        
    case 9      %Enfatizador de Altas Frecuecias
        x=handles.im;
        x = mat2gray(double(x),[0,255]);
        xlp=imfilter(x,fspecial('average',[3 3]));
        A=str2num(get(handles.edit1,'String'));
            if A>=1
                y = A*x-xlp;
                y = uint8(y*(255));
                axes(handles.graf2);
                axis off;
                imshow(y);
            else
                errordlg('Imposible Filtrar: Seleccione un valor de A >= 1');
            end
          handles.im2=y;  
          handles.op67=1;
          guidata(hObject,handles);
    
    case 10     %Laplaciano
        
        p=handles.im;
        f=mat2gray(p);
        
        b=str2num(get(handles.edit1,'String'));
        
        if (b>=0)&&(b<=1)
           
            H=fspecial('laplacian',b);
            y=imfilter(f,H,'replicate');
            final=f-y; 
            final=mat2gray(final,[0,255]);
            axes(handles.graf2);
            axis off;
            imshow(final,[]);
            handles.im2=final;
            handles.op67=0;
        else
            errordlg('Imposible Filtrar: Seleccione un valor de alpha valido entre 0 y 1');
        end
        guidata(hObject,handles);

    case 12        %Ecualizacion por Histograma
        x=handles.im;
        y=histeq(x,256);
        axes(handles.graf2);
        axis off;
        imshow(y,[]);
        rp=questdlg('Desear ver los Histogramas')
        switch rp
            case 'Yes'
                figure, subplot (1,2,1),imhist(x),subplot (1,2,2),imhist(y);
        end
        handles.im2=y;
        handles.op67=1;
          
        guidata(hObject,handles);
end

guidata(hObject,handles);


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

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

%Habilitacion/Desabilitacion de los cuadros segun la funcion Seleccionada
%en la lista desplegable
if(get(hObject,'Value'))==0
   set(handles.Filtrar,'Visible','On')
   set(handles.edit1,'Visible','Off')
   set(handles.text1,'Visible','Off')
   set(handles.parametros,'Visible','Off')
   set(handles.textalpha,'Visible','Off')
   set(handles.text5,'Visible','Off')
   set(handles.text6,'Visible','Off')
   set(handles.text7,'Visible','Off')
   set(handles.slider2,'Visible','Off')
   set(handles.Filtrar,'String','Filtrar')
end
if(get(hObject,'Value'))==1
    set(handles.Filtrar,'Visible','On')
    set(handles.edit1,'Visible','Off')
    set(handles.text1,'Visible','Off')
    set(handles.parametros,'Visible','Off')
    set(handles.textalpha,'Visible','Off')
    set(handles.text5,'Visible','Off')
    set(handles.text6,'Visible','Off')
    set(handles.text7,'Visible','Off')
    set(handles.slider2,'Visible','Off')
    set(handles.Filtrar,'String','Filtrar')
end
if(get(hObject,'Value'))==2
   set(handles.Filtrar,'Visible','On')
   set(handles.edit1,'Visible','Off')
   set(handles.text1,'Visible','Off')
   set(handles.parametros,'Visible','Off')
   set(handles.textalpha,'Visible','Off')
   set(handles.text5,'Visible','Off')
   set(handles.text6,'Visible','Off')
   set(handles.text7,'Visible','Off')
   set(handles.slider2,'Visible','Off')
   set(handles.Filtrar,'String','Filtrar')
end
if(get(hObject,'Value'))==3
   set(handles.Filtrar,'Visible','On')
   set(handles.edit1,'Visible','Off')
   set(handles.text1,'Visible','Off')
   set(handles.parametros,'Visible','Off')
   set(handles.textalpha,'Visible','Off')
   set(handles.text5,'Visible','Off')
   set(handles.text6,'Visible','Off')
   set(handles.text7,'Visible','Off')
   set(handles.slider2,'Visible','Off')
   set(handles.Filtrar,'String','Filtrar')
end
if(get(hObject,'Value'))==4
   set(handles.Filtrar,'Visible','On')
   set(handles.edit1,'Visible','Off')
   set(handles.text1,'Visible','Off')
   set(handles.parametros,'Visible','Off')
   set(handles.textalpha,'Visible','Off')
   set(handles.text5,'Visible','Off')
   set(handles.text6,'Visible','Off')
   set(handles.text7,'Visible','Off')
   set(handles.slider2,'Visible','Off')
   set(handles.Filtrar,'String','Filtrar')
end
if(get(hObject,'Value'))==5
   set(handles.Filtrar,'Visible','On')
   set(handles.edit1,'Visible','Off')
   set(handles.text1,'Visible','Off')
   set(handles.parametros,'Visible','Off')
   set(handles.textalpha,'Visible','Off')
   set(handles.text5,'Visible','Off')
   set(handles.text6,'Visible','Off')
   set(handles.text7,'Visible','Off')
   set(handles.slider2,'Visible','Off')
   set(handles.Filtrar,'String','Filtrar')
end



if(get(hObject,'Value'))==6
   set(handles.Filtrar,'Visible','On')
   set(handles.edit1,'Visible','Off')
   set(handles.text1,'Visible','Off')
   set(handles.parametros,'Visible','Off')
   set(handles.textalpha,'Visible','Off')
   set(handles.text5,'Visible','Off')
   set(handles.text6,'Visible','Off')
   set(handles.text7,'Visible','Off')
   set(handles.slider2,'Visible','Off')
   set(handles.Filtrar,'String','Filtrar')
end
if(get(hObject,'Value'))==7
   set(handles.Filtrar,'Visible','On')
   set(handles.edit1,'Visible','Off')
   set(handles.text1,'Visible','Off')
   set(handles.parametros,'Visible','Off')
   set(handles.textalpha,'Visible','Off')
   set(handles.text5,'Visible','Off')
   set(handles.text6,'Visible','Off')
   set(handles.text7,'Visible','Off')
   set(handles.slider2,'Visible','Off')
   set(handles.Filtrar,'String','Filtrar')
end


if(get(hObject,'Value'))==8
   set(handles.Filtrar,'Visible','On')
   set(handles.edit1,'Visible','Off')
   set(handles.text1,'Visible','Off')
   set(handles.parametros,'Visible','Off')
   set(handles.textalpha,'Visible','Off')
   set(handles.text5,'Visible','Off')
   set(handles.text6,'Visible','Off')
   set(handles.text7,'Visible','Off')
   set(handles.slider2,'Visible','Off')
   set(handles.Filtrar,'String','Filtrar')
end
if(get(hObject,'Value'))==9
   set(handles.Filtrar,'Visible','On')
   set(handles.edit1,'Visible','On')
   set(handles.edit1,'String','2')
   set(handles.text1,'Visible','On')
   set(handles.textalpha,'Visible','Off')
   set(handles.parametros,'Visible','Off')
   set(handles.text5,'Visible','Off')
   set(handles.text6,'Visible','Off')
   set(handles.text7,'Visible','Off')
   set(handles.slider2,'Visible','Off')
   set(handles.Filtrar,'String','Filtrar')
end
if(get(hObject,'Value'))==10
   set(handles.Filtrar,'Visible','On')
   set(handles.edit1,'Visible','On')
   set(handles.edit1,'String','0.2')
   set(handles.text1,'Visible','Off')
   set(handles.textalpha,'Visible','On')
   set(handles.parametros,'Visible','Off')
   set(handles.text5,'Visible','Off')
   set(handles.text6,'Visible','Off')
   set(handles.text7,'Visible','Off')
   set(handles.slider2,'Visible','Off')
   set(handles.Filtrar,'String','Filtrar')
end
if(get(hObject,'Value'))==11
    set(handles.Filtrar,'Visible','Off')
    set(handles.edit1,'Visible','Off')
    set(handles.text1,'Visible','Off')
    set(handles.textalpha,'Visible','Off')
    set(handles.text5,'Visible','Off')
    set(handles.text6,'Visible','Off')
     set(handles.text7,'Visible','Off')
    set(handles.slider2,'Visible','Off')
    set(handles.parametros,'Visible','On')
end

if(get(hObject,'Value'))==12
    set(handles.Filtrar,'Visible','On')
    set(handles.Filtrar,'String','Ecualizar')
    set(handles.edit1,'Visible','Off')
    set(handles.text1,'Visible','Off')
    set(handles.textalpha,'Visible','Off')
    set(handles.text5,'Visible','Off')
    set(handles.text6,'Visible','Off')
     set(handles.text7,'Visible','Off')
    set(handles.slider2,'Visible','Off')
    set(handles.parametros,'Visible','Off')
end
% --- Executes during object creation, after setting all properties.
function tfiltro_CreateFcn(hObject, eventdata, handles)
% hObject    handle to tfiltro (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 edit1_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (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 edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double



% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (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 Guardar.
function Guardar_Callback(hObject, eventdata, handles)
% hObject    handle to Guardar (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

%Boton 'Guardar'
if handles.im2==0
    errordlg('No hay imagen procesada')
else
     if handles.op67==0
        if min(min(handles.im2))<0; %Normalizo la imagen para grabarla
            handles.im2 = handles.im2 - min(min(handles.im2));
        end
        handles.im2 = handles.im2 / max(max(handles.im2));
     end
     
guidata(hObject,handles)
[newfile,newpath] = uiputfile('*.jpg','Guardar Como');
if isequal(newfile,0)
    return
else
filename=strcat(newpath,newfile);
imwrite(handles.im2,filename);    
end
end




% --- Executes on slider movement.
 function slider2_Callback(hObject, eventdata, handles)
% hObject    handle to slider2 (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

% Funcion de la barra de desplazamiento para Ajuste Logaritmo
t=0;
if handles.d>=1
    
    t=get(hObject,'Value');
    set(handles.text7,'String',t);
    p=handles.im;
    yp=log_adj(p,t,256);	
    axes(handles.graf2);
    axis off;
    imshow(yp,[]);
    handles.im2=yp;
    handles.op67=1;
    guidata(hObject,handles)
end
% --- Executes during object creation, after setting all properties.
function slider2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider2 (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 edit3_Callback(hObject, eventdata, handles)
% hObject    handle to edit3 (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 edit3 as text
%        str2double(get(hObject,'String')) returns contents of edit3 as a double


% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit3 (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 logval.
function logval_Callback(hObject, eventdata, handles)
% hObject    handle to logval (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
guidata(hObject,handles);



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


% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit5 (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 parametros.
function parametros_Callback(hObject, eventdata, handles)
% hObject    handle to parametros (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% Funciones del Boton 'parametros' para Ajuste Logaritmico
log_adj_sub   % Cargo la otra subinterface
waitfor(log_adj_sub) % Espero por OK, Cancel o X
  
                load haypar handles1      %Hay Parametros?
                haypar1=handles1.haypar
                handles.haypar1=haypar1
                
                if handles.haypar1==1     %Si hay parametros
                
                    load kmin handles1    %Cargo valores min y max del slider
                    smin=handles1.kmin
                    load kmax handles1
                    smax=handles1.kmax
                    handles.top=smax
                    handles.bot=smin
                    set(handles.slider2,'Min',handles.bot);
                    set(handles.slider2,'Max',handles.top);
                    set(handles.text5,'String',smin);
                    set(handles.text6,'String',smax);
                    pos=(smax+smin)/2      %Seteo la posicion inicial de la barra en la mitad
                    set(handles.slider2,'Value',pos);
                    set(handles.text7,'String',pos);
                    clear handles1        %Limpio los datos
                    delete kmax.mat
                    delete kmin.mat
                    delete haypar.mat
                    handles.haydata=1;
                    set(handles.slider2,'Visible','On')  %Solo si hay dato visualizo la barra (slider2)
                    set(handles.text5,'Visible','On')
                    set(handles.text6,'Visible','On')
                    set(handles.text7,'Visible','On')
                    p=handles.im;
                    yp=log_adj(p,pos,256);	
                    axes(handles.graf2);
                    axis off;
                    imshow(yp,[]);
                    handles.d=handles.d+1  % acumulador, sirve para verificacion si hubo datos
                    guidata(hObject,handles)
                          
                end



% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over slider2.
function slider2_ButtonDownFcn(hObject, eventdata, handles)
% hObject    handle to slider2 (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 Reutilizar.
function Reutilizar_Callback(hObject, eventdata, handles)
% hObject    handle to Reutilizar (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

%Funciones del boton 'Reutilizar'
if handles.im2==0
    errordlg('No hay imagen procesada')
else
     if handles.op67==0
        if min(min(handles.im2))<0; %Normalizo la imagen para grabarla
            handles.im2 = handles.im2 - min(min(handles.im2));
        end
        handles.im2 = handles.im2 / max(max(handles.im2));
     end
     
guidata(hObject,handles)

imwrite(handles.im2,'temp.jpg');
temp=imread('temp.jpg');
delete temp.jpg
handles.im=temp;
axes(handles.graf1);
axis off;
imshow(temp);
axes(handles.graf2)
axis off
cla reset
axis off
set(handles.slider2,'Visible','Off')  %Solo si hay dato visualizo la barra (slider2)
set(handles.text5,'Visible','Off')
set(handles.text6,'Visible','Off')
set(handles.text7,'Visible','Off')
guidata(hObject,handles)
end