code: public static double[] makeGaussianKernel( int radius ) {
          int rows = radius * 2 + 1;
          double r = (double) radius;
          double[] matrix = new double[rows];
          double sigma = r / 3;
          double sigma22 = 2 * sigma * sigma;
          double sigmaPi2 = 2 * Math.PI * sigma;
          double sqrtSigmaPi2 = Math.sqrt(sigmaPi2);
          double radius2 = r * r;
          double total = 0;
          int index = 0;
          for( int row = -radius; row <= radius; row++ ) {
              double distance = row * row;
              if (distance > radius2)
                  matrix[index] = 0;
              else
                  matrix[index] = (double) Math.exp(-(distance) / sigma22) / sqrtSigmaPi2;
              total += matrix[index];
              index++;
          }
          for( int i = 0; i < rows; i++ )
              matrix[i] /= total;
  
          return matrix;
      }
docs: Make a Gaussian blur kernel.