Anda di halaman 1dari 12

Universidad

Nacional del Callao


2014-B

Curso:

Procesamiento digital de seales.

Profesor:

Telles

Estudiantes:
Asencios Romero Hover Abel
cdigo: 060927D
Cancho Puse Erick Eduardo
cdigo: 1113210121
Felix Ramos Luis Felipe
cdigo: 1113220048
Panizo Boza Angel Xiomar
cdigo: 1113210077

ESCUELA DE INGENIERA ELECTRNICA

DIAGRAMA DE
BLOQUES:

PREVISUALIZACION DE
LA IMAGEN A
PROCESAR

CAPTURA DE IMAGEN,
HACIENDO USO DE LA
CAMARA WEB

FILTRADO DE LA
IMAGEN

CONVERSION A
IMAGEN BINARIA

CONTEO DE LENTEJAS
DE ACUERDO AL
COLOR

DIAGRAMA DE FLUJO:
INICIO

Funciones empleadas para configurar la cmara web,


este tendr una resolucin de 640x480 y el formato
de la imagen estar en RGB.
global vid
vid=videoinput('winvideo',1,'YUY2_640x480');
preview(vid);
set(vid,'ReturnedColorSpace','rgb');

Funciones empleadas para captura y visualizacin de


la imagen, adems se hace uso de variables globales,
es usual en guide para en manejo de datos.
global I vid;
I=getsnapshot(vid);
axes(handles.axes1)
imshow(I)
closepreview;

Funciones empleadas para la descomposicin de capas.


global I;
Iq = rgb2gray(I);
R = I(:,:,1);
G = I(:,:,2);
B = I(:,:,3);

Funciones empleadas para el aislamiento de capas,


filtrado, conversin a imagen binaria y nuevamente
filtrado para pixel menores a 100. X = R v G v B
X_im = X-Iq;
X_im = medfilt2(red_im, [3 3]);
X_im = im2bw(red_im,0.03);
X_im = bwareaopen(red_im,100);

Funciones empleadas para filtra los bordes de nuestra


imagen donde V es proporcional al grosor del borde.
V=8;
im_edge=edge(X_im,'sobel');
SE2=strel('square',V);
im_erode=imerode(not(im_edge),SE2);

Funcin empleada para obtener las propiedades de los


objetos.
[L,Ne]=bwlabel(im_erode);
prop=regionprops(L);

Funciones empleadas para el conteo de las letenjitas


partidas. La clasificacin se realiza dependiendo al
rea que posea cada lenteja de manera experimental el
rea debe de estar en el rango de <200 500>
a=0;
for n=1:length(prop)
x=prop(n).Area;
if x<500 && x>200
a=a+1;
end
end
set(handles.COLORDESIGNADOp,'string',a);

Funciones empleadas para el conteo de las letenjitas


enteras. La clasificacin se realiza dependiendo al
rea que posea cada lenteja de manera experimental el
rea debe de estar en el rango de <600 3000>
g=0;
for n=1:length(prop)
x=prop(n).Area;
if x<3000 && x>600
g=g+1;
end
end
set(handles. COLORDESIGNADO,'string',g);

FIN

INTERFAZ VISUAL

DESCRIPCION DE LOS ELEMENTOS QUE COMPONEN LA INTERFAZ


PREVIEW: Este bloque es usado para la configuracin de la cmara y la vista
previa a la captura de la imagen a procesar.
CAPTURA DE IMAGEN: Este bloque se encarga de la captura de la imagen.
AXES: Una vez capturada la imagen ser mostrada en el nico axes de la interfaz
para la verificacin si el nmero y color de las lentejas son las adecuadas.
PROCESAMIENTO: Este bloque se usa para el procesamiento de la imagen, el color
y rea de las lentejas.
ROJO_E: En los bloques se escribirn el nmero de lentejas enteras de color rojo.
ROJO_P: En los bloques se escribirn el nmero de lentejas partidas de color rojo.
VERDE_E: En los bloques se escribirn el nmero de lentejas enteras de color
verde.
VERDE_P: En los bloques se escribirn el nmero de lentejas partidas de color
verde.
AZUL_E: En los bloques se escribirn el nmero de lentejas enteras de color azul.
AZUL_P: En los bloques se escribirn el nmero de lentejas partidas de color azul.

EJEMPLO

ROJO

VERDE

AZUL

