why it is saying at i have declare kernel
<pre><code>    import numpy as np
    from numpy.fft import fft2, ifft2
    import cv2
    from PIL import Image
    def wiener_filter(img,kernel,K = 10):
        kernel=([3,1],[2,1])
        dummy = np.copy(img)
        kernel = np.pad(kernel, [(0, dummy.shape[0] - kernel.shape[0]), (0, dummy.shape[1] - kernel.shape[1])], 'constant')
        # Fourier Transform
        dummy = fft2(dummy)
        kernel = fft2(kernel)
        kernel = np.conj(kernel) / (np.abs(kernel) ** 2 + K)
        dummy = dummy * kernel
        dummy = np.abs(ifft2(dummy))
        return np.uint8(dummy)

    img = cv2.imread("C:\\Users\\anup\\Desktop\\New folder\\leo.jpg")
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    #gray1 = cv2.cvtColor(gray,cv2.COLOR_GRAY2RGB)
    kernel=([3,1],[2,1])
    fm = wiener_filter(img,kernel)
    cv2.imshow("Image", img)
    key = cv2.waitKey(0)
</code></pre>

<p>I am trying to implement the Wiener Filter to perform deconvolution on blurred image. My implementation is like this</p>

<p>While implementing this i got error</p>

<pre><code>Traceback (most recent call last):
  File "C:\Python27\deblur.py", line 21, in &lt;module&gt;
    fm = wiener_filter(img,kernel)
  File "C:\Python27\deblur.py", line 8, in wiener_filter
    kernel = np.pad(kernel, [(0, dummy.shape[0] - kernel.shape[0]), (0, dummy.shape[1] - kernel.shape[1])], 'constant')
AttributeError: 'tuple' object has no attribute 'shape'
</code></pre>

<p>There : </p>

<pre><code>def wiener_filter(img,kernel,K = 10):
    kernel=([3,1],[2,1])
</code></pre>

<p>You define a function that takes <code>kernel</code> as a parameter and you overwrite it directly.</p>

<p>Then you try to use <code>kernel.shape</code> which obviously doesn't exist in <code>([3,1],[2,1])</code></p>

<p>Apparently, <code>shape</code> is a method used for <code>numpy</code> <code>ndarray</code> objects.
So maybe this works for you : </p>

<pre><code>def wiener_filter(img,kernel,K = 10):
    kernel=np.array([[3,1],[2,1]])
</code></pre>

<p>Or as mentionned by @Eric :</p>

<pre><code>def wiener_filter(img,kernel,K = 10):
    kernel=np.array(kernel)
</code></pre>

python numpy