tuttelikz

gui_replica.m [v3latest]

Dec 28th, 2017
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 42.19 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 28-Dec-2017 17:16:11
  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.  
  64. % Choose default command line output for gui_replica
  65. handles.output = hObject;
  66.  
  67. % Update handles structure
  68. guidata(hObject, handles);
  69.  
  70. % UIWAIT makes gui_replica wait for user response (see UIRESUME)
  71. % uiwait(handles.figure1);
  72.  
  73.  
  74. % --- Outputs from this function are returned to the command line.
  75. function varargout = gui_replica_OutputFcn(hObject, eventdata, handles)
  76. % varargout  cell array for returning output args (see VARARGOUT);
  77. % hObject    handle to figure
  78. % eventdata  reserved - to be defined in a future version of MATLAB
  79. % handles    structure with handles and user data (see GUIDATA)
  80.  
  81. % Get default command line output from handles structure
  82. varargout{1} = handles.output;
  83.  
  84.  
  85. % --- Executes on button press in pushbutton1.
  86. function pushbutton1_Callback(hObject, eventdata, handles)
  87. % hObject    handle to pushbutton1 (see GCBO)
  88. % eventdata  reserved - to be defined in a future version of MATLAB
  89. % handles    structure with handles and user data (see GUIDATA)
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99. % --- Executes on button press in pushbutton2.
  100. function pushbutton2_Callback(hObject, eventdata, handles)
  101. % hObject    handle to pushbutton2 (see GCBO)
  102. % eventdata  reserved - to be defined in a future version of MATLAB
  103. % handles    structure with handles and user data (see GUIDATA)
  104. filePath = uigetdir;
  105. imgFilePath = dir([filePath '/*.jpg']);
  106. imgFilesNo = size(imgFilePath,1);
  107. imgName = imgFilePath(1).name;
  108.  
  109. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  110. handles.newDatasetFlag = true;
  111. handles.filePath = filePath;
  112. handles.imgFolderInfo = imgFilePath;
  113. handles.imgName = imgName;
  114. handles.imgOrder = 1;
  115. handles.imgTotal = imgFilesNo;
  116. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  117. handles.lcrop = 0;
  118. handles.rcrop = 0;
  119. handles.tcrop = 0;
  120. handles.bcrop = 0;
  121. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  122. handles.g1Val = 2;
  123. handles.g2Val = 4;
  124. handles.medVal = 20;
  125. handles.diff = 2;
  126. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  127. guidata(hObject,handles);
  128.  
  129. set(handles.imgOrderLabel, 'String', handles.imgOrder);
  130. set(handles.imgTotalLabel, 'String', imgFilesNo);
  131.  
  132. img = imread([filePath,'\',imgName]);
  133. axes(handles.axes1)
  134. %imshow(img)
  135. axis off
  136. axis image
  137. imshow(img);
  138.  
  139. % imgName = imgFilePath(1).name;
  140. [H,W] = size(img);
  141. img3d = zeros(H,W,imgFilesNo);
  142. handles.imgHeight = H;
  143. handles.imgWidth = W;
  144. guidata(hObject,handles);
  145.  
  146. for step = 1:imgFilesNo
  147.     file_name = imgFilePath(step).name;
  148. %     [H,W] = size(img);
  149.     img = imread([filePath,'\',file_name]);
  150.     img3d(:,:,step) = img;
  151.     fprintf('%d\n', step);
  152. end
  153.  
  154. avg = mean(img3d,1);
  155. avg = squeeze(avg);
  156. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  157. axes(handles.axes3)
  158. axis image
  159. imshow(avg,[]);
  160. hold on
  161.  
  162. x = [1 W];
  163. y = [handles.imgOrder handles.imgOrder];
  164. handles.lineRef  = line(x,y,'Color','red','LineStyle','--','LineWidth',2);
  165.  
  166. guidata(hObject,handles);
  167.  
  168. hold off
  169.  
  170. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  171. [img_crp,H,W] = crop(img,H,W,handles.lcrop,handles.rcrop,handles.tcrop,handles.bcrop);
  172.    
  173. img_gau = imgaussfilt(img_crp,handles.g1Val);
  174. img_diff_bef = filt_diff(img_gau,H,W,handles.diff);
  175. [img_rl_bef,ind_rl_bef,avg_rl_bef] = find_srf(img_diff_bef,H,W); %img_rl
  176.  
  177. img_med = medfilt2(img_gau,[handles.medVal*2 handles.medVal*2],'symmetric');
  178. img_med = filt_diff(img_med,H,W,handles.diff);
  179.  
  180. [img_idl,ind_idl,~] = find_srf(img_med,H,W);
  181. mrg = 60;
  182. [H,W] = size(img_crp);
  183. [img_flt,H,W] = flatten(img_crp,H,W,ind_idl,mrg);
  184.  
  185. img_gau = imgaussfilt(img_flt,handles.g2Val);
  186. img_diff = filt_diff(img_gau,H,W,handles.diff);
  187. [H,W] = size(img_crp);
  188. [img_rl,ind_rl,avg_rl] = find_srf(img_diff,H,W); %img_rl
  189. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  190. % axes(handles.imgOutputAxes)
  191. % axis image
  192. % imshow(img_rl,[]);
  193. % hold on
  194. % h2 = plot(img_flt,[])
  195.  
  196. axes(handles.imgOutputAxes)
  197. axis image
  198. imshow(img_flt,[]);
  199. hold on
  200. h4 = plot(ind_rl);
  201. set(h4,'LineWidth',3)
  202. hold off
  203. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  204. % axes(handles.imgOutputAxes)
  205. % axis image
  206. % imshow(img_flt,[]);
  207. % hold on
  208. % h2 = plot(ind_rl,[])
  209. % set(h2,'LineWidth',2)
  210. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  211.  
  212.  
  213.  
  214. % figure()
  215. % imshow(img_crp,[])
  216. % hold on
  217. % h2 = plot(ind_idl);
  218. % set(h2,'LineWidth',2)
  219.  
  220.  
  221.  
  222.  
  223. % [H,W,I] = size(img3d);
  224.  
  225. % avg = zeros(W,imgFilesNo);
  226. % for i = 1:W
  227. %     for j = 1:imgFilesNo
  228. %         avg(i,j) = sum(double(img3d(:,i,j)))/imgFilesNo;
  229. %     end
  230. % end
  231.  
  232.  
  233.  
  234. %     fprintf('%d\n', step);
  235.  
  236. % OpenfilePath = 'C:\Users\TBL\Documents\MATLAB\Yujin_Data\20170404_Amore_Replica\Eye-rim\5-Y';
  237.  
  238. % max_step = 994;
  239. % avg_rough = zeros(1,max_step);
  240. % rms_rough = zeros(1,max_step);
  241. % max_rough = zeros(1,max_step);
  242. % total_rough = zeros(1,max_step);
  243. %
  244. % % full_path = handles.filename;
  245. % diff = 2;
  246. % l_crop = 156;
  247. % r_crop = 10;
  248. % t_crop = 45;
  249. % b_crop = 5;
  250.  
  251. % for step = 1:max_step
  252. %     offset = 6;
  253. %     num = sprintf('%d',step+offset);
  254. %     file_name = strcat('bb _',num,'.jpg');
  255. %     img0 = imread([OpenfilePath,'\',file_name]);
  256. %     img = rgb2gray(img0);
  257. %     [H,W] = size(img);
  258. %     img = flip(img, 1);
  259. %     [img_crop,H_crop,W_crop] = crop(img,H,W,l_crop,r_crop,t_crop,b_crop);
  260. %     img_filt = imgaussfilt(img_crop,6);
  261. %     img_diff = filt_diff(img_filt,H_crop,W_crop,diff);
  262. %    
  263. %     %ref_line to ref+line_surf
  264. %     [img_line_surf,ind_line_surf,avg_index,ref_line_surf] = line_surf2(img_diff,H_crop,W_crop,diff);
  265. %     img3d(:,:,step) = img_line_surf;
  266. %
  267. %     [peak_height_front,valley_depth_front] = peak_valley(ind_line_surf,avg_index,W_crop);
  268. %     [avg_rough_front(step),rms_rough_front(step),max_rough_front(step),total_rough_front(step)] = roughness(peak_height_front,valley_depth_front);
  269. %
  270. %     fprintf('%d\n', step);
  271. %
  272. % end
  273.  
  274. % avg_roughness = zeros(1,W_crop);
  275. % rms_roughness = zeros(1,W_crop);
  276. % max_roughness = zeros(1,W_crop);
  277. % total_roughness = zeros(1,W_crop);
  278.  
  279. % for ii = 1:W_crop
  280. %     s = img3d(:,ii,:);
  281. %     s = squeeze(s);
  282. %     [Hs,Ws] = size(s);
  283. %     [row,col] = find(s);
  284. %
  285. %     avg_index_side = round(mean(row));
  286. %     ref_line = zeros(Hs,Ws);
  287. %     ref_line(avg_index_side,:) = 255;
  288. %
  289. %     abs_roughness = zeros(1,Ws);
  290. %    
  291. %     [peak_height_side,valley_depth_side] = peak_valley(row,avg_index_side,W_crop);
  292. %     [avg_rough_side(ii),rms_rough_side(ii),max_rough_side(ii),total_rough_side(ii)] = roughness(peak_height_side,valley_depth_side);
  293. %    
  294. %     fprintf('%d\n', ii);
  295. %  
  296. % end
  297.  
  298.  
  299.  
  300. %mean_avg_rough_front = mean(avg_rough_front)
  301. % mean_rms_rough_front = mean(rms_rough_front)
  302. % mean_max_rough_front = mean(max_rough_front)
  303. % mean_total_rough_front = mean(total_rough_front)
  304. % disp('Front view roughness');
  305. %
  306. % text_avg_rough_front = sprintf('%.2f', mean(avg_rough_front));
  307. % text_rms_rough_front = sprintf('%.2f', mean(rms_rough_front));
  308. % text_max_rough_front = sprintf('%.2f', mean(max_rough_front));
  309. % text_total_rough_front = sprintf('%.2f', mean(total_rough_front));
  310. %
  311. % set(handles.avgValueText, 'String', text_avg_rough_front);
  312. % set(handles.rmsValueText, 'String', text_rms_rough_front);
  313. % set(handles.maxValueText, 'String', text_max_rough_front);
  314. % set(handles.text16, 'String', text_total_rough_front);
  315. %
  316. %
  317. % disp('Side view roughness');
  318.  
  319. % text_avg_rough = sprintf('%.2f', mean(avg_rough_side));
  320. % text_rms_rough = sprintf('%.2f', mean(rms_rough_side));
  321. % text_max_rough = sprintf('%.2f', mean(max_rough_side));
  322. % text_total_rough = sprintf('%.2f', mean(total_rough_side));
  323. %
  324. % set(handles.avgValueTextSide, 'String', text_avg_rough);
  325. % set(handles.rmsValueTextSide, 'String', text_rms_rough);
  326. % set(handles.maxValueTextSide, 'String', text_max_rough);
  327. % set(handles.text30, 'String', text_total_rough);
  328. %
  329. %
  330. %
  331. %
  332. % axes(handles.axes1)
  333. % %imshow(img)
  334. % axis off
  335. % axis image
  336. % imshow(img0);
  337. %
  338. %
  339. % r1 = img_crop;
  340. % g1 = r1;
  341. % b1 = r1;
  342. % r1(img_line_surf > 0) = 255;
  343. % g1(img_line_surf > 0) = 0; %%
  344. % b1(ref_line_surf > 0) = 255; %
  345. %
  346. % axes(handles.axes3)
  347. % %imshow(img)
  348. % axis off
  349. % axis image
  350. % imshow(cat(3,r1,g1,b1),[]);
  351.  
  352.  
  353.  
  354.  
  355.  
  356.  
  357. % figure('Name','Wrinkle')
  358. % imshow();
  359.  
  360. % imshow(img_crop,[], 'parent',handle.axes1)
  361. % imshow(cat(3,r1,g1,b1),[], 'parent',handle.axes3)
  362.  
  363. % %% Roughness Values
  364. % text_avg_rough = sprintf('%.2f', avg_rough);
  365. % text_rms_rough = sprintf('%.2f', rms_rough);
  366. % text_max_rough = sprintf('%.2f', max_rough);
  367. % text_total_rough = sprintf('%.2f', total_rough);
  368. %
  369. % set(handles.avgValueText, 'String', text_avg_rough);
  370. % set(handles.rmsValueText, 'String', text_rms_rough);
  371. % set(handles.maxValueText, 'String', text_max_rough);
  372. % set(handles.text16, 'String', text_total_rough);
  373.  
  374.  
  375.  
  376.  
  377.  
  378.  
  379. % img = imread(full_path);
  380. % [H,W] = size(img);
  381. % %% Parameters setup
  382. % l_crop = 18;
  383. % r_crop = 18;
  384. % t_crop = 12;
  385. % b_crop = 10;
  386. % diff = 2;
  387. % med = 80;
  388. % wind_size = 40;
  389. % threshold = 30;
  390. % %% Preprocessing
  391. % [img_crop,H_crop,W_crop] = crop(img,H,W,l_crop,r_crop,t_crop,b_crop);
  392. % img_filt = imgaussfilt(img_crop,7);
  393. % %% Wrinkle surface
  394. % img_diff = filt_diff(img_filt,H_crop,W_crop,diff);
  395. % [img_line_wrinkle,ind_line_wrinkle,avg_index,ref_line] = line_surf1(img_diff,H_crop,W_crop,diff);
  396. %
  397. % [peak_height,valley_depth] = peak_valley(ind_line_wrinkle,avg_index,W_crop);
  398. % [avg_rough,rms_rough,max_rough,total_rough] = roughness(peak_height,valley_depth);
  399. %
  400. % %% Roughness Values
  401. % text_avg_rough = sprintf('%.2f', avg_rough);
  402. % text_rms_rough = sprintf('%.2f', rms_rough);
  403. % text_max_rough = sprintf('%.2f', max_rough);
  404. % text_total_rough = sprintf('%.2f', total_rough);
  405. %
  406. % set(handles.avgValueText, 'String', text_avg_rough);
  407. % set(handles.rmsValueText, 'String', text_rms_rough);
  408. % set(handles.maxValueText, 'String', text_max_rough);
  409. % set(handles.text16, 'String', text_total_rough);
  410.  
  411.  
  412.  
  413. % --- Executes on button press in pushbutton3.
  414. function pushbutton3_Callback(hObject, eventdata, handles)
  415. % hObject    handle to pushbutton3 (see GCBO)
  416. % eventdata  reserved - to be defined in a future version of MATLAB
  417. % handles    structure with handles and user data (see GUIDATA)
  418.  
  419.  
  420. % --- Executes on button press in pushbutton4.
  421. function pushbutton4_Callback(hObject, eventdata, handles)
  422. % hObject    handle to pushbutton4 (see GCBO)
  423. % eventdata  reserved - to be defined in a future version of MATLAB
  424. % handles    structure with handles and user data (see GUIDATA)
  425.  
  426.  
  427.  
  428. % --- Executes on button press in pushbutton5.
  429. function pushbutton5_Callback(hObject, eventdata, handles)
  430. % hObject    handle to pushbutton5 (see GCBO)
  431. % eventdata  reserved - to be defined in a future version of MATLAB
  432. % handles    structure with handles and user data (see GUIDATA)
  433.  
  434.  
  435. % --- Executes on button press in pushbutton6.
  436. function pushbutton6_Callback(hObject, eventdata, handles)
  437. % hObject    handle to pushbutton6 (see GCBO)
  438. % eventdata  reserved - to be defined in a future version of MATLAB
  439. % handles    structure with handles and user data (see GUIDATA)
  440.  
  441.  
  442. % --- Executes on button press in pushbutton7.
  443. function pushbutton7_Callback(hObject, eventdata, handles)
  444. % hObject    handle to pushbutton7 (see GCBO)
  445. % eventdata  reserved - to be defined in a future version of MATLAB
  446. % handles    structure with handles and user data (see GUIDATA)
  447.  
  448.  
  449. % --- Executes during object creation, after setting all properties.
  450. function text21_CreateFcn(hObject, eventdata, handles)
  451. % hObject    handle to text21 (see GCBO)
  452. % eventdata  reserved - to be defined in a future version of MATLAB
  453. % handles    empty - handles not created until after all CreateFcns called
  454.  
  455.  
  456. % --- Executes on button press in btnNext.
  457. function btnNext_Callback(hObject, eventdata, handles)
  458. % hObject    handle to btnNext (see GCBO)
  459. % eventdata  reserved - to be defined in a future version of MATLAB
  460. % handles    structure with handles and user data (see GUIDATA)
  461. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  462.  
  463. if handles.imgOrder < handles.imgTotal
  464.     handles.imgOrder = handles.imgOrder + 1;
  465.     guidata(hObject,handles);
  466.     set(handles.imgOrderLabel, 'String', handles.imgOrder);
  467.    
  468.    
  469.     filePath = handles.filePath;
  470.     imgFilePath = handles.imgFolderInfo;
  471.     imgName = imgFilePath(handles.imgOrder).name;
  472.    
  473.     img = imread([filePath,'\',imgName]);
  474.     axes(handles.axes1)
  475.     axis off
  476.     axis image
  477.     imshow(img);
  478.    
  479.     delete(handles.lineRef);
  480.    
  481.     axes(handles.axes3)
  482. %     axis image
  483. %     imshow(avg,[]);
  484. %     hold on
  485.  
  486.     x = [1 handles.imgWidth];
  487.     y = [handles.imgOrder handles.imgOrder];
  488.    
  489.    
  490.     %handles.lineRef = c1;
  491.    
  492.    
  493.     handles.lineRef = line(x,y,'Color','red','LineStyle','--','LineWidth',2);
  494.    
  495.     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  496.     handles.lcrop = 0;
  497.     handles.rcrop = 0;
  498.     handles.tcrop = 0;
  499.     handles.bcrop = 0;
  500.     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  501.     handles.g1Val = 2;
  502.     handles.g2Val = 4;
  503.     handles.medVal = 20;
  504.     handles.diff = 2;
  505.     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  506.  
  507.     guidata(hObject,handles);
  508.    
  509. %     hold off
  510.  
  511.     [H,W] = size(img);
  512.  
  513.     [img_crp,H,W] = crop(img,H,W,handles.lcrop,handles.rcrop,handles.tcrop,handles.bcrop);
  514.    
  515.     img_gau = imgaussfilt(img_crp,handles.g1Val);
  516.     img_diff_bef = filt_diff(img_gau,H,W,handles.diff);
  517.     [img_rl_bef,ind_rl_bef,avg_rl_bef] = find_srf(img_diff_bef,H,W); %img_rl
  518.  
  519.     img_med = medfilt2(img_gau,[handles.medVal*2 handles.medVal*2],'symmetric');
  520.     img_med = filt_diff(img_med,H,W,handles.diff);
  521.  
  522.     [img_idl,ind_idl,~] = find_srf(img_med,H,W);
  523.     mrg = 60;
  524.     [img_flt,H,W] = flatten(img_crp,H,W,ind_idl,mrg);
  525.  
  526.     img_gau = imgaussfilt(img_flt,handles.g2Val);
  527.     img_diff = filt_diff(img_gau,H,W,handles.diff);
  528.  
  529.     [img_rl,ind_rl,avg_rl] = find_srf(img_diff,H,W); %img_rl
  530.     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  531.    
  532.    
  533.     axes(handles.imgOutputAxes)
  534.     axis image
  535.     imshow(img_flt,[]);
  536.     hold on
  537.     h4 = plot(ind_rl);
  538.     set(h4,'LineWidth',3)
  539.     hold off
  540. end
  541.  
  542.  
  543.  
  544.  
  545.  
  546.  
  547.  
  548.  
  549.  
  550.  
  551.  
  552.  
  553.  
  554.  
  555.  
  556.  
  557.  
  558.  
  559.  
  560. % save the changes to the structure
  561.  
  562.  
  563.  
  564. % handles.imgOrder = 1;
  565. % handles.imgTotal = folderImgNo;
  566. % guidata(hObject,handles);
  567.  
  568.  
  569. % set(handles.imgTotalLabel, 'String', folderImgNo);
  570.  
  571.  
  572.  
  573.  
  574. % --- Executes on button press in btnPrev.
  575. function btnPrev_Callback(hObject, eventdata, handles)
  576. % hObject    handle to btnPrev (see GCBO)
  577. % eventdata  reserved - to be defined in a future version of MATLAB
  578. % handles    structure with handles and user data (see GUIDATA)
  579. if handles.imgOrder > 1
  580.     handles.imgOrder = handles.imgOrder - 1;
  581.     guidata(hObject,handles);
  582.     set(handles.imgOrderLabel, 'String', handles.imgOrder);
  583.    
  584.    
  585.     filePath = handles.filePath;
  586.     imgFilePath = handles.imgFolderInfo;
  587.     imgName = imgFilePath(handles.imgOrder).name;
  588.    
  589.     img = imread([filePath,'\',imgName]);
  590.     axes(handles.axes1)
  591.     axis off
  592.     axis image
  593.     imshow(img);
  594.    
  595.    
  596.    
  597.     delete(handles.lineRef);
  598.     axes(handles.axes3)
  599.  
  600.     x = [1 handles.imgWidth];
  601.     y = [handles.imgOrder handles.imgOrder];
  602.    
  603.     handles.lineRef = line(x,y,'Color','red','LineStyle','--','LineWidth',2);
  604.    
  605.     handles.lcrop = 0;
  606.     handles.rcrop = 0;
  607.     handles.tcrop = 0;
  608.     handles.bcrop = 0;
  609.     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  610.     handles.g1Val = 2;
  611.     handles.g2Val = 4;
  612.     handles.medVal = 20;
  613.     handles.diff = 2;
  614.     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  615.  
  616.     guidata(hObject,handles);
  617.    
  618.    
  619.    
  620.     [H,W] = size(img);
  621.  
  622.     [img_crp,H,W] = crop(img,H,W,handles.lcrop,handles.rcrop,handles.tcrop,handles.bcrop);
  623.    
  624.     img_gau = imgaussfilt(img_crp,handles.g1Val);
  625.     img_diff_bef = filt_diff(img_gau,H,W,handles.diff);
  626.     [img_rl_bef,ind_rl_bef,avg_rl_bef] = find_srf(img_diff_bef,H,W); %img_rl
  627.  
  628.     img_med = medfilt2(img_gau,[handles.medVal*2 handles.medVal*2],'symmetric');
  629.     img_med = filt_diff(img_med,H,W,handles.diff);
  630.  
  631.     [img_idl,ind_idl,~] = find_srf(img_med,H,W);
  632.     mrg = 60;
  633.     [img_flt,H,W] = flatten(img_crp,H,W,ind_idl,mrg);
  634.  
  635.     img_gau = imgaussfilt(img_flt,handles.g2Val);
  636.     img_diff = filt_diff(img_gau,H,W,handles.diff);
  637.  
  638.     [img_rl,ind_rl,avg_rl] = find_srf(img_diff,H,W); %img_rl
  639.     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  640.     axes(handles.imgOutputAxes)
  641.     axis image
  642.     imshow(img_flt,[]);
  643.     hold on
  644.     h4 = plot(ind_rl);
  645.     set(h4,'LineWidth',3)
  646.     hold off
  647.    
  648. end
  649.  
  650.  
  651. % --- Executes on slider movement.
  652. function rcropSlider_Callback(hObject, eventdata, handles)
  653. % hObject    handle to rcropSlider (see GCBO)
  654. % eventdata  reserved - to be defined in a future version of MATLAB
  655. % handles    structure with handles and user data (see GUIDATA)
  656.  
  657. % Hints: get(hObject,'Value') returns position of slider
  658. %        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
  659. r_crop_normalized = get(handles.rcropSlider,'Value');
  660.  
  661. filePath = handles.filePath;
  662. imgFilePath = handles.imgFolderInfo;
  663. imgName = imgFilePath(handles.imgOrder).name;
  664.  
  665. img = imread([filePath,'\',imgName]);
  666. [H,W] = size(img);
  667.  
  668. % l_crop = 0;
  669. r_crop = r_crop_normalized*W;
  670. % t_crop = 0;
  671. % b_crop = 0;
  672.  
  673. handles.rcrop = r_crop;
  674. guidata(hObject,handles);
  675.  
  676. [img_crp,H,W] = crop(img,H,W,int16(handles.lcrop),int16(handles.rcrop),int16(handles.tcrop),int16(handles.bcrop));
  677.  
  678. axes(handles.axes1)
  679. axis off
  680. axis image
  681. imshow(img_crp);
  682.  
  683.  
  684.  
  685. [H,W] = size(img);
  686.  
  687. [img_crp,H,W] = crop(img,H,W,handles.lcrop,handles.rcrop,handles.tcrop,handles.bcrop);
  688.  
  689. img_gau = imgaussfilt(img_crp,handles.g1Val);
  690. img_diff_bef = filt_diff(img_gau,H,W,handles.diff);
  691. [img_rl_bef,ind_rl_bef,avg_rl_bef] = find_srf(img_diff_bef,H,W); %img_rl
  692.  
  693. img_med = medfilt2(img_gau,[handles.medVal*2 handles.medVal*2],'symmetric');
  694. img_med = filt_diff(img_med,H,W,handles.diff);
  695.  
  696. [img_idl,ind_idl,~] = find_srf(img_med,H,W);
  697. mrg = 60;
  698. [img_flt,H,W] = flatten(img_crp,H,W,ind_idl,mrg);
  699.  
  700. img_gau = imgaussfilt(img_flt,handles.g2Val);
  701. img_diff = filt_diff(img_gau,H,W,handles.diff);
  702.  
  703. [img_rl,ind_rl,avg_rl] = find_srf(img_diff,H,W); %img_rl
  704. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  705. axes(handles.imgOutputAxes)
  706. axis image
  707. imshow(img_flt,[]);
  708. hold on
  709. h4 = plot(ind_rl);
  710. set(h4,'LineWidth',3)
  711. hold off
  712.  
  713.  
  714. % --- Executes during object creation, after setting all properties.
  715. function rcropSlider_CreateFcn(hObject, eventdata, handles)
  716. % hObject    handle to rcropSlider (see GCBO)
  717. % eventdata  reserved - to be defined in a future version of MATLAB
  718. % handles    empty - handles not created until after all CreateFcns called
  719.  
  720. % Hint: slider controls usually have a light gray background.
  721. if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  722.     set(hObject,'BackgroundColor',[.9 .9 .9]);
  723. end
  724.  
  725.  
  726. % --- Executes on slider movement.
  727. function lcropSlider_Callback(hObject, eventdata, handles)
  728. % hObject    handle to lcropSlider (see GCBO)
  729. % eventdata  reserved - to be defined in a future version of MATLAB
  730. % handles    structure with handles and user data (see GUIDATA)
  731.  
  732. % Hints: get(hObject,'Value') returns position of slider
  733. %        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
  734. l_crop_normalized = get(handles.lcropSlider,'Value')
  735.  
  736. filePath = handles.filePath;
  737. imgFilePath = handles.imgFolderInfo;
  738. imgName = imgFilePath(handles.imgOrder).name;
  739.  
  740. img = imread([filePath,'\',imgName]);
  741. [H,W] = size(img);
  742.  
  743. l_crop = l_crop_normalized*W;
  744. % r_crop = 0;
  745. % t_crop = 0;
  746. % b_crop = 0;
  747.  
  748. handles.lcrop = l_crop;
  749. guidata(hObject,handles);
  750.  
  751. [img_crp,H,W] = crop(img,H,W,int16(handles.lcrop),int16(handles.rcrop),int16(handles.tcrop),int16(handles.bcrop));
  752.  
  753. axes(handles.axes1)
  754. axis off
  755. axis image
  756. imshow(img_crp);
  757.  
  758.  
  759.  
  760.  
  761.  
  762.  
  763. [H,W] = size(img);
  764.  
  765. [img_crp,H,W] = crop(img,H,W,handles.lcrop,handles.rcrop,handles.tcrop,handles.bcrop);
  766.  
  767. img_gau = imgaussfilt(img_crp,handles.g1Val);
  768. img_diff_bef = filt_diff(img_gau,H,W,handles.diff);
  769. [img_rl_bef,ind_rl_bef,avg_rl_bef] = find_srf(img_diff_bef,H,W); %img_rl
  770.  
  771. img_med = medfilt2(img_gau,[handles.medVal*2 handles.medVal*2],'symmetric');
  772. img_med = filt_diff(img_med,H,W,handles.diff);
  773.  
  774. [img_idl,ind_idl,~] = find_srf(img_med,H,W);
  775. mrg = 60;
  776. [img_flt,H,W] = flatten(img_crp,H,W,ind_idl,mrg);
  777.  
  778. img_gau = imgaussfilt(img_flt,handles.g2Val);
  779. img_diff = filt_diff(img_gau,H,W,handles.diff);
  780.  
  781. [img_rl,ind_rl,avg_rl] = find_srf(img_diff,H,W); %img_rl
  782. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  783.  
  784. axes(handles.imgOutputAxes)
  785. axis image
  786. imshow(img_flt,[]);
  787. hold on
  788. h4 = plot(ind_rl);
  789. set(h4,'LineWidth',3)
  790. hold off
  791.  
  792.  
  793. % --- Executes during object creation, after setting all properties.
  794. function lcropSlider_CreateFcn(hObject, eventdata, handles)
  795. % hObject    handle to lcropSlider (see GCBO)
  796. % eventdata  reserved - to be defined in a future version of MATLAB
  797. % handles    empty - handles not created until after all CreateFcns called
  798.  
  799. % Hint: slider controls usually have a light gray background.
  800. if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  801.     set(hObject,'BackgroundColor',[.9 .9 .9]);
  802. end
  803.  
  804.  
  805. % --- Executes on slider movement.
  806. function tcropSlider_Callback(hObject, eventdata, handles)
  807. % hObject    handle to tcropSlider (see GCBO)
  808. % eventdata  reserved - to be defined in a future version of MATLAB
  809. % handles    structure with handles and user data (see GUIDATA)
  810.  
  811. % Hints: get(hObject,'Value') returns position of slider
  812. %        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
  813. t_crop_normalized = get(handles.tcropSlider,'Value');
  814.  
  815. filePath = handles.filePath;
  816. imgFilePath = handles.imgFolderInfo;
  817. imgName = imgFilePath(handles.imgOrder).name;
  818.  
  819. img = imread([filePath,'\',imgName]);
  820. [H,W] = size(img);
  821.  
  822.  
  823. t_crop = t_crop_normalized*W;
  824.  
  825. handles.tcrop = t_crop;
  826. guidata(hObject,handles);
  827.  
  828. [img_crp,H,W] = crop(img,H,W,int16(handles.lcrop),int16(handles.rcrop),int16(handles.tcrop),int16(handles.bcrop));
  829.  
  830. axes(handles.axes1)
  831. axis off
  832. axis image
  833. imshow(img_crp);
  834.  
  835.  
  836.  
  837.  
  838. [H,W] = size(img);
  839.  
  840. [img_crp,H,W] = crop(img,H,W,handles.lcrop,handles.rcrop,handles.tcrop,handles.bcrop);
  841.  
  842. img_gau = imgaussfilt(img_crp,handles.g1Val);
  843. img_diff_bef = filt_diff(img_gau,H,W,handles.diff);
  844. [img_rl_bef,ind_rl_bef,avg_rl_bef] = find_srf(img_diff_bef,H,W); %img_rl
  845.  
  846. img_med = medfilt2(img_gau,[handles.medVal*2 handles.medVal*2],'symmetric');
  847. img_med = filt_diff(img_med,H,W,handles.diff);
  848.  
  849. [img_idl,ind_idl,~] = find_srf(img_med,H,W);
  850. mrg = 60;
  851. [img_flt,H,W] = flatten(img_crp,H,W,ind_idl,mrg);
  852.  
  853. img_gau = imgaussfilt(img_flt,handles.g2Val);
  854. img_diff = filt_diff(img_gau,H,W,handles.diff);
  855.  
  856. [img_rl,ind_rl,avg_rl] = find_srf(img_diff,H,W); %img_rl
  857. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  858. axes(handles.imgOutputAxes)
  859. axis image
  860. imshow(img_flt,[]);
  861. hold on
  862. h4 = plot(ind_rl);
  863. set(h4,'LineWidth',3)
  864. hold off
  865.  
  866.  
  867. % --- Executes during object creation, after setting all properties.
  868. function tcropSlider_CreateFcn(hObject, eventdata, handles)
  869. % hObject    handle to tcropSlider (see GCBO)
  870. % eventdata  reserved - to be defined in a future version of MATLAB
  871. % handles    empty - handles not created until after all CreateFcns called
  872.  
  873. % Hint: slider controls usually have a light gray background.
  874. if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  875.     set(hObject,'BackgroundColor',[.9 .9 .9]);
  876. end
  877.  
  878.  
  879. % --- Executes on slider movement.
  880. function bcropSlider_Callback(hObject, eventdata, handles)
  881. % hObject    handle to bcropSlider (see GCBO)
  882. % eventdata  reserved - to be defined in a future version of MATLAB
  883. % handles    structure with handles and user data (see GUIDATA)
  884.  
  885. % Hints: get(hObject,'Value') returns position of slider
  886. %        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
  887. b_crop_normalized = get(handles.bcropSlider,'Value');
  888.  
  889. filePath = handles.filePath;
  890. imgFilePath = handles.imgFolderInfo;
  891. imgName = imgFilePath(handles.imgOrder).name;
  892.  
  893. img = imread([filePath,'\',imgName]);
  894. [H,W] = size(img);
  895.  
  896. % l_crop = 0;
  897. % r_crop = 0;
  898. % t_crop = 0;
  899. b_crop = b_crop_normalized*W;
  900.  
  901. handles.bcrop = b_crop;
  902. guidata(hObject,handles);
  903.  
  904. [img_crp,H,W] = crop(img,H,W,int16(handles.lcrop),int16(handles.rcrop),int16(handles.tcrop),int16(handles.bcrop));
  905.  
  906. axes(handles.axes1)
  907. axis off
  908. axis image
  909. imshow(img_crp);
  910.  
  911.  
  912.  
  913. [H,W] = size(img);
  914.  
  915. [img_crp,H,W] = crop(img,H,W,handles.lcrop,handles.rcrop,handles.tcrop,handles.bcrop);
  916.  
  917. img_gau = imgaussfilt(img_crp,handles.g1Val);
  918. img_diff_bef = filt_diff(img_gau,H,W,handles.diff);
  919. [img_rl_bef,ind_rl_bef,avg_rl_bef] = find_srf(img_diff_bef,H,W); %img_rl
  920.  
  921. img_med = medfilt2(img_gau,[handles.medVal*2 handles.medVal*2],'symmetric');
  922. img_med = filt_diff(img_med,H,W,handles.diff);
  923.  
  924. [img_idl,ind_idl,~] = find_srf(img_med,H,W);
  925. mrg = 60;
  926. [img_flt,H,W] = flatten(img_crp,H,W,ind_idl,mrg);
  927.  
  928. img_gau = imgaussfilt(img_flt,handles.g2Val);
  929. img_diff = filt_diff(img_gau,H,W,handles.diff);
  930.  
  931. [img_rl,ind_rl,avg_rl] = find_srf(img_diff,H,W); %img_rl
  932. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  933. axes(handles.imgOutputAxes)
  934. axis image
  935. imshow(img_flt,[]);
  936. hold on
  937. h4 = plot(ind_rl);
  938. set(h4,'LineWidth',3)
  939. hold off
  940.  
  941.  
  942.  
  943. % --- Executes during object creation, after setting all properties.
  944. function bcropSlider_CreateFcn(hObject, eventdata, handles)
  945. % hObject    handle to bcropSlider (see GCBO)
  946. % eventdata  reserved - to be defined in a future version of MATLAB
  947. % handles    empty - handles not created until after all CreateFcns called
  948.  
  949. % Hint: slider controls usually have a light gray background.
  950. if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  951.     set(hObject,'BackgroundColor',[.9 .9 .9]);
  952. end
  953.  
  954.  
  955. % --- Executes on slider movement.
  956. function slider8_Callback(hObject, eventdata, handles)
  957. % hObject    handle to slider8 (see GCBO)
  958. % eventdata  reserved - to be defined in a future version of MATLAB
  959. % handles    structure with handles and user data (see GUIDATA)
  960.  
  961. % Hints: get(hObject,'Value') returns position of slider
  962. %        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
  963.  
  964.  
  965. % --- Executes during object creation, after setting all properties.
  966. function slider8_CreateFcn(hObject, eventdata, handles)
  967. % hObject    handle to slider8 (see GCBO)
  968. % eventdata  reserved - to be defined in a future version of MATLAB
  969. % handles    empty - handles not created until after all CreateFcns called
  970.  
  971. % Hint: slider controls usually have a light gray background.
  972. if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  973.     set(hObject,'BackgroundColor',[.9 .9 .9]);
  974. end
  975.  
  976.  
  977. % --- Executes on slider movement.
  978. function g1Slider_Callback(hObject, eventdata, handles)
  979. % hObject    handle to g1Slider (see GCBO)
  980. % eventdata  reserved - to be defined in a future version of MATLAB
  981. % handles    structure with handles and user data (see GUIDATA)
  982.  
  983. % Hints: get(hObject,'Value') returns position of slider
  984. %        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
  985. handles.g1Val = get(handles.g1Slider,'Value');
  986. set(handles.g1ValLabel, 'String', handles.g1Val);
  987. guidata(hObject,handles);
  988.  
  989. % filePath = handles.filePath;
  990. imgFilePath = handles.imgFolderInfo;
  991. imgName = imgFilePath(handles.imgOrder).name;
  992.  
  993. img = imread([handles.filePath,'\',imgName]);
  994.    
  995.  
  996. [H,W] = size(img);
  997.  
  998. [img_crp,H,W] = crop(img,H,W,handles.lcrop,handles.rcrop,handles.tcrop,handles.bcrop);
  999.  
  1000. img_gau = imgaussfilt(img_crp,handles.g1Val);
  1001. img_diff_bef = filt_diff(img_gau,H,W,handles.diff);
  1002. [img_rl_bef,ind_rl_bef,avg_rl_bef] = find_srf(img_diff_bef,H,W); %img_rl
  1003.  
  1004. img_med = medfilt2(img_gau,[handles.medVal*2 handles.medVal*2],'symmetric');
  1005. img_med = filt_diff(img_med,H,W,handles.diff);
  1006.  
  1007. [img_idl,ind_idl,~] = find_srf(img_med,H,W);
  1008. mrg = 60;
  1009. [img_flt,H,W] = flatten(img_crp,H,W,ind_idl,mrg);
  1010.  
  1011. img_gau = imgaussfilt(img_flt,handles.g2Val);
  1012. img_diff = filt_diff(img_gau,H,W,handles.diff);
  1013.  
  1014. [img_rl,ind_rl,avg_rl] = find_srf(img_diff,H,W); %img_rl
  1015. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1016.    
  1017. axes(handles.imgOutputAxes)
  1018. axis image
  1019. imshow(img_flt,[]);
  1020. hold on
  1021. h4 = plot(ind_rl);
  1022. set(h4,'LineWidth',3)
  1023. hold off
  1024. % --- Executes during object creation, after setting all properties.
  1025. function g1Slider_CreateFcn(hObject, eventdata, handles)
  1026. % hObject    handle to g1Slider (see GCBO)
  1027. % eventdata  reserved - to be defined in a future version of MATLAB
  1028. % handles    empty - handles not created until after all CreateFcns called
  1029.  
  1030. % Hint: slider controls usually have a light gray background.
  1031. if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1032.     set(hObject,'BackgroundColor',[.9 .9 .9]);
  1033. end
  1034.  
  1035.  
  1036. % --- Executes on slider movement.
  1037. function g2Slider_Callback(hObject, eventdata, handles)
  1038. % hObject    handle to g2Slider (see GCBO)
  1039. % eventdata  reserved - to be defined in a future version of MATLAB
  1040. % handles    structure with handles and user data (see GUIDATA)
  1041.  
  1042. % Hints: get(hObject,'Value') returns position of slider
  1043. %        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
  1044. handles.g2Val = get(handles.g2Slider,'Value');
  1045. set(handles.g2ValLabel, 'String', handles.g2Val);
  1046. guidata(hObject,handles);
  1047.  
  1048. % filePath = handles.filePath;
  1049. imgFilePath = handles.imgFolderInfo;
  1050. imgName = imgFilePath(handles.imgOrder).name;
  1051.  
  1052. img = imread([handles.filePath,'\',imgName]);
  1053.    
  1054.  
  1055. [H,W] = size(img);
  1056.  
  1057. [img_crp,H,W] = crop(img,H,W,handles.lcrop,handles.rcrop,handles.tcrop,handles.bcrop);
  1058.  
  1059. img_gau = imgaussfilt(img_crp,handles.g1Val);
  1060. img_diff_bef = filt_diff(img_gau,H,W,handles.diff);
  1061. [img_rl_bef,ind_rl_bef,avg_rl_bef] = find_srf(img_diff_bef,H,W); %img_rl
  1062.  
  1063. img_med = medfilt2(img_gau,[handles.medVal*2 handles.medVal*2],'symmetric');
  1064. img_med = filt_diff(img_med,H,W,handles.diff);
  1065.  
  1066. [img_idl,ind_idl,~] = find_srf(img_med,H,W);
  1067. mrg = 60;
  1068. [img_flt,H,W] = flatten(img_crp,H,W,ind_idl,mrg);
  1069.  
  1070. img_gau = imgaussfilt(img_flt,handles.g2Val);
  1071. img_diff = filt_diff(img_gau,H,W,handles.diff);
  1072.  
  1073. [img_rl,ind_rl,avg_rl] = find_srf(img_diff,H,W); %img_rl
  1074. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1075. axes(handles.imgOutputAxes)
  1076. axis image
  1077. imshow(img_flt,[]);
  1078. hold on
  1079. h4 = plot(ind_rl);
  1080. set(h4,'LineWidth',3)
  1081. hold off
  1082.  
  1083. % --- Executes during object creation, after setting all properties.
  1084. function g2Slider_CreateFcn(hObject, eventdata, handles)
  1085. % hObject    handle to g2Slider (see GCBO)
  1086. % eventdata  reserved - to be defined in a future version of MATLAB
  1087. % handles    empty - handles not created until after all CreateFcns called
  1088.  
  1089. % Hint: slider controls usually have a light gray background.
  1090. if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1091.     set(hObject,'BackgroundColor',[.9 .9 .9]);
  1092. end
  1093.  
  1094.  
  1095. % --- Executes on slider movement.
  1096. function medSlider_Callback(hObject, eventdata, handles)
  1097. % hObject    handle to medSlider (see GCBO)
  1098. % eventdata  reserved - to be defined in a future version of MATLAB
  1099. % handles    structure with handles and user data (see GUIDATA)
  1100.  
  1101. % Hints: get(hObject,'Value') returns position of slider
  1102. %        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
  1103. handles.medVal = get(handles.medSlider,'Value');
  1104. set(handles.medValLabel, 'String', handles.medVal);
  1105. guidata(hObject,handles);
  1106.  
  1107. % filePath = handles.filePath;
  1108. imgFilePath = handles.imgFolderInfo;
  1109. imgName = imgFilePath(handles.imgOrder).name;
  1110.  
  1111. img = imread([handles.filePath,'\',imgName]);
  1112.    
  1113.  
  1114. [H,W] = size(img);
  1115.  
  1116. [img_crp,H,W] = crop(img,H,W,handles.lcrop,handles.rcrop,handles.tcrop,handles.bcrop);
  1117.  
  1118. img_gau = imgaussfilt(img_crp,handles.g1Val);
  1119. img_diff_bef = filt_diff(img_gau,H,W,handles.diff);
  1120. [img_rl_bef,ind_rl_bef,avg_rl_bef] = find_srf(img_diff_bef,H,W); %img_rl
  1121.  
  1122. img_med = medfilt2(img_gau,[handles.medVal*2 handles.medVal*2],'symmetric');
  1123. img_med = filt_diff(img_med,H,W,handles.diff);
  1124.  
  1125. [img_idl,ind_idl,~] = find_srf(img_med,H,W);
  1126. mrg = 60;
  1127. [img_flt,H,W] = flatten(img_crp,H,W,ind_idl,mrg);
  1128.  
  1129. img_gau = imgaussfilt(img_flt,handles.g2Val);
  1130. img_diff = filt_diff(img_gau,H,W,handles.diff);
  1131.  
  1132. [img_rl,ind_rl,avg_rl] = find_srf(img_diff,H,W); %img_rl
  1133. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1134. axes(handles.imgOutputAxes)
  1135. axis image
  1136. imshow(img_flt,[]);
  1137. hold on
  1138. h4 = plot(ind_rl);
  1139. set(h4,'LineWidth',3)
  1140. hold off
  1141.  
  1142. % --- Executes during object creation, after setting all properties.
  1143. function medSlider_CreateFcn(hObject, eventdata, handles)
  1144. % hObject    handle to medSlider (see GCBO)
  1145. % eventdata  reserved - to be defined in a future version of MATLAB
  1146. % handles    empty - handles not created until after all CreateFcns called
  1147.  
  1148. % Hint: slider controls usually have a light gray background.
  1149. if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1150.     set(hObject,'BackgroundColor',[.9 .9 .9]);
  1151. end
  1152.  
  1153.  
  1154. % --- Executes on button press in pushbutton10.
  1155. function pushbutton10_Callback(hObject, eventdata, handles)
  1156. % hObject    handle to pushbutton10 (see GCBO)
  1157. % eventdata  reserved - to be defined in a future version of MATLAB
  1158. % handles    structure with handles and user data (see GUIDATA)
  1159. filePath = handles.filePath;
  1160. imgFilePath = handles.imgFolderInfo;
  1161. imgName = imgFilePath(handles.imgOrder).name;
  1162.  
  1163. img = imread([filePath,'\',imgName]);
  1164.  
  1165. [H,W] = size(img);
  1166.  
  1167. [img_crp,H,W] = crop(img,H,W,handles.lcrop,handles.rcrop,handles.tcrop,handles.bcrop);
  1168.  
  1169. img_gau = imgaussfilt(img_crp,handles.g1Val);
  1170. img_diff_bef = filt_diff(img_gau,H,W,handles.diff);
  1171. [img_rl_bef,ind_rl_bef,avg_rl_bef] = find_srf(img_diff_bef,H,W); %img_rl
  1172.  
  1173. img_med = medfilt2(img_gau,[handles.medVal*2 handles.medVal*2],'symmetric');
  1174. img_med = filt_diff(img_med,H,W,handles.diff);
  1175.  
  1176. [img_idl,ind_idl,~] = find_srf(img_med,H,W);
  1177. mrg = 60;
  1178. [img_flt,H,W] = flatten(img_crp,H,W,ind_idl,mrg);
  1179.  
  1180. img_gau = imgaussfilt(img_flt,handles.g2Val);
  1181. img_diff = filt_diff(img_gau,H,W,handles.diff);
  1182.  
  1183. [img_rl,ind_rl,avg_rl] = find_srf(img_diff,H,W);
  1184. [avg_rgh,rms_rgh,max_rgh] = rgh_single(avg_rl,ind_rl);
  1185.  
  1186. text_avg_rough_front = sprintf('%.2f', avg_rgh);
  1187. text_rms_rough_front = sprintf('%.2f', rms_rgh);
  1188. text_max_rough_front = sprintf('%.2f', max_rgh);
  1189.  
  1190. set(handles.avgValueText, 'String', text_avg_rough_front);
  1191. set(handles.rmsValueText, 'String', text_rms_rough_front);
  1192. set(handles.maxValueText, 'String', text_max_rough_front);
  1193.  
  1194.  
  1195.  
  1196.  
  1197.  
  1198.  
  1199. % --- Executes on button press in pushbutton11.
  1200. function pushbutton11_Callback(hObject, eventdata, handles)
  1201. % hObject    handle to pushbutton11 (see GCBO)
  1202. % eventdata  reserved - to be defined in a future version of MATLAB
  1203. % handles    structure with handles and user data (see GUIDATA)
  1204. imgFilePath = handles.imgFolderInfo;
  1205.  
  1206. if handles.newDatasetFlag == true
  1207.     img3d = zeros(handles.imgHeight,handles.imgWidth,handles.imgTotal);
  1208.    
  1209.     avg_rghn_fr = zeros(1,handles.imgTotal);
  1210.     rms_rghn_fr = zeros(1,handles.imgTotal);
  1211.     max_rghn_fr = zeros(1,handles.imgTotal);
  1212.    
  1213.     img_no = 0;
  1214.    
  1215.     for step = 1:30 % handles.imgTotal
  1216.         imgName = imgFilePath(step).name;
  1217.         img = imread([handles.filePath,'\',imgName]);
  1218.         img3d(:,:,step) = img;
  1219.         fprintf('%d\n', step);
  1220.        
  1221.         [H,W] = size(img);
  1222.         img = uint8(img);
  1223.         gsigma1 = 2;
  1224.         img_gau = imgaussfilt(img,gsigma1);
  1225.    
  1226.         med = 20; %med_arr(sbj_no,part_no); %60
  1227.         diff_idl = 2;
  1228.         img_med = medfilt2(img_gau,[med*2 med*2],'symmetric');
  1229.         img_med = filt_diff(img_med,H,W,diff_idl);
  1230.         [img_idl,ind_idl,~] = find_srf(img_med,H,W);
  1231.    
  1232.         mrg = 60;
  1233.         [img_flt,H,W] = flatten(img,H,W,ind_idl,mrg);
  1234.  
  1235.         gsigma2 = 2;
  1236.         img_gau = imgaussfilt(img_flt,gsigma2);
  1237.  
  1238.         diff_rl = 2;
  1239.         img_diff = filt_diff(img_gau,H,W,diff_rl);
  1240.  
  1241.         [img_rl,ind_rl,avg_rl] = find_srf(img_diff,H,W); %img_rl
  1242.         [avg_rghn_fr(step),rms_rghn_fr(step),max_rghn_fr(step)] = rgh(avg_rl,ind_rl);
  1243.        
  1244.        
  1245.         if mod(step,10) == 0
  1246.             progressValue = (step*50 + img_no*50)*100/2500;
  1247.             text_progress = sprintf('%.2f', progressValue);
  1248.             set(handles.progressText, 'String', text_progress);
  1249.             guidata(hObject,handles);
  1250.             %text_progress = fprintf(step);
  1251. %             set(handles.progressText, 'String', step);
  1252.             guidata(hObject,handles);
  1253.             drawnow;
  1254.         end
  1255.     end
  1256.    
  1257.     mean_avg_rghn_front = mean(avg_rghn_fr);
  1258.     mean_rms_rghn_front = mean(rms_rghn_fr);
  1259.     mean_max_rghn_front = mean(max_rghn_fr);
  1260.    
  1261.     text_avg_rough_front = sprintf('%.2f', mean_avg_rghn_front);
  1262.     text_rms_rough_front = sprintf('%.2f', mean_rms_rghn_front);
  1263.     text_max_rough_front = sprintf('%.2f', mean_max_rghn_front);
  1264.  
  1265.     set(handles.avgValueTextFront, 'String', text_avg_rough_front);
  1266.     set(handles.rmsValueTextFront, 'String', text_rms_rough_front);
  1267.     set(handles.maxValueTextFront, 'String', text_max_rough_front);
  1268.     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1269.     avg_rghn = zeros(1,handles.imgTotal);
  1270.     rms_rghn = zeros(1,handles.imgTotal);
  1271.     max_rghn = zeros(1,handles.imgTotal);
  1272.        
  1273.     for img_no = 1:30 %handles.imgWidth %W
  1274.         avgSide = img3d(:,img_no,:);
  1275.         avgSide2 = squeeze(avgSide);
  1276.         img = avgSide2;
  1277.         [H,W] = size(img);
  1278.         fprintf('%d\n', img_no);
  1279.         img = uint8(img);
  1280. %        
  1281.         gsigma1 = 2;
  1282.         img_gau = imgaussfilt(img,gsigma1);
  1283.    
  1284.         med = 20; %med_arr(sbj_no,part_no); %60
  1285.         diff_idl = 2;
  1286.         img_med = medfilt2(img_gau,[med*2 med*2],'symmetric');
  1287.         img_med = filt_diff(img_med,H,W,diff_idl);
  1288.         [img_idl,ind_idl,~] = find_srf(img_med,H,W);
  1289.    
  1290.         mrg = 60;
  1291.         [img_flt,H,W] = flatten(img,H,W,ind_idl,mrg);
  1292.  
  1293.         gsigma2 = 2;
  1294.         img_gau = imgaussfilt(img_flt,gsigma2);
  1295.  
  1296.         diff_rl = 2;
  1297.         img_diff = filt_diff(img_gau,H,W,diff_rl);
  1298.  
  1299.         [img_rl,ind_rl,avg_rl] = find_srf(img_diff,H,W); %img_rl
  1300.         [avg_rghn(img_no),rms_rghn(img_no),max_rghn(img_no)] = rgh(avg_rl,ind_rl);
  1301.        
  1302.         if mod(img_no,10) == 0
  1303. %             progressValue = img_no;
  1304. %             text_progress = fprintf(progressValue);
  1305. %             set(handles.progressText, 'String', text_progress);
  1306. %             guidata(hObject,handles);
  1307. %             drawnow;
  1308.             progressValue = (step*50 + img_no*50)*100/2500;
  1309.             text_progress = sprintf('%.2f', progressValue);
  1310.             set(handles.progressText, 'String', text_progress);
  1311.             guidata(hObject,handles);
  1312.             drawnow
  1313.         end
  1314.     end
  1315.    
  1316.     mean_avg_rghn_side = mean(avg_rghn);
  1317.     mean_rms_rghn_side = mean(rms_rghn);
  1318.     mean_max_rghn_side = mean(max_rghn);
  1319.    
  1320.     text_avg_rough_side = sprintf('%.2f', mean_avg_rghn_side);
  1321.     text_rms_rough_side = sprintf('%.2f', mean_rms_rghn_side);
  1322.     text_max_rough_side = sprintf('%.2f', mean_max_rghn_side);
  1323.  
  1324.     set(handles.avgValueTextSide, 'String', text_avg_rough_side);
  1325.     set(handles.rmsValueTextSide, 'String', text_rms_rough_side);
  1326.     set(handles.maxValueTextSide, 'String', text_max_rough_side);
  1327.    
  1328.     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1329.    
  1330.     mean_avg_tot = mean_avg_rghn_front * mean_avg_rghn_side;
  1331.     mean_rms_tot = mean_rms_rghn_front * mean_rms_rghn_side;
  1332.     mean_max_tot = max(mean_max_rghn_front,mean_max_rghn_side);
  1333.    
  1334.     text_mean_avg_tot = sprintf('%.2f', mean_avg_tot);
  1335.     text_mean_rms_tot = sprintf('%.2f', mean_rms_tot);
  1336.     text_mean_max_tot = sprintf('%.2f', mean_max_tot);
  1337.  
  1338.     set(handles.avgValueTextTotal, 'String', text_mean_avg_tot);
  1339.     set(handles.rmsValueTextTotal, 'String', text_mean_rms_tot);
  1340.     set(handles.maxValueTextTotal, 'String', text_mean_max_tot);
  1341.    
  1342.    
  1343.  
  1344.    
  1345.    
  1346.     handles.newDatasetFlag = false;
  1347.     guidata(hObject,handles);
  1348. else
  1349. end
Advertisement
Add Comment
Please, Sign In to add comment