Exemple #1
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());
        }
Exemple #2
0
        public static void Notch(IOperand x, bool spawn = true, float radius1 = 0f, float radius2 = 0f)
        {
            if (x == null)
            {
                return;             // No tolerance!
            }
            //Fourier.CImage[] cimg = ((frmStandard)x).cimg;
            Fourier.CImage[] cimg = new Fourier.CImage[3];
            for (int i = 0; i < 3; i++)
            {
                cimg[i] = new Fourier.CImage(Normalize.ToFloat(((FormStandard)x).Image)[i], ((FormStandard)x).Image.Height, ((FormStandard)x).Image.Width);
            }
            if (!cimg[0].FrequencySpace)
            {
                for (int i = 0; i < 3; i++)
                {
                    cimg[i] = _FFT(cimg[i]);
                }
            }

            int H = cimg[0].Height, W = cimg[0].Width;

            for (int c = 0; c < 3; c++)
            {
                for (int j = 0; j < H; j++)
                {
                    for (int i = 0; i < W; i++)
                    {
                        if ((i - W / 2) * (i - W / 2) + (j - H / 2) * (j - H / 2) < radius2 * radius2 && (i - W / 2) * (i - W / 2) + (j - H / 2) * (j - H / 2) > radius1 * radius1)
                        {
                            cimg[c].Data[j * W + i].Re = 0f;
                            cimg[c].Data[j * W + i].Im = 0f;
                        }
                    }
                }
            }

            // Debug d1 = new Debug(cimg[0].ToBitmap());
            // d1.Show();

            for (int i = 0; i < 3; i++)
            {
                cimg[i] = _IFFT(cimg[i]);
            }

            float[][][] img = new float[3][][];
            for (int i = 0; i < 3; i++)
            {
                img[i] = cimg[i].FromFloatModulus();
            }

            if (spawn)
            {
                x.CreateSibling(img, "Notch filter of " + ((FormStandard)x).GetBitmap().ToString());
            }
            else
            {
                ((FormStandard)x).Image = Normalize.FromFloat(img);
            }
        }
Exemple #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;
            }
        }
Exemple #4
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;
            }
        }
Exemple #5
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);
            }
        }
Exemple #6
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());
        }
Exemple #7
0
        public static void Erode()
        {
            IOperand x = ExecutionStack.X;

            if (x == null)
            {
                return;
            }
            float[][][] img = Erode(x);
            x.CreateSibling(img, "Erosion image of " + ((FormStandard)x).Image.ToString());
        }
Exemple #8
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());
        }
Exemple #9
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());
        }
Exemple #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());
        }
Exemple #11
0
        public static void Close()
        {
            IOperand x = ExecutionStack.X;

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

            float[][][] img = Bin(x);
            img = Dilate(img, bmp.Height, bmp.Width);
            img = Erode(img, bmp.Height, bmp.Width);

            x.CreateSibling(img, "Closing of " + bmp.ToString());
        }
Exemple #12
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);
            }
        }
Exemple #13
0
        public static void Enhance(IOperand X = null, bool spawn = true)
        {
            if (X == null)
            {
                X = ExecutionStack.X;
            }
            if (X == null)
            {
                return;
            }

            Bitmap bmp = ((FormStandard)X).GetBitmap();

            float[][][] img = Normalize.ToFloat(bmp);
            float[][][] hsi = ToHSI(img, bmp.Height, bmp.Width);

            for (int h = 0; h < bmp.Height; h++)
            {
                for (int w = 0; w < bmp.Width; w++)
                {
                    hsi[1][h][w] = (hsi[1][h][w] * 1.10f > 1f ? 1f : hsi[1][h][w] * 1.10f);
                    hsi[2][h][w] = (hsi[2][h][w] * 1.10f > 1f ? 1f : hsi[2][h][w] * 1.10f);
                }
            }

            img = FromHSI(hsi, bmp.Height, bmp.Width);

            if (spawn)
            {
                X.CreateSibling(img, "HSI Color Enhancement of " + bmp.ToString());
            }
            else
            {
                ((FormStandard)X).Image = Normalize.FromFloat(img);
                Fourier.CImage[] cimg = new Fourier.CImage[3];
                for (int i = 0; i < 3; i++)
                {
                    cimg[i] = new Fourier.CImage(img[i], bmp.Height, bmp.Width);
                }
            }
        }
