WPF:图像处理(三)二值化(2)
来源:未知 责任编辑:责任编辑 发表时间:2014-05-20 18:33 点击:次
else
threshold = IterativeThreshold(GrayArray);
// 根据阈值进行二值化 www.2cto.com
Int32 PixelHeight = bitmap.PixelHeight;
Int32 PixelWidth = bitmap.PixelWidth;
Byte[,] BinaryArray = new Byte[PixelHeight, PixelWidth];
for (Int32 i = 0; i < PixelHeight; i++)
{
for (Int32 j = 0; j < PixelWidth; j++)
{
BinaryArray[i,j] = Convert.ToByte((GrayArray[i,j] > threshold) ? 255 : 0);
}
}
return BinaryArray;
}
/// <summary>
/// 全局阈值图像二值化
/// </summary>
/// <param name="bitmap">原始图像</param>
/// <param name="method">二值化方法</param>
/// <param name="threshold">输出:全局阈值</param>
/// <returns>二值化图像</returns>
public static BitmapSource ToBinaryBitmap(this BitmapSource bitmap, BinarizationMethods method, out Int32 threshold)
{ // 位图转换为灰度数组
Byte[,] GrayArray = bitmap.ToGrayArray();
// 计算全局阈值
if (method == BinarizationMethods.Otsu)
threshold = OtsuThreshold(GrayArray);
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>