-2

I am writing a code in python,Opencv for implementing a Gaussian low pass filter on compiling it gives the error 'can't assign to function call' at line 14 which is where I take square root .

`import cv2
import numpy as np
from math import sqrt
img = cv2.imread('polys.jpg',0)
f = np.fft.fft2(img)
fshift = np.fft.fftshift(f)
magnitude_spectrum = 20*np.log(np.abs(fshift))
m, n = img.shape
m2,n2 = m/2 , n/2
d=np.zeros((m,n))
for u in range(m):
for v in range(n):
    r=((u-m2)*(u-m2))+((v-n2)*(v-n2))
    d(u,v)=sqrt(r)
    d(u,v)=int(d(u,v))
    if d(u,v)>10:
       h(u,v)=0
    elif d(u,v)<=10:
       h(u,v)= math.exp(-(d(u,v)*d(u,v))/(2*10*10))

result=h*fshift    
f_ishift = np.fft.ifftshift(result)
img_back = np.fft.ifft2(f_ishift)
img_back = np.abs(img_back)


cv2.imshow('dft',img_back)
cv2.waitKey(0)
cv2.destroyAllWindows()

`

CS Thakur
  • 35
  • 1
  • 2
  • 6
  • 1
    I guess its just a code pasting issue, but I get an indentation error because of the unindented second `for` loop. – cdarke Sep 24 '17 at 08:43

1 Answers1

3

Replace:

d(u, v) = sqrt(r)

With:

d[u, v] = sqrt(r)

d(u, v) expression would throw:

TypeError: 'numpy.ndarray' object is not callable

But before that Python interpreter sees f() = x and throws:

SyntaxError: can't assign to function call

Danil Speransky
  • 29,891
  • 5
  • 68
  • 79