Exemple #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;
         }
     }
 }
Exemple #15
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());
        }
Exemple #16
0
        public static void IFFT(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);

            Fourier.CImage[] cimg = ((FormStandard)X).CImg;//new Fourier.CImage(Normalize.FromFloat(img));

            for (int i = 0; i < 3; i++)
            {
                cimg[i] = _IFFT(cimg[i]);


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

            if (spawn)
            {
                X.CreateSibling(img, "Inverse FFT of " + bmp.ToString());
            }
            else
            {
                ((FormStandard)X).Image = Normalize.FromFloat(img);
                ((FormStandard)X).CImg  = cimg;
            }
        }
Exemple #17
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);
                }
            }
        }
Exemple #18
0
        public static void ButterworthHigh(IOperand x, bool spawn = true, float radius = 0f)
        {
            if (x == null)
            {
                return;             // No tolerance!
            }
            //Fourier.CImage[] cimg = ((frmStandard)x).cimg;
            Fourier.CImage[] cimg = new Fourier.CImage[3];
            for (int i = 0; i < 3; i++)
            {
                cimg[i] = new Fourier.CImage(Normalize.ToFloat(((FormStandard)x).Image)[i], ((FormStandard)x).Image.Height, ((FormStandard)x).Image.Width);
            }
            if (!cimg[0].FrequencySpace)
            {
                for (int i = 0; i < 3; i++)
                {
                    cimg[i] = _FFT(cimg[i]);
                }
            }

            int H = cimg[0].Height, W = cimg[0].Width;

            for (int c = 0; c < 3; c++)
            {
                for (int j = 0; j < H; j++)
                {
                    for (int i = 0; i < W; i++)
                    {
                        int D  = (i - W / 2) * (i - W / 2) + (j - H / 2) * (j - H / 2);
                        int D0 = (int)(radius * radius);
                        if ((i - W / 2) * (i - W / 2) + (j - H / 2) * (j - H / 2) != 0)
                        {
                            cimg[c].Data[j * W + i].Re *= (1.0f - 1.0f / (float)Math.Pow(1.0f + (D / D0), 4));
                            cimg[c].Data[j * W + i].Im *= (1.0f - 1.0f / (float)Math.Pow(1.0f + (D / D0), 4));
                        }
                    }
                }
            }

            // Debug d1 = new Debug(cimg[0].ToBitmap());
            // d1.Show();

            for (int i = 0; i < 3; i++)
            {
                cimg[i] = _IFFT(cimg[i]);
            }

            float[][][] img = new float[3][][];
            for (int i = 0; i < 3; i++)
            {
                img[i] = cimg[i].FromFloatModulus();
            }

            if (spawn)
            {
                x.CreateSibling(img, "Butterworth High Pass filter of " + ((FormStandard)x).GetBitmap().ToString());
            }
            else
            {
                ((FormStandard)x).Image = Normalize.FromFloat(img);
            }
        }
Exemple #19
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);
            }
        }
