Vous êtes sur la page 1sur 5

function varargout = cargar(varargin)

% CARGAR M-file for cargar.fig


%
CARGAR, by itself, creates a new CARGAR or raises the existing
%
singleton*.
%
%
H = CARGAR returns the handle to a new CARGAR or the handle to
%
the existing singleton*.
%
%
CARGAR('CALLBACK',hObject,eventData,handles,...) calls the local
%
function named CALLBACK in CARGAR.M with the given input arguments.
%
%
CARGAR('Property','Value',...) creates a new CARGAR or raises the
%
existing singleton*. Starting from the left, property value pairs are
%
applied to the GUI before cargar_OpeningFcn gets called. An
%
unrecognized property name or invalid value makes property application
%
stop. All inputs are passed to cargar_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 cargar
% Last Modified by GUIDE v2.5 15-Oct-2015 13:58:14
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',
mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @cargar_OpeningFcn, ...
'gui_OutputFcn', @cargar_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 cargar is made visible.
function cargar_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 cargar (see VARARGIN)
% Choose default command line output for cargar
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);

% UIWAIT makes cargar wait for user response (see UIRESUME)


% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = cargar_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 CargarImagen.
function CargarImagen_Callback(hObject, eventdata, handles)
% hObject
handle to CargarImagen (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles
structure with handles and user data (see GUIDATA)
try
[filename,pathname] = uigetfile('*.jpg','selecciona imagen para abrir');
%Proporciona el cuadro de dialogo para seleccionar una imagen JPG
if isequal(filename,0)
%No se hace nada si se presiona cancelar
else
handles.myImage = imread(fullfile(pathname,filename));
%Carga la imagen seleccionada al indicador handles.myImage
Foto = handles.myImage;
%almacenamos la imagen en una variable llamada Foto
imshow(Foto,'Parent',handles.axes1)
%visualizamos la imagen seleccionada en axes1
end
guidata(hObject, handles);
%Nos permite guardar los indicadores existentes y volverlos a
%utilizar
% --- Executes on button press in ProcesarImagen.
function ProcesarImagen_Callback(hObject, eventdata, handles)
% hObject
handle to ProcesarImagen (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles
structure with handles and user data (see GUIDATA)
NewVal=('0');
%Inicializa NewVal en 0
NewVal= str2double(get(handles.edit1,'String'));
%Convierte las cadenas en valores numericos y obtiene el dato ingresado
%en el elemento profundidad (mm)
if isnan (NewVal)== 0 %Evalua si se introdujo un numero o una letra
NewVal = NewVal + 0;
else
errordlg('Debe Ingresar un Valor Numerico','ERROR')
NewVal = 0;
end
handles.edit1=NewVal;
%El valor obtenido en profundidad (mm), se almacena en un indicador

%Comienzo Procesamient de la Imagen


y = handles.myImage; %Se guarda la imagen Seleccionada en una variable "y"
gris = rgb2gray(y); %Se convierte a Escala de Grises con el fin de trabajar
el Histograma
%Filtro de Mediana para disminuir el ruido, con Mascara de [3x3]
gris=medfilt2(gris,[3,3]);
figure
imshow(gris)
%%Borrar Ruidos (seales con luminosidad inferior a X)
[nk rk]=imhist(gris); %Obtenemos los niveles de grises existentes en la imagen y
la intensidad en pixeles que existe de cada nivel de gris.
for n=1:255
if 20>nk(n);
nk(n)=0;
end
end
ban=0;
var=0;
pos=10;
n=10;
%%Primer Maximo
while ban==0
if var>nk(n);
ban=1;
end
if nk(n)>var;
var=nk(n);
pos=n;
end
n=n+1;
end
%%Seleccionar umbral
umb=pos/255;
%%Convertir Imagen a blanco y negro
byn=im2bw(gris,umb);
%%Invertir blanco y negro
byn=~byn;
%%Tamao de imagen
[a,b]=size(y);
npb=(a*b)*0.00002;
npb=round(npb);
%%Borrar areas menores a 10000 pixels
byn=bwareaopen(byn,npb);
%Etiqueta la pupila y carga en Ne el numero de etiquetas
[L Ne]=bwlabel(byn);
imshow(y,'Parent', handles.axes2);

prop=regionprops(L);
hold on
%Dibujar solamente area mayor
amay = 0
pmay = 0
vec = [0,0]
for n=1:length(prop)
Area = prop(n).Area
vec(1) = prop(n).BoundingBox(3)
vec(2) = prop(n).BoundingBox(4)
%%Protocolo de tamao cuadrado por lo menos 70%
co = min(vec)/max(vec)
if 0.7>co
Area = 0
end
if Area>amay
amay = Area
pmay = n
end
end
rectangle('position',prop(pmay).BoundingBox,'EdgeColor','g','LineWidth',2)
x=prop(pmay.BoundingBox(1)+prop(pmay).BoundingBox(3)/2);
y=prop(pmay.BoundingBox(2)+prop(pmay).BoundingBox(4)/2);
%%Calculo de tamao en milimetros
alfa = 90*(prop(pmay).BoundingBox(3)/b);
prof = handles.edit1
T = prof*tand(alfa)
plot(x,y,'+')
set(handles.text1,'string',T);
% --- Executes on button press in Reiniciar.
function Reiniciar_Callback(hObject, eventdata, handles)
% hObject
handle to Reiniciar (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles
structure with handles and user data (see GUIDATA)
ini=char(' ');
set(handles.text1,'String',ini);
%Limpia la casilla de texto donde se visualiza la longitud de la Pupila
clear all, clc
%Limpia la pantalla principal de Matlab y elimina las variables
close(gcbf)
%Cierra el programa
protect_1;
%Vuelve y Ejecuta el Programa
% --- Executes on button press in Editar.
function Editar_Callback(hObject, eventdata, handles)
% hObject
handle to Editar (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles
structure with handles and user data (see GUIDATA)
y=imcrop(handles.myImage);
%Nos permite recortar una zona deseada de la Imagen seleccionada

imshow(y,'Parent',handles.axes1);
%Visualizamos la imagen recortada en axes1
handles.myImage=y;
%Almacenamos en un indicador esta imagen
guidata(hObject,handles);
%Guardamos los indicadores Existentes
% --- Executes on button press in Salir.
function Salir_Callback(hObject, eventdata, handles)
% hObject
handle to Salir (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles
structure with handles and user data (see GUIDATA)

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,'defaultUicontrolBackgr
oundColor'))
set(hObject,'BackgroundColor','white');
end

function edit2_Callback(hObject, eventdata, handles)


% hObject
handle to edit2 (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 edit2 as text
%
str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject
handle to edit2 (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,'defaultUicontrolBackgr
oundColor'))
set(hObject,'BackgroundColor','white');
end

Vous aimerez peut-être aussi