PROGRAMA:
function varargout = color_conteo_RGB(varargin)
% COLOR_CONTEO_RGB MATLAB code for color_conteo_RGB.fig
%
COLOR_CONTEO_RGB, by itself, creates a new COLOR_CONTEO_RGB or raises the
existing
%
singleton*.
%
%
H = COLOR_CONTEO_RGB returns the handle to a new COLOR_CONTEO_RGB or the handle
to
%
the existing singleton*.
%
%
COLOR_CONTEO_RGB('CALLBACK',hObject,eventData,handles,...) calls the local
%
function named CALLBACK in COLOR_CONTEO_RGB.M with the given input arguments.
%
%
COLOR_CONTEO_RGB('Property','Value',...) creates a new COLOR_CONTEO_RGB or
raises the
%
existing singleton*. Starting from the left, property value pairs are
%
applied to the GUI before color_conteo_RGB_OpeningFcn gets called. An
%
unrecognized property name or invalid value makes property application
%
stop. All inputs are passed to color_conteo_RGB_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 color_conteo_RGB
% Last Modified by GUIDE v2.5 08-Dec-2014 13:14:07
% Begin initialization code - DO NOT
gui_Singleton = 1;
gui_State = struct('gui_Name',
'gui_Singleton',
'gui_OpeningFcn',

EDIT
mfilename, ...
gui_Singleton, ...
@color_conteo_RGB_OpeningFcn, ...

'gui_OutputFcn', @color_conteo_RGB_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 color_conteo_RGB is made visible.
function color_conteo_RGB_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 color_conteo_RGB (see VARARGIN)
% Choose default command line output for color_conteo_RGB
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes color_conteo_RGB wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = color_conteo_RGB_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 inicio.
function inicio_Callback(hObject, eventdata, handles)
% hObject
handle to inicio (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles
structure with handles and user data (see GUIDATA)
clc;
global vid
vid=videoinput('winvideo',1,'YUY2_640x480');
%Configuracion de la camara
preview(vid);
%Vista previa a la toma de la imagen
set(vid,'ReturnedColorSpace','rgb'); %Opcion para que devuelva la imagen en RGB
% --- Executes on button press in captura.
function captura_Callback(hObject, eventdata, handles)
% hObject
handle to captura (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles
structure with handles and user data (see GUIDATA)
global I vid;
I=getsnapshot(vid); %Captura de imagen
axes(handles.axes1)
imshow(I)
%Visualizacion de la imagen
closepreview;
% Cierre de vista previa

% --- Executes on button press in procesamiento.


function procesamiento_Callback(hObject, eventdata, handles)
% hObject
handle to procesamiento (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles
structure with handles and user data (see GUIDATA)
global I;
Iq
R
G
B

=
=
=
=

rgb2gray(I);
I(:,:,1);
I(:,:,2);
I(:,:,3);

%imagen en escala de grises


%Decomposicion de la imagen en su capas RGB

%%%%%%%%%%%%%%%%%%%ROJO%%%%%%%%%%%%%%%%%%%%%%
red_im = R-Iq;
%Aislaminto de capa roja
red_im = medfilt2(red_im, [3 3]); %filtro mediana
red_im = im2bw(red_im,0.03); %imagen binaria
red_im = bwareaopen(red_im,100); %Filtro para pixel menores a 100
V=8;
%Contante que se involucra con el grosor del contorno de la imagen
im_edge=edge(red_im,'sobel'); % filtro para visualizar solo bordes
SE2=strel('square',V);
%Grosor de los bordes
im_erode=imerode(not(im_edge),SE2); %Solo deja de color negro los borde el resto es de
color blanco
[L,Ne]=bwlabel(im_erode); %numero de objetos
prop=regionprops(L);
%Propiedades de la imagen
%LENTEJAS PARTIDAS
a=0;
for n=1:length(prop)
x=prop(n).Area;
%Area de los objetos
if x<500 && x>200
%Condicional para conteo
a=a+1;
%Acumulador
end
end
set(handles.rojop,'string',a); %Muestra el nuemro de objetos en el TEXT
g=0;
for n=1:length(prop)
x=prop(n).Area;
%Area de los objetos
if x<3000 && x>600 %Condicional para conteo
g=g+1;
%Acumulador
end
end
set(handles.rojo,'string',g);
%Muestra el nuemro de objetos en el TEXT
%%%%%%%%%%%%%%%%%%%VERDE%%%%%%%%%%%%%%%%%%%%%
green_im = G-Iq;
%Aislaminto de capa verde
green_im = medfilt2(green_im, [3 3]); %filtro mediana
green_im = im2bw(green_im,0.03); %imagen binaria
green_im = bwareaopen(green_im,100); %Filtro para pixel menores a 100
V=8;
%Contante que se involucra con el grosor del contorno de la imagen
im_edge=edge(green_im,'sobel'); % filtro para visualizar solo bordes
SE2=strel('square',V);
%Grosor de los bordes
im_erode=imerode(not(im_edge),SE2); %Solo deja de color negro los borde el resto es de
color blanco

[L,Ne]=bwlabel(im_erode); %numero de objetos


prop=regionprops(L);
%Propiedades de la imagen
%LENTEJAS PARTIDAS
a=0;
for n=1:length(prop)
x=prop(n).Area;
%Area de los objetos
if x<3000 && x>600 %Condicional para conteo
g=g+1;
%Acumulador
end
end
set(handles.verdep,'string',a); %Muestra el nuemro de objetos en el TEXT
g=0;
for n=1:length(prop)
x=prop(n).Area;
%Area de los objetos
if x<3000 && x>600 %Condicional para conteo
g=g+1;
%Acumulador
end
end
set(handles.verde,'string',g); %Muestra el nuemro de objetos en el TEXT
%%%%%%%%%%%%%%%%%%%AZUL%%%%%%%%%%%%%%%%%%%%%
blue_im = B-Iq;
%Aislaminto de capa azul
blue_im = medfilt2(blue_im, [3 3]); %filtro mediana
blue_im = im2bw(blue_im,0.03); %imagen binaria
blue_im = bwareaopen(blue_im,100); %Filtro para pixel menores a 100
V=8;
%Contante que se involucra con el grosor del contorno de la imagen
im_edge=edge(blue_im,'sobel'); % filtro para visualizar solo bordes
SE2=strel('square',V);
%Grosor de los bordes
im_erode=imerode(not(im_edge),SE2); %Solo deja de color negro los borde el resto es de
color blanco
[L,Ne]=bwlabel(im_erode); %numero de objetos
prop=regionprops(L);
%Propiedades de la imagen
%LENTEJAS PARTIDAS
a=0;
for n=1:length(prop)
x=prop(n).Area;
%Area de los objetos
if x<3000 && x>600 %Condicional para conteo
g=g+1;
%Acumulador
end
end
set(handles.azulp,'string',a); %Muestra el nuemro de objetos en el TEXT
g=0;
for n=1:length(prop)
x=prop(n).Area;
%Area de los objetos
if x<3000 && x>600 %Condicional para conteo
g=g+1;
%Acumulador
end
end
set(handles.azul,'string',g); %Muestra el nuemro de objetos en el TEXT
function rojo_Callback(hObject, eventdata, handles)
% hObject
handle to rojo (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 rojo as text


%
str2double(get(hObject,'String')) returns contents of rojo as a double
% --- Executes during object creation, after setting all properties.
function rojo_CreateFcn(hObject, eventdata, handles)
% hObject
handle to rojo (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 rojop_Callback(hObject, eventdata, handles)
% hObject
handle to rojop (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 rojop as text
%
str2double(get(hObject,'String')) returns contents of rojop as a double
% --- Executes during object creation, after setting all properties.
function rojop_CreateFcn(hObject, eventdata, handles)
% hObject
handle to rojop (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 verde_Callback(hObject, eventdata, handles)
% hObject
handle to verde (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 verde as text
%
str2double(get(hObject,'String')) returns contents of verde as a double
% --- Executes during object creation, after setting all properties.
function verde_CreateFcn(hObject, eventdata, handles)
% hObject
handle to verde (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 verdep_Callback(hObject, eventdata, handles)
% hObject
handle to verdep (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 verdep as text
%
str2double(get(hObject,'String')) returns contents of verdep as a double
% --- Executes during object creation, after setting all properties.
function verdep_CreateFcn(hObject, eventdata, handles)
% hObject
handle to verdep (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 azul_Callback(hObject, eventdata, handles)
% hObject
handle to azul (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 azul as text
%
str2double(get(hObject,'String')) returns contents of azul as a double
% --- Executes during object creation, after setting all properties.
function azul_CreateFcn(hObject, eventdata, handles)
% hObject
handle to azul (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 azulp_Callback(hObject, eventdata, handles)
% hObject
handle to azulp (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 azulp as text
%
str2double(get(hObject,'String')) returns contents of azulp as a double
% --- Executes during object creation, after setting all properties.
function azulp_CreateFcn(hObject, eventdata, handles)
% hObject
handle to azulp (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 when figure1 is resized.
function figure1_ResizeFcn(hObject, eventdata, handles)
% hObject
handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles
structure with handles and user data (see GUIDATA)

COMENTARIO Y CONCLUSIONES
Se concluye que para el presente trabajo fue fundamental el uso de
iluminacin, teniendo en cuenta la posicin de la misma.
El valor de la las capas RGB varan dependiendo al ngulo de incidencia de
la luz respecto al rea iluminada.

Anda mungkin juga menyukai