code: public double[][] Kernel2D(int size) {
          if (((size % 2) == 0) || (size < 3) || (size > 101)) {
              try {
                  throw new Exception("Wrong size");
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
  
          int r = size / 2;
          double[][] kernel = new double[size][size];
  
          // compute kernel
          double sum = 0;
          for (int y = -r, i = 0; i < size; y++, i++) {
              for (int x = -r, j = 0; j < size; x++, j++) {
                  kernel[i][j] = Function2D(x, y);
                  sum += kernel[i][j];
              }
          }
  
          for (int i = 0; i < kernel.length; i++) {
              for (int j = 0; j < kernel[0].length; j++) {
                  kernel[i][j] /= sum;
              }
          }
  
          return kernel;
      }
docs: 2-D Gaussian kernel.
  
  @param size Kernel size (should be odd), [3, 101].
  @return Returns 2-D Gaussian kernel of specified size.