ZOOM EN MATLAB USANDO SLIDER


Imagen de como debe hacerse la GUI chequen los nombres:




%ZOOM USANDO UN SLIDER CON MATLAB
%MTI JAIRO AVENDAÑO MALVAEZ
%PROFESOR EN EL TECNOLOGICO DE ZACATEPC
%E-MAIL:jairomarvin@hotmail.com
%MATERIA: HERRAMIENTAS COMPUTACIONALES
%LIBRE DE USARSE Y MODIFICARSE, SOLO MENCIONA LA FUENTE.. :)


%ESTE ES EL CODIGO FUENTE

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

% Last Modified by GUIDE v2.5 02-Nov-2011 19:30:11

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @capcuen_OpeningFcn, ...
                   'gui_OutputFcn',  @capcuen_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 webcam_tarea is made visible.
function capcuen_OpeningFcn(hObject, eventdata, handles, varargin)
set(gcf,'Color',[0.5 0.9 0.5])
scrsz = get(0, 'ScreenSize');
pos_act=get(gcf,'Position');
xr=scrsz(3) - pos_act(3);
xp=round(xr/2);
yr=scrsz(4) - pos_act(4);
yp=round(yr/2);
set(gcf,'Position',[xp yp pos_act(3) pos_act(4)]);
handles.output = hObject;
% Update handles structure
handles.rgb = [];
handles.noback = [];
guidata(hObject, handles);
handles.output = hObject;
% This sets up the video camera and starts the preview
% Only do this when it's invisible
if strcmp(get(hObject,'Visible'),'off')
try
handles.vidobj = videoinput('winvideo');
% 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 CÁMARA CONECTADA. Cargando Profile.jpg.')
hImage = image(imread('bacterias.jpg'), 'Parent',handles.video_cam);
end
end

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


% --- Outputs from this function are returned to the command line.
function varargout = capcuen_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 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)
try
handles.rgb = getsnapshot(handles.vidobj);
catch
handles.rgb = imread('bacterias.jpg');
end
% Update handles structure
guidata(hObject, handles);
image(handles.rgb,'Parent',handles.fotografia);
axes(handles.fotografia)
axis off

% --- Executes on button press in Cuenta.
function Cuenta_Callback(hObject, eventdata, handles)
% hObject    handle to Cuenta (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%% Convert image to BW
coin1 = im2bw(getimage(handles.fotografia));
%% Fill image regions and holes
coin2 = imfill(coin1,'holes');
%% Label and count connected components
[L Ne]=bwlabel(double(coin2));
%% Measure properties of image regions
prop=regionprops(L,'Area','Centroid','BoundingBox');
%% Counter
total=0;
%% Show image
axes(handles.axes3)
imshow(getimage(handles.fotografia));hold on
%% Money count based on area of coin


for n=1:size(prop,1) %For 1 to Total number of coins
    boundingBox = prop(n).BoundingBox;
    x1 = boundingBox(1);
    y1 = boundingBox(2);
    x2 = x1 + boundingBox(3) - 1;
    y2 = y1 + boundingBox(4) - 1;
verticesX = [x1 x2 x2 x1 x1];
verticesY = [y1 y1 y2 y2 y1];
plot(verticesX, verticesY, 'r-', 'LineWidth', 2);
    cent=prop(n).Centroid;
    X=cent(1);Y=cent(2);
    if prop(n).Area>10
        text(X,Y,'X')
        total=total+1;    
    end
end
hold on
set(handles.Respuesta,'string',total);

% --- 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)
foto=getimage(handles.axes3);

% Guardar imagen
imwrite(foto,'F:\Documents\MATLAB\Programas Mat\80 captura cuenta\foto.jpg');


% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)
% hObject    handle to slider1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Update handles structure


I=getimage(handles.fotografia);
[x,y,c]=size(I)
scale=get(hObject,'Value'); %returns position of slider
scale=scale*10;
an= imcrop(I,[x/2 y/2 x/scale y/scale]);
axes(handles.axes3)
imshow(an)
title('Zoom')


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

Comentarios