Complex image.

The class is used to keep image represented in complex numbers sutable for Fourier transformations.

Sample usage:

// create complex image ComplexImage complexImage = ComplexImage.FromBitmap( image ); // do forward Fourier transformation complexImage.ForwardFourierTransform( ); // get complex image as bitmat Bitmap fourierImage = complexImage.ToBitmap( );

Initial image:

Fourier image:

Inheritance: ICloneable
Ejemplo n.º 1
0
        /// <summary>
        /// Create complex image from grayscale bitmap.
        /// </summary>
        ///
        /// <param name="imageData">Source image data (8 bpp indexed).</param>
        ///
        /// <returns>Returns an instance of complex image.</returns>
        ///
        /// <exception cref="UnsupportedImageFormatException">The source image has incorrect pixel format.</exception>
        /// <exception cref="InvalidImagePropertiesException">Image width and height should be power of 2.</exception>
        ///
        public static ComplexImage FromBitmap(BitmapData imageData)
        {
            // check image format
            if (imageData.PixelFormat != PixelFormat.Format8bppIndexed)
            {
                throw new UnsupportedImageFormatException("Source image can be graysclae (8bpp indexed) image only.");
            }

            // get source image size
            int width  = imageData.Width;
            int height = imageData.Height;
            int offset = imageData.Stride - width;

            // check image size
            if ((!Accord.Math.Tools.IsPowerOf2(width)) || (!Accord.Math.Tools.IsPowerOf2(height)))
            {
                throw new InvalidImagePropertiesException("Image width and height should be power of 2.");
            }

            // create new complex image
            ComplexImage complexImage = new ComplexImage(width, height);

            Complex[,] data = complexImage.data;

            // do the job
            unsafe
            {
                byte *src = (byte *)imageData.Scan0.ToPointer();

                // for each line
                for (int y = 0; y < height; y++)
                {
                    // for each pixel
                    for (int x = 0; x < width; x++, src++)
                    {
                        data[y, x] = new Complex((float)*src / 255, data[y, x].Imaginary);
                    }

                    src += offset;
                }
            }

            return(complexImage);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Clone the complex image.
        /// </summary>
        ///
        /// <returns>Returns copy of the complex image.</returns>
        ///
        public object Clone()
        {
            // create new complex image
            ComplexImage dstImage = new ComplexImage(width, height);

            Complex[,] data = dstImage.data;

            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    data[i, j] = this.data[i, j];
                }
            }

            // clone mode as well
            dstImage.fourierTransformed = fourierTransformed;

            return(dstImage);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Create complex image from grayscale bitmap.
        /// </summary>
        /// 
        /// <param name="imageData">Source image data (8 bpp indexed).</param>
        /// 
        /// <returns>Returns an instance of complex image.</returns>
        /// 
        /// <exception cref="UnsupportedImageFormatException">The source image has incorrect pixel format.</exception>
        /// <exception cref="InvalidImagePropertiesException">Image width and height should be power of 2.</exception>
        /// 
        public static ComplexImage FromBitmap(BitmapData imageData)
        {
            // check image format
            if (imageData.PixelFormat != PixelFormat.Format8bppIndexed)
            {
                throw new UnsupportedImageFormatException("Source image can be graysclae (8bpp indexed) image only.");
            }

            // get source image size
            int width = imageData.Width;
            int height = imageData.Height;
            int offset = imageData.Stride - width;

            // check image size
            if ((!Accord.Math.Tools.IsPowerOf2(width)) || (!Accord.Math.Tools.IsPowerOf2(height)))
            {
                throw new InvalidImagePropertiesException("Image width and height should be power of 2.");
            }

            // create new complex image
            ComplexImage complexImage = new ComplexImage(width, height);

            Complex[,] data = complexImage.data;

            // do the job
            unsafe
            {
                byte* src = (byte*)imageData.Scan0.ToPointer();

                // for each line
                for (int y = 0; y < height; y++)
                {
                    // for each pixel
                    for (int x = 0; x < width; x++, src++)
                        data[y, x] = new Complex((float)*src / 255, data[y, x].Imaginary);

                    src += offset;
                }
            }

            return complexImage;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Clone the complex image.
        /// </summary>
        /// 
        /// <returns>Returns copy of the complex image.</returns>
        /// 
        public object Clone()
        {
            // create new complex image
            ComplexImage dstImage = new ComplexImage(width, height);
            Complex[,] data = dstImage.data;

            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    data[i, j] = this.data[i, j];
                }
            }

            // clone mode as well
            dstImage.fourierTransformed = fourierTransformed;

            return dstImage;
        }