Esempio n. 1
0
        private unsafe void miGaussianBlur_Click(object sender, System.EventArgs e)
        {
            if (this.ActiveCImage == null)
            {
                return;
            }

            CImage cimage = this.ActiveCImage;
            float  scale  = 1f / (float)Math.Sqrt(cimage.Width * cimage.Height);

            ComplexF[] data = cimage.Data;

            Fourier.FFT3(data, cimage.Width, cimage.Height, 1, FourierDirection.Forward);

            for (int i = 0; i < data.Length; i++)
            {
                data[i] *= scale;
            }

            Fourier.FFT3(data, cimage.Width, cimage.Height, 1, FourierDirection.Backward);

            for (int i = 0; i < data.Length; i++)
            {
                data[i] *= scale;
            }

            cimage.FrequencySpace = true;

            this.ActiveCImage = cimage;
        }
Esempio n. 2
0
		private static ComplexF[] GetImageFFTArray(Bitmap bitmap) {
			float scale = 1F / (float) System.Math.Sqrt(bitmap.Width * bitmap.Height);
			ComplexF[] data = new ComplexF [bitmap.Width * bitmap.Height * 4];

			int offset = 0;
			for( int y = 0; y < bitmap.Height; y ++ )
				for( int x = 0; x < bitmap.Width; x ++ ) {
					Color c = bitmap.GetPixel (x, y);
					float s = 1F;
					if( (( x + y ) & 0x1 ) != 0 ) {
						s = -1F;
					}

					data [offset++] = new ComplexF( c.A * s / 256F, 0);
					data [offset++] = new ComplexF( c.R * s / -256F, 0);
					data [offset++] = new ComplexF( c.G * s / 256F, 0);
					data [offset++] = new ComplexF( c.B * s / -256F, 0);
				}
			

			Fourier.FFT3( data, 4, bitmap.Width, bitmap.Height, FourierDirection.Forward );
			
			for( int i = 0; i < data.Length; i ++ ) {
				data[i] *= scale;
			}

			return data;
		}
Esempio n. 3
0
        private static unsafe ComplexF[] GetImageFFTArray(Bitmap bitmap)
        {
            Bitmap squared = MakeSquared(bitmap);
            bool   dispose = (object)squared != (object)bitmap;

            bitmap = squared;

            float scale = 1F / (float)Math.Sqrt(bitmap.Width * bitmap.Height);

            ComplexF [] data        = new ComplexF [bitmap.Width * bitmap.Height];
            Rectangle   rect        = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
            BitmapData  bitmap_data = bitmap.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);

            int *color_data = (int *)bitmap_data.Scan0.ToPointer();

            for (int i = 0; i < bitmap.Width * bitmap.Height; i++)
            {
                Color c = Color.FromArgb(color_data [i]);
                data [i].Re = ((float)c.R + (float)c.G + (float)c.B) / (3f * 256f);
            }
            bitmap.UnlockBits(bitmap_data);

            Fourier.FFT3(data, bitmap.Width, bitmap.Height, 1, FourierDirection.Forward);

            for (int i = 0; i < data.Length; i++)
            {
                data [i] *= scale;
            }

            if (dispose)
            {
                bitmap.Dispose();
            }

            return(data);
        }