示例#1
0
        public static void Laplacian4(IOperand x = null, bool spawn = true)
        {
            if (x == null)
            {
                x = ExecutionStack.X;
            }
            if (x == null)
            {
                return;
            }
            Bitmap bmp = x.GetBitmap();

            float[] filter = new float[9] {
                0f, -1f, 0f, -1f, 4f, -1f, 0f, -1f, 0f
            };
            //float[] filter = new float[9] { 0f, -1f / scale, 0f, -1f / 4f, 4f / 4f, -1f / 4f, 0f, -1f / 4f, 0f };
            Filter f = new Filter(filter);

            bmp = Normalize.FromFloat(f.Apply(Normalize.ToFloat(bmp), bmp.Height, bmp.Width));

            if (spawn)
            {
                x.CreateSibling(Normalize.ToFloat(bmp), "Laplacian(4) of " + bmp.ToString());
            }
            else
            {
                ((FormStandard)x).Image = bmp;
            }
        }
示例#2
0
        public static void Invert()
        {
            IOperand x = ExecutionStack.X;

            if (x == null)
            {
                return;
            }
            Bitmap bmp = x.GetBitmap();

            float[][][] img = Normalize.ToFloat(bmp);
            for (int h = 0; h < bmp.Height; h++)
            {
                for (int w = 0; w < bmp.Width; w++)
                {
                    float r = img[Normalize.RGBPLANE_RED][h][w];
                    float g = img[Normalize.RGBPLANE_GREEN][h][w];
                    float b = img[Normalize.RGBPLANE_BLUE][h][w];
                    img[Normalize.RGBPLANE_RED][h][w]   = 1.0f - r;
                    img[Normalize.RGBPLANE_GREEN][h][w] = 1.0f - g;
                    img[Normalize.RGBPLANE_BLUE][h][w]  = 1.0f - b;
                }
            }
            x.CreateSibling(img, "Inversion of " + bmp.ToString());
        }
示例#3
0
        public static void Rotate(int angle, IOperand x = null, bool spawn = true)
        {
            if (x == null)
            {
                x = ExecutionStack.X;
            }
            if (x == null)
            {
                return;
            }
            Bitmap bmp = new Bitmap(x.GetBitmap());

            switch (angle)
            {
            case 90: bmp.RotateFlip(RotateFlipType.Rotate90FlipNone); break;

            case 180: bmp.RotateFlip(RotateFlipType.Rotate180FlipNone); break;

            case -90: bmp.RotateFlip(RotateFlipType.Rotate270FlipNone); break;

            default: bmp = Rotate(bmp, angle); break;
            }
            ;
            if (spawn)
            {
                x.CreateSibling(Normalize.ToFloat(bmp), "Rotation of " + bmp.ToString());
            }
            else
            {
                ((FormStandard)x).Image = bmp;
            }
        }
示例#4
0
        public static void Mean(IOperand x = null, bool spawn = true)
        {
            if (x == null)
            {
                x = ExecutionStack.X;
            }
            if (x == null)
            {
                return;
            }
            Bitmap bmp = x.GetBitmap();

            float[][][] img = Normalize.ToFloat(bmp), result = Normalize.ToFloat(bmp);


            float weight = 1f / 9f;

            for (int h = 0; h < bmp.Height; h++)
            {
                for (int w = 0; w < bmp.Width; w++)
                {
                    for (int c = 0; c < 3; c++)
                    {
                        result[c][h][w] =
                            ((h > 0 && w > 0 ? weight * img[c][h - 1][w - 1] : 0) + (h > 0 ? weight * img[c][h - 1][w] : 0) + (h > 0 && w + 1 < bmp.Width ? weight * img[c][h - 1][w + 1] : 0) +
                             (w > 0 ? weight * img[c][h][w - 1] : 0) + (weight * img[c][h][w]) + (w + 1 < bmp.Width ? weight * img[c][h][w + 1] : 0) +
                             (w > 0 && h + 1 < bmp.Height ? weight * img[c][h + 1][w - 1] : 0) + (h + 1 < bmp.Height ? weight * img[c][h + 1][w] : 0) + (h + 1 < bmp.Height && w + 1 < bmp.Width ? weight * img[c][h + 1][w + 1] : 0));
                        if (result[c][h][w] < 0.0f)
                        {
                            result[c][h][w] = 0.0f;
                        }
                        if (result[c][h][w] > 1.0f)
                        {
                            result[c][h][w] = 1.0f;
                        }
                    }
                }
            }

            /*
             * float weight = 1f / 9f;
             * float[] filter = new float[9] { weight, weight, weight, weight, weight, weight, weight, weight, weight };
             * Filter f = new Filter(filter);
             *
             * bmp = Normalize.FromFloat(f.Apply(Normalize.ToFloat(bmp), bmp.Height, bmp.Width));
             *
             */

            if (spawn)
            {
                x.CreateSibling(result, "Mean of " + bmp.ToString());
            }
            else
            {
                ((FormStandard)x).Image = Normalize.FromFloat(result);
            }
        }
