Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void polyReg(double[][] picture, MatOfKeyPoint featurept) {
- int i, j, n, k = 2, N = 0; // k ist Grad des Polynoms, N Anzahl der Arraypunkte,
- double[] featurept_x = null;
- double[] featurept_y = null;
- double[] picture_x = null;
- double[] picture_y = null;
- KeyPoint[] featurePoints = featurept.toArray();
- for (i = 0; i < featurePoints.length; i++) {
- N++;
- }
- for (i = 0; i < featurePoints.length; i++) {
- featurept_x[i] = featurePoints[i].pt.x;
- }
- for (i = 0; i < featurePoints.length; i++) {
- featurept_y[i] = featurePoints[i].pt.y;
- }
- for (i = 0; i < picture.length; i++){
- picture_x[i] = picture[i][0];
- }
- for (i = 0; i < picture.length; i++){
- picture_y[i] = picture[i][0];
- }
- calculate(N, picture_x, featurept_x); // calculate for x-variables
- calculate(N, picture_y, featurept_y); // calculate for y-variables
- }
- private double[] calculate(int N, double[] picture, double[] featurepts) {
- int i, j, n, k = 2;
- double[] X = new double[2 * k + 1];
- for (i = 0; i < 2 * k + 1; i++) {
- X[i] = 0;
- for (j = 0; j < N; j++) {
- X[i] = X[i] + Math.pow(picture[j], i);
- }
- }
- double[][] B = new double[k + 1][k + 2]; //augmentierte normale Matrix
- double[] a = new double[k + 1]; //koeffizienten
- for (i = 0; i <= k; i++) {
- for (j = 0; j <= k; j++) {
- B[i][j] = X[i + j];
- }
- }
- double[] Y = new double[k + 1];
- for (i = 0; i < k + 1; i++) {
- Y[i] = 0;
- for (j = 0; j < N; j++) {
- Y[i] = Y[i] + Math.pow(picture[j], i) * featurepts[j];
- }
- }
- for (i = 0; i <= k; i++) {
- B[i][k + 1] = Y[i];
- }
- k = k + 1; // für Gaussche Eliminierung
- for (i = 0; i < k; i++) // Pivotation
- {
- for (n = i + 1; n < k; n++) {
- if (B[i][i] < B[n][i]) {
- for (j = 0; j <= k; j++) {
- double temp = B[i][j];
- B[i][j] = B[n][j];
- B[n][j] = temp;
- }
- }
- }
- }
- for (i = 0; i < k - 1; i++) // Gaussche Eliminierung
- {
- for (n = i + 1; n < k; n++) {
- double t = B[n][i] / B[i][i];
- for (j = 0; j <= k; j++) {
- B[n][j] = B[n][j] - t * B[i][j];
- }
- }
- }
- for (i = k - 1; i >= 0; i--) { // Rücksubstitution
- a[i] = B[i][k];
- for (j = 0; j < k; j++) {
- if (j != i) {
- a[i] = a[i] - B[i][j] * a[j];
- }
- }
- a[i] = a[i] / B[i][i];
- }
- return a;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement