Accord.Imaging.ComplexImage.FromBitmap C# (CSharp) Method

FromBitmap() public static method

Create complex image from grayscale bitmap.
The source image has incorrect pixel format. Image width and height should be power of 2.
public static FromBitmap ( BitmapData imageData ) : ComplexImage
imageData System.Drawing.Imaging.BitmapData Source image data (8 bpp indexed).
return ComplexImage
        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;
        }

Same methods

ComplexImage::FromBitmap ( Bitmap image ) : ComplexImage