Link źródłowy to:
http://en.wikipedia.org/wiki/Otsu's_method
http://www.codeproject.com/KB/graphics/OtsuSharp.aspx [kod źródłowy]
ot.Convert2GrayScaleFast(temp);
int otsuThreshold= ot.getOtsuThreshold((Bitmap)temp);
ot.threshold(temp,otsuThreshold);
textBox1.Text = otsuThreshold.ToString();
pictureBox1.Image = temp;
{
byte t=0;
float[] vet=new float[256];
int[] hist=new int[256];
vet.Initialize();
float p1,p2,p12;
int k;
BitmapData bmData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height),
ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
unsafe
{
byte* p = (byte*)(void*)bmData.Scan0.ToPointer();
getHistogram(p,bmp.Width,bmp.Height,bmData.Stride, hist);
for (k = 1; k != 255; k++)
{
p1 = Px(0, k, hist);
p2 = Px(k + 1, 255, hist);
p12 = p1 * p2;
if (p12 == 0)
p12 = 1;
float diff=(Mx(0, k, hist) * p2) - (Mx(k + 1, 255, hist) * p1);
vet[k] = (float)diff * diff / p12;
}
}
bmp.UnlockBits(bmData);
t = (byte)findMax(vet, 256);
return t;
}
W C# pisałem na razie mało.
http://chomikuj.pl/kwgr/Ciekawostki/Ots ... 529825.zip C#
Dzięki za pomoc w przerobieniu funkcji.