Last active
August 29, 2015 14:13
-
-
Save larsberg/32dd5562fb0474bb7bd3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1D gaussian kernel | |
// pretty much ripped from here: http://www.apileofgrains.nl/blur-filters-c/ | |
vector<float> gaussianKernel( int radius, float weight = 1.) | |
{ | |
int mem_amount = (radius*2)+1; | |
vector<float> kernel( (radius*2) + 1 ); | |
float twoRadiusSquaredRecip = 1.0 / (2.0 * radius * radius); | |
float sqrtTwoPiTimesRadiusRecip = 1.0 / (sqrt(2.0 * PI) * radius); | |
// Create Gaussian Kernel | |
int r = -radius; | |
float sum = 0, x, v; | |
for (int i = 0; i < kernel.size(); i++) | |
{ | |
v = sqrtTwoPiTimesRadiusRecip * exp(-pow(r * weight, 2) * twoRadiusSquaredRecip); | |
kernel[i] = v; | |
sum+=v; | |
r++; | |
} | |
// normalize | |
for (auto& k: kernel) k /= sum; | |
return kernel; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment