原文:Win8MetroC#数字图像处理--2.2图像二值化函数

[函数代码]

        /// <summary>
/// Binary process.
/// </summary>
/// <param name="src">Source image.</param>
/// <param name="threshould">Define a threshould value for binary processing, from 0 to 255.</param>
/// <returns></returns>
public static WriteableBitmap BinaryProcess(WriteableBitmap src, int threshould)////2 二值化处理
{
if(src!=null )
{
int w = src.PixelWidth;
int h = src.PixelHeight;
WriteableBitmap binaryImage = new WriteableBitmap(w,h);
byte[] temp = src.PixelBuffer.ToArray();
for (int i = 0; i < temp.Length; i += 4)
{
byte tempByte = (byte)(((temp[i] + temp[i + 1] + temp[i + 2]) / 3) < threshould ? 0 : 255);
temp[i] = tempByte;
temp[i + 1] = tempByte;
temp[i + 2] = tempByte;
}
Stream sTemp = binaryImage.PixelBuffer.AsStream();
sTemp.Seek(0, SeekOrigin.Begin);
sTemp.Write(temp, 0, w * 4 * h);
return binaryImage;
}
else
{
return null;
}
}

最新文章

  1. 剑指Offer面试题:21.从上到下打印二叉树
  2. NumberFormat DecimalFormat
  3. File system needs to be upgraded. You have version null and I want version 7
  4. 2014 网选 上海赛区 hdu 5047 Sawtooth
  5. Java学习-数组
  6. Pro/TOOLKIT入门教程汇总
  7. 20162323周楠《Java程序设计与数据结构》第五周总结
  8. 并发库应用之十一 &amp; 阻塞队列的应用
  9. tkinter简介(一)
  10. spring cloud使用Feign做消费端时的eureka.client.registerWithEureka/eureka.client.fetchRegistry是否配置的问题
  11. C++ 语法--变量和常量
  12. u3d内嵌H5游戏 设置cookie
  13. Python生成目录树代码
  14. 向大家推荐一个在.Net下使用C#语言和Managed DirectX 9开发游戏的视频教程
  15. ROS知识(9)----NodeHandle命令空间问题
  16. iOS边练边学--UIScrollView的属性简单使用,代理的简单介绍以及内容缩放
  17. bootstrap-table教程演示
  18. Spring Security静态资源访问
  19. 实战Nginx负载均衡高冗余高可用WEB架构
  20. 使用vue和web3创建你的第一个以太坊APP

热门文章

  1. Python 网络爬虫与信息获取(一)—— requests 库的网络爬虫
  2. js匿名自执行函数
  3. arm-linux内存管理学习笔记(1)-内存页表的硬件原理
  4. POJ 1985 - 树的直径
  5. MapReduce wordcount 输入路径为目录 java.lang.UnsatisfiedLinkError: org.apache.hadoop.io.nativeio.NativeIO$POSIX.stat(Ljava/lang/String;)Lorg/apache/hadoop/io/nativeio/NativeIO$POSIX$Stat;
  6. hadoop 3.x 集群/单个节点的启动与停止
  7. word 论文排版 —— 按指定格式章节的自动编号
  8. Vue中import &#39;@...&#39;是什么
  9. 【17.76%】【codeforces round 382C】Tennis Championship
  10. Android Studio:Grade 全局参数定义