Win8MetroC#数字图像处理--2.2图像二值化函数
2024-10-02 02:23:06
原文: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;
}
}
最新文章
- 剑指Offer面试题:21.从上到下打印二叉树
- NumberFormat DecimalFormat
- File system needs to be upgraded. You have version null and I want version 7
- 2014 网选 上海赛区 hdu 5047 Sawtooth
- Java学习-数组
- Pro/TOOLKIT入门教程汇总
- 20162323周楠《Java程序设计与数据结构》第五周总结
- 并发库应用之十一 &; 阻塞队列的应用
- tkinter简介(一)
- spring cloud使用Feign做消费端时的eureka.client.registerWithEureka/eureka.client.fetchRegistry是否配置的问题
- C++ 语法--变量和常量
- u3d内嵌H5游戏 设置cookie
- Python生成目录树代码
- 向大家推荐一个在.Net下使用C#语言和Managed DirectX 9开发游戏的视频教程
- ROS知识(9)----NodeHandle命令空间问题
- iOS边练边学--UIScrollView的属性简单使用,代理的简单介绍以及内容缩放
- bootstrap-table教程演示
- Spring Security静态资源访问
- 实战Nginx负载均衡高冗余高可用WEB架构
- 使用vue和web3创建你的第一个以太坊APP
热门文章
- Python 网络爬虫与信息获取(一)—— requests 库的网络爬虫
- js匿名自执行函数
- arm-linux内存管理学习笔记(1)-内存页表的硬件原理
- POJ 1985 - 树的直径
- MapReduce wordcount 输入路径为目录 java.lang.UnsatisfiedLinkError: org.apache.hadoop.io.nativeio.NativeIO$POSIX.stat(Ljava/lang/String;)Lorg/apache/hadoop/io/nativeio/NativeIO$POSIX$Stat;
- hadoop 3.x 集群/单个节点的启动与停止
- word 论文排版 —— 按指定格式章节的自动编号
- Vue中import &#39;@...&#39;是什么
- 【17.76%】【codeforces round 382C】Tennis Championship
- Android Studio:Grade 全局参数定义