Win8 Metro(C#)数字图像处理--2.42图像光照效果算法
原文:Win8 Metro(C#)数字图像处理--2.42图像光照效果算法
[函数名称]
图像光照效果 SunlightProcess(WriteableBitmap src,int X,int Y,float thresould)
[算法说明]
图像光照效果就是在图像中添加上一个太阳光源,以此模仿光照条件。主要算法包括:
1光源选择;2光照像素值求取。
1,光源选择。我们假设光源位置坐标为S(X,Y),其中光源坐标一定要保证在图像大小
范围内。有了光源位置,我们就可以来构建一个圆形区域模拟光照了。我们设定光源半
径为R,那么,光照范围就是以S(X,Y)为圆心,以R为半径的圆了。
根据光源特性,在图像中表现为中间靠近圆心最亮,亮度延半径方向向四周逐渐减弱。
因此,我们根据光源圆形的范围内像素距离圆心的欧几里得距离来构建线性变换的公式,
假设欧几里得距离为D,变换后的像素值为f,则公式如下:
/// <summary>
/// Sun light process.
/// </summary>
/// <param name="src">The source image.</param>
/// <param name="A">X location of light source.</param>
/// <param name="B">Y location of light source.</param>
/// <param name="thresould">Light intensity value.</param>
/// <returns></returns>
public static WriteableBitmap SunlightProcess(WriteableBitmap src,int X,int Y,float thresould)////41图像光照函数
{
if (src != null)
{
int w = src.PixelWidth;
int h = src.PixelHeight;
WriteableBitmap srcImage = new WriteableBitmap(w, h);
byte[] temp = src.PixelBuffer.ToArray();
byte[] tempMask = (byte[])temp.Clone();
double b = 0, g = 0, r = 0;
if (X >= w || Y >= h || X < 0 || Y < 0)
{
X = w / 2;
Y = h / 2;
}
Point Cen = new Point(X, Y);
int R = Math.Min(X, Y);
float curR = 0;
float pixelValue = 0;
for (int j = 0; j < h; j++)
{
for (int i = 0; i < w; i ++)
{
b = tempMask[i * 4 + j * w * 4];
g = tempMask[i * 4 + 1 + j * w * 4];
r = tempMask[i * 4 + 2 + j * w * 4];
curR=(float)Math .Sqrt(Math .Pow((i-Cen .X ),2)+Math .Pow ((j-Cen.Y ),2));
if (curR < R)
{
pixelValue = thresould * (1.0f - curR / R);
b = b + pixelValue;
g = g + pixelValue;
r = r + pixelValue;
temp[i*4 + j * w * 4] = (byte)(b > 0 ? (b < 255 ? b : 255) : 0);
temp[i * 4 + 1 + j * w * 4] = (byte)(g > 0 ? (g < 255 ? g : 255) : 0);
temp[i * 4 + 2 + j * w * 4] = (byte)(r > 0 ? (r < 255 ? r : 255) : 0);
b = 0; g = 0; r = 0;
}
}
}
Stream sTemp = srcImage.PixelBuffer.AsStream();
sTemp.Seek(0, SeekOrigin.Begin);
sTemp.Write(temp, 0, w * 4 * h);
return srcImage;
}
else
{
return null;
}
}
Win8 Metro(C#)数字图像处理--2.42图像光照效果算法的更多相关文章
- Win8 Metro(C#)数字图像处理--2.45图像雾化效果算法
原文:Win8 Metro(C#)数字图像处理--2.45图像雾化效果算法 [函数名称] 图像雾化 AtomizationProcess(WriteableBitmap src,i ...
- Win8 Metro(C#)数字图像处理--3.2图像方差计算
原文:Win8 Metro(C#)数字图像处理--3.2图像方差计算 /// <summary> /// /// </summary>Variance computing. / ...
- Win8 Metro(C#)数字图像处理--3.3图像直方图计算
原文:Win8 Metro(C#)数字图像处理--3.3图像直方图计算 /// <summary> /// Get the array of histrgram. /// </sum ...
- Win8 Metro(C#)数字图像处理--3.4图像信息熵计算
原文:Win8 Metro(C#)数字图像处理--3.4图像信息熵计算 [函数代码] /// <summary> /// Entropy of one image. /// </su ...
- Win8 Metro(C#)数字图像处理--3.5图像形心计算
原文:Win8 Metro(C#)数字图像处理--3.5图像形心计算 /// <summary> /// Get the center of the object in an image. ...
- Win8 Metro(C#)数字图像处理--3.1图像均值计算
原文:Win8 Metro(C#)数字图像处理--3.1图像均值计算 /// <summary> /// Mean value computing. /// </summary> ...
- Win8 Metro(C#)数字图像处理--2.74图像凸包计算
原文:Win8 Metro(C#)数字图像处理--2.74图像凸包计算 /// <summary> /// Convex Hull compute. /// </summary> ...
- Win8 Metro(C#)数字图像处理--2.68图像最小值滤波器
原文:Win8 Metro(C#)数字图像处理--2.68图像最小值滤波器 /// <summary> /// Min value filter. /// </summary> ...
- Win8 Metro(C#)数字图像处理--2.52图像K均值聚类
原文:Win8 Metro(C#)数字图像处理--2.52图像K均值聚类 [函数名称] 图像KMeans聚类 KMeansCluster(WriteableBitmap src,i ...
随机推荐
- 非常实用全面的 C++框架,库类等资源
这次的资源涉及到了标准库.Web应用框架.人工智能.数据库.图片处理.机器学习.日志.代码分析等,C++程序员学习必备! Jason frozen : C/C++的Jason解析生成器 Jansson ...
- Expression Blend 的点滴(1)--ListBox华丽大变身
原文:Expression Blend 的点滴(1)--ListBox华丽大变身 最近,在园子里有不少朋友写了关于Blend的优秀并且实用的文章,在此,我先代表silverlight的爱好者感谢他们的 ...
- fatal error: expat.h: No such file or directory
在CentOS7最小安装版下,编译安装apr-util时报错: fatal error: expat.h: No such file or directory 解决办法:yum install exp ...
- lucene 统计单词次数(词频tf)并进行排序
public class WordCount { static Directory directory; // 创建分词器 static Analyzer analyzer = new IKAnaly ...
- 【39.77%】【codeforces 724B】Batch Sort
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 一个简易版的Function.prototype.bind实现
重新看<JavaScript设计模式与开发实践>一书,第32页发现个简易版的Function.prototype.bind实现,非常容易理解,记录在这了. Function.prototy ...
- JIL 编译与 AOT 编译
JIT:Just-in-time compilation,即时编译:AOT:Ahead-of-time compilation,事前编译. JVM即时编译(JIT) 1. 动态编译与静态编译 动态编译 ...
- 深度神经网络(DNN)
深度神经网络(DNN) 深度神经网络(Deep Neural Networks, 以下简称DNN)是深度学习的基础,而要理解DNN,首先我们要理解DNN模型,下面我们就对DNN的模型与前向传播算法做一 ...
- mysql 权限命令
grant all on *.* to 'root' identified by 'root';
- windows mysql5.7 InnoDB 通过frm与ibd对数据进行恢复
参考:https://www.jianshu.com/p/50a2e13cd5cf 安装MySQL Utilities 下载地址:https://dev.mysql.com/downloads/uti ...