public Bitmap ToBitmap()
{
// create new image
Bitmap dstImage = Accord.Imaging.Image.CreateGrayscaleImage(width, height);
// lock destination bitmap data
BitmapData dstData = dstImage.LockBits(
new Rectangle(0, 0, width, height),
ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
int offset = dstData.Stride - width;
double scale = (fourierTransformed) ? Math.Sqrt(width * height) : 1;
// do the job
unsafe
{
byte* dst = (byte*)dstData.Scan0.ToPointer();
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++, dst++)
{
*dst = (byte)System.Math.Max(0, System.Math.Min(255, data[y, x].Magnitude * scale * 255));
}
dst += offset;
}
}
// unlock destination images
dstImage.UnlockBits(dstData);
return dstImage;
}