Win8 Metro(C#)数字图像处理--2.56简单统计法图像二值化
2024-08-25 05:52:44
原文:Win8 Metro(C#)数字图像处理--2.56简单统计法图像二值化
[函数名称]
简单统计法图像二值化 WriteableBitmap StatisticalThSegment(WriteableBitmap src)
/// <summary>
/// Statistical method of image segmention.
/// </summary>
/// <param name="src">The source image.</param>
/// <returns></returns>
public static WriteableBitmap StatisticalThSegment(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 eX = 0;
int eY = 0;
int sumEF = 0;
int sumE = 0;
int eMax = 0;
//定义阈值变量
int Th = 0;
for (int j = 0; j < h; j++)
{
for (int i = 0; i < w; i++)
{
srcData[i + j * w] = (int)((double)tempMask[i * 4 + j * w * 4] * 0.114 + (double)tempMask[i * 4 + 1 + j * w * 4] * 0.587 + (double)tempMask[i * 4 + 2 + j * w * 4] * 0.299);
}
}
for (int j = 1; j < h - 1; j++)
{
for (int i = 1; i < w - 1; i++)
{
eX = srcData[i - 1 + j * w] - srcData[i + 1 + j * w];
eY = srcData[i + (j - 1) * w] - srcData[i + (j + 1) * w];
eMax = Math.Max(eX, eY);
sumE += eMax;
sumEF += eMax * srcData[i + j * w];
}
}
Th = (int)(sumEF / sumE);
for (int j = 0; j < h; j++)
{
for (int i = 0; i < w; i++)
{
temp[i * 4 + j * w * 4] = temp[i * 4 + 1 + j * w * 4] = temp[i * 4 + 2 + j * w * 4] = (byte)(srcData[i + j * w] < Th ? 0 : 255);
}
}
Stream sTemp = dstImage.PixelBuffer.AsStream();
sTemp.Seek(0, SeekOrigin.Begin);
sTemp.Write(temp, 0, w * 4 * h);
return dstImage;
}
else
{
return null;
}
}
最新文章
- iOS播放器 - AVAudioPlayer
- 【python】zip()函数
- linux:centos准备及安装
- C# CsvFile 类
- 【转】Java JDBC连接SQL Server2005错误:通过端口 1433 连接到主机 localhost 的 TCP/IP 连接失败
- UVa 575 Skew Binary 歪斜二进制
- 嵌入式 uboot引导kernel,kernel引导fs
- Delphi Variant oleVariant
- HTML案例练习一
- CSS样式总结
- Dancing Stars on Me(判断正多边形)
- BZOJ 1863: [Zjoi2006]trouble 皇帝的烦恼( 二分答案 )
- QT操作Excel(通过QAxObject使用了OLE,前提是本地安装了Excel)
- LINUX编程学习笔记(十三) 遍历目录的两种方法
- python自动化运维二:业务服务监控
- [知了堂学习笔记]_纯JS制作《飞机大战》游戏_第2讲(对象的实现及全局变量的定义)
- Java源码学习:HashMap实现原理
- June 5. 2018 Week 23rd Tuesday
- java异常Exception
- 第一周学习总结-Java
热门文章
- 【iOS】自己定义TabBarController
- php标准库中的优先队列SplPriorityQueue怎么使用?(继承)
- 浏览器jsp、html之间的关系
- Qt 子窗口内嵌到父窗口中
- Hierarchical Tree Traversal in Graphics Pipeline Stages
- 十年磨一剑 Delphi再写传奇(不争辩,不解释,十年坚持不懈的努力)
- C 删除字符串1字符串2
- 常见数据结构与算法的 Python 实现
- HDU1164_Eddy&;#39;s research I【Miller Rabin素数测试】【Pollar Rho整数分解】
- ASP.NET Page执行顺序(ASP.NET生命周期)