using System
using System
namespace Splash
{
/// <summary>
/// 二值化方法
/// </summary>
public enum BinarizationMethods
{
Otsu
Iterative // 迭代法
}
/// <summary>
/// 圖像處理
/// </summary>
public static partial class Binarize
{
/// <summary>
/// 全局阈值圖像二值化
/// </summary>
/// <param name=
/// <param name=
/// <param name=
/// <returns>二值化後的圖像數組</returns>
public static Byte[
{ // 位圖轉換為灰度數組
Byte[
// 計算全局阈值
if (method == BinarizationMethods
threshold = OtsuThreshold(GrayArray)
else
threshold = IterativeThreshold(GrayArray)
// 根據阈值進行二值化
Int
Int
Byte[
for (Int
{
for (Int
{
BinaryArray[i
}
}
return BinaryArray;
}
/// <summary>
/// 全局阈值圖像二值化
/// </summary>
/// <param name=
/// <param name=
/// <param name=
/// <returns>二值化圖像</returns>
public static BitmapSource ToBinaryBitmap(this BitmapSource bitmap
{ // 位圖轉換為灰度數組
Byte[
// 計算全局阈值
if (method == BinarizationMethods
threshold = OtsuThreshold(GrayArray)
else
threshold = IterativeThreshold(GrayArray)
// 將灰度數組轉換為二值數據
Int
Int
Int
Byte[] Pixels = new Byte[PixelHeight * Stride];
for (Int
{
Int
for (Int
{
if (GrayArray[i
{
Pixels[Base + (j 》
}
}
}
// 從灰度數據中創建灰度圖像
return BitmapSource
}
}
}
From:http://tw.wingwit.com/Article/program/net/201311/13277.html