Matlab - obtener imagen de un axes

 
Vista:
sin imagen de perfil

obtener imagen de un axes

Publicado por Pedro (7 intervenciones) el 29/10/2012 12:32:16
Hola! tengo una duda acerca de cómo obtener una imagen de un axes.
Tengo mi gui creado, en la cual tomo la imagen de una webcam. Al darle a capturar, me saca la imagen en otro axes, llamado "fotowebcam". Luego, tengo creados dos botones, uno que me guarda la imagen que he tomado, y otro que me abre una imagen anterior y me la saca por "fotowebcam".
La duda que tengo ahora, es cómo tomar el dato directamente desde fotowebcam. He estado mirando con imhandles, imgca, imgcf y get, pero no me coge la imagen.

Gracias, un saludo.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil

obtener imagen de un axes

Publicado por Pedro (7 intervenciones) el 07/11/2012 10:14:41
Perdona por tardar en contestar.

Mi idea, es que despues de capturar mi imagen (que sale en "fotowebcam"), la pueda coger directamente de "fotowebcam" para analizarla.


function varargout = gui2(varargin)

gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @gui2_OpeningFcn, ...
'gui_OutputFcn', @gui2_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 gui2 is made visible.
function gui2_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 gui2 (see VARARGIN)

% Choose default command line output for gui2

handles.output = hObject;
handles.rgb = [];
handles.noback = [];
% Update handles structure
guidata(hObject, handles);

% UIWAIT makes gui2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
if strcmp(get(hObject,'Visible'),'off')
try
handles.vidobj = videoinput('winvideo',1);
% 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.webcam);
preview(handles.vidobj,hImage);
catch
msgbox('Error. No hay ninguna cámara conectada. Cargando Profile.jpg.')
hImage = image(imread('profile.jpg'), 'Parent',handles.webcam);
end
end

function varargout = gui2_OutputFcn(hObject, eventdata, handles)

varargout{1} = handles.output;

% --- Executes on button press in abrir.
function abrir_Callback(hObject, eventdata, handles)
% hObject handle to abrir (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[FileName Path]=uigetfile({'*.jpg;*.bmp'},'Abrir Imagen Guardada');
if isequal(FileName,0)
%no hace nada
return
else
abririmagen=imread(strcat(Path,FileName));
image(abririmagen,'Parent',handles.fotowebcam); %me abre la imagen en fotowebcam.
%imshow(abririmagen); me abre la imagen, pero la abre en otro axes
end
%handles.direccion=strcat(Path,FileName);
guidata(hObject,handles) %guidata es la sentencia para salvar los datos de la aplicación.


% --- Executes on button press in calcularw.
function calcularw_Callback(hObject, eventdata, handles)
% hObject handle to calcularw (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

%%% La idea es que coja la foto del axes.fotowebcam directamente,
%%% o de una imagen guardada. (imhandles-imgca-imgcf)

fotodouble = imread('123gris.bmp');
maximatriz = max(fotodouble); % maximos en cada columna; puestos en un vector fila
maxvector = max(maximatriz); % maximo valor en toda la imagen.
[posicionx, posiciony] = find(fotodouble==maxvector); % posiciones en los que se encuentra el maximo valor.

%%% Sacamos el punto central de nuestro objeto, y con ello obtenemos la
%%% fila y la columna por la que pasa, con eso, sacamos nuestros radios.
%%% Este código está cogido de la funcion imgca de la ayuda.

bw=im2bw(fotodouble,0.8); %convierte la imagen a binario, y le pongo un valor 0.8 para no ajustarlo demasiado al blanco
figure, imshow(bw); %nos muestra la imagen pasada a binario
L=bwlabel(bw,4);
objects=regionprops(L,'centroid');
imtool(bw);
columna=floor(objects.Centroid(1));
fila=floor(objects.Centroid(2));

% axes(handles.ejex);
% plot(imagen(columna,:));
% axis on
% axes(handles.eje_y);
% plot(imagen(:,fila));
% axis on
% axes(handles.axes5);
% surf(imagen,'facecolor','texturemap');colorbar
% axis on
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar