Advertisement
bkit4s0

[Harris] finished 4 step v2

Dec 27th, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 7.82 KB | None | 0 0
  1. function varargout = cornerdetect(varargin)
  2. gui_Singleton = 1;
  3. gui_State = struct('gui_Name',       mfilename, ...
  4.                    'gui_Singleton',  gui_Singleton, ...
  5.                    'gui_OpeningFcn', @cornerdetect_OpeningFcn, ...
  6.                    'gui_OutputFcn',  @cornerdetect_OutputFcn, ...
  7.                    'gui_LayoutFcn',  [] , ...
  8.                    'gui_Callback',   []);
  9. if nargin && ischar(varargin{1})
  10.     gui_State.gui_Callback = str2func(varargin{1});
  11. end
  12. if nargout
  13.     [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
  14. else
  15.     gui_mainfcn(gui_State, varargin{:});
  16. end
  17.  
  18.  
  19. % --- Executes just before cornerdetect is made visible.
  20. function cornerdetect_OpeningFcn(hObject, eventdata, handles, varargin)
  21. %set initial parameters
  22. handles.output = hObject;
  23. set(handles.button_detectcorner1,'Enable','Off');
  24.  
  25. % Update handles structure
  26. guidata(hObject, handles);
  27.  
  28. % UIWAIT makes cornerdetect wait for user response (see UIRESUME)
  29. % uiwait(handles.figure1);
  30.  
  31. function varargout = cornerdetect_OutputFcn(hObject, eventdata, handles)
  32. varargout{1} = handles.output;
  33.  
  34. % ---------------------------------------------------------------------------------------------------------------
  35. function button_loadimage1_Callback(hObject, eventdata, handles)
  36. [FileName,PathName] = uigetfile({'*.jpg;*.tif;*.png;*.gif;*.bmp','All Image Files';...
  37.           '*.*','All Files' });
  38. [handles.i1,handles.map1,handles.g1,handles.d1]=loadimage(PathName,FileName);
  39. %imageshow(handles.i1,handles.map1,handles.axes1);
  40. axis equal;
  41. colormap(handles.map1);
  42. imageHandle = image(handles.i1,'Parent',handles.axes1);
  43. set(imageHandle,'ButtonDownFcn',@ImageClickCallback);
  44. %-------
  45. set(handles.button_detectcorner1,'Enable','On');
  46. guidata(gcf,handles);
  47.  
  48. % --- Executes during object creation, after setting all properties.
  49. function popupmenu_selectdetector1_CreateFcn(hObject, eventdata, handles)
  50. if ispc
  51.     set(hObject,'BackgroundColor','white');
  52. else
  53.     set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
  54. end
  55.  
  56. % --- Executes on button press in button_detectcorner1.
  57. function button_detectcorner1_Callback(hObject, eventdata, handles)
  58. %[cim,r,c]=corner(handles.g1);
  59. prompt = {'Enter sigma:','Enter thresh:','Enter radius:'};
  60. dlg_title = 'Input parameters for harris corner detector';
  61. num_lines= 1;
  62. def     = {'1','300','20'};
  63. answer  = inputdlg(prompt,dlg_title,num_lines,def);
  64. sigma=str2double(answer{1});
  65. thresh=str2double(answer{2});
  66. radius=str2double(answer{3});
  67. %save input
  68. handles.sigma = sigma;
  69. handles.thresh = thresh;
  70. handles.radius = radius;
  71. [cim,r,c]=harris(handles.g1,sigma,thresh,radius);
  72.        
  73. set(handles.axes1,'NextPlot','add');
  74. plot(c,r,'*','Parent',handles.axes1);
  75. str=strcat('Number of corners :  ',num2str(size(r,1)));
  76. set(handles.text_cornernumber1,'String',str);
  77. guidata(hObject,handles);
  78.  
  79. % --- Executes on button press in button_Iy.
  80. function button_Ix_Callback(hObject, eventdata, handles)
  81. % hObject    handle to button_Iy (see GCBO)
  82. % eventdata  reserved - to be defined in a future version of MATLAB
  83. % handles    structure with handles and user data (see GUIDATA)
  84. %data = get(
  85. dx = [-1 0 1; -1 0 1; -1 0 1];
  86. dy = dx';
  87. im = handles.d1;
  88. Ix = conv2(im, dx, 'same');  
  89. set(handles.uitable1, 'data', Ix);
  90.  
  91. % --- Executes on button press in button_Iy.
  92. function button_Iy_Callback(hObject, eventdata, handles)
  93. % hObject    handle to button_Iy (see GCBO)
  94. % eventdata  reserved - to be defined in a future version of MATLAB
  95. % handles    structure with handles and user data (see GUIDATA)
  96. %data = get(
  97. dx = [-1 0 1; -1 0 1; -1 0 1];
  98. dy = dx';
  99. im = handles.d1;
  100. Iy = conv2(im, dy, 'same');
  101. set(handles.uitable1, 'data', Iy);
  102.  
  103. % --- Executes on button press in button_Ix2.
  104. function button_Ix2_Callback(hObject, eventdata, handles)
  105. % hObject    handle to button_Ix2 (see GCBO)
  106. % eventdata  reserved - to be defined in a future version of MATLAB
  107. % handles    structure with handles and user data (see GUIDATA)
  108. dx = [-1 0 1; -1 0 1; -1 0 1];
  109. dy = dx';
  110. im = handles.d1;
  111. Ix = conv2(im, dx, 'same');
  112. Iy = conv2(im, dy, 'same');  
  113. Ix2 = Ix.^2;
  114. set(handles.uitable1, 'data', Ix2);
  115.  
  116. % --- Executes on button press in button_Iy2.
  117. function button_Iy2_Callback(hObject, eventdata, handles)
  118. % hObject    handle to button_Iy2 (see GCBO)
  119. % eventdata  reserved - to be defined in a future version of MATLAB
  120. % handles    structure with handles and user data (see GUIDATA)
  121. dx = [-1 0 1; -1 0 1; -1 0 1];
  122. dy = dx';
  123. im = handles.d1;
  124. Ix = conv2(im, dx, 'same');
  125. Iy = conv2(im, dy, 'same');  
  126. Iy2 = Iy.^2;
  127. set(handles.uitable1, 'data', Iy2);
  128.  
  129. % --- Executes on button press in button_Ixy.
  130. function button_Ixy_Callback(hObject, eventdata, handles)
  131. % hObject    handle to button_Ixy (see GCBO)
  132. % eventdata  reserved - to be defined in a future version of MATLAB
  133. % handles    structure with handles and user data (see GUIDATA)
  134. dx = [-1 0 1; -1 0 1; -1 0 1];
  135. dy = dx';
  136. im = handles.d1;
  137. Ix = conv2(im, dx, 'same');
  138. Iy = conv2(im, dy, 'same');  
  139. Ixy = Ix.*Iy;
  140. set(handles.uitable1, 'data', Ixy);
  141.  
  142. % --- Executes on button press in button_Sx2.
  143. function button_Sx2_Callback(hObject, eventdata, handles)
  144. % hObject    handle to button_Sx2 (see GCBO)
  145. % eventdata  reserved - to be defined in a future version of MATLAB
  146. % handles    structure with handles and user data (see GUIDATA)
  147. dx = [-1 0 1; -1 0 1; -1 0 1];
  148. dy = dx';
  149. im = handles.d1;
  150. Ix = conv2(im, dx, 'same');
  151. Iy = conv2(im, dy, 'same');
  152. sigma = handles.sigma;
  153. g = fspecial('gaussian',max(1,fix(6*sigma)), sigma);    
  154. Sx2 = conv2(Ix.^2, g, 'same');
  155. set(handles.uitable1, 'data', Sx2);
  156.  
  157. % --- Executes on button press in button_Sy2.
  158. function button_Sy2_Callback(hObject, eventdata, handles)
  159. % hObject    handle to button_Sy2 (see GCBO)
  160. % eventdata  reserved - to be defined in a future version of MATLAB
  161. % handles    structure with handles and user data (see GUIDATA)
  162. dx = [-1 0 1; -1 0 1; -1 0 1];
  163. dy = dx';
  164. im = handles.d1;
  165. Ix = conv2(im, dx, 'same');
  166. Iy = conv2(im, dy, 'same');
  167. sigma = handles.sigma;
  168. g = fspecial('gaussian',max(1,fix(6*sigma)), sigma);    
  169. Sy2 = conv2(Iy.^2, g, 'same');
  170. set(handles.uitable1, 'data', Sy2);
  171.  
  172. % --- Executes on button press in button_Sxy.
  173. function button_Sxy_Callback(hObject, eventdata, handles)
  174. % hObject    handle to button_Sxy (see GCBO)
  175. % eventdata  reserved - to be defined in a future version of MATLAB
  176. % handles    structure with handles and user data (see GUIDATA)
  177. dx = [-1 0 1; -1 0 1; -1 0 1];
  178. dy = dx';
  179. im = handles.d1;
  180. Ix = conv2(im, dx, 'same');
  181. Iy = conv2(im, dy, 'same');
  182. sigma = handles.sigma;
  183. g = fspecial('gaussian',max(1,fix(6*sigma)), sigma);    
  184. Sxy = conv2(Ix.*Iy, g, 'same');
  185. set(handles.uitable1, 'data', Sxy);
  186. % --- Executes on mouse press over axes background.
  187.  
  188. function axes1_ButtonDownFcn(hObject, eventdata, handles)
  189. % hObject    handle to axes1 (see GCBO)
  190. % eventdata  reserved - to be defined in a future version of MATLAB
  191. % handles    structure with handles and user data (see GUIDATA)
  192. % handles    structure with handles and user data (see GUIDATA)
  193. disp('yes');
  194.  
  195. % --------------------------------------------------------------------
  196.  
  197. function [I,map,G,D]=loadimage(pathname,filename)
  198. [I,map]=imread([pathname filename]);
  199. iii =  size(size(I));
  200. if iii(2) == 3
  201.     G = rgb2gray(I);
  202. else
  203.     G = I;
  204. end
  205. D=double(G);
  206.  
  207. function imageshow(I,map,axes_handle)
  208. axis equal;
  209. colormap(map);
  210. image(I,'Parent',axes_handle);%,'XData',-n1/2,'YData',-m1/2);
  211.  
  212. function [cim,r,c]=corner(G)
  213. prompt = {'Enter sigma:','Enter thresh:','Enter radius:'};
  214. dlg_title = 'Input parameters for harris corner detector';
  215. num_lines= 1;
  216. def     = {'1','300','20'};
  217. answer  = inputdlg(prompt,dlg_title,num_lines,def);
  218. sigma=str2double(answer{1});
  219. thresh=str2double(answer{2});
  220. radius=str2double(answer{3});
  221. [cim,r,c]=harris(G,sigma,thresh,radius);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement