Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 && 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
- % --- Executes just before cornerdetect is made visible.
- function cornerdetect_OpeningFcn(hObject, eventdata, handles, varargin)
- global m;
- %set initial parameters
- handles.output = hObject;
- set(handles.button_detectcorner1,'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({'*.jpg;*.tif;*.png;*.gif;*.bmp','All Image Files';...
- '*.*','All Files' });
- [handles.i1,handles.map1,handles.g1,handles.d1]=loadimage(PathName,FileName);
- %imageshow(handles.i1,handles.map1,handles.axes1);
- axis equal;
- colormap(handles.map1);
- imageHandle = image(handles.i1,'Parent',handles.axes1);
- set(imageHandle,'ButtonDownFcn',@ImageClickCallback);
- %-------
- 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 button press in button_detectcorner1.
- function button_detectcorner1_Callback(hObject, eventdata, handles)
- %[cim,r,c]=corner(handles.g1);
- prompt = {'Enter sigma:','Enter thresh:','Enter radius:'};
- dlg_title = 'Input parameters for harris corner detector';
- num_lines= 1;
- def = {'1','300','20'};
- answer = inputdlg(prompt,dlg_title,num_lines,def);
- sigma=str2double(answer{1});
- thresh=str2double(answer{2});
- radius=str2double(answer{3});
- %save input
- handles.sigma = sigma;
- handles.thresh = thresh;
- handles.radius = radius;
- [cim,r,c]=harris(handles.g1,sigma,thresh,radius);
- set(handles.axes1,'NextPlot','add');
- plot(c,r,'*','Parent',handles.axes1);
- str=strcat('Number of corners : ',num2str(size(r,1)));
- set(handles.text_cornernumber1,'String',str);
- guidata(hObject,handles);
- % --- Executes on button press in button_Iy.
- function button_Ix_Callback(hObject, eventdata, handles)
- % hObject handle to button_Iy (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- %data = get(
- dx = [-1 0 1; -1 0 1; -1 0 1];
- dy = dx';
- im = handles.d1;
- Ix = conv2(im, dx, 'same');
- set(handles.uitable1, 'data', Ix);
- % --- Executes on button press in button_Iy.
- function button_Iy_Callback(hObject, eventdata, handles)
- % hObject handle to button_Iy (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- %data = get(
- dx = [-1 0 1; -1 0 1; -1 0 1];
- dy = dx';
- im = handles.d1;
- Iy = conv2(im, dy, 'same');
- set(handles.uitable1, 'data', Iy);
- % --- Executes on button press in button_Ix2.
- function button_Ix2_Callback(hObject, eventdata, handles)
- % hObject handle to button_Ix2 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- dx = [-1 0 1; -1 0 1; -1 0 1];
- dy = dx';
- im = handles.d1;
- Ix = conv2(im, dx, 'same');
- Iy = conv2(im, dy, 'same');
- Ix2 = Ix.^2;
- set(handles.uitable1, 'data', Ix2);
- % --- Executes on button press in button_Iy2.
- function button_Iy2_Callback(hObject, eventdata, handles)
- % hObject handle to button_Iy2 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- dx = [-1 0 1; -1 0 1; -1 0 1];
- dy = dx';
- im = handles.d1;
- Ix = conv2(im, dx, 'same');
- Iy = conv2(im, dy, 'same');
- Iy2 = Iy.^2;
- set(handles.uitable1, 'data', Iy2);
- % --- Executes on button press in button_Ixy.
- function button_Ixy_Callback(hObject, eventdata, handles)
- % hObject handle to button_Ixy (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- dx = [-1 0 1; -1 0 1; -1 0 1];
- dy = dx';
- im = handles.d1;
- Ix = conv2(im, dx, 'same');
- Iy = conv2(im, dy, 'same');
- Ixy = Ix.*Iy;
- set(handles.uitable1, 'data', Ixy);
- % --- Executes on button press in button_Sx2.
- function button_Sx2_Callback(hObject, eventdata, handles)
- % hObject handle to button_Sx2 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- dx = [-1 0 1; -1 0 1; -1 0 1];
- dy = dx';
- im = handles.d1;
- Ix = conv2(im, dx, 'same');
- Iy = conv2(im, dy, 'same');
- sigma = handles.sigma;
- g = fspecial('gaussian',max(1,fix(6*sigma)), sigma);
- Sx2 = conv2(Ix.^2, g, 'same');
- set(handles.uitable1, 'data', Sx2);
- % --- Executes on button press in button_Sy2.
- function button_Sy2_Callback(hObject, eventdata, handles)
- % hObject handle to button_Sy2 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- dx = [-1 0 1; -1 0 1; -1 0 1];
- dy = dx';
- im = handles.d1;
- Ix = conv2(im, dx, 'same');
- Iy = conv2(im, dy, 'same');
- sigma = handles.sigma;
- g = fspecial('gaussian',max(1,fix(6*sigma)), sigma);
- Sy2 = conv2(Iy.^2, g, 'same');
- set(handles.uitable1, 'data', Sy2);
- % --- Executes on button press in button_Sxy.
- function button_Sxy_Callback(hObject, eventdata, handles)
- % hObject handle to button_Sxy (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- dx = [-1 0 1; -1 0 1; -1 0 1];
- dy = dx';
- im = handles.d1;
- Ix = conv2(im, dx, 'same');
- Iy = conv2(im, dy, 'same');
- sigma = handles.sigma;
- g = fspecial('gaussian',max(1,fix(6*sigma)), sigma);
- Sxy = conv2(Ix.*Iy, g, 'same');
- set(handles.uitable1, 'data', Sxy);
- % --- Executes on mouse press over axes background.
- function axes1_ButtonDownFcn(hObject, eventdata, handles)
- % hObject handle to axes1 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- % handles structure with handles and user data (see GUIDATA)
- disp('yes');
- % --- Executes on button press in button_M.
- function button_M_Callback(hObject, eventdata, handles)
- % hObject handle to button_M (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- global m;
- %disp(m);
- dx = [-1 0 1; -1 0 1; -1 0 1];
- dy = dx';
- im = handles.d1;
- Ix = conv2(im, dx, 'same');
- Iy = conv2(im, dy, 'same');
- sigma = handles.sigma;
- g = fspecial('gaussian',max(1,fix(6*sigma)), sigma);
- Ix2 = conv2(Ix.^2, g, 'same');
- Iy2 = conv2(Iy.^2, g, 'same');
- Ixy = conv2(Ix.*Iy, g, 'same');
- M = [Ix2(m(1),m(2)) Ixy(m(1),m(2)); Ixy(m(1),m(2)) Iy2(m(1),m(2))];
- R = det(M) - 0.04*trace(M);
- message = sprintf('M(%.f,%.f)',m(1),m(2));
- set(handles.text_M,'String',message);
- set(handles.uitable2, 'data', M);
- set(handles.text_R,'String',num2str(R));
- % --------------------------------------------------------------------
- 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]=corner(G)
- prompt = {'Enter sigma:','Enter thresh:','Enter radius:'};
- dlg_title = 'Input parameters for harris corner detector';
- num_lines= 1;
- def = {'1','300','20'};
- answer = inputdlg(prompt,dlg_title,num_lines,def);
- sigma=str2double(answer{1});
- thresh=str2double(answer{2});
- radius=str2double(answer{3});
- [cim,r,c]=harris(G,sigma,thresh,radius);
- function ImageClickCallback(objectHandle, eventData, handles)
- global m;
- axesHandle = get(objectHandle, 'Parent');
- coordinates = get(axesHandle, 'CurrentPoint');
- coordinates = coordinates(1,1:2);
- m = [int8(coordinates(1)) int8(coordinates(2))];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement