博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Win8Metro(C#)数字图像处理--2.8图像线性变换
阅读量:6916 次
发布时间:2019-06-27

本文共 1294 字,大约阅读时间需要 4 分钟。

原文:



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;

           }  

       }

[图像效果]

你可能感兴趣的文章
机器学习的算法选择
查看>>
java:正则表达式 --转http://blog.csdn.net/yangjiali014/archive/2007/06/19/1658235.aspx
查看>>
猜想:一组勾股数a^2+b^2=c^2中,a,b之一必为4的倍数。
查看>>
RVM 安装与使用帮助
查看>>
django学习笔记(4)
查看>>
Hadoop集群(第3期)_VSFTP安装配置
查看>>
centos7查看系统版本,查看机器位数x86-64
查看>>
Android GIS开发系列-- 入门季(6)GraphicsLayer添加文字与图片标签
查看>>
.Net处理Oracle中Clob类型字段总结
查看>>
当看到某些人月薪十万而觉得郁闷时,看看下面的话
查看>>
五款最佳Linux下载管理器推荐
查看>>
再谈下 Silverlight 跨线程
查看>>
宇瞻U盘出现无法格式化 写保护的完美解决办法 厂家提供的
查看>>
Hadoop概念学习系列之Hadoop的文件系统(十六)
查看>>
C++ 打开exe文件的方法(VS2008)
查看>>
Windows服务安装后自动启动
查看>>
IGT中国
查看>>
Android消息循环分析
查看>>
11. 系统状态管理
查看>>
Java:java+内存分配及变量存储位置的区别
查看>>