I need to create a gaussian kernel, this is the formula:
This is what I've tried, but it returns a black picture.
import matplotlib
import numpy as np
from matplotlib import pyplot as plt, colors
def gaussian_kernel(row, col, mean_v=0, std_v=None, mean_h=0, std_h=None):
if std_v is None:
std_v = (row) / 2
if std_h is None:
std_h = (col) / 2
if std_v == 0 or std_h == 0:
raise Exception("std cannot be 0")
M = np.zeros((row, col))
xx = np.array(row)
yy = np.array(col)
x, y = np.meshgrid(xx, yy)
g = (1 / (std_h * std_v * 2 * np.pi)) \
* np.exp(-1 * ((((x - mean_h) ** 2) / (2 * (std_h) ** 2))
+ (((y - mean_v) ** 2) / (2 * (std_v) ** 2))))
M[i, j] = g
return M
g_ker = gaussian_kernel(50, 100, mean_v=-10, std_v=10, mean_h=0, std_h=10)
plt.imshow(g_ker, cmap='gray')
print(g_ker)
plt.show()