Example #1
0
        private static MyColor[,] Convert_Color_MyColor(Color[,] Image)
        {
            int Height = Image.GetLength(0);
            int Width  = Image.GetLength(1);

            MyColor[,] Copy_Image = new MyColor[Height, Width];
            for (int i = 0; i < Height; i++)
            {
                for (int j = 0; j < Width; j++)
                {
                    Copy_Image[i, j].red   = (byte)Image[i, j].R;
                    Copy_Image[i, j].blue  = (byte)Image[i, j].B;
                    Copy_Image[i, j].green = (byte)Image[i, j].G;
                }
            }
            return(Copy_Image);
        }
Example #2
0
        /// <summary>
        /// Normal resize of an image
        /// </summary>
        /// <param name="ImageMatrix">2D array of image values</param>
        /// <param name="NewWidth">desired width</param>
        /// <param name="NewHeight">desired height</param>
        /// <returns>Resized image</returns>

        public static MyColor[,] NormalResize(MyColor[,] ImageMatrix, int NewWidth, int NewHeight)
        {
            int i = 0, j = 0;
            int Height = ImageMatrix.GetLength(0);
            int Width  = ImageMatrix.GetLength(1);

            double WidthRatio  = (double)(Width) / (double)(NewWidth);
            double HeightRatio = (double)(Height) / (double)(NewHeight);

            int OldWidth  = Width;
            int OldHeight = Height;

            MyColor P1, P2, P3, P4;

            MyColor Y1, Y2, X = new MyColor();

            MyColor[,] Data = new MyColor[NewHeight, NewWidth];

            Width  = NewWidth;
            Height = NewHeight;

            int floor_x, ceil_x;
            int floor_y, ceil_y;

            double x, y;
            double fraction_x, one_minus_x;
            double fraction_y, one_minus_y;

            for (j = 0; j < NewHeight; j++)
            {
                for (i = 0; i < NewWidth; i++)
                {
                    x = (double)(i) * WidthRatio;
                    y = (double)(j) * HeightRatio;

                    floor_x = (int)(x);
                    ceil_x  = floor_x + 1;
                    if (ceil_x >= OldWidth)
                    {
                        ceil_x = floor_x;
                    }

                    floor_y = (int)(y);
                    ceil_y  = floor_y + 1;
                    if (ceil_y >= OldHeight)
                    {
                        ceil_y = floor_y;
                    }

                    fraction_x  = x - floor_x;
                    one_minus_x = 1.0 - fraction_x;

                    fraction_y  = y - floor_y;
                    one_minus_y = 1.0 - fraction_y;

                    P1 = ImageMatrix[floor_y, floor_x];
                    P2 = ImageMatrix[ceil_y, floor_x];
                    P3 = ImageMatrix[floor_y, ceil_x];
                    P4 = ImageMatrix[ceil_y, ceil_x];

                    Y1.red   = (byte)(one_minus_y * P1.red + fraction_y * P2.red);
                    Y1.green = (byte)(one_minus_y * P1.green + fraction_y * P2.green);
                    Y1.blue  = (byte)(one_minus_y * P1.blue + fraction_y * P2.blue);

                    Y2.red   = (byte)(one_minus_y * P3.red + fraction_y * P4.red);
                    Y2.green = (byte)(one_minus_y * P3.green + fraction_y * P4.green);
                    Y2.blue  = (byte)(one_minus_y * P3.blue + fraction_y * P4.blue);

                    X.red   = (byte)(one_minus_x * Y1.red + fraction_x * Y2.red);
                    X.green = (byte)(one_minus_x * Y1.green + fraction_x * Y2.green);
                    X.blue  = (byte)(one_minus_x * Y1.blue + fraction_x * Y2.blue);

                    Data[j, i] = X;
                }
            }

            return(Data);
        }
Example #3
0
        /// <summary>
        /// Calculate energy between the given two pixels
        /// </summary>
        /// <param name="Pixel1">First pixel color</param>
        /// <param name="Pixel2">Second pixel color</param>
        /// <returns>Energy between the 2 pixels</returns>
        public static int CalculatePixelsEnergy(MyColor Pixel1, MyColor Pixel2)
        {
            int Energy = Math.Abs(Pixel1.red - Pixel2.red) + Math.Abs(Pixel1.green - Pixel2.green) + Math.Abs(Pixel1.blue - Pixel2.blue);

            return(Energy);
        }