0
$\begingroup$

I want to make a 2D gaussian Blur coeffients. Now I am making 1D gaussian Blur term as following.

double Cmfc_test5Dlg::Guassian(int x, double sigma)
{
        double c = 2.0 * sigma * sigma;
        return exp(-x * x / c) / sqrt(c * 3.141592f);
}
double Cmfc_test5Dlg::GuassianTerms(int kernalSize, double sigma, int *terms)
{
        for (int i = 0; i < kernalSize; ++i) {
                terms[i] = Guassian(i - kernalSize / 2, sigma)*1024;
        }
        return 1;
}

But I want to make 2D instead of 1D. What should I do ?

$\endgroup$
0
$\begingroup$

It's real easy. Multi-dimensional Gaussian functions are separable, that is they can be calculated as the product of the Gaussian function along all axes. For the 2-d case it means:

terms[x, y] = terms[x]*terms[y]

Note that separability also means that you obtain the same result as by using the 2-d filter, by first 1-d filtering along one axis and then 1-d filtering the output along the other axis.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.