Esempio n. 1
0
        //this helper function returns a new PixImage with pixels on the edges reflected across the axis
        //so that each pixel in the original image has 9 neighbors (including itself)
        private PixImage GetReflection()
        {
            var newMatrix = new PixImage(Width + 2, Height + 2);

            for (int x = 1; x < newMatrix.Width - 1; x++)
            {
                for (int y = 1; y < newMatrix.Height - 1; y++)
                {
                    newMatrix.setPixel(x, y, this.getRed(x - 1, y - 1), this.getGreen(x - 1, y - 1), this.getBlue(x - 1, y - 1));
                }
            }

            for (int x = 0; x < newMatrix.Width; x++)
            {
                for (int y = 0; y < newMatrix.Height; y++)
                {
                    int   a   = x;
                    int   b   = y;
                    short red = 0;

                    if (x == 0)
                    {
                        a = 1;
                    }
                    if (y == 0)
                    {
                        b = 1;
                    }
                    if (x == newMatrix.Width - 1)
                    {
                        a = newMatrix.Width - 2;
                    }
                    if (y == newMatrix.Height - 1)
                    {
                        b = newMatrix.Height - 2;
                    }
                    red = (short)newMatrix.getRed(a, b);

                    //Console.WriteLine("getting a: {0}, b: {1}, for x: {2}, y: {3} which is: {4}", a,  b, x, y, red);
                    newMatrix.setPixel(x, y, red, red, red);
                }
            }
            //Console.WriteLine(newMatrix);
            return(newMatrix);
        }
Esempio n. 2
0
        /// <summary>
        /// equals() checks whether two images are the same, i.e. have the same
        /// dimensions and pixels.
        /// </summary>
        /// <param name="image"> a PixImage to compare with "this" PixImage. </param>
        /// <returns> true if the specified PixImage is identical to "this" PixImage. </returns>
        public virtual bool Equals(PixImage image)
        {
            int width  = Width;
            int height = Height;

            if (image == null || width != image.Width || height != image.Height)
            {
                return(false);
            }

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    if (!(getRed(x, y) == image.getRed(x, y) && getGreen(x, y) == image.getGreen(x, y) && getBlue(x, y) == image.getBlue(x, y)))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }