Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- double Guassian(int x, double sigma)
- {
- double c = 2.0 * sigma * sigma;
- return Math.Exp(-x * x / c) / Math.Sqrt(c * Math.PI);
- }
- double[] GuassianTerms(int kernalSize, double sigma)
- {
- var terms = new double[kernalSize];
- for (int i = 0; i < kernalSize; ++i) {
- terms[i] = Guassian(i - kernalSize / 2, sigma);
- }
- return terms;
- }
- void Main()
- {
- var terms = GuassianTerms(5, 1);
- var sum = terms.Aggregate((t1, t2) => t1 + t2); // aggregate to normalise result
- Console.WriteLine(String.Join("\r\n", terms.Select(i => (i / sum).ToString("0.00000"))));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement