public Image ThresholdMM(float thresh)
{
Bitmap b = new Bitmap(_image);
BitmapData bData = b.LockBits(new Rectangle(0, 0, _image.Width, _image.Height),ImageLockMode.ReadWrite, b.PixelFormat);
byte bitsPerPixel = GetBitsPerPixel(bData.PixelFormat);
int size=bData.Stride * bData.Height;
byte[] data = new byte[size];
System.Runtime.InteropServices.Marshal.Copy(bData.Scan0, data, 0, size);
for (int i = 0; i < size; i+=bitsPerPixel/8)
{
double magnitude = Math.Sqrt(Math.Pow(data[i], 2) + Math.Pow(data[i + 1], 2) + Math.Pow(data[i + 2], 2));
if (magnitude < thresh)
{
data[i] = 0;
data[i + 1] = 0;
data[i + 2] = 0;
}
else
{
data[i] = 255;
data[i + 1] = 255;
data[i + 2] = 255;
}
}
System.Runtime.InteropServices.Marshal.Copy(data, 0, bData.Scan0, data.Length);
b.UnlockBits(bData);
return b;
}