How to create a Gaussian kernel by only specifying its width w (3,5,7,9...), and without specifying its variance sigma?
In other word, how to adapt sigma so that the Gaussian distribution 'fits well' w?
I would be interested in a C++ implementation:
void create_gaussian_kernel(int w, std::vector<std::vector<float>>& kernel)
{
    kernel = std::vector<std::vector<float>>(w, std::vector<float>(w, 0.f)); // 2D array of size w x w 
    const Scalar sigma = 1.0; // how to adapt sigma to w ???
    const int hw = (w-1)/2; // half width
    for(int di = -hw; di <= +hw; ++di)
    {
        const int i = hw + di;
        for(int dj = -hw; dj <= +hw; ++dj)
        {
            const int j = hw + dj;
            kernel[i][j] = gauss2D(di, dj, sigma);
        }
    } 
}
Everything I see on the Internet use a fixed size w and a fixed variance sigma :