示例#5
0
        public static void Add()
        {
            IOperand x = ExecutionStack.X;
            IOperand y = ExecutionStack.Y;

            if (x == null || y == null)
            {
                return;
            }
            Bitmap bmp  = x.GetBitmap();
            Bitmap bmp2 = y.GetBitmap();

            float[][][] img  = Normalize.ToFloat(bmp);
            float[][][] img2 = Normalize.ToFloat(bmp2);
            int         maxw = bmp.Width > bmp2.Width ? bmp.Width : bmp2.Width;
            int         maxh = bmp.Height > bmp2.Height ? bmp.Height : bmp2.Height;
            int         minw = bmp.Width < bmp2.Width ? bmp.Width : bmp2.Width;
            int         minh = bmp.Height < bmp2.Height ? bmp.Height : bmp2.Height;

            float[][][] newimg = new float[Normalize.RGBPLANE_LENGTH][][];
            for (int c = 0; c < Normalize.RGBPLANE_LENGTH; c++)
            {
                newimg[c] = new float[maxh][];
                for (int h = 0; h < maxh; h++)
                {
                    newimg[c][h] = new float[maxw];
                    for (int w = 0; w < maxw; w++)
                    {
                        newimg[c][h][w] = 0.0f;
                    }
                }
            }


            for (int h = 0; h < bmp.Height; h++)
            {
                for (int w = 0; w < bmp.Width; w++)
                {
                    newimg[Normalize.RGBPLANE_RED][h][w]   += img[Normalize.RGBPLANE_RED][h][w];
                    newimg[Normalize.RGBPLANE_GREEN][h][w] += img[Normalize.RGBPLANE_GREEN][h][w];
                    newimg[Normalize.RGBPLANE_BLUE][h][w]  += img[Normalize.RGBPLANE_BLUE][h][w];
                }
            }

            for (int h = 0; h < bmp2.Height; h++)
            {
                for (int w = 0; w < bmp2.Width; w++)
                {
                    newimg[Normalize.RGBPLANE_RED][h][w]   += img2[Normalize.RGBPLANE_RED][h][w];
                    newimg[Normalize.RGBPLANE_GREEN][h][w] += img2[Normalize.RGBPLANE_GREEN][h][w];
                    newimg[Normalize.RGBPLANE_BLUE][h][w]  += img2[Normalize.RGBPLANE_BLUE][h][w];
                }
            }

            x.CreateSibling(newimg, "Addition of " + bmp.ToString() + " and " + bmp2.ToString());
        }
示例#6
0
        public static void ChangeIntensity(IOperand x, bool spawn = true)
        {
            if (x == null)
            {
                return;
            }
            FormIntensity fi = new FormIntensity(x.GetBitmap(), x, spawn);

            fi.Show();
            return;
        }
