示例#1
0
        public static ComplexImage FromImage(Image image)
        {
            ComplexImage cimg = new ComplexImage();

            cimg.Create(image.Width, image.Height, image.Bitmap.Palette);
            cimg.data = new Complex[image.Height, image.Width];

            image.OpenData(System.Drawing.Imaging.ImageLockMode.ReadOnly, false);

            for (int y = 0; y < cimg.Height; y++)
            {
                for (int x = 0; x < cimg.Width; x++)
                {
                    cimg.data[y, x].Re = (double)image.GetPixel(x) / 255.0;
                }

                image.IncLine();
            }

            image.CloseData();

            for (int y = 0; y < cimg.Height; y++)
            {
                for (int x = 0; x < cimg.Width; x++)
                {
                    if (((x + y) & 0x1) != 0)
                    {
                        cimg.data[y, x].Re *= -1.0;
                        cimg.data[y, x].Im *= -1.0;
                    }
                }
            }

            cimg.DFT2(false);

            cimg.OpenData(System.Drawing.Imaging.ImageLockMode.WriteOnly, false);

            double scale = Math.Sqrt(cimg.Width * cimg.Height);

            for (int y = 0; y < cimg.Height; y++)
            {
                for (int x = 0; x < cimg.Width; x++)
                {
                    cimg.SetPixel(x, (byte)Math.Max(Math.Min(cimg.data[y, x].Magnitude * scale * 255.0, 255.0), 0.0));
                }

                cimg.IncLine();
            }

            cimg.CloseData();

            return(cimg);
        }
示例#2
0
        public static ComplexImage FromImage(Image image)
        {
            ComplexImage cimg = new ComplexImage();
            cimg.Create(image.Width, image.Height, image.Bitmap.Palette);
            cimg.data = new Complex[image.Height, image.Width];

            image.OpenData(System.Drawing.Imaging.ImageLockMode.ReadOnly, false);

            for (int y = 0; y < cimg.Height; y++)
            {
                for (int x = 0; x < cimg.Width; x++)
                    cimg.data[y, x].Re = (double)image.GetPixel(x) / 255.0;

                image.IncLine();
            }

            image.CloseData();

            for (int y = 0; y < cimg.Height; y++)
            {
                for (int x = 0; x < cimg.Width; x++)
                {
                    if (((x + y) & 0x1) != 0)
                    {
                        cimg.data[y, x].Re *= -1.0;
                        cimg.data[y, x].Im *= -1.0;
                    }
                }
            }

            cimg.DFT2(false);

            cimg.OpenData(System.Drawing.Imaging.ImageLockMode.WriteOnly, false);

            double scale = Math.Sqrt(cimg.Width * cimg.Height);

            for (int y = 0; y < cimg.Height; y++)
            {
                for (int x = 0; x < cimg.Width; x++)
                    cimg.SetPixel(x, (byte)Math.Max(Math.Min(cimg.data[y, x].Magnitude * scale * 255.0, 255.0), 0.0));

                cimg.IncLine();
            }

            cimg.CloseData();

            return cimg;
        }