I have two 2D arrays: $A$ is the original matrix that contains only 0s and 1s, and $B$ is the convolved matrix. I know the size of the convolution kernel $K$. Generally, it follows $B = A*K + S$, where $S$ is the additional noise with Gaussian distribution.
I want to estimate the kernel based on $A$ and $B$, how can I do it in Python?
Here is my example code:
import numpy as np
from scipy.signal import convolve2d,oaconvolve,fftconvolve
the dimension of the original matrix
N = 100
create an example original matrix with around 20% 1s
src_mat = np.random.binomial(n=1, p=0.2, size=(N, N))
a kernel function with a dimension of 2*N-1, the values decay outwards from center of the matrix, as a function of distance (here 1/r)
kernel = np.fromfunction(lambda x,y:np.sqrt((x-(N-1))2+(y-(N-1))2)*(-1) ,(2N -1,2*N-1))
kernel[N-1,N-1] = 0
the convolved matrix in the form of B=A*K+S
tgt_mat = oaconvolve(src_mat,kernel,mode='same') + np.random.normal(0,1,src_mat.shape)
```