Editor de imagenes

by

 

El siguiente archivo permite crear un editor de imagenes con varios filtros y opciones de ruido

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

% Last Modified by GUIDE v2.5 01-Mar-2013 11:27:02

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

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = filtros_interface_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 selection change in popupmenu2.
function popupmenu2_Callback(hObject, eventdata, handles)
val=get(hObject, 'Value');
str=get(hObject, 'String');

switch str {val}
case 'Filtro promedio'
        fotopr=imread('lena.jpg');
        foto_R= fotopr(:,:,1);
        foto_G= fotopr(:,:,2);
        foto_B= fotopr(:,:,3);
        filtro=1/9*[010;010;010];
        fotop_R=filter2(filtro,double(foto_R));
        fotop_G=filter2(filtro,double(foto_G));
        fotop_B=filter2(filtro,double(foto_B));
        PromedioFiltro(:,:,1)=fotop_R;
        PromedioFiltro(:,:,2)=fotop_G;
        PromedioFiltro(:,:,3)=fotop_B;
        imshow(uint8(fotopr));
        imshow(uint8( PromedioFiltro));
 case 'Filtro mediano'
        fotome=imread('lena.jpg');
        fotome_fil=rgb2gray(fotome);
        imshow(fotome_fil);
        MedianoFiltro=medfilt2(fotome_fil);
        imshow(MedianoFiltro);
        
 case 'Enfoque'
      enfo=imread('lena.jpg');
      enfo_R=enfo(:,:,1);
      enfo_G=enfo(:,:,2);
      enfo_B=enfo(:,:,3);
      filtro=[0, -1, 0, -1, 5, -1, 0, -1, 0];
      enfoq_R=filter2(filtro,double(enfo_R));
      enfoq_G=filter2(filtro,double(enfo_G));
      enfoq_B=filter2(filtro,double(enfo_B));
      EnfoqFiltro(:,:,1)=enfoq_R;
      EnfoqFiltro(:,:,2)=enfoq_G;
      EnfoqFiltro(:,:,3)=enfoq_B;
      imshow(uint8(EnfoqFiltro));
 case 'Desenfoque'
      pict=imread('lena.jpg');
      foto_R=pict(:,:,1);
      foto_G=pict(:,:,2);
      foto_B=pict(:,:,3);
      filtro=[0	1	0; 1 -3	1; 0 1 0];
      foto2_R=filter2(filtro,double(foto_R));
      foto2_G=filter2(filtro,double(foto_G));
      foto2_B=filter2(filtro,double(foto_B));
      imgFiltro(:,:,1)=foto2_R;
      imgFiltro(:,:,2)=foto2_G;
      imgFiltro(:,:,3)=foto2_B;
      imshow(uint8(imgFiltro));
      
    case 'Resalte de Bordes'

fotoRGB=imread('lena.jpg');
filtro=[0.000 0.707 1.414;-0.707 0.000 0.707;-1.414 -0.707 0.000];
imagen_gris=rgb2gray(fotoRGB);
imagen_borde=filter2(filtro,imagen_gris);
imshow(uint8(imagen_borde));
      
    case 'Realce de bordes'
      pict=imread('lena.jpg');
      foto_R=pict(:,:,1);
      foto_G=pict(:,:,2);
      foto_B=pict(:,:,3);
      filtro=[0, 0, 0, -1, 1, 0, 0, 0, 0];
      foto2_R=filter2(filtro,double(foto_R));
      foto2_G=filter2(filtro,double(foto_G));
      foto2_B=filter2(filtro,double(foto_B));
      imgFiltro(:,:,1)=foto2_R;
      imgFiltro(:,:,2)=foto2_G;
      imgFiltro(:,:,3)=foto2_B;
      imshow(uint8(imgFiltro));
      
   case 'Deteccin de bordes'
   detec=imread('lena.jpg');
   filtroborde=[-1 2 0;-1 1 0;0 0 0];
   detec_gris=rgb2gray(detec);
   deteccion=filter2(filtroborde,detec_gris);
   imshow(deteccion);   
end


% hObject    handle to popupmenu2 (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 popupmenu2 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu2


% --- Executes during object creation, after setting all properties.
function popupmenu2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu2 (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 popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
val=get(hObject, 'Value');
str=get(hObject, 'String');

switch str {val}
case 'Gaussian'
foto=imread('lena.jpg');
%fotoruido=imnoise(foto,'poisson');
foto_R=foto(:,:,1);
foto_G=foto(:,:,2);
foto_B=foto(:,:,3);

filtro=[1 2 1; 2 4 2;  1 2 1]*(1/16);
foto2_R=filter2(filtro,double(foto_R));
foto2_G=filter2(filtro,double(foto_G));
foto2_B=filter2(filtro,double(foto_B));

imgFiltro(:,:,1)=foto2_R;
imgFiltro(:,:,2)=foto2_G;
imgFiltro(:,:,3)=foto2_B;

imshow(uint8(imgFiltro));

case 'Zero-mean Gaussian'
foto=imread('lena.jpg');
fotozem=imnoise( foto(:,:,1), 'localvar',[0:0.1:1],[0:0.1:1].^3);
imshow(fotozem);   
    
case 'Poisson noise'
     fotopois=imread('lena.jpg');
     fotopois=imnoise( fotopois, 'poisson');
     imshow( fotopois);
case 'Salt & Pepper'
     foton=imread('lena.jpg');
     foton_gris=rgb2gray(foton);
     foton_gris=imnoise(foton_gris, 'salt & pepper');
     imshow(foton_gris);
case 'Multiplicative noise'
     fotom=imread('lena.jpg');
     fotom_gris=rgb2gray(fotom);
     fotom_gris=imnoise(fotom_gris, 'speckle');
     imshow(fotom_gris);
    
end

% hObject    handle to popupmenu1 (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 popupmenu1 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu1


% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (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 button press in gris.
function gris_Callback(hObject, eventdata, handles)
Imagen=imread('lena.jpg');
R=Imagen(:,:,1);G=Imagen(:,:,2);B=Imagen(:,:,3);
ImagenGris=R*0.2989+G*0.5870+B*0.1140;
imshow(ImagenGris);
% hObject    handle to gris (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 cargar.
function cargar_Callback(hObject, eventdata, handles)
Imagen=imread('lena.jpg');
imshow(Imagen);
image(Imagen,'Parent', handles.axes5);
% 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)


% --- Executes during object creation, after setting all properties.
function background_CreateFcn(hObject, eventdata, handles)


% hObject    handle to background (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: place code in OpeningFcn to populate background


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


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

Contact us