Win8 Metro(C#)数字图像处理--2.57一维最大熵法图像二值化
原文:Win8 Metro(C#)数字图像处理--2.57一维最大熵法图像二值化
[函数名称]
一维最大熵法图像二值化WriteableBitmap EntropymaxThSegment(WriteableBitmap src)
[算法说明]
一维最大熵法图像分割就是利用图像的灰度分布密度函数定义图像的信息熵,通过优化一定的熵
准则得到熵最大时对应的阈值,从而进行图像分割的方法。
算法过程:
1,对于一幅灰度图像,灰度范围为[0,L-1],求取图像的最小灰度级min,最大灰度级max;
[函数代码]
/// <summary>
/// Entropy max method of image segmention.
/// </summary>
/// <param name="src">The source iamge.</param>
/// <returns></returns>
public static WriteableBitmap EntropymaxThSegment(WriteableBitmap src) ////一维熵最大法阈值分割
{
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;
//定义直方图存储变量
int[] histogram = new int[256];
//定义熵值变量
double Ht = 0.0;
double Hl = 0.0;
double sigma = 0.0;
//定义灰度最值变量
int max = 0;
int min = 255;
//定义临时变量
double t = 0.0, pt = 0.0, tempMax = 0.0;
int tempV = 0;
for (int j = 0; j < h; j++)
{
for (int i = 0; i < w; i++)
{
tempV = (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);
srcData[i + j * w] = tempV;
histogram[tempV]++;
if (tempV > max)
{
max = tempV;
}
if (tempV < min)
{
min = tempV;
}
}
}
for (int i = min; i < max; i++)
{
t = (double)((double)histogram[i] / (double)(w * h));
if (t > 0.00000001)
{
Hl += -t * Math.Log10(t);
}
else
continue;
}
for (int i = min; i < max; i++)
{
t = (double)((double)histogram[i] / (double)(w * h));
pt += t;
if (t > 0.00000001)
{
Ht += -t * Math.Log10(t);
sigma = Math.Log10(pt * (1 - pt)) * Ht / pt + (Hl - Ht) / (1 - pt);
if (sigma > tempMax)
{
tempMax = (int)sigma;
Th = i;
}
}
else
continue;
}
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;
}
}
Win8 Metro(C#)数字图像处理--2.57一维最大熵法图像二值化的更多相关文章
- Win8 Metro(C#)数字图像处理--2.59 P分位法图像二值化
原文:Win8 Metro(C#)数字图像处理--2.59 P分位法图像二值化 [函数名称] P分位法图像二值化 [算法说明] 所谓P分位法图像分割,就是在知道图像中目标所占的比率Rat ...
- Win8 Metro(C#)数字图像处理--2.73一种背景图像融合特效
原文:Win8 Metro(C#)数字图像处理--2.73一种背景图像融合特效 /// <summary> /// Image merge process. /// </summar ...
- Win8 Metro(C#)数字图像处理--2.55OSTU法图像二值化
原文:Win8 Metro(C#)数字图像处理--2.55OSTU法图像二值化 [函数名称] Ostu法图像二值化 WriteableBitmap OstuThSegment(Writ ...
- Win8 Metro(C#)数字图像处理--2.58双峰法图像二值化
原文:Win8 Metro(C#)数字图像处理--2.58双峰法图像二值化 [函数名称] 双峰法图像二值化 WriteableBitmap PeakshistogramThSegment( ...
- Win8 Metro(C#)数字图像处理--2.64图像高斯滤波算法
原文:Win8 Metro(C#)数字图像处理--2.64图像高斯滤波算法 [函数名称] 高斯平滑滤波器 GaussFilter(WriteableBitmap src,int r ...
- Win8 Metro(C#)数字图像处理--2.53图像傅立叶变换
原文:Win8 Metro(C#)数字图像处理--2.53图像傅立叶变换 [函数名称] 1,一维FFT变换函数 Complex[] FFT(Complex[] sourceDat ...
- Win8 Metro(C#)数字图像处理--2.75灰度图像的形态学算法
原文:Win8 Metro(C#)数字图像处理--2.75灰度图像的形态学算法 前面章节中介绍了二值图像的形态学算法,这里讲一下灰度图的形态学算法,主要是公式,代码略. 1,膨胀算法 2,腐蚀算法 3 ...
- Win8 Metro(C#)数字图像处理--4图像颜色空间描述
原文:Win8 Metro(C#)数字图像处理--4图像颜色空间描述 图像颜色空间是图像颜色集合的数学表示,本小节将针对几种常见颜色空间做个简单介绍. /// <summary> / ...
- Win8 Metro(C#)数字图像处理--3.2图像方差计算
原文:Win8 Metro(C#)数字图像处理--3.2图像方差计算 /// <summary> /// /// </summary>Variance computing. / ...
随机推荐
- js如何实现动态在表格中添加标题和去掉标题?
js如何实现动态在表格中添加标题和去掉标题? 一.总结 1.通过table标签的createCaption(),deleteCaption()方法实现. document.getElementById ...
- 切换-5.7-传统复制切换成GTID复制
1.基本环境: Master Slave MySQL版本 MySQL-5.7.16-X86_64 MySQL-5.7.16-X86_64 IP 192.168.56.156 192.168.5 ...
- HDU 5044 Tree(树链剖分)
HDU 5044 Tree field=problem&key=2014+ACM%2FICPC+Asia+Regional+Shanghai+Online&source=1&s ...
- php课程 6-22 字符串格式化函数有哪些(精问)
php课程 6-22 字符串格式化函数有哪些(精问) 一.总结 一句话总结: 1.猜测一下$_GET()怎么来的? 函数赋值给变量的操作:$_YZM=get(); 这样就可以很好的解释哪些全局变量 ...
- javaScript实现简单网页倒计时代码
<div id="button"> <input type="button" value="同意" id="b0 ...
- BZOJ1010玩具装箱 - 斜率优化dp
传送门 题目分析: 设\(f[i]\)表示装前i个玩具的花费. 列出转移方程:\[f[i] = max\{f[j] + ((i - (j + 1)) + sum[i] - sum[j] - L))^2 ...
- Apacheserver自己定义404页面的两种方法以及.htaccess的重要命令总结
Apacheserver自己定义404错误页面有两种方法: 第一种方法最简单,直接在Apache的httpd.conf下进行配置改动命令,改动的内容请參看.htaccess命令写法中的自己定义错误页面 ...
- hadoop 3.x 完全分布式集群搭建/异常处理/测试
共计三台虚拟机分别为hadoop002(master,存放namenode),hadoop003(workers,datanode以及resourcemanage),hadoop004(workers ...
- FreeBSD中的SYSINIT框架【转】
SYSINIT是一个通用的调用排序与分别执行机制的框架.FreeBSD目前使用它来进行内核的动态初始化.SYSINIT使得FreeBSD的内核各子系统可以在内核或模块动态加载链接时被重整.添加.删除. ...
- Optimizing concurrent accesses in a directory-based coherency protocol
In one embodiment, the present invention includes a directory to aid in maintaining control of a cac ...