I am wondering is there a program defined for 2D circular convolution? If not, I am looking for how to perform it. I did search for it. Could not find anything. So I am wondering does anybody know it. Here is a sample 2D data I have taken
a= np.array([[ -3-3j, 0-10j, +3-3j, +3-3j],
[-10+0j, 0+ 0j, +10+0j, 0-10.8j],
[ -3+3j, 0+10j, +3+3j, 0-10.7j],
[-10+0j, 0+ 0j, +2+0.2j, -1+0j]]);
b = np.array([[ -3-3.2j, 0-10.8j, +3-3j, +3.2+4j],
[-10+0j, 0+ 0j, +2+0.2j, -1+0j],
[ -3+3j, 0+10j, +3+4j, 0+ 0j],
[ -3-3j, 0-10j, +3-3j, +3-3j]]);
I tried c = scipy.signal.convolve2d(a, b, boundary='wrap')
.
It's output is
[[ 166.96 -60.j -66.4 -8.1j -393.4 -37.6j -158.9 -30.1j
166.96 -60.j -66.4 -8.1j -393.4 -37.6j ]
[ -25.84 +35.2j 46.1 +77.1j -23.9 -76.86j -62.66 -35.5j
-25.84 +35.2j 46.1 +77.1j -23.9 -76.86j]
[ 106.64+102.2j 106.66 +70.9j 96. -2.64j 61.56+166.3j
106.64+102.2j 106.66 +70.9j 96. -2.64j]
[ 180. -46.j -15.06-113.16j -271.16 -22.9j -89.44+138.j
180. -46.j -15.06-113.16j -271.16 -22.9j ]
[ 166.96 -60.j -66.4 -8.1j -393.4 -37.6j -158.9 -30.1j
166.96 -60.j -66.4 -8.1j -393.4 -37.6j ]
[ -25.84 +35.2j 46.1 +77.1j -23.9 -76.86j -62.66 -35.5j
-25.84 +35.2j 46.1 +77.1j -23.9 -76.86j]
[ 106.64+102.2j 106.66 +70.9j 96. -2.64j 61.56+166.3j
106.64+102.2j 106.66 +70.9j 96. -2.64j]]
It is giving correct result. But this correct result is only a subset of the above output. i.e. I have extract the first few rows and columns of size as much as the input size. So this way I got the correct output.
[[ 166.96 -60.j -66.4 -8.1j -393.4 -37.6j -158.9 -30.1j ]
[ -25.84 +35.2j 46.1 +77.1j -23.9 -76.86j -62.66 -35.5j ]
[ 106.64+102.2j 106.66 +70.9j 96. -2.64j 61.56+166.3j ]
[ 180. -46.j -15.06-113.16j -271.16 -22.9j -89.44+138.j ]]
I tried spicy.fft.fftshift
with using mode='same'
in spicy.fft.convolve2D
but it is not giving correct output.
I am looking for either a built in function
or normal code