示例#1
0
    private SimpleMatrix GetAdjustment(ScalePoint point,
                                       int level, int x, int y, out double dp)
    {
        dp = 0.0;
        if (point.Level <= 0 || point.Level >= (spaces.Length - 1))
        {
            throw (new ArgumentException("point.Level is not within [bottom-1;top-1] range"));
        }

        ImageMap below   = spaces[level - 1];
        ImageMap current = spaces[level];
        ImageMap above   = spaces[level + 1];

        SimpleMatrix H = new SimpleMatrix(3, 3);

        H[0, 0] = below[x, y] - 2 * current[x, y] + above[x, y];
        H[0, 1] = H[1, 0] = 0.25 * (above[x, y + 1] - above[x, y - 1] -
                                    (below[x, y + 1] - below[x, y - 1]));
        H[0, 2] = H[2, 0] = 0.25 * (above[x + 1, y] - above[x - 1, y] -
                                    (below[x + 1, y] - below[x - 1, y]));
        H[1, 1] = current[x, y - 1] - 2 * current[x, y] + current[x, y + 1];
        H[1, 2] = H[2, 1] = 0.25 * (current[x + 1, y + 1] - current[x - 1, y + 1] -
                                    (current[x + 1, y - 1] - current[x - 1, y - 1]));
        H[2, 2] = current[x - 1, y] - 2 * current[x, y] + current[x + 1, y];

        SimpleMatrix d = new SimpleMatrix(3, 1);

        d[0, 0] = 0.5 * (above[x, y] - below[x, y]);
        d[1, 0] = 0.5 * (current[x, y + 1] - current[x, y - 1]);
        d[2, 0] = 0.5 * (current[x + 1, y] - current[x - 1, y]);

        SimpleMatrix b = (SimpleMatrix)d.Clone();

        b.Negate();

        H.SolveLinear(b);

        dp = b.Dot(d);

        return(b);
    }