public Bitmap ToBitmap()
{
// check if Hough transformation was made already
if (houghMap == null)
throw new InvalidOperationException("Hough transformation was not done yet.");
int width = houghMap.GetLength(1);
int height = houghMap.GetLength(0);
// create new image
Bitmap image = Accord.Imaging.Image.CreateGrayscaleImage(width, height);
// lock destination bitmap data
BitmapData imageData = image.LockBits(
new Rectangle(0, 0, width, height),
ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
int offset = imageData.Stride - width;
float scale = 255.0f / maxMapIntensity;
// do the job
unsafe
{
byte* dst = (byte*)imageData.Scan0.ToPointer();
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++, dst++)
{
*dst = (byte)System.Math.Min(255, (int)(scale * houghMap[y, x]));
}
dst += offset;
}
}
// unlock destination images
image.UnlockBits(imageData);
return image;
}