示例#7
0
        public static void Subtract()
        {
            IOperand x = ExecutionStack.X;
            IOperand y = ExecutionStack.Y;

            if (x == null || y == null)
            {
                return;
            }
            Bitmap bmp  = x.GetBitmap();
            Bitmap bmp2 = y.GetBitmap();

            float[][][] img  = Normalize.ToFloat(bmp);
            float[][][] img2 = Normalize.ToFloat(bmp2);


            float[][][] newimg = new float[Normalize.RGBPLANE_LENGTH][][];
            for (int c = 0; c < Normalize.RGBPLANE_LENGTH; c++)
            {
                newimg[c] = new float[bmp.Height][];
                for (int h = 0; h < bmp.Height; h++)
                {
                    newimg[c][h] = new float[bmp.Width];
                    for (int w = 0; w < bmp.Width; w++)
                    {
                        newimg[c][h][w] = 0.0f;
                    }
                }
            }


            for (int h = 0; h < bmp.Height; h++)
            {
                for (int w = 0; w < bmp.Width; w++)
                {
                    newimg[Normalize.RGBPLANE_RED][h][w]   += img[Normalize.RGBPLANE_RED][h][w];
                    newimg[Normalize.RGBPLANE_GREEN][h][w] += img[Normalize.RGBPLANE_GREEN][h][w];
                    newimg[Normalize.RGBPLANE_BLUE][h][w]  += img[Normalize.RGBPLANE_BLUE][h][w];
                }
            }

            for (int h = 0; h < bmp2.Height; h++)
            {
                for (int w = 0; w < bmp2.Width; w++)
                {
                    newimg[Normalize.RGBPLANE_RED][h][w]   -= img2[Normalize.RGBPLANE_RED][h][w];
                    newimg[Normalize.RGBPLANE_GREEN][h][w] -= img2[Normalize.RGBPLANE_GREEN][h][w];
                    newimg[Normalize.RGBPLANE_BLUE][h][w]  -= img2[Normalize.RGBPLANE_BLUE][h][w];
                }
            }

            x.CreateSibling(newimg, "Subtraction of " + bmp.ToString() + " and " + bmp2.ToString());
        }
示例#8
0
        public static void Invert()
        {
            IOperand x = ExecutionStack.X;

            if (x == null)
            {
                return;
            }
            Bitmap bmp = x.GetBitmap();

            float[][][] img = Invert(bmp);
            x.CreateSibling(img, "Inversion of " + bmp.ToString());
        }
示例#9
0
        public static void ChangeIntensity()
        {
            IOperand x = ExecutionStack.X;

            if (x == null)
            {
                return;
            }
            FormIntensity fi = new FormIntensity(x.GetBitmap());

            fi.Show();
            return;
        }
示例#10
0
        public static void ToGrayScale()
        {
            IOperand x = ExecutionStack.X;

            if (x == null)
            {
                return;
            }
            Bitmap grayScale = x.GetBitmap();

            float[][][] img = ToGrayScale(grayScale);
            x.CreateSibling(img, "Grayscale of " + grayScale.ToString());
        }
示例#11
0
        public static void ChangeIntensity(float c = 0.0f, IOperand x = null, bool spawn = true)
        {
            if (x == null)
            {
                x = ExecutionStack.X;
            }
            if (x == null)
            {
                return;
            }
            Bitmap bmp = x.GetBitmap();

            float[][][] img = Normalize.ToFloat(bmp);
            for (int h = 0; h < bmp.Height; h++)
            {
                for (int w = 0; w < bmp.Width; w++)
                {
                    img[Normalize.RGBPLANE_RED][h][w]   *= (1.0f + c);
                    img[Normalize.RGBPLANE_GREEN][h][w] *= (1.0f + c);
                    img[Normalize.RGBPLANE_BLUE][h][w]  *= (1.0f + c);
                    if (img[Normalize.RGBPLANE_RED][h][w] > 1.0f)
                    {
                        img[Normalize.RGBPLANE_RED][h][w] = 1.0f;
                    }
                    if (img[Normalize.RGBPLANE_GREEN][h][w] > 1.0f)
                    {
                        img[Normalize.RGBPLANE_GREEN][h][w] = 1.0f;
                    }
                    if (img[Normalize.RGBPLANE_BLUE][h][w] > 1.0f)
                    {
                        img[Normalize.RGBPLANE_BLUE][h][w] = 1.0f;
                    }
                }
            }
            MessageBox.Show("Here.");
            if (spawn)
            {
                x.CreateSibling(img, "Intensity change of " + bmp.ToString());
            }
            else
            {
                ((FormStandard)x).Image = Normalize.FromFloat(img);
            }
        }
