daily pastebin goal
28%
SHARE
TWEET

parfortest

tuttelikz Jan 13th, 2018 (edited) 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. tic;
  2. clc, clear all, close all
  3. addpath('D:\Labview Projects\matlab_script_skin');
  4.  
  5. %filePath = 'C:\Users\iptea\Documents\MATLAB\MEMS_SD';
  6. filePath = 'C:\Users\iptea\Documents\MATLAB\MEMS_SD'
  7.  
  8. imgFilePath = dir([filePath '/*.jpg']);
  9. imgFilesNo = size(imgFilePath,1);
  10. imgName = imgFilePath(1).name;
  11. srcimg = imread([filePath,'\',imgName]);
  12.  
  13. l_crop = 78;
  14. r_crop = 112;
  15. t_crop = 35;
  16. b_crop = 47;
  17.  
  18. srcimg = rgb2gray(srcimg);
  19. [H,W] = size(srcimg);
  20. [srcimg,H,W] = crop(srcimg,H,W,l_crop,r_crop,t_crop,b_crop);
  21. img3d = zeros(H,W,imgFilesNo);
  22. imgWidth = W;
  23. avg_rghn_fr = zeros(1,imgFilesNo);
  24. rms_rghn_fr = zeros(1,imgFilesNo);
  25. max_rghn_fr = zeros(1,imgFilesNo);
  26.  
  27. mrg = 60;
  28.  
  29. diff_idl = 2;
  30. diff_rl = 2;
  31. gsigma1 = 2;
  32. gsigma2 = 2;
  33. med = 5;
  34.  
  35. hbar = parfor_progressbar(imgFilesNo+imgWidth,'Please wait...'); %create the progress bar
  36. %parfor_progress(imgFilesNo); % Initialize
  37.  
  38. parfor step = 1:imgFilesNo
  39.         imgName = imgFilePath(step).name;
  40.         img = imread([filePath,'\',imgName]);
  41.         img = rgb2gray(img);
  42.         [H,W] = size(img);
  43.  
  44.         [img,H,W] = crop(img,H,W,l_crop,r_crop,t_crop,b_crop);
  45.  
  46.         img = uint8(img);
  47.  
  48.         img3d(:,:,step) = img;
  49.  
  50.         img_gau = imgaussfilt(img,gsigma1);
  51.         %imshow(img_gau)
  52.         img_med = medfilt2(img_gau,[med*2 med*2],'symmetric');
  53.  
  54.         img_med = filt_diff(img_med,H,W,diff_idl);
  55.         %imshow(img_med,[])
  56.         %[~,ind_idl,~] = find_srf(img_med,H,W); %img_idl
  57.         [~,ind_idl,~] = find_srf(img_med,H,W); %img_idl
  58.         %imshow(img_idl)
  59.         [img_flt,H,W] = flatten(img,H,W,ind_idl,mrg);
  60.  
  61.         img_gau = imgaussfilt(img_flt,gsigma2);
  62.  
  63.         img_diff = filt_diff(img_gau,H,W,diff_rl);
  64.         %imshow(img_diff,[])
  65.         [~,ind_rl,avg_rl] = find_srf(img_diff,H,W); %img_rl
  66.         %imshow(img_rl,[])
  67.         [avg_rghn_fr(step),rms_rghn_fr(step),max_rghn_fr(step)] = rgh(avg_rl,ind_rl);
  68.    
  69.         pause(rand); % computation
  70.         hbar.iterate(1);
  71. end
  72.  
  73. mean_avg_rghn_front = mean(avg_rghn_fr);
  74. mean_rms_rghn_front = mean(rms_rghn_fr);
  75. mean_max_rghn_front = mean(max_rghn_fr);
  76.  
  77. avg_rghn = zeros(1,imgWidth);
  78. rms_rghn = zeros(1,imgWidth);
  79. max_rghn = zeros(1,imgWidth);
  80.  
  81. parfor img_no = 1:imgWidth
  82.         avgSide = img3d(:,img_no,:);
  83.         img = squeeze(avgSide);
  84.         [H,W] = size(img);
  85.         img = uint8(img);
  86.  
  87.         img_gau = imgaussfilt(img,gsigma1);
  88.    
  89.         img_med = medfilt2(img_gau,[med*2 med*2],'symmetric');
  90.         img_med = filt_diff(img_med,H,W,diff_idl);
  91.         [~,ind_idl,~] = find_srf(img_med,H,W); %img_idl
  92.        
  93.         [img_flt,H,W] = flatten(img,H,W,ind_idl,mrg);
  94.  
  95.         img_gau = imgaussfilt(img_flt,gsigma2);
  96.  
  97.         img_diff = filt_diff(img_gau,H,W,diff_rl);
  98.        
  99.         [~,ind_rl,avg_rl] = find_srf(img_diff,H,W); %img_rl
  100.  
  101.         [avg_rghn(img_no),rms_rghn(img_no),max_rghn(img_no)] = rgh(avg_rl,ind_rl);
  102.  
  103.         pause(rand);
  104.         hbar.iterate(1);
  105. end
  106.  
  107. mean_avg_rghn_side = mean(avg_rghn);
  108. mean_rms_rghn_side = mean(rms_rghn);
  109. mean_max_rghn_side = mean(max_rghn);
  110.  
  111. area_avg_rghn = mean_avg_rghn_side * mean_avg_rghn_front;
  112. area_rms_rghn = mean_rms_rghn_side * mean_rms_rghn_front;
  113. area_max_rghn = max(mean_max_rghn_side,mean_max_rghn_front);
  114.  
  115. wholetime = toc;
  116. close(hbar);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top