Win8 Metro(C#)数字图像处理--2.55OSTU法图像二值化
标签:fill mpm eth == ase view win edit return
原文:Win8 Metro(C#)数字图像处理--2.55OSTU法图像二值化
[函数名称]
Ostu法图像二值化 WriteableBitmap OstuThSegment(WriteableBitmap src)
[函数代码]
///
/// Ostu method of image segmention.
///
/// The source image.
///
public static WriteableBitmap OstuThSegment(WriteableBitmap src) ////Ostu法阈值分割
{
if (src != null)
{
int w = src.PixelWidth;
int h = src.PixelHeight;
WriteableBitmap dstImage = new WriteableBitmap(w, h);
byte[] temp = src.PixelBuffer.ToArray();
byte[] tempMask = (byte[])temp.Clone();
//定义灰度图像信息存储变量
int[] srcData = new int[w * h];
//定义阈值变量
int Th = 0; ;
//定义背景和目标像素数目变量N1,N2,灰度变量U1,U2,灰度和变量Sum1,Sum2,临时缓存变量Temp
int N1 = 0, N2 = 0, Sum1 = 0, Sum2 = 0;
//定义背景和目标像素比例变量W1,W2,图像整体平均灰度变量U,方差变量g,对比阈值变量TT
double W1 = 0, W2 = 0, U1 = 0, U2 = 0, g = 0, TT = 0;
for (int j = 0; j T)
{
N2++;
Sum2 += srcData[i];
}
else
{
N1++;
Sum1 += srcData[i];
}
}
W1 = (double)(N1 / (N1 + N2));
W2 = (double)(1.0 - W1);
U1 = (N1 == 0 ? 0.0 : (Sum1 / N1));
U2 = (N2 == 0 ? 0.0 : (Sum2 / N2));
g = N1 * N2 * (U1 - U2) * (U1 - U2);
if (g > TT)
{
TT = g;
Th = T;
}
N1 = 0; N2 = 0;
Sum1 = 0; Sum2 = 0; W1 = 0.0; W2 = 0.0; U1 = 0.0; U2 = 0.0; g = 0.0;
}
for (int j = 0; j
Win8 Metro(C#)数字图像处理--2.55OSTU法图像二值化
标签:fill mpm eth == ase view win edit return
原文地址:https://www.cnblogs.com/lonelyxmas/p/8554531.html
评论