原文: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;

}

}

[图像效果]


最新文章

  1. transition
  2. mybatis:Invalid bound statement (not found)
  3. string、math类、random随机数、datetime、异常保护
  4. python安装requests (win7 &amp; centos7)
  5. vector 释放内存 swap
  6. NServiceBus-日志
  7. eclipse - copy类的全名
  8. BZOJ3394: [Usaco2009 Jan]Best Spot 最佳牧场
  9. Linux -FHS 标准
  10. jQuery之事件移除
  11. 关于celery django django-celery版的搭配的报错问题及解决方法
  12. leetcode之旅(7)-Move Zeroes
  13. python 爬虫之beautifulsoup(bs4)使用 --待完善
  14. 响应消息的内容类型 text/html; charset=utf-8 与绑定(application/soap+xml; charset=utf-8)的内容类型不匹配。
  15. Wannafly挑战赛 22
  16. Django开发笔记二
  17. ASP防止SQL注入
  18. bug提单规范
  19. js将时间戳转换成日期格式-陈远波
  20. Java基础-编写问候语-“Hello World”

热门文章

  1. Android selector背景以及透明色
  2. [HTML5] Focus management using CSS, HTML, and JavaScript
  3. [ES2016] Check if an array contains an item using Array.prototype.includes
  4. iOS9.0 生成证书流程一(非推送)
  5. CentOS使用(一)-----各种环境搭建
  6. Role-based access control modeling and auditing system
  7. 【非常高%】【codeforces 733A】Grasshopper And the String
  8. UVA 1428 - Ping pong(树状数组)
  9. unity3d 学习笔记(三)
  10. 让ProgressDialog在setCancelable(false)时按返回键可dismiss