示例#12
0
        public static void FFT(IOperand X = null, bool spawn = true)
        {
            if (X == null)
            {
                X = ExecutionStack.X;
            }
            if (X == null)
            {
                return;
            }
            Bitmap bmp = X.GetBitmap();

            float[][][] img = Normalize.ToFloat(bmp);

            int H = bmp.Height, W = bmp.Width;

            img = Pad(img, H, W);

            Bitmap temp = Normalize.FromFloat(img);

            Fourier.CImage[] cimg = new Fourier.CImage[3];
            for (int i = 0; i < 3; i++)
            {
                cimg[i] = new Fourier.CImage(img[i], temp.Height, temp.Width);
                cimg[i] = _FFT(cimg[i]);


                img[i] = cimg[i].FromFloatModulus();
            }


            if (spawn)
            {
                ((FormStandard)X).CreateSibling(img, "( Magnitude) FFT of " + bmp.ToString(), cimg);
            }
            else
            {
                ((FormStandard)X).Image = Normalize.FromFloat(img);
                ((FormStandard)X).CImg  = cimg;
            }
        }
示例#13
0
        public static void ChangeIntensity(float c = 0.0f)
        {
            IOperand x = ExecutionStack.X;

            if (x == null)
            {
                return;
            }
            Bitmap bmp = x.GetBitmap();

            float[][][] img = Normalize.ToFloat(bmp);
            for (int h = 0; h < bmp.Height; h++)
            {
                for (int w = 0; w < bmp.Width; w++)
                {
                    img[Normalize.RGBPLANE_RED][h][w]   += c;
                    img[Normalize.RGBPLANE_GREEN][h][w] += c;
                    img[Normalize.RGBPLANE_BLUE][h][w]  += c;
                }
            }
            x.CreateSibling(img, "Intensity change of " + bmp.ToString());
        }
示例#14
0
 public static void Scale(int w, int h, IOperand x = null, bool spawn = true)
 {
     if (x == null)
     {
         x = ExecutionStack.X;
     }
     if (x == null)
     {
         return;
     }
     using (Bitmap bmp = new Bitmap(x.GetBitmap(), new Size(w, h)))
     {
         if (spawn)
         {
             x.CreateSibling(Normalize.ToFloat(bmp), "Scale change of " + bmp.ToString());
         }
         else
         {
             ((FormStandard)x).Image = bmp;
         }
     }
 }
示例#15
0
        public static void Crop(int x1, int y1, int x2, int y2, IOperand x = null, bool spawn = true)
        {
            if (x == null)
            {
                x = ExecutionStack.X;
            }
            if (x == null)
            {
                return;
            }
            Rectangle crect = new Rectangle(x1, y1, x2 - x1, y2 - y1);

            using (Bitmap cbmp = new Bitmap(crect.Width, crect.Height))
            {
                float[][][] old = Normalize.ToFloat(x.GetBitmap());
                float[][][] img = Normalize.ToFloat(cbmp);
                for (int c = 0; c < Normalize.RGBPLANE_LENGTH; c++)
                {
                    for (int w = 0; w < crect.Width; w++)
                    {
                        for (int h = 0; h < crect.Height; h++)
                        {
                            img[c][h][w] = old[c][h + y1][w + x1];
                        }
                    }
                }
                if (spawn)
                {
                    x.CreateSibling(img, "Crop of " + x.ToString());
                }
                else
                {
                    ((FormStandard)x).Image = Normalize.FromFloat(img);
                }
            }
        }
