Пример #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 ((!Tools.IsPowerOf2(width)) || (!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].Re = (float)*src / 255;
                    }
                    src += offset;
                }
            }

            return(complexImage);
        }
Пример #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);
        }