Archive

Posts Tagged ‘gui’

Simple Selecting Points in 2 images using Matlab GUIDE

January 9, 2010 4 comments

Following is the program that lets you load two images and click points in both of them. It does not store the correspondence however because it stores points in the array so if you keep the order same in the both images it could be used for the point correspondence.
Use the guide command to make it them you can work on the each component by clicking on each component and selecting callback function.

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

% Last Modified by GUIDE v2.5 09-Jan-2010 14:30:50

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @momentsGUI_OpeningFcn, ...
                   'gui_OutputFcn',  @momentsGUI_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 momentsGUI is made visible.
function momentsGUI_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 momentsGUI (see VARARGIN)

% Choose default command line output for momentsGUI
handles.output   = hObject;
handles.selected = 0;
handles.point1 = [];
handles.point2 = [];

% Update handles structure
guidata(hObject, handles);

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

% --- Outputs from this function are returned to the command line.
function varargout = momentsGUI_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 pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[FileName,PathName,FilterIndex] = uigetfile('*.*');
img1 = imread([PathName FileName]);
%img1 = imread('carstick.bmp');
axes(handles.axes1);
imshow(img1);
handles.img1 = img1;
handles.size1 = size(img1);
% Update handles structure
guidata(hObject, handles);

% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[FileName,PathName,FilterIndex] = uigetfile('*.*');
img2 = imread([PathName FileName]);
axes(handles.axes2);
imshow(img2);
handles.img2 = img2;
handles.size2 = size(img2);
% Update handles structure
guidata(hObject, handles);
%ginput(2)

% --- Executes on button press in selectImg1PtsPushButton.
function selectImg1PtsPushButton_Callback(hObject, eventdata, handles)
% hObject    handle to selectImg1PtsPushButton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
axes(handles.axes1);
pt = ginput(1);
pt=fliplr(pt);

if (sum(pt <=handles.size1(1:2))*sum(pt>[0 0]))
    handles.point1 = [handles.point1 ; pt];
    guidata(hObject, handles);
    handles.point1
    pt = round(pt);
    axes(handles.axes1);
    hold on;
    plot(pt(2), pt(1), 'r*');
end

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

axes(handles.axes2);
pt = ginput(1);
pt=fliplr(pt);

if (sum(pt <=handles.size2(1:2))*sum(pt>[0 0]))
    handles.point2 = [handles.point2 ; pt];
    guidata(hObject, handles);
    handles.point1
    pt = round(pt);
    axes(handles.axes2);
    hold on;
    plot(pt(2), pt(1), 'r*');
end