示例#16
0
        public static void Median(IOperand x = null, bool spawn = true)
        {
            if (x == null)
            {
                x = ExecutionStack.X;
            }
            if (x == null)
            {
                return;
            }

            float[][][] img = Normalize.ToFloat(x.GetBitmap());
            float[][][] omg = Normalize.ToFloat(x.GetBitmap());
            int         H = x.GetBitmap().Height, W = x.GetBitmap().Width;

            for (int c = 0; c < 3; c++)
            {
                for (int h = 0; h < H; h++)
                {
                    for (int w = 0; w < W; w++)
                    {
                        if (h == 0)
                        {
                            if (w == 0)
                            {
                                float[] n     = new float[4];
                                int     count = 0;
                                for (int i = 0; i < 2; i++)
                                {
                                    for (int j = 0; j < 2; j++)
                                    {
                                        n[count++] = img[c][h + j][w + i];
                                    }
                                }
                                omg[c][h][w] = Mid(n);
                            }
                            else if (w == W - 1)
                            {
                                float[] n     = new float[4];
                                int     count = 0;
                                for (int i = -1; i < 1; i++)
                                {
                                    for (int j = 0; j < 2; j++)
                                    {
                                        n[count++] = img[c][h + j][w + i];
                                    }
                                }
                                omg[c][h][w] = Mid(n);
                            }
                            else
                            {
                                float[] n     = new float[6];
                                int     count = 0;
                                for (int i = -1; i < 2; i++)
                                {
                                    for (int j = 0; j < 2; j++)
                                    {
                                        n[count++] = img[c][h + j][w + i];
                                    }
                                }
                                omg[c][h][w] = Mid(n);
                            }
                        }
                        else if (h == H - 1)
                        {
                            if (w == 0)
                            {
                                float[] n     = new float[4];
                                int     count = 0;
                                for (int i = 0; i < 2; i++)
                                {
                                    for (int j = -1; j < 1; j++)
                                    {
                                        n[count++] = img[c][h + j][w + i];
                                    }
                                }
                                omg[c][h][w] = Mid(n);
                            }
                            else if (w == W - 1)
                            {
                                float[] n     = new float[4];
                                int     count = 0;
                                for (int i = -1; i < 1; i++)
                                {
                                    for (int j = -1; j < 1; j++)
                                    {
                                        n[count++] = img[c][h + j][w + i];
                                    }
                                }
                                omg[c][h][w] = Mid(n);
                            }
                            else
                            {
                                float[] n     = new float[6];
                                int     count = 0;
                                for (int i = -1; i < 2; i++)
                                {
                                    for (int j = -1; j < 1; j++)
                                    {
                                        n[count++] = img[c][h + j][w + i];
                                    }
                                }
                                omg[c][h][w] = Mid(n);
                            }
                        }
                        else
                        {
                            if (w == 0)
                            {
                                float[] n     = new float[6];
                                int     count = 0;
                                for (int i = 0; i < 2; i++)
                                {
                                    for (int j = -1; j < 2; j++)
                                    {
                                        n[count++] = img[c][h + j][w + i];
                                    }
                                }
                                omg[c][h][w] = Mid(n);
                            }
                            else if (w == W - 1)
                            {
                                float[] n     = new float[6];
                                int     count = 0;
                                for (int i = -1; i < 1; i++)
                                {
                                    for (int j = -1; j < 2; j++)
                                    {
                                        n[count++] = img[c][h + j][w + i];
                                    }
                                }
                                omg[c][h][w] = Mid(n);
                            }
                            else
                            {
                                float[] n     = new float[9];
                                int     count = 0;
                                for (int i = -1; i < 2; i++)
                                {
                                    for (int j = -1; j < 2; j++)
                                    {
                                        n[count++] = img[c][h + j][w + i];
                                    }
                                }
                                omg[c][h][w] = Mid(n);
                            }
                        }
                    }
                }
            }

            if (spawn)
            {
                x.CreateSibling(omg, "Median filter of " + ((FormStandard)x).GetBitmap().ToString());
            }
            else
            {
                ((FormStandard)x).Image = Normalize.FromFloat(omg);
            }
        }