Win8Metro(C#)数字图像处理--2.8图像线性变换
原文:Win8Metro(C#)数字图像处理--2.8图像线性变换
2.8图像线性变换
[函数名称]
图像线性变换函数LinearTransformProcess(WriteableBitmap
src, double k,int
v)
[函数代码]
///<summary>
///
Linear transform process(f=kf+v).
///</summary>
///<param
name="src">Source image.</param>
///<param
name="k">Parameter,from 0 to 5.</param>
///<param
name="v">Parameter,from -128 to 128.</param>
///<returns></returns>
publicstaticWriteableBitmap
LinearTransformProcess(WriteableBitmap src,double
k,int v)////8线性变换处理
{
if(src!=null
)
{
int
w = src.PixelWidth;
int
h = src.PixelHeight;
WriteableBitmap
linearImage =newWriteableBitmap(w,h);
byte[]
temp = src.PixelBuffer.ToArray();
for
(int i = 0; i < temp.Length; i +=4)
{
temp[i] = (byte)(((k
* temp[i] + v + 0.5) > 255 ? 255 : (k * temp[i] + v + 0.5)) < 0 ? 0 : ((k * temp[i] + v + 0.5) > 255 ? 255 : (k * temp[i] + v + 0.5)));
temp[i+1] = (byte)(((k
* temp[i+1] + v + 0.5) > 255 ? 255 : (k * temp[i+1] + v + 0.5)) < 0 ? 0 : ((k * temp[i+1] + v + 0.5) > 255 ? 255 : (k * temp[i+1] + v + 0.5)));
temp[i+2] = (byte)(((k
* temp[i+2] + v + 0.5) > 255 ? 255 : (k * temp[i+2] + v + 0.5)) < 0 ? 0 : ((k * temp[i+2] + v + 0.5) > 255 ? 255 : (k * temp[i+2] + v + 0.5)));
}
Stream
sTemp = linearImage.PixelBuffer.AsStream();
sTemp.Seek(0,SeekOrigin.Begin);
sTemp.Write(temp, 0, w * 4 * h);
return
linearImage;
}
else
{
returnnull;
}
}
[图像效果]
最新文章
- transition
- mybatis:Invalid bound statement (not found)
- string、math类、random随机数、datetime、异常保护
- python安装requests (win7 &; centos7)
- vector 释放内存 swap
- NServiceBus-日志
- eclipse - copy类的全名
- BZOJ3394: [Usaco2009 Jan]Best Spot 最佳牧场
- Linux -FHS 标准
- jQuery之事件移除
- 关于celery django django-celery版的搭配的报错问题及解决方法
- leetcode之旅(7)-Move Zeroes
- python 爬虫之beautifulsoup(bs4)使用 --待完善
- 响应消息的内容类型 text/html; charset=utf-8 与绑定(application/soap+xml; charset=utf-8)的内容类型不匹配。
- Wannafly挑战赛 22
- Django开发笔记二
- ASP防止SQL注入
- bug提单规范
- js将时间戳转换成日期格式-陈远波
- Java基础-编写问候语-“Hello World”
热门文章
- Android selector背景以及透明色
- [HTML5] Focus management using CSS, HTML, and JavaScript
- [ES2016] Check if an array contains an item using Array.prototype.includes
- iOS9.0 生成证书流程一(非推送)
- CentOS使用(一)-----各种环境搭建
- Role-based access control modeling and auditing system
- 【非常高%】【codeforces 733A】Grasshopper And the String
- UVA 1428 - Ping pong(树状数组)
- unity3d 学习笔记(三)
- 让ProgressDialog在setCancelable(false)时按返回键可dismiss