Advertisement
bkit4s0

[Harris] finished 4 step

Dec 27th, 2014
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 7.36 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. set(handles.button_detectcorner1,'Enable','On');
  41. guidata(gcf,handles);
  42.  
  43. % --- Executes during object creation, after setting all properties.
  44. function popupmenu_selectdetector1_CreateFcn(hObject, eventdata, handles)
  45. if ispc
  46.     set(hObject,'BackgroundColor','white');
  47. else
  48.     set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
  49. end
  50.  
  51.  
  52. % --- Executes on button press in button_detectcorner1.
  53. function button_detectcorner1_Callback(hObject, eventdata, handles)
  54. %[cim,r,c]=corner(handles.g1);
  55. prompt = {'Enter sigma:','Enter thresh:','Enter radius:'};
  56. dlg_title = 'Input parameters for harris corner detector';
  57. num_lines= 1;
  58. def     = {'1','300','20'};
  59. answer  = inputdlg(prompt,dlg_title,num_lines,def);
  60. sigma=str2double(answer{1});
  61. thresh=str2double(answer{2});
  62. radius=str2double(answer{3});
  63. %save input
  64. handles.sigma = sigma;
  65. handles.thresh = thresh;
  66. handles.radius = radius;
  67. [cim,r,c]=harris(handles.g1,sigma,thresh,radius);
  68.        
  69. set(handles.axes1,'NextPlot','add');
  70. plot(c,r,'*','Parent',handles.axes1);
  71. str=strcat('Number of corners :  ',num2str(size(r,1)));
  72. set(handles.text_cornernumber1,'String',str);
  73. guidata(hObject,handles);
  74.  
  75. % --------------------------------------------------------------------
  76.  
  77. function [I,map,G,D]=loadimage(pathname,filename)
  78. [I,map]=imread([pathname filename]);
  79. iii =  size(size(I));
  80. if iii(2) == 3
  81.     G = rgb2gray(I);
  82. else
  83.     G = I;
  84. end
  85. D=double(G);
  86.  
  87. function imageshow(I,map,axes_handle)
  88. axis equal;
  89. colormap(map);
  90. image(I,'Parent',axes_handle);%,'XData',-n1/2,'YData',-m1/2);
  91.  
  92.  
  93. function [cim,r,c]=corner(G)
  94.         prompt = {'Enter sigma:','Enter thresh:','Enter radius:'};
  95.         dlg_title = 'Input parameters for harris corner detector';
  96.         num_lines= 1;
  97.         def     = {'1','300','20'};
  98.         answer  = inputdlg(prompt,dlg_title,num_lines,def);
  99.         sigma=str2double(answer{1});
  100.         thresh=str2double(answer{2});
  101.         radius=str2double(answer{3});
  102.         [cim,r,c]=harris(G,sigma,thresh,radius);
  103.  
  104.  
  105. % --- Executes on button press in button_Iy.
  106. function button_Ix_Callback(hObject, eventdata, handles)
  107. % hObject    handle to button_Iy (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. %data = get(
  111. dx = [-1 0 1; -1 0 1; -1 0 1];
  112. dy = dx';
  113. im = handles.d1;
  114. Ix = conv2(im, dx, 'same');  
  115. set(handles.uitable1, 'data', Ix);
  116.  
  117. % --- Executes on button press in button_Iy.
  118. function button_Iy_Callback(hObject, eventdata, handles)
  119. % hObject    handle to button_Iy (see GCBO)
  120. % eventdata  reserved - to be defined in a future version of MATLAB
  121. % handles    structure with handles and user data (see GUIDATA)
  122. %data = get(
  123. dx = [-1 0 1; -1 0 1; -1 0 1];
  124. dy = dx';
  125. im = handles.d1;
  126. Iy = conv2(im, dy, 'same');
  127. set(handles.uitable1, 'data', Iy);
  128.  
  129. % --- Executes on button press in button_Ix2.
  130. function button_Ix2_Callback(hObject, eventdata, handles)
  131. % hObject    handle to button_Ix2 (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. Ix2 = Ix.^2;
  140. set(handles.uitable1, 'data', Ix2);
  141.  
  142. % --- Executes on button press in button_Iy2.
  143. function button_Iy2_Callback(hObject, eventdata, handles)
  144. % hObject    handle to button_Iy2 (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. Iy2 = Iy.^2;
  153. set(handles.uitable1, 'data', Iy2);
  154.  
  155. % --- Executes on button press in button_Ixy.
  156. function button_Ixy_Callback(hObject, eventdata, handles)
  157. % hObject    handle to button_Ixy (see GCBO)
  158. % eventdata  reserved - to be defined in a future version of MATLAB
  159. % handles    structure with handles and user data (see GUIDATA)
  160. dx = [-1 0 1; -1 0 1; -1 0 1];
  161. dy = dx';
  162. im = handles.d1;
  163. Ix = conv2(im, dx, 'same');
  164. Iy = conv2(im, dy, 'same');  
  165. Ixy = Ix.*Iy;
  166. set(handles.uitable1, 'data', Ixy);
  167.  
  168. % --- Executes on button press in button_Sx2.
  169. function button_Sx2_Callback(hObject, eventdata, handles)
  170. % hObject    handle to button_Sx2 (see GCBO)
  171. % eventdata  reserved - to be defined in a future version of MATLAB
  172. % handles    structure with handles and user data (see GUIDATA)
  173. dx = [-1 0 1; -1 0 1; -1 0 1];
  174. dy = dx';
  175. im = handles.d1;
  176. Ix = conv2(im, dx, 'same');
  177. Iy = conv2(im, dy, 'same');
  178. sigma = handles.sigma;
  179. g = fspecial('gaussian',max(1,fix(6*sigma)), sigma);    
  180. Sx2 = conv2(Ix.^2, g, 'same');
  181. set(handles.uitable1, 'data', Sx2);
  182.  
  183. % --- Executes on button press in button_Sy2.
  184. function button_Sy2_Callback(hObject, eventdata, handles)
  185. % hObject    handle to button_Sy2 (see GCBO)
  186. % eventdata  reserved - to be defined in a future version of MATLAB
  187. % handles    structure with handles and user data (see GUIDATA)
  188. dx = [-1 0 1; -1 0 1; -1 0 1];
  189. dy = dx';
  190. im = handles.d1;
  191. Ix = conv2(im, dx, 'same');
  192. Iy = conv2(im, dy, 'same');
  193. sigma = handles.sigma;
  194. g = fspecial('gaussian',max(1,fix(6*sigma)), sigma);    
  195. Sy2 = conv2(Iy.^2, g, 'same');
  196. set(handles.uitable1, 'data', Sy2);
  197.  
  198. % --- Executes on button press in button_Sxy.
  199. function button_Sxy_Callback(hObject, eventdata, handles)
  200. % hObject    handle to button_Sxy (see GCBO)
  201. % eventdata  reserved - to be defined in a future version of MATLAB
  202. % handles    structure with handles and user data (see GUIDATA)
  203. dx = [-1 0 1; -1 0 1; -1 0 1];
  204. dy = dx';
  205. im = handles.d1;
  206. Ix = conv2(im, dx, 'same');
  207. Iy = conv2(im, dy, 'same');
  208. sigma = handles.sigma;
  209. g = fspecial('gaussian',max(1,fix(6*sigma)), sigma);    
  210. Sxy = conv2(Ix.*Iy, g, 'same');
  211. set(handles.uitable1, 'data', Sxy);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement