Guest User

Untitled

a guest
Oct 18th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. clear vars
  2. reading_text_dk;
  3. reading_text_2dk;
  4. reading_text_3dk;
  5.  
  6. X_uni = location_3d_bad.';%(x,y,z) column vectors
  7. x_camera = pixelLocation.'; % (column, row) column vectors
  8.  
  9. [ W_est,T_est,R_est ] = camera_param_est( X_uni,x_camera );
  10. x_camera_est = project3d_2d( X_uni,W_est,R_est, T_est);
  11. distance = (sum((x_camera_est-x_camera).^2,1)).^1/2;
  12. average_distance = mean(distance);
  13.  
  14. modelSize = 15;
  15. maxCount = 0;
  16. maxIndexes = 0;
  17. maxModelSet = zeros(1,modelSize);
  18. maxIteration = 10;
  19. errorMargin = average_distance/1e2;
  20.  
  21. prob = 1 - (1-(1-0.18)^modelSize)^maxIteration
  22. % prob = %desired probability that t
  23. % noIteration = ln(1-0.99)/ln(1-(1-0.18)^10)
  24. countOfInlier = zeros( 1, maxIteration);
  25. meanDistance = zeros( 1, maxIteration);
  26. inlier_Index_matrix = zeros( maxIteration, size(x_camera,2));
  27.  
  28. j = 1;
  29.  
  30. while ( j <= maxIteration)
  31.  
  32. rand_vector = [];
  33. while( size(rand_vector,2) <modelSize )
  34. rand_no = randi(72);
  35. dk = find(rand_vector ==rand_no);
  36. if isempty(dk)
  37. rand_vector = [rand_vector rand_no];
  38. end
  39. end
  40. rand_index = rand_vector;
  41. % rand_index = randi(72,1,modelSize);
  42. model_set = X_uni(:,rand_index); % selecting our samples from the input
  43. model_set_output = x_camera(:,rand_index);
  44.  
  45. %learning part
  46. [ W_est,T_est,R_est ] = camera_param_est( model_set,model_set_output ); % we estimate the parameters according to our model set
  47. %testing part
  48. x_camera_est = project3d_2d( X_uni,W_est,R_est, T_est); % estimate all yi according to parameters obtained using model samples
  49.  
  50. distance = (sum((x_camera_est-x_camera).^2,1)).^1/2; %euclidean distance between (c_est,r_est) (c,r)
  51.  
  52. inlier_index = find( distance <= errorMargin ); %finding the data instance of inliers
  53. totalCount = length(inlier_index); %counting the total number of inliers
  54.  
  55. % countOfInlier(1,j) = totalCount;
  56. % meanDistance(1,j) = mean(distance);
  57. %
  58. % if ( totalCount > 0)
  59. % inlier_Index_matrix(j,1:totalCount) =inlier_index ;
  60. % end
  61. if( totalCount > maxCount) %if number of inliers is bigger than current best
  62. maxCount = totalCount; %store the inlier indexes and set the maxCount
  63. maxIndexes = inlier_index;
  64. maxModelSet = rand_index;
  65. end
  66. j = j+1;
  67. % display(countOfInlier)
  68. end
  69.  
  70. selectIndex = union(maxIndexes,maxModelSet); % selected Inliers + elements of model set which have the most total count of inliers
  71. X_inliers = X_uni(:,selectIndex);
  72. x_inliers =x_camera(:,selectIndex);
  73. [ W_est,T_est,R_est ] = camera_param_est( X_inliers,x_inliers ); % we estimate the parameters according to our model set
  74.  
  75. x_camera_est = project3d_2d( X_uni,W_est,R_est, T_est); %estimating total error using the parameters obtained from selected inliers and model set
  76. distance = (sum((x_camera_est-x_camera).^2,1)).^1/2;
  77. average_distance_final = mean(distance);
  78. display(['max total count = ' num2str(maxCount) ]);
  79. display(['number of union inliners and model set = ' num2str(size(X_inliers,2)) ]);
  80.  
  81. display(['average distance' num2str(average_distance_final)] );
  82.  
  83.  
  84.  
  85. % we want to ideally select modelset + inlinear amount points from the
  86. % distorted 3dcoordinates by comparing them to actual 3d coordinates
  87. X_uni_ideal = location_3d.';
  88. distance_betweenIdeal =(sum((X_uni_ideal-X_uni).^2,1)).^1/2;
  89. [B,I] = sort(distance_betweenIdeal);
  90. idealInliners = I(1:size(X_inliers,2));
  91.  
  92. [ W_est,T_est,R_est ] = camera_param_est( X_uni(:,idealInliners),x_camera(:,idealInliners)); % we estimate the parameters according to our model set
  93. x_camera_est = project3d_2d( X_uni,W_est,R_est, T_est); %estimating total error using the parameters obtained from selected inliers and model set
  94. distance_id = (sum((x_camera_est-x_camera).^2,1)).^1/2;
  95. average_distance_final_id = mean(distance_id);
Add Comment
Please, Sign In to add comment