コード例 #1
0
        public static Tuple <Image, Image, Complex[, ]> CalculateFFT(Image source)
        {
            Bitmap       resultAmplitude       = new Bitmap(source);
            Bitmap       result                = new Bitmap(source);
            FasterBitmap fasterBitmapSrc       = new FasterBitmap(source as Bitmap);
            FasterBitmap fasterBitmapAmplitude = new FasterBitmap(resultAmplitude);
            FasterBitmap fasterBitmapResult    = new FasterBitmap(result);

            fasterBitmapAmplitude.LockBits();
            fasterBitmapSrc.LockBits();
            fasterBitmapResult.LockBits();

            Complex[,] original = new Complex[source.Width, source.Height];

            for (int x = 0; x < source.Width; x++)
            {
                for (int y = 0; y < source.Height; y++)
                {
                    original[x, y] = fasterBitmapSrc.GetPixel(x, y).R;
                }
            }

            Complex[,] fourier = fft2(original);
            fourier            = ShiftComplex(fourier);
            double[,] modulus  = new double[fourier.GetLength(0), fourier.GetLength(1)];

            for (int x = 0; x < fourier.GetLength(0); x++)
            {
                for (int y = 0; y < fourier.GetLength(1); y++)
                {
                    modulus[x, y] = Modulus(fourier[x, y].Real, fourier[x, y].Imaginary);
                }
            }

            double[,] amplitude = Normalize(modulus, source.Width, source.Height);

            for (int x = 0; x < source.Width; x++)
            {
                for (int y = 0; y < source.Height; y++)
                {
                    byte color = Convert.ToByte(amplitude[x, y]);
                    fasterBitmapAmplitude.SetPixel(x, y, Color.FromArgb(color, color, color));
                }
            }



            Complex[,] fourierTAB = new Complex[fourier.GetLength(0), fourier.GetLength(1)];
            fourierTAB            = fourier;


            fasterBitmapAmplitude.UnlockBits();
            fasterBitmapSrc.UnlockBits();
            fasterBitmapResult.UnlockBits();
            return(new Tuple <Image, Image, Complex[, ]>(resultAmplitude, null, fourierTAB));
        }
コード例 #2
0
ファイル: Histogram.cs プロジェクト: AD-7/PrzetwarzanieObrazu
 private Histogram(FasterBitmap bitmap, int channel = 0)
 {
     Values = new int[256];
     for (int i = 0; i < bitmap.Width; i++)
     {
         for (int j = 0; j < bitmap.Height; j++)
         {
             var color = bitmap.GetSingleChannel(i, j, channel);
             Values[color]++;
         }
     }
 }
コード例 #3
0
ファイル: Histogram.cs プロジェクト: AD-7/PrzetwarzanieObrazu
        public static List <Histogram> CreateHistogram(Image image)
        {
            var result       = new Bitmap(image);
            var fasterBitmap = new FasterBitmap(result);
            var list         = new List <Histogram>();

            fasterBitmap.LockBits();

            if (Image.GetPixelFormatSize(image.PixelFormat) == 8)
            {
                list.Add(new Histogram(fasterBitmap, 0));
                fasterBitmap.UnlockBits();
                return(list);
            }

            list.Add(new Histogram(fasterBitmap, 0));
            list.Add(new Histogram(fasterBitmap, 1));
            list.Add(new Histogram(fasterBitmap, 2));
            fasterBitmap.UnlockBits();
            return(list);
        }
コード例 #4
0
        public static Tuple <Image, Image> ApplyFilter(Image source, Complex[,] fourierTAB, int filtr, int radius, int radius2, int K, int L, double angle, double phiOffset)
        {
            Bitmap       result             = new Bitmap(source);
            Bitmap       resultMask         = new Bitmap(source);
            FasterBitmap fasterBitmapResult = new FasterBitmap(result);
            FasterBitmap fasterBitmapMask   = new FasterBitmap(resultMask);

            fasterBitmapResult.LockBits();
            fasterBitmapMask.LockBits();
            double[,] modulus = new double[fourierTAB.GetLength(0), fourierTAB.GetLength(1)];

            switch (filtr)
            {
            case 0:
                fourierTAB = LowpassFilter(fourierTAB, radius);
                break;

            case 1: fourierTAB = HighpassFilter(fourierTAB, radius); break;

            case 2: fourierTAB = BandWithFilter(fourierTAB, radius, radius2); break;

            case 3: fourierTAB = BandPassFilter(fourierTAB, radius, radius2); break;

            case 4: fourierTAB = EdgeDetection.createEdgeDetectionFilter(fourierTAB, fourierTAB.GetLength(0), fourierTAB.GetLength(1), angle, phiOffset, radius); break;

            case 5: fourierTAB = ModifyFourierPnm(fourierTAB, K, L); break;
            }


            //

            for (int x = 0; x < fourierTAB.GetLength(0); x++)
            {
                for (int y = 0; y < fourierTAB.GetLength(1); y++)
                {
                    modulus[x, y] = Modulus(fourierTAB[x, y].Real, fourierTAB[x, y].Imaginary);
                }
            }
            modulus = Normalize(modulus, modulus.GetLength(0), modulus.GetLength(1));

            for (int x = 0; x < source.Width; x++)
            {
                for (int y = 0; y < source.Height; y++)
                {
                    byte color = Convert.ToByte(modulus[x, y]);
                    fasterBitmapMask.SetPixel(x, y, Color.FromArgb(color, color, color));
                }
            }


            fourierTAB = ShiftComplex(fourierTAB);
            fourierTAB = ifft2(fourierTAB);


            for (int x = 0; x < fourierTAB.GetLength(0); x++)
            {
                for (int y = 0; y < fourierTAB.GetLength(1); y++)
                {
                    modulus[x, y] = Modulus(fourierTAB[x, y].Real, fourierTAB[x, y].Imaginary);
                }
            }


            for (int x = 0; x < source.Width; x++)
            {
                for (int y = 0; y < source.Height; y++)
                {
                    if (modulus[x, y] > 254)
                    {
                        modulus[x, y] = 255;
                    }
                    if (modulus[x, y] < 0)
                    {
                        modulus[x, y] = 0;
                    }
                    byte color = Convert.ToByte(modulus[x, y]);
                    fasterBitmapResult.SetPixel(x, y, Color.FromArgb(color, color, color));
                }
            }
            fasterBitmapResult.UnlockBits();
            fasterBitmapMask.UnlockBits();
            return(new Tuple <Image, Image>(result, resultMask));
        }