原文: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一维最大熵法图像二值化的更多相关文章

  1. Win8 Metro(C#)数字图像处理--2.59 P分位法图像二值化

    原文:Win8 Metro(C#)数字图像处理--2.59 P分位法图像二值化  [函数名称]   P分位法图像二值化 [算法说明]   所谓P分位法图像分割,就是在知道图像中目标所占的比率Rat ...

  2. Win8 Metro(C#)数字图像处理--2.73一种背景图像融合特效

    原文:Win8 Metro(C#)数字图像处理--2.73一种背景图像融合特效 /// <summary> /// Image merge process. /// </summar ...

  3. Win8 Metro(C#)数字图像处理--2.55OSTU法图像二值化

    原文:Win8 Metro(C#)数字图像处理--2.55OSTU法图像二值化  [函数名称] Ostu法图像二值化      WriteableBitmap OstuThSegment(Writ ...

  4. Win8 Metro(C#)数字图像处理--2.58双峰法图像二值化

    原文:Win8 Metro(C#)数字图像处理--2.58双峰法图像二值化  [函数名称]   双峰法图像二值化 WriteableBitmap  PeakshistogramThSegment( ...

  5. Win8 Metro(C#)数字图像处理--2.64图像高斯滤波算法

    原文:Win8 Metro(C#)数字图像处理--2.64图像高斯滤波算法  [函数名称]   高斯平滑滤波器      GaussFilter(WriteableBitmap src,int r ...

  6. Win8 Metro(C#)数字图像处理--2.53图像傅立叶变换

    原文:Win8 Metro(C#)数字图像处理--2.53图像傅立叶变换  [函数名称] 1,一维FFT变换函数         Complex[] FFT(Complex[] sourceDat ...

  7. Win8 Metro(C#)数字图像处理--2.75灰度图像的形态学算法

    原文:Win8 Metro(C#)数字图像处理--2.75灰度图像的形态学算法 前面章节中介绍了二值图像的形态学算法,这里讲一下灰度图的形态学算法,主要是公式,代码略. 1,膨胀算法 2,腐蚀算法 3 ...

  8. Win8 Metro(C#)数字图像处理--4图像颜色空间描述

    原文:Win8 Metro(C#)数字图像处理--4图像颜色空间描述  图像颜色空间是图像颜色集合的数学表示,本小节将针对几种常见颜色空间做个简单介绍. /// <summary> / ...

  9. Win8 Metro(C#)数字图像处理--3.2图像方差计算

    原文:Win8 Metro(C#)数字图像处理--3.2图像方差计算 /// <summary> /// /// </summary>Variance computing. / ...

随机推荐

  1. Android Gradle Plugin指南(三)——依赖关系、android库和多项目配置

    原文地址:http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Dependencies-Android-Librari ...

  2. [Vue] Parent and Child component communcation

    By building components, you can extend basic HTML elements and reuse encapsulated code. Most options ...

  3. 让Apache 和nginx支持跨域訪问

    1,怎样让Apache支持跨域訪问呢? 步骤: 改动httpd.conf,windows中相应的文件夹是:C:\wamp\bin\apache\Apache2.4.4\conf\httpd.conf ...

  4. oracle 内存结构具体解释

    Oracle 内存结构 与 Oracle 实例关联的基本内存结构包含: 系统全局区 (SGA):由全部server和后台进程共享.SGA 中存储的数据演示样例包含快速缓存的数据块和共享 SQL 区域. ...

  5. .net core 下使用StackExchange的Redis库访问超时解决

    原文:.net core 下使用StackExchange的Redis库访问超时解决 目录 问题:并发稍微多的情况下Redis偶尔返回超时 给出了参考网址? 结论 小备注 引用链接 问题:并发稍微多的 ...

  6. matplotlib tricks(一)—— 多类别数据的 scatter(cmap)

    cmap 的选择: binary seismic Reds 多类别数据的 scatter(逐点散列),在 matplotlib 中的实现关键在于,color关键字的定义: def plot_scatt ...

  7. java-线程-ABCABC

    public class OneByOne { private Lock lock = new ReentrantLock(); private Condition conditionA = lock ...

  8. WPF 使用鼠标拖动一个控件的实现[2018.7.15]

    原文:WPF 使用鼠标拖动一个控件的实现[2018.7.15] Q:已经把一个Shape和一个TextBlock组合起来放到了一个Grid中,现在想要实现用鼠标拖动这个Grid到任意位置的功能,如何做 ...

  9. C#生成二维码,把二维码图片放入Excel中

    /// <summary> /// 把图片保存到excel中 /// </summary> /// <param name="excelFilePath&quo ...

  10. js声明json数据,打印json数据,遍历json数据,转换json数据为数组

    1.js声明json数据: 2.打印json数据: 3.遍历json数据: 4.转换json数据为数组; //声明JSON var json = {}; json.a = 1; //第一种赋值方式(仿 ...