Exemple #20
0
        public static void HighPass(IOperand x, bool spawn = true, float radius = 0f)
        {
            if (x == null)
            {
                return;             // No tolerance!
            }
            //Fourier.CImage[] cimg = ((frmStandard)x).cimg;
            Fourier.CImage[] cimg = new Fourier.CImage[3];
            for (int i = 0; i < 3; i++)
            {
                cimg[i] = new Fourier.CImage(Normalize.ToFloat(((FormStandard)x).Image)[i], ((FormStandard)x).Image.Height, ((FormStandard)x).Image.Width);
            }
            if (!cimg[0].FrequencySpace)
            {
                for (int i = 0; i < 3; i++)
                {
                    cimg[i] = _FFT(cimg[i]);
                }
            }

            int H = cimg[0].Height, W = cimg[0].Width;

            for (int c = 0; c < 3; c++)
            {
                for (int j = 0; j < H; j++)
                {
                    for (int i = 0; i < W; i++)
                    {
                        if ((i - W / 2) * (i - W / 2) + (j - H / 2) * (j - H / 2) < radius * radius && !((i - W / 2) * (i - W / 2) + (j - H / 2) * (j - H / 2) == 0))
                        {
                            cimg[c].Data[j * W + i].Re = 0f;
                            cimg[c].Data[j * W + i].Im = 0f;
                        }
                    }
                }
            }

            // Debug d1 = new Debug(cimg[0].ToBitmap());
            // d1.Show();

            for (int i = 0; i < 3; i++)
            {
                cimg[i] = _IFFT(cimg[i]);
            }

            float[][][] img = new float[3][][];
            for (int i = 0; i < 3; i++)
            {
                img[i] = cimg[i].FromFloatModulus();
            }

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

            /*
             *
             * float[][][] real = new float[3][][];
             * float[][][] imag = new float[3][][];
             * for (int c = 0; c < 3; c++ )
             * {
             *  real[c] = cimg[c].FromFloatReal();
             *  imag[c] = cimg[c].FromFloatImag();
             * }
             * /*
             * for (int c = 0; c < 3; c++ )
             *  for (int j = 0; j < cimg[0].Height; j++)
             *  {
             *      for (int i = 0; i < cimg[0].Width; i++)
             *      {
             *          if ((i - W / 2) * (i - W / 2) + (j - H / 2) * (j - H / 2) < radius * radius)
             *          {
             *              real[c][j][i] = 0f;
             *              imag[c][j][i] = 0f;
             *
             *          }
             *      }
             *  }
             */
            /*
             * Fourier.CImage[] cr = new Fourier.CImage[3], ci = new Fourier.CImage[3];
             * float[][][] img = new float[3][][];
             * for (int i = 0; i < 3; i++ )
             * {
             * cr[i] = new Fourier.CImage(real[i], H, W);
             * ci[i] = new Fourier.CImage(imag[i], H, W);
             * for (int j=0; j<cr[i].Data.Length; j++)
             * {
             *    cr[i].Data[j].Im = ci[i].Data[j].Re;
             * }
             * cr[i] = _FFT(cr[i]);
             * img[i] = cr[i].FromFloatModulus();
             * }
             */
            //Fourier.CImage ci2 = new Fourier.CImage(Normalize.FromFloat(real), Normalize.FromFloat(imag));

            //ci2 = _IFFT(ci2);

            /*
             * Fourier.CImage ci2 = new Fourier.CImage(Normalize.FromFloat(real), Normalize.FromFloat(imag));
             *
             * Debug w1 = new Debug(ci2.ToBitmap());
             * Debug w2 = new Debug(ci2.Magnitude());
             * Debug w3 = new Debug(Normalize.FromFloat(real));
             * Debug w4 = new Debug(Normalize.FromFloat(real));
             * Debug w5 = new Debug(Normalize.FromFloat(imag));
             *
             * ci2 = _IFFT(ci2);
             *
             * for (int i = 0; i < 3; i++ )
             *  cimg = new Fourier.CImage(cimg.Real(), cimg.Imag());
             * //cimg = _IFFT(cimg);
             * float[][][] img = Normalize.ToFloat(cimg.ToBitmap());
             *
             * Debug w6 = new Debug(ci2.ToBitmap());
             * Debug w7 = new Debug(ci2.Magnitude());
             * Debug w8 = new Debug(ci2.Real());
             *
             * w1.Show();
             * w2.Show();
             * w3.Show();
             * w4.Show();
             * w5.Show();
             * w6.Show();
             * w7.Show();
             * w8.Show();
             *
             *
             * cimg = _IFFT(cimg);
             *
             * Debug w9 = new Debug(cimg.ToBitmap());
             * Debug w10 = new Debug(cimg.Magnitude());
             * Debug w11 = new Debug(cimg.Real());
             *
             * w9.Show();
             * w10.Show();
             * w11.Show();
             */
            //float[][][] img = new float[3][][];
            //for (int i = 0; i < 3; i++)
            //{
            // img[i] = real[i];
            //}
        }