示例#1
0
        //private static double[] polynom(double x)
        //{
        //    double[] ans = new double[poly_degree + 1];
        //    ans[0] = 1.0;
        //    for (int i = 1; i < poly_degree + 1; i++) ans[i] = x * ans[i - 1];
        //    return ans;
        //}

        private static double ApproxAlongColumn(int column, int row, int wing, int degree)
        {
            Fitter fitter = new Fitter();
            double f1;

            double[] x     = new double[1 + 2 * wing];
            double[] y     = new double[1 + 2 * wing];
            double[] sigma = new double[1 + 2 * wing];

            int k1 = row - wing;
            int k2 = row + wing;

            for (int i = 0; i < x.Length; i++)
            {
                x[i] = i + k1;
                y[i] = image[i + k1, column];
                if (y[i] > 1)
                {
                    sigma[i] = Math.Sqrt(y[i]);
                }
                else
                {
                    sigma[i] = 1;
                }
            }

            double[] coeffs = fitter.WightedPolynom(x, y, sigma, degree);
            f1 = Polynom(coeffs, (double)row);

            return(f1);
        }
示例#2
0
        private static void ImproveTraces(double[] pix_x, ref double[] pix_y, int polynom_degree)
        {
            double[] pix_x_1   = new double[pix_x.Length];
            double[] pix_y_1   = new double[pix_y.Length];
            double[] pix_y_fit = new double[pix_y.Length];
            double   max_x     = pix_x[pix_x.Length - 1];
            double   max_y     = pix_y[pix_y.Length - 1];

            double[] coeffs;

            for (int i = 0; i < pix_x_1.Length; i++)
            {
                pix_x_1[i] = pix_x[i] / max_x;
            }

            for (int i = 0; i < pix_y_1.Length; i++)
            {
                pix_y_1[i] = pix_y[i] / max_y;
            }

            Fitter fitter = new Fitter();

            coeffs = fitter.Polynom(pix_x_1, pix_y_1, polynom_degree);

            for (int i = 0; i < pix_x_1.Length; i++)
            {
                double sum = 0;
                for (int j = 0; j < polynom_degree + 1; j++)
                {
                    sum += coeffs[j] * Math.Pow(pix_x_1[i], j);
                }
                pix_y_fit[i] = sum;
            }

            for (int i = 0; i < pix_x.Length; i++)
            {
                pix_y[i] = max_y * pix_y_fit[i];
            }
        }