Beispiel #1
0
        public int Dot(Point3Di other)
        {
            int t1 = this.X * other.X;
            int t2 = this.Y * other.Y;
            int t3 = this.Z * other.Z;

            return(t1 + t2 + t3);
        }
Beispiel #2
0
        public Point3Di Cross(Point3Di other)
        {
            int rx = this.Y * other.Z - this.Z * other.Y;
            int ry = this.Z * other.X - this.X * other.Z;
            int rz = this.X * other.Y - this.Y * other.X;

            return(new Point3Di(rx, ry, rz));
        }
Beispiel #3
0
        // Returns the absolute difference between the pixels at pt1 and pt2 in images img1 and
        // img2 respectively. pt1 must be within img1, and pt2 must be within img2.
        public static int Compare(Image img1, Point2Di pt1, Image img2, Point2Di pt2)
        {
            Point3Di img1PixVal = img1.GetPixelValue(pt1);
            Point3Di img2PixVal = img2.GetPixelValue(pt2);

            return(Math.Abs(img1PixVal.X - img2PixVal.X) +
                   Math.Abs(img1PixVal.Y - img2PixVal.Y) +
                   Math.Abs(img1PixVal.Z - img2PixVal.Z));
        }
Beispiel #4
0
        // CHECKME calling compare from an instance could be more efficient - data cursors
        // Returns the absolute difference between the pixels within the kernel centered around pt1
        // and pt2 in img1 and img2 respectively. pt1 must be within img1, and pt2 must be within
        // img2. The kernel must have odd dimensions. None of these conditions are checked, for
        // efficiency.
        public static double Compare(Image img1, Point2Di pt1, Image img2, Point2Di pt2,
                                     double[][] kernel)
        {
            double errorSum   = 0;
            double weightsSum = 0;

            int kernelHalfHeight = kernel.Length / 2;
            int kernelHalfWidth  = kernel[0].Length / 2;

            // CHECKME enforce square kernel?
            // Stores half of the actual width and height being used, rounded down. Each dimension
            // is shrunk symmetrically until the kernel fits within the bounds of both images.
            // Symmetry is to prevent skewing of the amount of information coming from each side of
            // the center point.
            int halfWidth = Util.Min(kernelHalfWidth, pt1.X, pt2.X,
                                     img1.Width - pt1.X - 1, img2.Width - pt2.X - 1);
            int halfHeight = Util.Min(kernelHalfHeight, pt1.Y, pt2.Y,
                                      img1.Height - pt1.Y - 1, img2.Height - pt2.Y - 1);

            int startX1 = pt1.X - halfWidth;
            int startX2 = pt2.X - halfWidth;

            int y1 = pt1.Y - halfHeight;
            int y2 = pt2.Y - halfHeight;

            for (int yOff = -halfHeight; yOff <= halfHeight; yOff++)
            {
                int x1 = startX1;
                int x2 = startX2;

                for (int xOff = -halfWidth; xOff <= halfWidth; xOff++)
                {
                    int xKernel = kernelHalfWidth + xOff;
                    int yKernel = kernelHalfHeight + yOff;

                    double weight = kernel[yKernel][xKernel];
                    weightsSum += weight;

                    Point3Di pix1 = img1.GetPixelValue(x1, y1);
                    Point3Di pix2 = img2.GetPixelValue(x2, y2);

                    int error = Math.Abs(pix1.X - pix2.X) +
                                Math.Abs(pix1.Y - pix2.Y) +
                                Math.Abs(pix1.Z - pix2.Z);
                    errorSum += error * weight;

                    x1++;
                    x2++;
                }

                y1++;
                y2++;
            }

            return(errorSum / weightsSum);
        }
Beispiel #5
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            Point3Di other = obj as Point3Di;

            if ((object)other == null)
            {
                return(false);
            }

            return((this.X == other.X) && (this.Y == other.Y) && (this.Z == other.Z));
        }