Advertisement
bkit4s0

[Harris] finished 5 step

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