All problems
Laplacian of Gaussian Kernel
Problem
Generate a zero-mean Laplacian of Gaussian (LoG) kernel.
For each offset d = (i - c)^2 + (j - c)^2 with c = size // 2, compute -1 / (pi * sigma^4) * (1 - d / (2 * sigma^2)) * exp(-d / (2 * sigma^2)), then subtract the kernel mean so all entries sum to 0. Round each entry to 6 decimal places; size is odd.
Hint
Compute the raw LoG values, then subtract their mean to force a zero sum.
Test cases
case 1
in: [3,1]
expected: [[0.078271,-0.018261,0.078271],[-0.018261,-0.240039,-0.018261],[0.078271,-0.018261,0.078271]]
case 2
in: [5,1]
expected: [[0.023435,0.045138,0.049023,0.045138,0.023435],[0.045138,0.005945,-0.090587,0.005945,0.045138],[0.049023,-0.090587,-0.312365,-0.090587,0.049023],[0.045138,0.00…
case 3
in: [1,1]
expected: [[0]]
case 4
in: [3,0.5]
expected: [[0.415016,0.82443,0.415016],[0.82443,-4.957785,0.82443],[0.415016,0.82443,0.415016]]
Starter codePython
def log_kernel(size, sigma):
# Your code here
pass4 test cases · run your code against them in the editor