Advertisement
Guest User

besseres PolyReg

a guest
Feb 22nd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. private void polyReg(double[][] picture, MatOfKeyPoint featurept) {
  2. int i, j, n, k = 2, N = 0; // k ist Grad des Polynoms, N Anzahl der Arraypunkte,
  3. double[] featurept_x = null;
  4. double[] featurept_y = null;
  5. double[] picture_x = null;
  6. double[] picture_y = null;
  7.  
  8. KeyPoint[] featurePoints = featurept.toArray();
  9. for (i = 0; i < featurePoints.length; i++) {
  10. N++;
  11. }
  12.  
  13. for (i = 0; i < featurePoints.length; i++) {
  14. featurept_x[i] = featurePoints[i].pt.x;
  15. }
  16. for (i = 0; i < featurePoints.length; i++) {
  17. featurept_y[i] = featurePoints[i].pt.y;
  18. }
  19. for (i = 0; i < picture.length; i++){
  20. picture_x[i] = picture[i][0];
  21. }
  22. for (i = 0; i < picture.length; i++){
  23. picture_y[i] = picture[i][0];
  24. }
  25.  
  26. calculate(N, picture_x, featurept_x); // calculate for x-variables
  27. calculate(N, picture_y, featurept_y); // calculate for y-variables
  28.  
  29. }
  30.  
  31. private double[] calculate(int N, double[] picture, double[] featurepts) {
  32. int i, j, n, k = 2;
  33.  
  34. double[] X = new double[2 * k + 1];
  35. for (i = 0; i < 2 * k + 1; i++) {
  36. X[i] = 0;
  37. for (j = 0; j < N; j++) {
  38. X[i] = X[i] + Math.pow(picture[j], i);
  39. }
  40. }
  41.  
  42. double[][] B = new double[k + 1][k + 2]; //augmentierte normale Matrix
  43. double[] a = new double[k + 1]; //koeffizienten
  44.  
  45. for (i = 0; i <= k; i++) {
  46. for (j = 0; j <= k; j++) {
  47. B[i][j] = X[i + j];
  48. }
  49. }
  50.  
  51. double[] Y = new double[k + 1];
  52. for (i = 0; i < k + 1; i++) {
  53. Y[i] = 0;
  54. for (j = 0; j < N; j++) {
  55. Y[i] = Y[i] + Math.pow(picture[j], i) * featurepts[j];
  56. }
  57. }
  58.  
  59. for (i = 0; i <= k; i++) {
  60. B[i][k + 1] = Y[i];
  61. }
  62.  
  63. k = k + 1; // für Gaussche Eliminierung
  64.  
  65. for (i = 0; i < k; i++) // Pivotation
  66. {
  67. for (n = i + 1; n < k; n++) {
  68. if (B[i][i] < B[n][i]) {
  69. for (j = 0; j <= k; j++) {
  70. double temp = B[i][j];
  71. B[i][j] = B[n][j];
  72. B[n][j] = temp;
  73. }
  74. }
  75. }
  76. }
  77.  
  78. for (i = 0; i < k - 1; i++) // Gaussche Eliminierung
  79. {
  80. for (n = i + 1; n < k; n++) {
  81. double t = B[n][i] / B[i][i];
  82. for (j = 0; j <= k; j++) {
  83. B[n][j] = B[n][j] - t * B[i][j];
  84. }
  85. }
  86. }
  87.  
  88. for (i = k - 1; i >= 0; i--) { // Rücksubstitution
  89. a[i] = B[i][k];
  90. for (j = 0; j < k; j++) {
  91. if (j != i) {
  92. a[i] = a[i] - B[i][j] * a[j];
  93. }
  94. }
  95. a[i] = a[i] / B[i][i];
  96. }
  97. return a;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement