Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.23 KB | None | 0 0
  1. %Change path wherever required, keep images in data_selected folder
  2. workspace_add = 'C:\Users\Gautams\Desktop\medium\';
  3. data_folder = strcat(workspace_add,'mat3_ear\data_selected');
  4. filePattern = fullfile(data_folder, '*.abs');
  5. absFiles = dir(filePattern);
  6. numberofFiles = length(absFiles);
  7. %fwid = fopen('mat3_ear\earFeatures.txt', 'w');
  8.  
  9. count = 0;
  10. for k = 1: numberofFiles
  11. baseFileName = absFiles(k).name;
  12. flName = strtok(baseFileName,'.');
  13. [sub_id, im_id] = strtok(flName,'d');
  14.  
  15. if length(im_id) > 4
  16. continue
  17. % orgImg = [X1 Y1 Z1];
  18. % aligned_ptCloud = alignICP(orgImg);
  19. % makePly(aligned_ptCloud, 'aligned.ply');
  20. % ptCloud = pcread('aligned.ply');
  21. % pcshow(ptCloud);
  22. end
  23. %fullFlnm = strcat('mat3_ear\ear_cloud_points\',flName);
  24. %fulltxtFlnm = strcat(fullFlnm, '.txt');
  25. %fid = fopen(fulltxtFlnm, 'w');
  26. fullFileName = fullfile(data_folder, baseFileName);
  27. [X,Y,Z,FL] = absload(fullFileName);
  28. Z= abs(Z);
  29. X= X(:);
  30. Y = Y(:);
  31. Z = Z(:);
  32.  
  33. X1 = X(X~=-999999);
  34. Y1 = Y(Y~=-999999);
  35. Z1 = Z(Z~=999999);
  36. ptCloud = pointCloud2mesh([X1 Y1 Z1]);
  37. makePly(ptCloud, 'rawEar.ply');
  38. ptCloud = pcread('rawEar.ply');
  39. pcshow(ptCloud);
  40.  
  41.  
  42. [nose_z, nose_ind] = min(ptCloud.Location(:,1));
  43. [ear_tip_z, ear_tip_ind] = min(ptCloud.Location(:,3));
  44. nose_pt = ptCloud.Location(nose_ind,:);
  45. ear_tip = ptCloud.Location(ear_tip_ind,:);
  46.  
  47. cropped_points = zeros(1,3);
  48. for ind = 1:length(ptCloud.Location)
  49. if inxrange(ptCloud.Location(ind,1),nose_pt) && inyrange(ptCloud.Location(ind,2), nose_pt)
  50. cropped_points = [cropped_points; ptCloud.Location(ind,:)];
  51. end
  52. end
  53.  
  54.  
  55. cropped_points = cropped_points((2:end),:);
  56.  
  57. xx = double(cropped_points(:,1));
  58. yy = double(cropped_points(:,2));
  59. zz = double(cropped_points(:,3));
  60. %zz = -zz;
  61. %uncomment if you want to see cropped image
  62. mm = pointCloud2mesh([xx yy zz]);
  63. makePly(mm, 'croppedEar.ply');
  64. mm = pcread('croppedEar.ply');
  65. pcshow(mm);
  66. try
  67. zz_despiked = medfilt3(zz);
  68. %%%zz_despiked = medfilt3([xx,yy,zz]);
  69.  
  70. %Multidimensional data interpolation (table lookup)
  71. ZI = interpn([xx,yy,zz_despiked],.9,'cubic');
  72. %%%ZI = interpn(zz_despiked,.9,'cubic');
  73.  
  74. zz_denoised = imgaussfilt3(ZI(:,3));
  75.  
  76. %uncomment if want to save raw mesh file
  77. %ear_deskiped_fillhole_denoised = pointCloud2rawMesh([xx,yy,zz_denoised],0.6,1);
  78. %makePly(ear_deskiped_fillhole_denoised, 'ear_deskiped_fillhole_denoised.ply');
  79. %read_ear_deskiped_fillhole_denoised = pcread('ear_deskiped_fillhole_denoised.ply');
  80. %pcshow(read_ear_deskiped_fillhole_denoised);
  81.  
  82.  
  83. mesh = pointCloud2mesh([xx,yy,zz_denoised]);
  84. % standard deviation feature
  85.  
  86. count = count+1;
  87. catch MExc
  88. end
  89. end
  90. %end
  91. function inRng = inxrange(val, nose_pt)
  92. x_llmt = 90 + nose_pt(:,1);
  93. x_ulmt = 160 + nose_pt(:,1);
  94. if val >= x_llmt && val <= x_ulmt
  95. inRng = 1;
  96. else
  97. inRng = 0;
  98. end
  99. end
  100.  
  101. function inRng = inyrange(val, nose_pt)
  102. y_llmt = -25 + nose_pt(:,2);
  103. y_ulmt = 50 + nose_pt(:,2);
  104. if val >= y_llmt && val <= y_ulmt
  105. inRng = 1;
  106. else
  107. inRng = 0;
  108. end
  109. end
  110.  
  111. function inRng = inzrange(val, nose_pt)
  112. z_llmt = nose_pt(:,3);
  113. z_ulmt = 25 + nose_pt(:,3);
  114. if val >= z_llmt && val <= z_ulmt
  115. inRng = 1;
  116. else
  117. inRng = 0;
  118. end
  119. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement