tuttelikz

gui_replica.m

Dec 20th, 2017
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 11.47 KB | None | 0 0
  1. function varargout = gui_replica(varargin)
  2. % gui_replica MATLAB code for gui_replica.fig
  3. %      gui_replica, by itself, creates a new gui_replica or raises the existing
  4. %      singleton*.
  5. %
  6. %      H = gui_replica returns the handle to a new gui_replica or the handle to
  7. %      the existing singleton*.
  8. %
  9. %      gui_replica('CALLBACK',hObject,eventData,handles,...) calls the local
  10. %      function named CALLBACK in gui_replica.M with the given input arguments.
  11. %
  12. %      gui_replica('Property','Value',...) creates a new gui_replica or raises the
  13. %      existing singleton*.  Starting from the left, property value pairs are
  14. %      applied to the GUI before gui_replica_OpeningFcn gets called.  An
  15. %      unrecognized property name or invalid value makes property application
  16. %      stop.  All inputs are passed to gui_replica_OpeningFcn via varargin.
  17. %
  18. %      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
  19. %      instance to run (singleton)".
  20. %
  21. % See also: GUIDE, GUIDATA, GUIHANDLES
  22.  
  23. % Edit the above text to modify the response to help gui_replica
  24.  
  25. % Last Modified by GUIDE v2.5 21-Dec-2017 10:11:26
  26.  
  27. % Begin initialization code - DO NOT EDIT
  28. gui_Singleton = 1;
  29. gui_State = struct('gui_Name',       mfilename, ...
  30.                    'gui_Singleton',  gui_Singleton, ...
  31.                    'gui_OpeningFcn', @gui_replica_OpeningFcn, ...
  32.                    'gui_OutputFcn',  @gui_replica_OutputFcn, ...
  33.                    'gui_LayoutFcn',  [] , ...
  34.                    'gui_Callback',   []);
  35. if nargin && ischar(varargin{1})
  36.     gui_State.gui_Callback = str2func(varargin{1});
  37. end
  38.  
  39. if nargout
  40.     [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
  41. else
  42.     gui_mainfcn(gui_State, varargin{:});
  43. end
  44. % End initialization code - DO NOT EDIT
  45.  
  46.  
  47. % --- Executes just before gui_replica is made visible.
  48. function gui_replica_OpeningFcn(hObject, eventdata, handles, varargin)
  49. % This function has no output args, see OutputFcn.
  50. % hObject    handle to figure
  51. % eventdata  reserved - to be defined in a future version of MATLAB
  52. % handles    structure with handles and user data (see GUIDATA)
  53. % varargin   command line arguments to gui_replica (see VARARGIN)
  54.  
  55.  
  56.  
  57.  
  58. img = imread('logo-tbl.png');
  59. axes(handles.axes4)
  60. imshow(img)
  61. axis off
  62. axis image
  63. % Choose default command line output for gui_replica
  64. handles.output = hObject;
  65.  
  66. % Update handles structure
  67. guidata(hObject, handles);
  68.  
  69. % UIWAIT makes gui_replica wait for user response (see UIRESUME)
  70. % uiwait(handles.figure1);
  71.  
  72.  
  73. % --- Outputs from this function are returned to the command line.
  74. function varargout = gui_replica_OutputFcn(hObject, eventdata, handles)
  75. % varargout  cell array for returning output args (see VARARGOUT);
  76. % hObject    handle to figure
  77. % eventdata  reserved - to be defined in a future version of MATLAB
  78. % handles    structure with handles and user data (see GUIDATA)
  79.  
  80. % Get default command line output from handles structure
  81. varargout{1} = handles.output;
  82.  
  83.  
  84. % --- Executes on button press in pushbutton1.
  85. function pushbutton1_Callback(hObject, eventdata, handles)
  86. % hObject    handle to pushbutton1 (see GCBO)
  87. % eventdata  reserved - to be defined in a future version of MATLAB
  88. % handles    structure with handles and user data (see GUIDATA)
  89.  
  90.  
  91.  
  92.  
  93. % [file_name,path_name] = uigetfile('*.jpg','Select image file');
  94. % full_path = [path_name,'\',file_name];
  95. % handles.filename=full_path;
  96. % guidata(hObject,handles)
  97. % img = imread(full_path);
  98. % axes(handles.axes1)
  99. % imshow(img)
  100. % axis off
  101. % axis image
  102.  
  103.  
  104.  
  105.  
  106.  
  107. % --- Executes on button press in pushbutton2.
  108. function pushbutton2_Callback(hObject, eventdata, handles)
  109. % hObject    handle to pushbutton2 (see GCBO)
  110. % eventdata  reserved - to be defined in a future version of MATLAB
  111. % handles    structure with handles and user data (see GUIDATA)
  112. OpenfilePath = uigetdir;
  113.  
  114. % OpenfilePath = 'C:\Users\TBL\Documents\MATLAB\Yujin_Data\20170404_Amore_Replica\Eye-rim\5-Y';
  115.  
  116. max_step = 994;
  117. avg_rough = zeros(1,max_step);
  118. rms_rough = zeros(1,max_step);
  119. max_rough = zeros(1,max_step);
  120. total_rough = zeros(1,max_step);
  121.  
  122. % full_path = handles.filename;
  123. diff = 2;
  124. l_crop = 156;
  125. r_crop = 10;
  126. t_crop = 45;
  127. b_crop = 5;
  128.  
  129. for step = 1:max_step
  130.     offset = 6;
  131.     num = sprintf('%d',step+offset);
  132.     file_name = strcat('bb _',num,'.jpg');
  133.     img0 = imread([OpenfilePath,'\',file_name]);
  134.     img = rgb2gray(img0);
  135.     [H,W] = size(img);
  136.     img = flip(img, 1);
  137.     [img_crop,H_crop,W_crop] = crop(img,H,W,l_crop,r_crop,t_crop,b_crop);
  138.     img_filt = imgaussfilt(img_crop,6);
  139.     img_diff = filt_diff(img_filt,H_crop,W_crop,diff);
  140.    
  141.     %ref_line to ref+line_surf
  142.     [img_line_surf,ind_line_surf,avg_index,ref_line_surf] = line_surf2(img_diff,H_crop,W_crop,diff);
  143.     img3d(:,:,step) = img_line_surf;
  144.  
  145.     [peak_height_front,valley_depth_front] = peak_valley(ind_line_surf,avg_index,W_crop);
  146.     [avg_rough_front(step),rms_rough_front(step),max_rough_front(step),total_rough_front(step)] = roughness(peak_height_front,valley_depth_front);
  147.  
  148.     fprintf('%d\n', step);
  149.  
  150. end
  151.  
  152. avg_roughness = zeros(1,W_crop);
  153. rms_roughness = zeros(1,W_crop);
  154. max_roughness = zeros(1,W_crop);
  155. total_roughness = zeros(1,W_crop);
  156.  
  157. for ii = 1:W_crop
  158.     s = img3d(:,ii,:);
  159.     s = squeeze(s);
  160.     [Hs,Ws] = size(s);
  161.     [row,col] = find(s);
  162.  
  163.     avg_index_side = round(mean(row));
  164.     ref_line = zeros(Hs,Ws);
  165.     ref_line(avg_index_side,:) = 255;
  166.  
  167.     abs_roughness = zeros(1,Ws);
  168.    
  169.     [peak_height_side,valley_depth_side] = peak_valley(row,avg_index_side,W_crop);
  170.     [avg_rough_side(ii),rms_rough_side(ii),max_rough_side(ii),total_rough_side(ii)] = roughness(peak_height_side,valley_depth_side);
  171.    
  172.     fprintf('%d\n', ii);
  173.  
  174. end
  175.  
  176.  
  177.  
  178. %mean_avg_rough_front = mean(avg_rough_front)
  179. % mean_rms_rough_front = mean(rms_rough_front)
  180. % mean_max_rough_front = mean(max_rough_front)
  181. % mean_total_rough_front = mean(total_rough_front)
  182. disp('Front view roughness');
  183.  
  184. text_avg_rough_front = sprintf('%.2f', mean(avg_rough_front));
  185. text_rms_rough_front = sprintf('%.2f', mean(rms_rough_front));
  186. text_max_rough_front = sprintf('%.2f', mean(max_rough_front));
  187. text_total_rough_front = sprintf('%.2f', mean(total_rough_front));
  188.  
  189. set(handles.text13, 'String', text_avg_rough_front);
  190. set(handles.text14, 'String', text_rms_rough_front);
  191. set(handles.text15, 'String', text_max_rough_front);
  192. set(handles.text16, 'String', text_total_rough_front);
  193.  
  194.  
  195. disp('Side view roughness');
  196.  
  197. text_avg_rough = sprintf('%.2f', mean(avg_rough_side));
  198. text_rms_rough = sprintf('%.2f', mean(rms_rough_side));
  199. text_max_rough = sprintf('%.2f', mean(max_rough_side));
  200. text_total_rough = sprintf('%.2f', mean(total_rough_side));
  201.  
  202. set(handles.text25, 'String', text_avg_rough);
  203. set(handles.text26, 'String', text_rms_rough);
  204. set(handles.text29, 'String', text_max_rough);
  205. set(handles.text30, 'String', text_total_rough);
  206.  
  207.  
  208.  
  209.  
  210. axes(handles.axes1)
  211. %imshow(img)
  212. axis off
  213. axis image
  214. imshow(img0);
  215.  
  216.  
  217. r1 = img_crop;
  218. g1 = r1;
  219. b1 = r1;
  220. r1(img_line_surf > 0) = 255;
  221. g1(img_line_surf > 0) = 0; %%
  222. b1(ref_line_surf > 0) = 255; %
  223.  
  224. axes(handles.axes3)
  225. %imshow(img)
  226. axis off
  227. axis image
  228. imshow(cat(3,r1,g1,b1),[]);
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235. % figure('Name','Wrinkle')
  236. % imshow();
  237.  
  238. % imshow(img_crop,[], 'parent',handle.axes1)
  239. % imshow(cat(3,r1,g1,b1),[], 'parent',handle.axes3)
  240.  
  241. % %% Roughness Values
  242. % text_avg_rough = sprintf('%.2f', avg_rough);
  243. % text_rms_rough = sprintf('%.2f', rms_rough);
  244. % text_max_rough = sprintf('%.2f', max_rough);
  245. % text_total_rough = sprintf('%.2f', total_rough);
  246. %
  247. % set(handles.text13, 'String', text_avg_rough);
  248. % set(handles.text14, 'String', text_rms_rough);
  249. % set(handles.text15, 'String', text_max_rough);
  250. % set(handles.text16, 'String', text_total_rough);
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257. % img = imread(full_path);
  258. % [H,W] = size(img);
  259. % %% Parameters setup
  260. % l_crop = 18;
  261. % r_crop = 18;
  262. % t_crop = 12;
  263. % b_crop = 10;
  264. % diff = 2;
  265. % med = 80;
  266. % wind_size = 40;
  267. % threshold = 30;
  268. % %% Preprocessing
  269. % [img_crop,H_crop,W_crop] = crop(img,H,W,l_crop,r_crop,t_crop,b_crop);
  270. % img_filt = imgaussfilt(img_crop,7);
  271. % %% Wrinkle surface
  272. % img_diff = filt_diff(img_filt,H_crop,W_crop,diff);
  273. % [img_line_wrinkle,ind_line_wrinkle,avg_index,ref_line] = line_surf1(img_diff,H_crop,W_crop,diff);
  274. %
  275. % [peak_height,valley_depth] = peak_valley(ind_line_wrinkle,avg_index,W_crop);
  276. % [avg_rough,rms_rough,max_rough,total_rough] = roughness(peak_height,valley_depth);
  277. %
  278. % %% Roughness Values
  279. % text_avg_rough = sprintf('%.2f', avg_rough);
  280. % text_rms_rough = sprintf('%.2f', rms_rough);
  281. % text_max_rough = sprintf('%.2f', max_rough);
  282. % text_total_rough = sprintf('%.2f', total_rough);
  283. %
  284. % set(handles.text13, 'String', text_avg_rough);
  285. % set(handles.text14, 'String', text_rms_rough);
  286. % set(handles.text15, 'String', text_max_rough);
  287. % set(handles.text16, 'String', text_total_rough);
  288.  
  289.  
  290.  
  291. % --- Executes on button press in pushbutton3.
  292. function pushbutton3_Callback(hObject, eventdata, handles)
  293. % hObject    handle to pushbutton3 (see GCBO)
  294. % eventdata  reserved - to be defined in a future version of MATLAB
  295. % handles    structure with handles and user data (see GUIDATA)
  296.  
  297.  
  298. % --- Executes on button press in pushbutton4.
  299. function pushbutton4_Callback(hObject, eventdata, handles)
  300. % hObject    handle to pushbutton4 (see GCBO)
  301. % eventdata  reserved - to be defined in a future version of MATLAB
  302. % handles    structure with handles and user data (see GUIDATA)
  303.  
  304.  
  305.  
  306. % --- Executes on button press in pushbutton5.
  307. function pushbutton5_Callback(hObject, eventdata, handles)
  308. % hObject    handle to pushbutton5 (see GCBO)
  309. % eventdata  reserved - to be defined in a future version of MATLAB
  310. % handles    structure with handles and user data (see GUIDATA)
  311.  
  312.  
  313. % --- Executes on button press in pushbutton6.
  314. function pushbutton6_Callback(hObject, eventdata, handles)
  315. % hObject    handle to pushbutton6 (see GCBO)
  316. % eventdata  reserved - to be defined in a future version of MATLAB
  317. % handles    structure with handles and user data (see GUIDATA)
  318.  
  319.  
  320. % --- Executes on button press in pushbutton7.
  321. function pushbutton7_Callback(hObject, eventdata, handles)
  322. % hObject    handle to pushbutton7 (see GCBO)
  323. % eventdata  reserved - to be defined in a future version of MATLAB
  324. % handles    structure with handles and user data (see GUIDATA)
  325.  
  326.  
  327. % --- Executes during object creation, after setting all properties.
  328. function text21_CreateFcn(hObject, eventdata, handles)
  329. % hObject    handle to text21 (see GCBO)
  330. % eventdata  reserved - to be defined in a future version of MATLAB
  331. % handles    empty - handles not created until after all CreateFcns called
  332.  
  333.  
  334. % --- Executes during object creation, after setting all properties.
  335. function axes1_CreateFcn(hObject, eventdata, handles)
  336. % hObject    handle to axes1 (see GCBO)
  337. % eventdata  reserved - to be defined in a future version of MATLAB
  338. % handles    empty - handles not created until after all CreateFcns called
  339.  
  340. % Hint: place code in OpeningFcn to populate axes1
  341.  
  342.  
  343. % --- Executes during object deletion, before destroying properties.
  344. function axes1_DeleteFcn(hObject, eventdata, handles)
  345. % hObject    handle to axes1 (see GCBO)
  346. % eventdata  reserved - to be defined in a future version of MATLAB
  347. % handles    structure with handles and user data (see GUIDATA)
  348.  
  349.  
  350. % --- Executes on mouse press over axes background.
  351. function axes1_ButtonDownFcn(hObject, eventdata, handles)
  352. % hObject    handle to axes1 (see GCBO)
  353. % eventdata  reserved - to be defined in a future version of MATLAB
  354. % handles    structure with handles and user data (see GUIDATA)
Advertisement
Add Comment
Please, Sign In to add comment