function varargout = cornerdetect(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @cornerdetect_OpeningFcn, ...
'gui_OutputFcn', @cornerdetect_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin & isstr(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
% --- Executes just before cornerdetect is made visible.
function cornerdetect_OpeningFcn(hObject, eventdata, handles, varargin)
%set initial parameters
handles.output = hObject;
handles.type1=1;
handles.type2=1;
set(handles.button_detectcorner1,'Enable','Off');
set(handles.popupmenu_selectdetector1,'Enable','Off');
set(handles.button_detectcorner2,'Enable','Off');
set(handles.popupmenu_selectdetector2,'Enable','Off');
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes cornerdetect wait for user response (see UIRESUME)
% uiwait(handles.figure1);
function varargout = cornerdetect_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
% ---------------------------------------------------------------------------------------------------------------
function button_loadimage1_Callback(hObject, eventdata, handles)
[FileName,PathName] = uigetfile('*.bmp','Select BMP file');
[handles.i1,handles.map1,handles.g1,handles.d1]=loadimage(PathName,FileName);
imageshow(handles.i1,handles.map1,handles.axes1);
set(handles.popupmenu_selectdetector1,'Enable','On');
set(handles.button_detectcorner1,'Enable','On');
guidata(gcf,handles);
% --- Executes during object creation, after setting all properties.
function popupmenu_selectdetector1_CreateFcn(hObject, eventdata, handles)
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes on selection change in popupmenu_selectdetector1.
function popupmenu_selectdetector1_Callback(hObject, eventdata, handles)
handles.type1=get(hObject,'Value');
guidata(hObject,handles);
% --- Executes on button press in button_detectcorner1.
function button_detectcorner1_Callback(hObject, eventdata, handles)
[cim,r,c]=cornertype(handles.g1,handles.type1);
set(handles.axes1,'NextPlot','add');
plot(c,r,'g+','Parent',handles.axes1);
str=strcat('Number of corners : ',num2str(size(r,1)));
set(handles.text_cornernumber1,'String',str);
guidata(hObject,handles);
% --------------------------------------------------------------------
function button_loadimage2_Callback(hObject, eventdata, handles)
[FileName,PathName] = uigetfile('*.bmp','Select BMP file');
[handles.i2,handles.map2,handles.g2,handles.d2]=loadimage(PathName,FileName);
imageshow(handles.i2,handles.map2,handles.axes2);
set(handles.popupmenu_selectdetector2,'Enable','On');
set(handles.button_detectcorner2,'Enable','On');
guidata(gcf,handles);
function button_detectcorner2_Callback(hObject, eventdata, handles)
[cim,r,c]=cornertype(handles.g2,handles.type2);
set(handles.axes2,'NextPlot','add');
plot(c,r,'r+','Parent',handles.axes2);
str=strcat('Number of corners : ',num2str(size(r,1)));
set(handles.text_cornernumber2,'String',str);
guidata(hObject,handles);
function popupmenu_selectdetector2_CreateFcn(hObject, eventdata, handles)
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function popupmenu_selectdetector2_Callback(hObject, eventdata, handles)
handles.type2=get(hObject,'Value');
guidata(hObject,handles);
function [I,map,G,D]=loadimage(pathname,filename)
[I,map]=imread([pathname filename]);
iii = size(size(I));
if iii(2) == 3
G = rgb2gray(I);
else
G = I;
end
D=double(G);
function imageshow(I,map,axes_handle)
axis equal;
colormap(map);
image(I,'Parent',axes_handle);%,'XData',-n1/2,'YData',-m1/2);
function [cim,r,c]=cornertype(G,type)
switch type
case 1
sigma=1;
thresh=30000;
radius=2;
prompt = {'Enter sigma:','Enter thresh:','Enter radius:'};
dlg_title = 'Input parameters for harris corner detector';
num_lines= 1;
def = {'1','30000','2'};
answer = inputdlg(prompt,dlg_title,num_lines,def);
sigma=str2num(answer{1});
thresh=str2num(answer{2});
radius=str2num(answer{3});
[cim,r,c]=harris(G,sigma,thresh,radius);
end
评论5