Professional Documents
Culture Documents
'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @COINS_COUNTERespaldo_OpeningFcn, ... 'gui_OutputFcn', @COINS_COUNTERespaldo_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 COINS_COUNTERespaldo is made visible. function COINS_COUNTERespaldo_OpeningFcn(hObject, eventdata, handles, varargin) % Choose default command line output for COINS_COUNTERespaldo
% UIWAIT makes COINS_COUNTERespaldo wait for user response (see UIRESUME) % uiwait(handles.figure1); if strcmp(get(hObject,'Visible'),'off') try handles.vidobj = videoinput('winvideo',2); % Update handles structure start(handles.vidobj); guidata(hObject, handles); vidRes = get(handles.vidobj, 'VideoResolution'); nBands = get(handles.vidobj, 'NumberOfBands'); hImage = image(zeros(vidRes(2), vidRes(1), nBands), 'Parent',... handles.video_cam); preview(handles.vidobj,hImage); catch msgbox('NO HAY CMARA CONECTADA. Cargando Profile.jpg.') hImage = image(imread('profile.jpg'), 'Parent', handles.video_cam); end
end
% --- Outputs from this function are returned to the command line. function varargout = COINS_COUNTERespaldo_OutputFcn(hObject, eventdata, handles)
% Get default command line output from handles structure varargout{1} = handles.output;
% --- Executes during object creation, after setting all properties. function figure1_CreateFcn(hObject, eventdata, handles)
% --- Executes on button press in CAPTURE. function CAPTURE_Callback(hObject, eventdata, handles) %handles.rgb=getsnapshot(handles.vidobj) im_rgb=imread('mon2.jpg'); try %handles.rgb=getsnapshot(handles.vidobj) im_rgb=imread('mon2.jpg');
% Update handles structure guidata(hObject, handles); %image(handles.rgb,'Parent',handles.img_capture); image(im_rgb,'Parent',handles.img_capture); axes(handles.img_capture) axis off
% --- Executes on button press in SAVE. function SAVE_Callback(hObject, eventdata, handles) % hObject handle to SAVE (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) rgb = getimage(handles.img_capture); if isempty(rgb), return, end %guardar como archivo fileTypes = supportedImageTypes; % Funcin auxiliar. [f,p] = uiputfile(fileTypes); if f==0, return, end fName = fullfile(p,f); imwrite(rgb,fName); msgbox(['Imagen guardada en ' fName]); function fileTypes = supportedImageTypes % Funcin auxiliar: formatos de imgenes.
% --- Executes on button press in CONTADOR. function CONTADOR_Callback(hObject, eventdata, handles) im_color = imread('mon2.jpg'); %im_color = imread(handles.rgb); % brillo=5; % im_color=im_color-(brillo); % [f c]=size(im_color(:,:,1)); % k=3; % for m=1:k % % j=0; i=0;
% end % end
% image(im_color,'Parent',handles.img_capture); % axes(handles.img_capture); % imshow(im_color); % axis off; im_colorbw1=im_color(:,:,1)<128; im_colorc1=imcomplement(im_colorbw1); im_colorbw2=im_color(:,:,2)<1280; im_colorc2=imcomplement(im_colorbw2); im_colorbw3=im_color(:,:,3)<128; im_colorc3=imcomplement(im_colorbw3);
image(im_colorc,'Parent',handles.img_capture); axes(handles.img_capture); imshow(im_colorc); axis off; dimopen=size(im_open0) [L Ne]=bwlabel(im_open0); a=Ne prop=regionprops(L,'All');1 areas = [prop.Area]; perimetros=[prop.Perimeter]; FC=4*pi*areas./(perimetros).^2 circ=find(FC>0.85&FC<1.1) a_circ=areas(circ);
end
im_color1=immultiply(im_circ,im_color(:,:,1)); im_color2=immultiply(im_circ,im_color(:,:,2)); im_color3=immultiply(im_circ,im_color(:,:,3)); im_color(:,:,1)=im_color1; im_color(:,:,2)=im_color2; im_color(:,:,3)=im_color3; % image(im_color,'Parent',handles.img_capture); axes(handles.img_capture); imshow(im_color); axis off; % %definimos la tolerancia tol=5;%26 % %tomamos una muestra de color de la imagen que % %est siendo mostrada
pixn=impixel pixc=impixel pixl=impixel pixb=impixel % %definimos los colores de referencia para niquel crefRn=double(pixn(1,1)); crefGn=double(pixn(1,2)); crefBn=double(pixn(1,3)); % %%%color ref del cobre crefRc=double(pixc(1,1)); crefGc=double(pixc(1,2)); crefBc=double(pixc(1,3)); % %%%color ref del laton crefRl=double(pixl(1,1)); crefGl=double(pixl(1,2)); crefBl=double(pixl(1,3)); %%%color ref del bronce crefRb=double(pixb(1,1)); crefGb=double(pixb(1,2)); crefBb=double(pixb(1,3)); % % C5=[crefRn crefRc crefRl crefRb] C6=[crefGn crefGc crefGl crefGb]
colb=C5(4)
k=1 k1=3
end
coln1=C6(1) colc1=C6(2) coll1=C6(3) colb1=C6(4) k=3 k1=2 end if(C7media<=C5media&C5media<=C6media) coln=C7(1) colc=C7(2)
coll=C7(3) colb=C7(4)
segn(:,:,k)=tkn;
im_in=segn(:,:,k)|segc(:,:,k)|segl(:,:,k)|segb(:,:,k); im_in1=segn1(:,:,k1)|segc1(:,:,k1)|segl1(:,:,k1)|segb1(:,:,k1);
im_cleanin= bwmorph(im_in,'clean');
im_fillin = bwmorph(im_cleanin,'fill',Inf); se=strel('disk',5) im_dilatein = imdilate(im_fillin,se); im_rop = bwareaopen(im_dilatein,500); se1=strel('line',15,0); se2=strel('line',15,90); im_erodein = imerode(im_rop,[se1, se2]); im_erodein = imerode(im_erodein,[se1, se2]); im_a= bwmorph(im_erodein,'clean'); im_d= imdilate(im_a,se); im_d= imdilate(im_d,se);
for i=1:Neo if(areas_r(i)==areas_o(i)) areas_r(i)=0; j=Neo+1; else j=i end ix(i)=j end a_seg=ismember(Lr,ix); im_aseg=imfill(a_seg,'holes');
% % m100 = find(areas_s > 12000 & areas_s <13000) % prop100 = prop(m100) %cantidad=length(prop100)*1; % for idx = 1:length(prop100) % h = rectangle('Position',prop100(idx).BoundingBox,'Curvature',[0.8,0.4],'LineWidth',2,'LineStyle','--'); % % set(h,'EdgeColor',[0.75 0 0.75]); hold on
% end %% % m50 = find(areas_s >20000 & areas_s < 20500) % prop50 = prop(m50); %cantidad=cantidad+length(prop100)*0.5; % for idx = 1:length(prop50) % h rectangle('Position',prop50(idx).BoundingBox,'Curvature',[0.8,0.4],'LineWidth',2,'LineStyle','--'); % % set(h,'EdgeColor',[0.75 0.5 0]); hold on =
% end % % m25 = find(areas_s > 8000 & areas_s < 9000); % prop25 = prop(m25); % % for idx = 1:length(prop25)
% end %%%% % m10 = find(areas_s > 4000 & areas_s < 4100); % prop10 = prop(m10); % %% % for idx = 1:length(prop10) % h rectangle('Position',prop10(idx).BoundingBox,'Curvature',[0.8,0.4],'LineWidth',2,'LineStyle','--'); % % set(h,'EdgeColor',[0.25 .7 0]); hold on =
% end %%%% % m5 = find(areas_s > 6000 & areas_s < 7000); % prop5 = prop(m5); % hold on; % %% % for idx = 1:length(prop5) % h rectangle('Position',prop5(idx).BoundingBox,'Curvature',[0.8,0.4],'LineWidth',2,'LineStyle','--'); % % set(h,'EdgeColor',[0.1 0 .8]); hold on =
% end %%% % m1 = find(areas_s > 4700 & areas_s < 4900); % prop1 = prop(m1); % hold on; % % % for idx = 1:length(prop1) % h rectangle('Position',prop1(idx).BoundingBox,'Curvature',[0.8,0.4],'LineWidth',2,'LineStyle','--'); % % set(h,'EdgeColor',[0.75 0 0]); hold on =
% --- Executes on selection change in listbox1. function listbox1_Callback(hObject, eventdata, handles) % hObject handle to listbox1 (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 listbox1 contents as cell array % contents{get(hObject,'Value')} returns selected item from listbox1
% --- Executes during object creation, after setting all properties. function listbox1_CreateFcn(hObject, eventdata, handles) % hObject handle to listbox1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows. % See ISPC and COMPUTER.
% --- 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) clear,clc,close all
function border_Callback(hObject, eventdata, handles) % hObject handle to border (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 border contents as cell array % contents{get(hObject,'Value')} returns selected item from border
T=handles.threshold; I=handles.rgb;
if ME==1
im_g=rgb2gray(I); %pasar imgen a escala de grises umb=graythresh(im_g); %definir umbral bw=im2bw(im_g, umb); %Binarizar imgen handles.bw1=edge(bw,'sobel',T);
axes(handles.img_capture) imshow(handles.bw1)
axis off
elseif ME==2
im_g=rgb2gray(I); %pasar imgen a escala de grises umb=graythresh(im_g); %definir umbral bw=im2bw(im_g, umb); %Binarizar imgen handles.bw1=edge(bw,'prewitt',T);
elseif ME==3
im_g=rgb2gray(I); %pasar imgen a escala de grises umb=graythresh(im_g); %definir umbral bw=im2bw(im_g, umb); %Binarizar imgen handles.bw1=edge(bw,'roberts',T);
elseif ME==4
im_g=rgb2gray(I); %pasar imgen a escala de grises umb=graythresh(im_g); %definir umbral bw=im2bw(im_g, umb); %Binarizar imgen handles.bw1=edge(bw,'log',T)
elseif ME==5
im_g=rgb2gray(I); %pasar imgen a escala de grises umb=graythresh(im_g); %definir umbral bw=im2bw(im_g, umb); %Binarizar imgen handles.bw1=edge(bw,'zerocross');
elseif ME==6
im_g=rgb2gray(I); %pasar imgen a escala de grises umb=graythresh(im_g); %definir umbral bw=im2bw(im_g, umb); %Binarizar imgen handles.bw1=edge(bw,'canny',T);
end
function threshold_Callback(hObject, eventdata, handles) % hObject handle to threshold (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 threshold as text % str2double(get(hObject,'String')) returns contents of threshold as a double
% --- Executes during object creation, after setting all properties. function border_CreateFcn(hObject, eventdata, handles) % hObject handle to border (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.
% --- Executes during object creation, after setting all properties. function threshold_CreateFcn(hObject, eventdata, handles) % hObject handle to threshold (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.
set(hObject,'BackgroundColor','white'); end