码迷,mamicode.com
首页 > 其他好文 > 详细

高斯模糊

时间:2018-02-28 23:02:32      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:core   version   ota   image   amp   +=   out   return   img   

  原始图像

  技术分享图片

  处理后

  技术分享图片

  核心源码

  

 1 #version 330 core
 2 out vec4 FragColor;
 3 
4 in vec2 TexCoords; 5 6 uniform sampler2D texture1; 7 uniform float gauss[21]; 8 9 const vec2 texSize = vec2(1000, 800); 10 11 void main() 12 { 13 float xStep, yStep; 14 xStep = 1.0 / 1000.0; 15 vec4 color = vec4(0.0); 16 //X方向 17 for(int i = 1; i < 21; i++) 18 { 19 if(TexCoords.x - xStep * i > 0.0) 20 { 21 color += (texture(texture1, vec2(TexCoords.x - xStep * i, TexCoords.y)) * gauss[i]) ; 22 } 23 24 if(TexCoords.x + xStep * i < 1.0) 25 { 26 color += (texture(texture1, vec2(TexCoords.x + xStep * i, TexCoords.y)) * gauss[i]); 27 } 28 } 29 FragColor = color; 30 }
 1 float g_GaussNum[21];
 2 float gauss(int x)
 3 {
 4     float pi = 3.1415927f;
 5     float e = 2.71828f;
 6     float theta = 0.1f;
 7     float theta2 = theta * theta;
 8     float temp1 = 1.0f / (theta * sqrt(2 * pi));
 9     float temp2 = pow(e, -(x * x) / 2 * theta2);
10     return temp1 * temp2;
11 }
12 
13 void calculateGauss()
14 {
15     g_GaussNum[0] = 1.0f;
16 
17     for (int i = 1; i < sizeof(g_GaussNum) / sizeof(g_GaussNum[0]); i++) {
18         g_GaussNum[i] = gauss(i);
19     }
20 
21     float total = 0.0f;
22     for (int i = 0; i < sizeof(g_GaussNum) / sizeof(g_GaussNum[0]); i++) {
23         total += g_GaussNum[i];
24     }
25 
26     for (int i = 0; i < sizeof(g_GaussNum) / sizeof(g_GaussNum[0]); i++) {
27         g_GaussNum[i] = g_GaussNum[i] / total;
28     }
29 }

 

高斯模糊

标签:core   version   ota   image   amp   +=   out   return   img   

原文地址:https://www.cnblogs.com/TooManyWayToBe/p/8485927.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!